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)

2013年6月14日 星期五

[Android] Bluetooth Chat receive data lost

原先: 
while (true) {
                try {
                    // Read from the InputStream
                    bytes = mmInStream.read(buffer);
                    // Send the obtained bytes to the UI Activity
                    mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, buffer)
                            .sendToTarget();
                } catch (IOException e) {
                    Log.e(TAG, "disconnected", e);
                    connectionLost();
                    // Start the service over to restart listening mode
                    BluetoothChatService.this.start();
                    break;
                }
            }

2013年4月29日 星期一

[Android] remember me checkbox


private CheckBox checkBox;
SharedPreferences login_pref;
private SharedPreferences.Editor loginPrefsEditor;
private Boolean saveLogin;

// onCreate

username = (EditText) findViewById(R.id.editText_username);
password = (EditText) findViewById(R.id.editText_password);
login = (Button) findViewById(R.id.button_login);
checkBox = (CheckBox)findViewById(R.id.checkBox1);
login.setOnClickListener(this);

login_pref = getSharedPreferences("loginPrefs", MODE_PRIVATE);
loginPrefsEditor = login_pref.edit();
saveLogin = login_pref.getBoolean("saveLogin", false);
if (saveLogin == true) {
        username.setText(login_pref.getString("username", ""));
        password.setText(login_pref.getString("password", ""));
        checkBox.setChecked(true);
}

2013年4月25日 星期四

PandaBoard driver install

PandaBoard Driver Install

find sdk\extras\google\usb_driver\android_winusb.inf
open it and
add:

;OMAP-3/4 
%SingleAdbInterface% = USB_Install, USB\VID_18D1&PID_D002&REV_0216 
%CompositeAdbInterface% = USB_Install, USB\VID_0451&PID_D102&MI_01 
%CompositeAdbInterface% = USB_Install, USB\VID_0451&PID_D106&MI_02 
%CompositeAdbInterface% = USB_Install, USB\VID_0451&PID_D107&MI_03 
%SingleAdbInterface% = USB_Install, USB\VID_0451&PID_FFFFE 
%CompositeAdbInterface% = USB_Install, USB\VID_0451&PID_FFFE&MI_01

in [Google.NTx86]


( PandaBoard 硬體識別碼)

設定好之後, 再更新驅動程式 from sdk\extras\google\usb_driver folder
便可以順利安裝