<code id="ymukc"><xmp id="ymukc">

最強大腦記憶撲克牌

GerD82的頭像 GerD82 -1 2016-04-13 07:33 0

 基本信息

× 1   

瀏覽數: 38058

分享時間: 2 年 前

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

	}

}

12 [下一頁]

  • tumubai的頭像 tumubai 2016-05-18 22:26 代碼數:0

    謝謝樓主分享

  • 出入江湖的頭像 出入江湖 2016-05-24 00:16 代碼數:0

    學習了

  • cixexey的頭像 cixexey 2018-05-14 19:20 代碼數:0

    Great Information sharing .. I am very happy to read this article .. thanks for giving us go through info.Fantastic nice. I appreciate this post.click here

  • cixexey的頭像 cixexey 2018-05-14 19:20 代碼數:0

    I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.click here

  • wxx199702的頭像 wxx199702 2018-03-13 22:41 代碼數:0

    寫的不錯

  • lwh123的頭像 lwh123 2018-03-21 17:09 代碼數:0

    可以可以 很強

  • csmyg的頭像 csmyg 2017-05-04 11:07 代碼數:0

    踩一踩

  • cixexey的頭像 cixexey 2018-08-20 15:30 代碼數:0

    I really like your take on the issue. I now have a clear idea on what this matter is all about..responsive web design

  • cixexey的頭像 cixexey 2018-08-21 20:04 代碼數:0

    Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. Just Cannabis

  • wind-zz的頭像 wind-zz 2017-10-14 21:44 代碼數:0

    多謝分享

您的評論:

  
六合特码资料
<code id="ymukc"><xmp id="ymukc">
<code id="ymukc"><xmp id="ymukc">