Monthly Archives: July 2012

Sharing Facebook Object across multiple activities (Invalid Application ID Error)

I encounter an issue where I tried to handle facebook login/logout in all activities under my tabhost. I have an wrapper for facebook where i handle all my login/logout and posts events. The issue was if I logout from outside of the activity I login from, I will get Invalid Application ID Error and that leads to token not able to reset on the next login.
However I do have a workaround as follow:

Every time I call my wrapper constructor I have the following static softreference for my facebook object.

StaticClass.java

static SoftReference<Facebook>  fb_ref = null;

Facebookwrapper.java

Facebook facebook;
public constructor() {
  if(staticVar.facebook == null){
    facebook = new Facebook(<AppID>);
    fb_ref = new SoftReference<Facebook>(facebook);
  }else{
    facebook = StaticClass.fb_ref;
  }
}
Advertisements

Using Google Drive as private Git

Setting up local git repo
For Ubuntu Users :

  1. Install grive (sudo apt-get install grive)
  2. Create a folder (treat it as google drive root folder)
  3. Enter “grive -a”
  4. Go to the link returned on shell in browser and get the passkey
  5. Enter passkey
  6. DONE!
  7. Enter “git init –bare”
  8. Create another folder outside of your google drive folder (where your project will be)
  9. CD into the folder on step 8
  10. Enter “git init”
  11. Add files into it and perform an initial push (git add <files> -> git commit -m “<message>” -> git push origin <google drive root folder>)
  12. Just enter “grive” in the folder for pushing/pulling new files from the google drive.

For Windows User:

  1. Install  drive.google.com
  2. Install msysgit
  3. Launch msysgit
  4. Create a folder
  5. Open command prompt into the folder created from step 4
  6. Enter “git init –bare”
  7. Create another folder outside of your google drive folder (where your project will be)
  8. CD into the folder on step 7
  9. Enter “git init”
  10. Add files into it and perform an initial push (git add <files> -> git commit -m “<message>” )
  11. Add your master to remote branch (git remote add origin <google drive project folder>)
  12. Now you are ready to push your first commit (git push origin master)

To clone your code in another machine:
For all users:

  1. Install google drive.
  2. Sync all the files from server (command grive for ubuntu users)
  3. Check if you have the correct files uploaded before
  4. CD to folder where you want your project to be on
  5. Enter “git clone <path to your google drive root folder locally> <your new folder name>”
  6. DONE! you can view your committed files in your new folder

Object oriented PHP

to create a class:

class.php

<?php
class testclass{
private static $obj;
function __construc(){
//do your stuff
}
function method1($arg1,$arg2){
//to use the private variable
self::$obj = something;
}
function method2($arg1,$arg2){
//to use local function
self::method1($arg1,$arg2);
}
}
?>

Now the main file:
main.php

<?php
include_once 'class.php';

//Construct
$class_object = new testclass();

//using method from class
$class_object->method1($arg1,$arg2);
?>

Android ListView that has RatingBar

If you are using a ratingbar as indicators to number of stars in a custom listview, the ratingbar will take over the onclick event coming into the list. listview.setonitemclickedlistener() will not work in this case.

To overcome this issue, you just need to set the RatingBar attribute the xml file (android:isIndicator=”true”).

Android create option menu with icon

To put an image/icon on your option menu in Android, simply just set something like the below code in your activity
</pre>
@Override

public boolean onCreateOptionsMenu(Menu menu) {
 menu.add(0, Menu.FIRST, 1, "Export").setIcon(R.drawable.music_playqueue_save_playlist);

return super.onCreateOptionsMenu(menu);

}