Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switch to resource name

  • Loading branch information...
commit ae8bb33dcd6ac76766db3352ff974b7436f407fb 1 parent 2a3c092
@Danesh Danesh authored
Showing with 17 additions and 19 deletions.
  1. +5 −5 README
  2. +12 −14 src/com/cyanogenmod/iconpicker/CmPickerActivity.java
View
10 README
@@ -3,13 +3,13 @@ CmIconPicker
How it works :
It captures com.cyanogenmod.ACTION_PICK_ICON and shows the list of icons
-Upon choosing one, it appends
-"image_normal" and "image_activated" as extra's to the return intent.
-Those 2 extra's are bitmaps of the appropriate drawable states.
+
+Upon choosing one, it returns an intent with the following extras :
+"resource_name" - Name of the drawable resource
+"package_name" - Name of the package holding the resource
How to add new images :
-Images must be of format ic_*_normal.png and have a corresponding
-ic_*_activated.png
+Images must be of format ic_*_normal.png and have a corresponding ic_*_activated.png
Just drop a pair into the drawable folders and thats it.
View
26 src/com/cyanogenmod/iconpicker/CmPickerActivity.java
@@ -6,7 +6,6 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
-import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
@@ -29,8 +28,8 @@ public void onCreate(Bundle savedInstanceState) {
public void onItemClick(AdapterView<?> adapterView, View v, int position, long id) {
Intent in = new Intent();
DrawableInfo d = (DrawableInfo) adapterView.getAdapter().getItem(position);
- in.putExtra("image_normal", ((BitmapDrawable)d.draw_normal).getBitmap());
- in.putExtra("image_activated", ((BitmapDrawable)d.draw_activated).getBitmap());
+ in.putExtra("resource_name", d.resource_name);
+ in.putExtra("package_name", getPackageName());
setResult(Activity.RESULT_OK, in);
finish();
}
@@ -50,10 +49,9 @@ public ImageAdapter(Context c) {
int idNorm = getResources().getIdentifier(f.getName(), "drawable", getPackageName());
int idAct = getResources().getIdentifier(f.getName().replaceAll("_normal", "_activated"), "drawable", getPackageName());
if (idNorm != 0 && idAct != 0) {
- Drawable drawNorm = getResources().getDrawable(idNorm);
- Drawable drawAct = getResources().getDrawable(idAct);
- if (drawNorm != null && drawAct != null) {
- mDrawables.add(new DrawableInfo(drawNorm, drawAct));
+ Drawable draw = getResources().getDrawable(idNorm);
+ if (draw != null) {
+ mDrawables.add(new DrawableInfo(draw, f.getName()));
}
}
}
@@ -82,18 +80,18 @@ public View getView(int position, View convertView, ViewGroup parent) {
} else {
imageView = (ImageView) convertView;
}
- imageView.setImageDrawable(((DrawableInfo) getItem(position)).draw_normal);
+ imageView.setImageDrawable(((DrawableInfo) getItem(position)).drawable);
return imageView;
}
}
private class DrawableInfo {
- Drawable draw_normal;
- Drawable draw_activated;
- DrawableInfo(Drawable norm, Drawable act) {
- draw_normal = norm;
- draw_activated = act;
+ Drawable drawable;
+ String resource_name;
+ DrawableInfo(Drawable d, String n) {
+ drawable = d;
+ resource_name = n;
}
}
-}
Please sign in to comment.
Something went wrong with that request. Please try again.