最强大脑记忆扑克牌.docx
《最强大脑记忆扑克牌.docx》由会员分享,可在线阅读,更多相关《最强大脑记忆扑克牌.docx(10页珍藏版)》请在冰豆网上搜索。
最强大脑记忆扑克牌
java最强大脑记忆扑克牌
S60412-141706.jpg
S60412-141751.jpg
[图片] S60412-141706.jpg
[图片] S60412-141751.jpg
[图片] S60412-141706.jpg
[图片] S60412-141751.jpg
RememberUi.java ~ 5KB
packagecom.example.memory_test;
importjava.util.Random;
importcom.example.adapter.ImageGalleryAdapter;
importandroid.app.Activity;
importandroid.app.AlertDialog;
importandroid.content.DialogInterface;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.util.Log;
importandroid.view.Choreographer;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.AdapterView;
importandroid.widget.AdapterView.OnItemClickListener;
importandroid.widget.Button;
importandroid.widget.Chronometer;
importandroid.widget.Gallery;
importandroid.widget.Toast;
@SuppressWarnings("deprecation")
publicclassRememberUiextendsActivity{
privateGallerycard_gallery;
privateChronometerchronometer;
privateButtonreplay;
privateButtonremember_done;
privateint[]image_sort;
privateHandlerhandler;
publicfinalint[]image=newint[]{R.drawable.a1,R.drawable.a2,R.drawable.a3,R.drawable.a4,
R.drawable.a5,R.drawable.a6,R.drawable.a7,R.drawable.a8,R.drawable.a9,R.drawable.a0,R.drawable.aj,R.drawable.aq,R.drawable.ak,
R.drawable.b1,R.drawable.b2,R.drawable.b3,R.drawable.b4,
R.drawable.b5,R.drawable.b6,R.drawable.b7,R.drawable.b8,R.drawable.b9,R.drawable.b0,R.drawable.bj,R.drawable.bq,R.drawable.bk,
R.drawable.c1,R.drawable.c2,R.drawable.c3,R.drawable.c4,
R.drawable.c5,R.drawable.c6,R.drawable.c7,R.drawable.c8,R.drawable.c9,R.drawable.c0,R.drawable.cj,R.drawable.cq,R.drawable.ck,
R.drawable.d1,R.drawable.d2,R.drawable.d3,R.drawable.d4,
R.drawable.d5,R.drawable.d6,R.drawable.d7,R.drawable.d8,R.drawable.d9,R.drawable.d0,R.drawable.dj,R.drawable.dq,R.drawable.dk,};
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.remember_ui);
card_gallery=(Gallery)findViewById(R.id.card_gallery);
chronometer=(Chronometer)findViewById(R.id.chronometer1);
replay=(Button)findViewById(R.id.replay);
remember_done=(Button)findViewById(R.id.remember_done);
handler=newHandler(){
@Override
publicvoidhandleMessage(Messagemsg){
//TODOAuto-generatedmethodstub
super.handleMessage(msg);
switch(msg.what){
case0:
updateGallery();
break;
default:
break;
}
}
};
Messagemsg=newMessage();
msg.what=0;
handler.sendMessage(msg);
}
privatevoidupdateGallery(){
image_sort=doSort(image);
card_gallery.setAdapter(newImageGalleryAdapter(this,image_sort));
card_gallery.setOnItemClickListener(newOnItemClickListenerImpl());
chronometer.setFormat("用时:
%s");
chronometer.start();
replay.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewarg0){
//TODOAuto-generatedmethodstub
Intenti=newIntent(RememberUi.this,TimerView.class);
startActivity(i);
RememberUi.this.finish();
}
});
remember_done.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewarg0){
//TODOAuto-generatedmethodstub
StringstopTime=chronometer.getText().toString();
chronometer.stop();
Intenti=newIntent(RememberUi.this,RestoreUi.class);
i.putExtra("remember_time",stopTime);
i.putExtra("image_sort",image_sort);
startActivity(i);
RememberUi.this.finish();
}
});
}
publicint[]doSort(intsArr[]){
int[]tempArr=newint[sArr.length];
for(inti=0;itempArr[i]=0;
}
Randomrandom=newRandom();
intrandomIndex=-1;
for(inti=0;iwhile(tempArr[i]==0){
randomIndex=random.nextInt(sArr.length);
if(sArr[randomIndex]!
=0){
tempArr[i]=sArr[randomIndex];
sArr[randomIndex]=0;
}
}
}
returntempArr;
}
@Override
publicvoidonBackPressed(){
//TODOAuto-generatedmethodstub
//super.onBackPressed();
newAlertDialog.Builder(RememberUi.this).setTitle("退出提示")//设置对话框标题
.setMessage("防止记忆中误触碰,请确认是否退出记忆")//设置显示的内容
.setPositiveButton("确定",newDialogInterface.OnClickListener(){//添加确定按钮
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){//确定按钮的响应事件
//TODOAuto-generatedmethodstub
RememberUi.this.finish();
}
}).setNegativeButton("返回",newDialogInterface.OnClickListener(){//添加返回按钮
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){//响应事件
//TODOAuto-generatedmethodstub
Log.i("alertdialog","继续记忆");
}
}).show();//在按键响应事件中显示此对话框
}
privateclassOnItemClickListenerImplimplementsOnItemClickListener{
@Override
publicvoidonItemClick(AdapterView
>arg0,Viewarg1,intarg2,
longarg3){
//TODOAuto-generatedmethodstub
Toast.makeText(RememberUi.this,"这是第"+String.valueOf(arg2+1)+"张牌",
Toast.LENGTH_SHORT).show();
}
}
}