S60412-141706.jpg
S60412-141751.jpg
[图片] S60412-141706.jpg
[图片] S60412-141751.jpg
[图片] S60412-141706.jpg
[图片] S60412-141751.jpg
RememberUi.java ~ 5KB
package com.example.memory_test; import java.util.Random; import com.example.adapter.ImageGalleryAdapter; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.Choreographer; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Button; import android.widget.Chronometer; import android.widget.Gallery; import android.widget.Toast; @SuppressWarnings("deprecation") public class RememberUi extends Activity{ private Gallery card_gallery; private Chronometer chronometer; private Button replay; private Button remember_done; private int[] image_sort; private Handler handler; public final int[] image = new int[] { 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 protected void onCreate(Bundle savedInstanceState) { 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 = new Handler(){ @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); switch (msg.what) { case 0: updateGallery(); break; default: break; } } }; Message msg = new Message(); msg.what = 0; handler.sendMessage(msg); } private void updateGallery(){ image_sort = doSort(image); card_gallery.setAdapter(new ImageGalleryAdapter(this,image_sort)); card_gallery.setOnItemClickListener(new OnItemClickListenerImpl()); chronometer.setFormat("用时:%s"); chronometer.start(); replay.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent i = new Intent(RememberUi.this, TimerView.class); startActivity(i); RememberUi.this.finish(); } }); remember_done.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub String stopTime = chronometer.getText().toString(); chronometer.stop(); Intent i = new Intent(RememberUi.this, RestoreUi.class); i.putExtra("remember_time", stopTime); i.putExtra("image_sort", image_sort); startActivity(i); RememberUi.this.finish(); } }); } public int[] doSort(int sArr[]){ int[] tempArr= new int[sArr.length]; for (int i = 0; i < tempArr.length; i++) { tempArr[i] = 0; } Random random = new Random(); int randomIndex = -1; for(int i=0;i<tempArr.length;i++){ while(tempArr[i] == 0){ randomIndex = random.nextInt(sArr.length); if(sArr[randomIndex] != 0){ tempArr[i] = sArr[randomIndex]; sArr[randomIndex] = 0; } } } return tempArr; } @Override public void onBackPressed() { // TODO Auto-generated method stub //super.onBackPressed(); new AlertDialog.Builder(RememberUi.this).setTitle("退出提示")//设置对话框标题 .setMessage("防止记忆中误触碰,请确认是否退出记忆")//设置显示的内容 .setPositiveButton("确定",new DialogInterface.OnClickListener() {//添加确定按钮 @Override public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件 // TODO Auto-generated method stub RememberUi.this.finish(); } }).setNegativeButton("返回",new DialogInterface.OnClickListener() {//添加返回按钮 @Override public void onClick(DialogInterface dialog, int which) {//响应事件 // TODO Auto-generated method stub Log.i("alertdialog"," 继续记忆"); } }).show();//在按键响应事件中显示此对话框 } private class OnItemClickListenerImpl implements OnItemClickListener { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub Toast.makeText(RememberUi.this, "这是第"+String.valueOf(arg2+1)+"张牌", Toast.LENGTH_SHORT).show(); } } }
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/10140.html