package android.game.puke;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
public class PuKeActivity extends Activity {
private PuKe mPuKe = null;
private boolean isBig = false;
private int mBigI = -1;
private int mBigJ = -1;
private boolean isThreeBig = false;
private boolean isSameBig = false;
private int mSameBig = -1;
private Context mContext = null;
private int mNum = 0;
private TextView mTextView = null;
private TextView mTextViewTime = null;
private TextView mTextViewBest = null;
private int time = 0;
private int bestNum = 0;
private int bestTime = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
mContext = this;
mTextView = (TextView)findViewById(R.id.all_num);
mTextViewTime = (TextView)findViewById(R.id.all_time);
mTextViewBest = (TextView)findViewById(R.id.best_num_time);
restartGame();
String time_dian = this.getString(R.string.all_time);
mTextViewTime.setText("00"+time_dian+"00"+time_dian+"00");
Message msg = new Message();
msg.what = TIME_HANDLER;
mHandler.sendMessageDelayed(msg, 1000);
}
private void getBestNumTime(){
SharedPreferences sprefs = mContext.getSharedPreferences("puke_num_time", 0);
bestNum = sprefs.getInt("puke_num", 0);
bestTime = sprefs.getInt("puke_time", 0);
}
private void setBestNumTime(int bestNum,int bestTime){
SharedPreferences sprefs = mContext.getSharedPreferences("puke_num_time", 0);
SharedPreferences.Editor editor = sprefs.edit();
editor.putInt("puke_num", bestNum);
editor.putInt("puke_time", bestTime);
editor.commit();
}
private void restartGame(){
getBestNumTime();
if(bestNum > 0){
String string1 = this.getString(R.string.all_num3);
String string2 = this.getString(R.string.all_num2);
String time_dian = this.getString(R.string.all_time);
int num = bestTime/60;
int num1 = bestTime%60;
int num2 = num/60;
int num3 = num%60;
mTextViewBest.setText(string1+bestNum+string2+num2+time_dian+num3+time_dian+num1);
}else{
mTextViewBest.setText(this.getString(R.string.all_num4));
}
String num1 = this.getString(R.string.all_num1);
String num2 = this.getString(R.string.all_num2);
mTextView.setText(num1+"0"+num2);
mNum = 0;
mPuKe = new PuKe();
reflesh();
time = 0;
}
private void reflesh(){
boolean sec = youwin();
if(sec){
if((bestNum > mNum)||(bestNum <= 0)){
setBestNumTime(mNum,time);
myDialog(((Activity)mContext).getString(R.string.out_restart3));
}else{
myDialog(((Activity)mContext).getString(R.string.out_restart2));
}
}else{
intiPuKeDiff();
initPuKeAll();
initPuKeSame();
}
}
private void showNum(){
mNum++;
String num1 = this.getString(R.string.all_num1);
String num2 = this.getString(R.string.all_num2);
mTextView.setText(num1+mNum+num2);
}
private final static int TIME_HANDLER = 999;
private Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
if(msg.what == TIME_HANDLER){
Message msg0 = new Message();
msg0.what = TIME_HANDLER;
mHandler.sendMessageDelayed(msg0, 1000);
time++;
int num = time/60;
int num1 = time%60;
int num2 = num/60;
int num3 = num%60;
String string1 = ""+num1;
String string2 = ""+num2;
String string3 = ""+num3;
if(num1 < 10)string1 = "0"+string1;
if(num2 < 10)string2 = "0"+string2;
if(num3 < 10)string3 = "0"+string3;
String time_dian = mContext.getString(R.string.all_time);
mTextViewTime.setText(string2+time_dian+string3+time_dian+string1);
}
}
};
@Override
public void onBackPressed() {
myDialog(((Activity)mContext).getString(R.string.out_restart));
}
private void myDialog(String string){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(string)
.setCancelable(false)
.setPositiveButton(((Activity)mContext).getString(R.string.out), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
((Activity)mContext).finish();
}
})
.setNegativeButton(((Activity)mContext).getString(R.string.restart), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
restartGame();
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private OnTouchListener onTouchListener = new OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Log.d("zhouzhiyuan_555","onTouch");
if(view.getId() == PuKeUtils.all_view_id){
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
if(isThreeBig){
isThreeBig = false;
setImageViewWidthAndHeight(mContext,PuKeUtils.all_view_show_id[mPuKe.getThreePuKeNum() - 1],isThreeBig);
}else if(isBig){
isBig = false;
setImageViewWidthAndHeight(mContext,PuKeUtils.diff_all_id[mBigI][mBigJ],isBig);
}else if(isSameBig){
isSameBig = false;
setImageViewWidthAndHeight(mContext,PuKeUtils.same_view_id[mSameBig],isSameBig);
}
showThreePuKe();
}
}else if((view.getId() == PuKeUtils.all_view_show_id[0])
||(view.getId() == PuKeUtils.all_view_show_id[1])
||(view.getId() == PuKeUtils.all_view_show_id[2])){
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
int num = mPuKe.getThreePuKeNum();
if((num <= 3)&&(num > 0)){
if(isThreeBig){
isThreeBig = false;
setImageViewWidthAndHeight(mContext,PuKeUtils.all_view_show_id[num - 1],isThreeBig);
}else if(isBig){
isBig = false;
setImageViewWidthAndHeight(mContext,PuKeUtils.diff_all_id[mBigI][mBigJ],isBig);
}else if(isSameBig){
isSameBig = false;
setImageViewWidthAndHeight(mContext,PuKeUtils.same_view_id[mSameBig],isSameBig);
}else{
isThreeBig = true;
setImageViewWidthAndHeight(mContext,PuKeUtils.all_view_show_id[num - 1],isThreeBig);
}
}else{
}
}
}else if((view.getId() == PuKeUtils.same_view_id[0])
||(view.getId() == PuKeUtils.same_view_id[1])
||(view.getId() == PuKeUtils.same_view_id[2])
||(view.getId() == PuKeUtils.same_view_id[3])){
if(motionEvent.getAction() =