2014年9月24日 星期三

Xcode 6.0.1 / iOS 8 UIAlertController

UIAlertControllerStyleAlert with Buttons

UIAlertController  *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
   
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Cancel Action");
        }];
   
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"Delete"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"Delete Action");
}];

[alertController addAction:cancelAction];
[alertController addAction:deleteAction];

[self presentViewController:alertController animated:YES completion:nil];

2014年9月10日 星期三

iOS set UIImageView to CircleView


- (id)imageViewSetCornerRadius:(UIImageView *)imageView withImage:(UIImage *)image {
    
    imageView.image = image;
    imageView.layer.borderWidth = 3.0f;
    imageView.layer.borderColor = [UIColor whiteColor].CGColor;
    imageView.layer.cornerRadius = imageView.frame.size.width / 2;
    imageView.clipsToBounds = YES;
    
    return imageView;
}

2014年7月13日 星期日

[iOS] Objective-c sharedApplication delegate, global @property



AppDelegate.h

#define appDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])


@property (nonatomic, assign)NSInteger globalCount;


How to use?

2014年7月10日 星期四

[Android] ArrayList save HashMap



ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();

//Save
for(int i=0;i<5;i++) {
        HashMap<String,String> tempMap = new HashMap<String,String>();
        String name = "server"+i;
        String mac = "11:22:33:44:55:6"+i;
        tempMap.put("DEVICE_NAME",name);
        tempMap.put("DEVICE_MAC",mac);
        peripheralScanResultList.add(tempMap);
}

//Get
for(HashMap<String, String> tempMap: peripheralScanResultList) {
        Iterator<String> iterator = tempMap.keySet().iterator();
        while( iterator.hasNext() ){
                String key=(String)iterator.next();
                String value=(String)tempMap.get(key);
                Log.i(TAG, key + ", " +value);
        }
}

[Android] SQLite execSQL, rawQuery

SQLiteDatabase db = dbHelper.getWritableDatabase();

a. Create table

 String INIT_TABLE = "CREATE TABLE IF NOT EXISTS " + tableName + " ("
                                     + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
                                     + field1 + " TEXT, "
                                     + field2 + INTEGER, "
                                     + field3 + VARCHAR );" ;


db.execSQL(INIT_TABLE);

b. Delete table

    try {
          db.execSQL("delete from "+ tableName);
    } catch (SQLException e) {
          Log.e("ERROR", e.toString());
    }
    
    db.close();

2014年6月20日 星期五

[iOS] Objective-c save/load image under APP document

Objective-c save/load image under APP document

Save image: 
   [self saveImageInDocumenet:Image withName:@"blue"];

Load image with name: 
   UIImage *image = [self loadImageFromDocumentWithName:@"blue"];


- (void)saveImageInDocumenet:(UIImage *)image withName:(NSString *)name {
    
    if (image != nil) {
        
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString* path = [documentsDirectory stringByAppendingPathComponent:name];

        NSData* data = UIImagePNGRepresentation(image);
        [data writeToFile:path atomically:YES];

    }
}

[iOS] Objective-c NSString to Hex string

Objective-c NSString to Hex string


NSData *data = [self parseMacAddress:@"AABBCCDDEEFF "];

NSLog(@"After transfer: %@", data); 
= > AABBCCDDEEFF (Hex)