Monday, January 24, 2011

ColorDict Intent API for 3rd party developers

-------------- SEARCH API ---------------------
- You can use PopUp dialog style ColorDict result on your app.
- You can specify FrameLayout LayoutParams for dialog.

public static final String SEARCH_ACTION   = "colordict.intent.action.SEARCH";
public static final String EXTRA_QUERY    = "EXTRA_QUERY";
public static final String EXTRA_FULLSCREEN = "EXTRA_FULLSCREEN";
public static final String EXTRA_HEIGHT   = "EXTRA_HEIGHT";
public static final String EXTRA_WIDTH    = "EXTRA_WIDTH";
public static final String EXTRA_GRAVITY   = "EXTRA_GRAVITY";
public static final String EXTRA_MARGIN_LEFT  = "EXTRA_MARGIN_LEFT";
public static final String EXTRA_MARGIN_TOP   = "EXTRA_MARGIN_TOP";
public static final String EXTRA_MARGIN_BOTTOM  = "EXTRA_MARGIN_BOTTOM";
public static final String EXTRA_MARGIN_RIGHT  = "EXTRA_MARGIN_RIGHT";


Intent intent = new Intent(SEARCH_ACTION);
intent.putExtra(EXTRA_QUERY, "hello"); //Search Query
intent.putExtra(EXTRA_FULLSCREEN, false); //
intent.putExtra(EXTRA_HEIGHT, 400); //400pixel, if you don't specify, fill_parent"
intent.putExtra(EXTRA_GRAVITY, Gravity.BOTTOM);
intent.putExtra(EXTRA_MARGIN_LEFT, 100);
startActivity(intent);


- Check intent before using it

public static boolean isIntentAvailable(Context context, Intent intent) {
 final PackageManager packageManager = context.getPackageManager();
 List list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
 return list.size() > 0; 
}


-------------- PICK API ---------------------

[Constant]
public static final String PICK_RESULT_ACTION  = "colordict.intent.action.PICK_RESULT";

[Code]
Intent intent = new Intent(PICK_RESULT_ACTION);
intent.putExtra(EXTRA_QUERY, "hello"); //Search Query
intent.putExtra(EXTRA_FULLSCREEN, false); //
intent.putExtra(EXTRA_HEIGHT, 400); //400pixel, if you don't specify, fill_parent"
intent.putExtra(EXTRA_GRAVITY, Gravity.BOTTOM);
intent.putExtra(EXTRA_MARGIN_LEFT, 100);
startActivityForResult(intent, 5);


[RESULT]
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 super.onActivityResult(requestCode, resultCode, data);
 if(resultCode == RESULT_OK) {
   Log.d("test", data.getStringExtra(Intent.EXTRA_SUBJECT));
   Log.d("test", data.getStringExtra(Intent.EXTRA_TEXT));
 }
}