iDemo_app_puzzle_runnable

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;
}


}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值