public class ChooseImages implements Runnable {
private static final String LOG_TAG = "KeyCode";
int[] resIds = { R.drawable.pintu, R.drawable.a, R.drawable.b,
R.drawable.c, R.drawable.d, R.drawable.e, R.drawable.f,
R.drawable.g, R.drawable.h, R.drawable.i, R.drawable.j,
R.drawable.k, R.drawable.l, R.drawable.m, R.drawable.n,
R.drawable.o, R.drawable.p, R.drawable.q, R.drawable.r,
R.drawable.s, R.drawable.t, R.drawable.u, R.drawable.v,
R.drawable.w, R.drawable.x, R.drawable.y, R.drawable.z };
Button menu;
ImageAdapter ia ;
Context mContext;
ViewGroup mContainer;
public ChooseImages() {
}
public void init(Context context, ViewGroup container, HashMap<?,?> params){
this.mContext = context;
this.mContainer = container;
}
private static ChooseImages instants;
public static ChooseImages getInstants(){
if(instants==null){
instants = new ChooseImages();
}
return instants;
}
View.OnKeyListener l = new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
Log.d(LOG_TAG," KeyEvent: " + event );
if(keyCode == KeyEvent.KEYCODE_MENU){
showDialog();
return true;
}
return false;
}
};
public void run() {
// TODO Auto-generated method stub
View view1 = View.inflate(mContext, R.layout.images, null);
view1.requestFocus();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(-1, -1);
mContainer.removeAllViews();
mContainer.addView(view1, lp);
GridView gv = (GridView) mContainer.findViewById(R.id.gridView1);
menu = (Button) mContainer.findViewById(R.id.menu);
menu.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showDialog();
}
});
ia = new ImageAdapter();
gv.setNumColumns(2);
gv.setAdapter(ia);
gv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
HashMap<String,Integer> params = new HashMap<String, Integer>();
params.put("res", resIds[position]);
Play.getInstants().init(mContext, mContainer, params);
Play.getInstants().run();
}
});
ArrayList<View> views = view1.getFocusables(View.FOCUSABLES_ALL);
for(View v:views){
v.setOnKeyListener(l);
}
}
protected void showDialog() {
final View dialogView = LayoutInflater.from(mContext).inflate(R.layout.dialog_gamininfo, null);
mContainer.addView(dialogView);
dialogView.requestFocus();
Button sure = (Button) dialogView.findViewById(R.id.dialog_sure);
sure.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mContainer.removeView(dialogView);
}
});
}
class ImageAdapter extends BaseAdapter {
public int getCount() {
return resIds.length;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = LayoutInflater.from(mContext).inflate(R.layout.image, null);
ImageView iv = (ImageView) v.findViewById(R.id.imageView1);
iv.setImageBitmap(ImageUtil.createMirrorImageWithOrigain(ImageUtil.drawableToBitmap(mContext.getResources().getDrawable(resIds[position]))));
return v;
}
}
}
private static final String LOG_TAG = "KeyCode";
int[] resIds = { R.drawable.pintu, R.drawable.a, R.drawable.b,
R.drawable.c, R.drawable.d, R.drawable.e, R.drawable.f,
R.drawable.g, R.drawable.h, R.drawable.i, R.drawable.j,
R.drawable.k, R.drawable.l, R.drawable.m, R.drawable.n,
R.drawable.o, R.drawable.p, R.drawable.q, R.drawable.r,
R.drawable.s, R.drawable.t, R.drawable.u, R.drawable.v,
R.drawable.w, R.drawable.x, R.drawable.y, R.drawable.z };
Button menu;
ImageAdapter ia ;
Context mContext;
ViewGroup mContainer;
public ChooseImages() {
}
public void init(Context context, ViewGroup container, HashMap<?,?> params){
this.mContext = context;
this.mContainer = container;
}
private static ChooseImages instants;
public static ChooseImages getInstants(){
if(instants==null){
instants = new ChooseImages();
}
return instants;
}
View.OnKeyListener l = new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
Log.d(LOG_TAG," KeyEvent: " + event );
if(keyCode == KeyEvent.KEYCODE_MENU){
showDialog();
return true;
}
return false;
}
};
public void run() {
// TODO Auto-generated method stub
View view1 = View.inflate(mContext, R.layout.images, null);
view1.requestFocus();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(-1, -1);
mContainer.removeAllViews();
mContainer.addView(view1, lp);
GridView gv = (GridView) mContainer.findViewById(R.id.gridView1);
menu = (Button) mContainer.findViewById(R.id.menu);
menu.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showDialog();
}
});
ia = new ImageAdapter();
gv.setNumColumns(2);
gv.setAdapter(ia);
gv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
HashMap<String,Integer> params = new HashMap<String, Integer>();
params.put("res", resIds[position]);
Play.getInstants().init(mContext, mContainer, params);
Play.getInstants().run();
}
});
ArrayList<View> views = view1.getFocusables(View.FOCUSABLES_ALL);
for(View v:views){
v.setOnKeyListener(l);
}
}
protected void showDialog() {
final View dialogView = LayoutInflater.from(mContext).inflate(R.layout.dialog_gamininfo, null);
mContainer.addView(dialogView);
dialogView.requestFocus();
Button sure = (Button) dialogView.findViewById(R.id.dialog_sure);
sure.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mContainer.removeView(dialogView);
}
});
}
class ImageAdapter extends BaseAdapter {
public int getCount() {
return resIds.length;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = LayoutInflater.from(mContext).inflate(R.layout.image, null);
ImageView iv = (ImageView) v.findViewById(R.id.imageView1);
iv.setImageBitmap(ImageUtil.createMirrorImageWithOrigain(ImageUtil.drawableToBitmap(mContext.getResources().getDrawable(resIds[position]))));
return v;
}
}
}