View All Icons in android.R.drawable
2009 Oktober 23
Based on an IconViewer I found in the web I desigend this app to show all icons on android.R.drawable. If you need you might change the Class easily.
Icon Viewer App
package de.dailab.iconviewer;
import java.lang.reflect.Field;
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;
public class IconViewer extends Activity {
private int[] IDS;
private int[] getIDS(){
// android.R.drawable.ic_menu_zoom
// 17301504
// 17301655
// android.R.drawable.ic_menu_zoom
int[] ids = new int[800];
for (int i = 0; i < ids.length; i++) {
ids[i]= 17301504+i;
}
return ids;
}
/**
* Determines the Name of a Resource,
* by passing the R.xyz.class and
* the resourceID of the class to it.
* @param aClass : like R.drawable.class
* @param resourceID : like R.drawable.icon
* @throws IllegalArgumentException if field is not found.
* @throws NullPointerException if aClass-Parameter is null.
* <br><br>
* <b>Example-Call:</b><br>
* String resName = getResourceNameFromClassByID(R.drawable.class, R.drawable.icon);<br>
* Then resName would be '<b>icon</b>'.*/
public String getResourceNameFromClassByID(Class<?> aClass, int resourceID)
throws IllegalArgumentException{
/* Get all Fields from the class passed. */
Field[] drawableFields = aClass.getFields();
/* Loop through all Fields. */
for(Field f : drawableFields){
try {
/* All fields within the subclasses of R
* are Integers, so we need no type-check here. */
/* Compare to the resourceID we are searching. */
if (resourceID == f.getInt(null))
return f.getName(); // Return the name.
} catch (Exception e) {
e.printStackTrace();
}
}
/* Throw Exception if nothing was found*/
throw new IllegalArgumentException();
}
private OnClickListener onClicker;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
IDS = getIDS();
requestWindowFeature(Window.FEATURE_NO_TITLE);
onClicker = new OnClickListener(){
@Override
public void onClick(View v) {
myImageView mv = (myImageView) v;
String resName = "noname";
try {
resName = getResourceNameFromClassByID(android.R.drawable.class, mv.resId);
} catch (IllegalArgumentException e) {
// TODO: handle exception
}
String str = "this image is: " + mv.getResId() + "\n And name: "+ resName;
System.out.println(str);
Toast.makeText(getBaseContext(), str, Toast.LENGTH_SHORT).show();
}
};
AbsoluteLayout layout=new AbsoluteLayout(this);
layout.setBackgroundColor(Color.rgb(255,255,255));
setContentView(layout);
GridView gridView=new GridView(this);
setALParams(gridView,0,0);
gridView.setNumColumns(4);
gridView.setGravity(Gravity.CENTER);
gridView.setAdapter(new ImageAdapter(this));
layout.addView(gridView);
}
public class myImageView extends ImageView{
private int resId;
public int getResId() {
return resId;
}
public myImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public void setImageResource(int res){
super.setImageResource(res);
resId = res;
}
}
public class ImageAdapter extends BaseAdapter {
private Context context;//コンテキスト
public ImageAdapter(Context c) {
context=c;
}
public int getCount() {
return IDS.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position,View convertView,ViewGroup parent) {
ImageView imageView;
if (convertView==null) {
imageView=new myImageView(context);
imageView.setLayoutParams(new GridView.LayoutParams(45,45));
imageView.setAdjustViewBounds(false);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8,8,8,8);
} else {
imageView=(ImageView)convertView;
}
imageView.setImageResource(IDS[position]);
imageView.setOnClickListener(onClicker);
return imageView;
}
}
private static void setALParams(View view,int x,int y) {
setALParams(view,x,y,
AbsoluteLayout.LayoutParams.WRAP_CONTENT,
AbsoluteLayout.LayoutParams.WRAP_CONTENT);
}
private static void setALParams(View view,int x,int y,int w,int h) {
view.setLayoutParams(
new AbsoluteLayout.LayoutParams(w,h,x,y));
}
}
Yes thats rly awesome shit
?