android ViewFlipper製作,OnGestureListener手勢監聽不靈敏問題

項目須有需要做一個新功能引導採用了ViewFlipper,做好後,發現滑動很不靈敏,有時候可以滑動,有時候滑動不了,特別是滑動得快的時候,基本滑動不了。

太奇怪了,之前做過這個東西是完全沒問題的。

經調試,發現OnGestureListener 接口的方法經常監聽不到。

上網查了會,發現應該是焦點被搶了,所以經常纔沒反應,

看源碼:

package com.lordcard.ui;

import game.card.dizhu.R;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.cnzz.mobile.android.sdk.MobileProbe;
import com.google.gson.reflect.TypeToken;
import com.lordcard.common.bean.DataCentreBean;
import com.lordcard.common.exception.CrashApplication;
import com.lordcard.common.mydb.DBHelper;
import com.lordcard.common.net.HttpUtils;
import com.lordcard.common.pay.SDKFactory;
import com.lordcard.common.task.GenericTask;
import com.lordcard.common.task.base.TaskParams;
import com.lordcard.common.task.base.TaskResult;
import com.lordcard.common.upgrade.UpdateService;
import com.lordcard.common.upgrade.UpdateUtils;
import com.lordcard.common.util.ActivityPool;
import com.lordcard.common.util.ActivityUtils;
import com.lordcard.common.util.DateUtil;
import com.lordcard.common.util.DialogUtils;
import com.lordcard.common.util.EncodeUtils;
import com.lordcard.common.util.ImageUtil;
import com.lordcard.common.util.JsonHelper;
import com.lordcard.common.util.PatternUtils;
import com.lordcard.constant.Constant;
import com.lordcard.constant.Database;
import com.lordcard.entity.GameUser;
import com.lordcard.entity.JsonResult;
import com.lordcard.entity.MessageCenter;
import com.lordcard.entity.NoticesVo;
import com.lordcard.net.http.HttpRequest;
import com.lordcard.net.http.HttpURL;
import com.lordcard.network.http.GetHttpCache;
import com.lordcard.ui.base.BaseActivity;
import com.lordcard.ui.base.FastJoinTask;
import com.lordcard.ui.base.ILoginView;
import com.lordcard.ui.dizhu.DoudizhuRoomListActivity;
import com.lordcard.ui.view.dialog.AccountBindDialog;
import com.lordcard.ui.view.dialog.ChangeAccountDialog;
import com.lordcard.ui.view.dialog.GameDialog;

@SuppressLint({ "HandlerLeak", "DefaultLocale", "SimpleDateFormat", "WorldReadableFiles" })
public class LoginActivity extends BaseActivity implements ILoginView, OnTouchListener, OnGestureListener {
	private TextView accountTv, goldTv; // 賬號,智豆
	private Button loginBtn, changeAccountBtn, bindAccountBtn, quickMatch, quickLogin, updateBtn;
	private AccountBindDialog mAccountBindDialog;// 綁定賬號對話框
	private SharedPreferences sharedPrefrences;
	private SharedPreferences sharedViewfiper;
	private Editor editor;
	public static final String KEY_USER = "user_key";
	public static final int UPDATE_USER = 10;
	public static final int RESIGSTER_USER = 20;
	// 登錄的時候需要的幾個常量
	public final static String ACCOUNT = "account";
	public final static String PASSWORD = "userPwd";
	private RelativeLayout gameBg = null;
	private RelativeLayout katong, loginBg = null;
	private ChangeAccountDialog mChangeAccountDialog = null;
	private TextView zhezhao;
	// 是否更新支付數據
	private RelativeLayout ggdetaiLayout;
	private TextView titleView, contentView, timeView, textName, textTeam;
	private static Boolean boolean1;
	private static int i;
	private static int PXZ, PX_MST, PX_LAST_MST;
	private TextView t1;
	private Timer timer;
	private ScrollView scrollView;
	private Button gonggao;
	private boolean ToastIsShow = false;//土司彈出過(避免土司重複彈出,霸佔屏幕)
	private GenericTask rjoinTask;
	public static DBHelper dbHelper;
	private GestureDetector mGestureDetector = null;
	private ViewFlipper mViewFlipper;
	private boolean isShown;
	private int[] imageId = new int[] { R.drawable.login_guide1, R.drawable.login_guide2, R.drawable.login_guide3 };
	private Handler handler = new Handler() {

		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
			case UPDATE_USER: // 更新界面賬戶
				if (Database.USER != null) {
					// 優先使用綁定賬號
					String account = Database.USER.getAccount();
					if (!TextUtils.isEmpty(Database.USER.getRelaAccount())) {
						account = Database.USER.getRelaAccount();
					}

					accountTv.setText(account); // 賬號
					goldTv.setText(PatternUtils.changeZhidou(Database.USER.getBean()));// 智豆
				}
				break;
			case RESIGSTER_USER://註冊賬號
				register(true);
				break;
			case 1:
				PXZ = PXZ + PX_MST;
				LayoutParams lp = (LayoutParams) t1.getLayoutParams();
				lp.height = PXZ;
				t1.setLayoutParams(lp);
				i = i + 1;
				break;
			case 2:
				PXZ = PXZ - PX_MST;
				LayoutParams lp2 = (LayoutParams) t1.getLayoutParams();
				lp2.height = PXZ;
				t1.setLayoutParams(lp2);
				i = i - 1;
				break;
			case 3:
				scrollView.setVisibility(View.VISIBLE);
				gonggao.setClickable(true);
				break;
			case 4:
				ggdetaiLayout.setVisibility(View.GONE);
				gonggao.setClickable(true);
				break;
			default:
				break;
			}
		};
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);// 設置標題欄不顯示
		overridePendingTransition(R.anim.fade, R.anim.hold);
		setContentView(R.layout.game_login);
		mGestureDetector = new GestureDetector(this);
		initView(); // 初始化View控件
		i = 1;
		PXZ = 0;
		PX_MST = mst.adjustYIgnoreDensity(13);//公告每段高度
		PX_LAST_MST = PX_MST * 20;//高度總高度
		t1 = (TextView) findViewById(R.id.t1);
		timer = new Timer();
		boolean1 = true; //公告標誌
		ToastIsShow = false;//土司彈出標誌
		dbHelper = new DBHelper(CrashApplication.getInstance());
		GenericTask gameNoticeTask = new GameNoticeTask();
		gameNoticeTask.execute();
		taskManager.addTask(gameNoticeTask);
		new Thread() {
			public void run() {
				try {
					Database.PAYTYPE = SDKFactory.getPayType();
					HttpRequest.getConfig(Database.PAYTYPE);
					SDKFactory.UpdatePayDate();//獲取是否更新支付
					SDKFactory.getPayDate();// 拿緩存的支付內容或者更新
				} catch (Exception e) {
				}
			};
		}.start();
		final Timer timer = new Timer(true);
		timer.schedule(new TimerTask() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				if (Database.USER != null) {
					try {
						getGameMessage();
					} catch (Exception e) {
						// TODO: handle exception
					}
					timer.cancel();
				}
			}
		}, 100, 100);

		login(false); // 登錄
		mst.adjustView(gameBg);
	}

	@Override
	public void onBackPressed() {
		NotificationManager notificationManager = (NotificationManager) getSystemService(android.content.Context.NOTIFICATION_SERVICE);
		notificationManager.cancel(UpdateService.NOTIFICATION_ID);// 多次下載的
		UpdateUtils.stopDownLoadNewVesionSev(this);
		ActivityPool.exitApp();
	}

	/**
	 * 初始化view控件
	 */
	private void initView() {

		mViewFlipper = (ViewFlipper) findViewById(R.id.viewflipper);
		sharedViewfiper = getSharedPreferences("viewflipper", MODE_WORLD_READABLE);
		isShown = sharedViewfiper.getBoolean("flipper", false);
		if (!isShown) {
			mViewFlipper.setVisibility(View.VISIBLE);
			for (int i = 0; i < imageId.length; i++) {
				ImageView mImageView = new ImageView(this);
				mImageView.setBackgroundDrawable(ImageUtil.getResDrawable(imageId[i], false));
				mImageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
				mViewFlipper.addView(mImageView);
			}
		}

		mChangeAccountDialog = new ChangeAccountDialog(this, handler);
		mAccountBindDialog = new AccountBindDialog(this, handler);
		updateBtn = (Button) findViewById(R.id.update);
		updateBtn.setOnClickListener(mOnClickListener);
		loginBtn = (Button) findViewById(R.id.game_login_in);
		loginBtn.setOnClickListener(mOnClickListener);
		quickMatch = (Button) findViewById(R.id.game_quick_match);
		quickMatch.setOnClickListener(mOnClickListener);
		quickLogin = (Button) findViewById(R.id.game_quick_login);
		quickLogin.setOnClickListener(mOnClickListener);
		changeAccountBtn = (Button) findViewById(R.id.game_login_change_account);
		changeAccountBtn.setOnClickListener(mOnClickListener);
		bindAccountBtn = (Button) findViewById(R.id.game_login_bind_account);
		bindAccountBtn.setOnClickListener(mOnClickListener);

		accountTv = (TextView) findViewById(R.id.game_login_id);
		goldTv = (TextView) findViewById(R.id.game_login_gold);
		accountTv.setText("遊客"); // 賬號
		goldTv.setText("20000"); // 智豆

		gameBg = (RelativeLayout) findViewById(R.id.layout);
		gameBg.setBackgroundDrawable(ImageUtil.getResDrawable(R.drawable.join_bj, false));

		katong = (RelativeLayout) findViewById(R.id.katong);
		katong.setBackgroundDrawable(ImageUtil.getResDrawable(R.drawable.katong, true));

		titleView = (TextView) findViewById(R.id.gg_title);
		contentView = (TextView) findViewById(R.id.gg_content);
		timeView = (TextView) findViewById(R.id.gg_time);
		textName = (TextView) findViewById(R.id.gg_name);
		textTeam = (TextView) findViewById(R.id.gg_team);

		ggdetaiLayout = (RelativeLayout) findViewById(R.id.gg_detail);
		scrollView = (ScrollView) findViewById(R.id.room_list_scrollView);
		gonggao = (Button) findViewById(R.id.gonggao);
		gonggao.setOnClickListener(mOnClickListener);
		loginBg = (RelativeLayout) findViewById(R.id.login_bg);
		loginBg.setBackgroundDrawable(ImageUtil.getResDrawable(R.drawable.loginbj, true));

	}

	@Override
	public void onResume() {
		super.onResume();
		if (Database.USER != null) {
			String account = Database.USER.getAccount();
			if (!TextUtils.isEmpty(Database.USER.getRelaAccount())) {
				account = Database.USER.getRelaAccount();
			}
			ToastIsShow = false;
			accountTv.setText(account); // 賬號
			goldTv.setText(PatternUtils.changeZhidou(Database.USER.getBean())); // 智豆
		}
	}

	private synchronized void login(boolean isLogin) {
		Database.LOGIN_TIME = DateUtil.formatTimesTampDate(new Date());
		GameUser localUser = ActivityUtils.loadLocalAccount();//加載最近登錄賬號
		if (localUser != null) {
			GameUser userCache = GetHttpCache.readLoginCache(localUser.getAccount() + KEY_USER);
			if (userCache != null) {
				accountTv.setText(userCache.getAccount()); // 賬號
				goldTv.setText(PatternUtils.changeZhidou(userCache.getBean())); // 智豆
			}
		}
		if (localUser == null) { // MAC註冊新賬號
			register(isLogin);
		} else { // 本地賬號登錄
			// 登錄遊戲
			GenericTask loginTask = new LoginTask();
			if (isLogin) {
				loginTask.setFeedback(feedback);
			}
			TaskParams params = new TaskParams();
			params.put(ACCOUNT, localUser.getAccount());
			params.put(PASSWORD, localUser.getMd5Pwd());
			loginTask.execute(params);
			taskManager.addTask(loginTask);
		}
	}

	/**
	 * 註冊 賬號
	 */
	private void register(boolean isLogin) {
		GenericTask registerTask = new RegisterTask();
		if (isLogin) {
			registerTask.setFeedback(feedback);
		}
		registerTask.execute();
		taskManager.addTask(registerTask);
	}

	/**
	 * 登錄跳轉
	 * 
	 * @param gameUser
	 */
	private void userLogin(final GameUser gameUser) {
		Database.USER = gameUser;
		Database.ROOM_FRESH_TIME = Database.USER.getRoomTime();
		Database.GAME_SERVER = Database.USER.getGameServer();
		GetHttpCache.saveLoginCache(gameUser.getAccount() + KEY_USER, gameUser);//緩存用戶信息

		Database.USER.setRound(0);
		Database.SIGN_KEY = gameUser.getAuthKey();

		SharedPreferences sharedData = getApplication().getSharedPreferences(Constant.GAME_ACTIVITE, Context.MODE_PRIVATE);
		Editor editor = sharedData.edit();
		editor.putString(ACCOUNT, gameUser.getAccount());
		editor.commit();

		runOnUiThread(new Runnable() {
			public void run() {
				// 優先使用綁定賬號
				String account = gameUser.getAccount();
				if (!TextUtils.isEmpty(gameUser.getRelaAccount())) {
					account = gameUser.getRelaAccount();
				}
				accountTv.setText(account); // 賬號
				goldTv.setText(PatternUtils.changeZhidou(gameUser.getBean())); // 智豆
			}
		});
	}
	
	OnClickListener mOnClickListener=new OnClickListener() {
		@Override
		public void onClick(View v) {
			if (mViewFlipper.getVisibility() != View.VISIBLE) {
				switch (v.getId()) {
				case R.id.gonggao:
					MobileProbe.onEvent(LoginActivity.this, "公告", 1L);
					gonggao.setClickable(false);
					if (boolean1 == false) {
						scrollView.setVisibility(View.GONE);
						timer.scheduleAtFixedRate(new TimerTask() {

							@Override
							public void run() {
								if (i <= 20 && i >= 1) {
									handler.sendEmptyMessage(2);
								} else {
									PXZ = 0;
									i = 1;
									this.cancel();
									timer.scheduleAtFixedRate(new TimerTask() {


										@Override
										public void run() {
											handler.sendEmptyMessage(4);
											this.cancel();
										}
									}, 500l, 30l);

								}

							}
						}, 0l, 30l);
						boolean1 = true;
					} else {
						gonggao.setClickable(false);
						ggdetaiLayout.setVisibility(View.VISIBLE);
						timer.scheduleAtFixedRate(new TimerTask() {

							@Override
							public void run() {
								if (i >= 1 && i <= 20) {
									handler.sendEmptyMessage(1);
								} else {
									PXZ = PX_LAST_MST;
									i = 20;
									handler.sendEmptyMessage(3);

									this.cancel();
								}

							}
						}, 0l, 30l);
						boolean1 = false;
					}
					break;
				case R.id.game_login_in:// 遊戲大廳
					MobileProbe.onEvent(LoginActivity.this, "遊戲大廳", 1L);
					if (Database.USER == null) {
						login(true);
					} else {
						Intent intent = new Intent();
						intent.setClass(LoginActivity.this, DoudizhuRoomListActivity.class);
						startActivity(intent);
					}
					break;
				case R.id.game_login_change_account:// 切換賬號
					MobileProbe.onEvent(LoginActivity.this, "切換賬號", 1L);
					if (null != mChangeAccountDialog && !mChangeAccountDialog.isShowing()) {
						mChangeAccountDialog = new ChangeAccountDialog(LoginActivity.this, handler);
						mChangeAccountDialog.show();
					}
					break;
				case R.id.game_login_bind_account:// 綁定賬號
					MobileProbe.onEvent(LoginActivity.this, "綁定賬號D", 1L);
					if (Database.USER == null) {
						login(true);
					} else {
						if (!mAccountBindDialog.isShowing()) {
							mAccountBindDialog.show();
							mAccountBindDialog.initView();
						}
					}
					break;
				case R.id.game_quick_match://參加 比賽
					MobileProbe.onEvent(LoginActivity.this, "快速比賽", 1L);
					if (Database.USER == null) {
						login(true);
					} else {
						Bundle bundle = new Bundle();
						bundle.putInt("page", 2);
						Intent intent = new Intent();
						intent.setClass(LoginActivity.this, DoudizhuRoomListActivity.class);
						intent.putExtras(bundle);
						startActivity(intent);
					}
					break;
				case R.id.game_quick_login:// 快速遊戲
					MobileProbe.onEvent(LoginActivity.this, "快速遊戲D", 1L);
					FastJoinTask.fastJoin();
					break;
				case R.id.update:// 升級遊戲
					if (Database.UPDATED) {
						UpdateUtils.newVersionTip();
						//				UpdateUtils.updateTip(null, false, UPVersion.infolis, "更新內容如下:", this, true);
					} else {
						if (!ToastIsShow) {
							DialogUtils.mesToastTip("您當前已經是最新版本,暫時無需更新!");
							ToastIsShow = true;
						}
					}
					break;
				default:
					break;
				}
			}
		}
	};


	/**
	 * 登錄遊戲 com.lordcard.ui.LoginTask
	 * 
	 * @author Administrator <br/>
	 *         create at 2013 2013-4-8 下午4:17:56
	 */
	private class LoginTask extends GenericTask {

		protected TaskResult _doInBackground(TaskParams... params) {
			try {
				TaskParams param = null;
				if (params.length <= 0) {
					return TaskResult.FAILED;
				}
				param = params[0];
				// 登錄
				String loginPwd = param.getString(PASSWORD);
				if (loginPwd.length() < 30) { //長度大於30則認爲當前密碼是保存的密文
					loginPwd = EncodeUtils.MD5(loginPwd);
				}
				String result = HttpRequest.login(param.getString(ACCOUNT), loginPwd);
				if (TextUtils.isEmpty(result)) {
					return TaskResult.FAILED;
				}
				JsonResult jsonResult = JsonHelper.fromJson(result, JsonResult.class);
				if (JsonResult.SUCCESS.equals(jsonResult.getMethodCode())) {
					String gameUserJson = jsonResult.getMethodMessage();
					Log.i("gameUserJson", "登錄gameUserJson: " + gameUserJson);
					GameUser gameUser = JsonHelper.fromJson(gameUserJson, GameUser.class);

					String account = gameUser.getAccount();
					if (!TextUtils.isEmpty(gameUser.getRelaAccount())) {
						account = gameUser.getRelaAccount();
					}
					ActivityUtils.saveAccount(account, gameUser.getMd5Pwd());
					userLogin(gameUser);

					String roomTime = Database.USER.getRoomTime();
					if (roomTime != null) {
						Database.ROOM_UPDATE = roomTime;
					}
				} else {
					mesTip(jsonResult.getMethodMessage(), false, false);
					return TaskResult.FAILED;
				}
			} catch (Exception e) {
				return TaskResult.FAILED;
			}
			return TaskResult.OK;
		}
	}

	/**
	 * 註冊賬號 com.lordcard.ui.LoginTask
	 * 
	 * @author Administrator <br/>
	 *         create at 2013 2013-4-8 下午4:17:56
	 */
	private class RegisterTask extends GenericTask {

		protected TaskResult _doInBackground(TaskParams... params) {
			try {
				// 註冊
				String result = HttpRequest.register();
				if (TextUtils.isEmpty(result)) {
					return TaskResult.FAILED;
				}
				JsonResult jsonResult = JsonHelper.fromJson(result, JsonResult.class);
				if (JsonResult.SUCCESS.equals(jsonResult.getMethodCode())) {
					String gameUserJson = jsonResult.getMethodMessage();
					GameUser gameUser = JsonHelper.fromJson(gameUserJson, GameUser.class);
					//保存註冊賬號和密碼
					String account = gameUser.getAccount();
					if (!TextUtils.isEmpty(gameUser.getRelaAccount())) {
						account = gameUser.getRelaAccount();
					}
					ActivityUtils.saveAccount(account, gameUser.getMd5Pwd());
					ActivityUtils.saveAccount(account, gameUser.getMd5Pwd());
					Log.i("saveLoginAccount", "登錄界面》註冊》賬戶:" + gameUser.getAccount() + "密碼:" + gameUser.getMd5Pwd());
					userLogin(gameUser);
				} else {
					DialogUtils.mesTip(jsonResult.getMethodMessage(), false);
				}
			} catch (Exception e) {
				return TaskResult.FAILED;
			}
			return TaskResult.OK;
		}
	}

	/**
	 * 遊戲公告信息
	 */
	private class GameNoticeTask extends GenericTask {

		protected TaskResult _doInBackground(TaskParams... params) {
			try {
				String result = HttpUtils.post(HttpURL.GAME_NOTICE_URL, null);
				if (TextUtils.isEmpty(result)) {
					return TaskResult.FAILED;
				}
				final NoticesVo notices = JsonHelper.fromJson(result, NoticesVo.class);

				SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
				Date dt = format.parse(notices.getCtime());
				format = new SimpleDateFormat("yyyy-MM-dd");
				final String time1 = format.format(dt);
				final String content1 = notices.getContent();// 獲取的公告內容
				sharedPrefrences = getSharedPreferences("account_ban", MODE_WORLD_READABLE);
				final String time2 = sharedPrefrences.getString("time", null);
				//				final String content2 = sharedPrefrences.getString("content", null);// 保存的公告內容

				runOnUiThread(new Runnable() {
					public void run() {

						ggdetaiLayout.setOnClickListener(null);
						ggdetaiLayout.setVisibility(View.VISIBLE);

						if (time1.equals(time2)) {
							ggdetaiLayout.setVisibility(View.GONE);
							titleView.setText(notices.getTitle());
							contentView.setText("    " + notices.getContent());
							timeView.setText(time1);
							textName.setText("尊敬的玩家:");
							textTeam.setText("千千遊運營團隊");
							boolean1 = true;
							// mSignDialog.show();
						} else {
							boolean1 = false;
							ggdetaiLayout.setVisibility(View.VISIBLE);
							titleView.setText(notices.getTitle());
							contentView.setText("    " + notices.getContent());
							timeView.setText(time1);
							textName.setText("尊敬的玩家:");
							textTeam.setText("千千遊運營團隊");
							editor = sharedPrefrences.edit();
							editor.putString("content", content1);
							editor.putString("time", time1);
							editor.commit();
							timer.schedule(new TimerTask() {
								@Override
								public void run() {
									if (i <= 20 && i >= 0) {
										handler.sendEmptyMessage(1);
									} else {
										i = 20;
										PXZ = PX_LAST_MST;
										handler.sendEmptyMessage(3);

										this.cancel();
									}
								}
							}, 2000l, 30l);
						}
					}
				});

			} catch (Exception e) {
				return TaskResult.FAILED;
			}
			return TaskResult.OK;
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		//		mst.unRegisterView(gameBg);
		recyleDrawable();
		timer.cancel();

		if (rjoinTask != null) {
			rjoinTask.cancel(true);
			rjoinTask = null;
		}

	}

	public void recyleDrawable() {
		RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
		layout.removeAllViews();
	}

	private void mesTip(final String msg, final boolean showCancel, final boolean isFinish) {
		try {
			Database.currentActivity.runOnUiThread(new Runnable() {
				public void run() {
					GameDialog gameDialog = new GameDialog(Database.currentActivity, showCancel) {
						public void okClick() {
							if (isFinish) {
								ActivityUtils.finishAcitivity();
							}
							if (null != mChangeAccountDialog && !mChangeAccountDialog.isShowing()) {
								mChangeAccountDialog = new ChangeAccountDialog(LoginActivity.this, handler);
								mChangeAccountDialog.show();
							}
						}
					};
					gameDialog.show();
					gameDialog.setText(msg);
				}
			});

		} catch (Exception e) {
		}
	}

	/**
	 * 遊戲公告推送插入數據庫
	 */
	private void getGameMessage() {
		Database.MESSAGE_CENTER = JsonHelper.fromJson(HttpRequest.getGameData(), new TypeToken<List<MessageCenter>>() {
		});
		if (Database.MESSAGE_CENTER != null && Database.MESSAGE_CENTER.size() > 0 && Database.MESSAGE_CENTER.get(0) != null) {
			for (int i = 0; i < Database.MESSAGE_CENTER.size(); i++) {
				ContentValues values3 = new ContentValues();
				String id;
				if (Database.MESSAGE_CENTER.get(i).getType() == 0) {
					values3.put(DataCentreBean.DATA_ID, Database.MESSAGE_CENTER.get(i).getId() + "0");
					id = Database.MESSAGE_CENTER.get(i).getId() + "0";
				} else {
					values3.put(DataCentreBean.DATA_ID, Database.MESSAGE_CENTER.get(i).getId() + "1");
					id = Database.MESSAGE_CENTER.get(i).getId() + "1";
				}
				values3.put(DataCentreBean.DATA_CONTENT, Database.MESSAGE_CENTER.get(i).getContent());
				values3.put(DataCentreBean.DATA_RACE, Database.MESSAGE_CENTER.get(i).getType());
				values3.put(DataCentreBean.DATA_TIME, Database.MESSAGE_CENTER.get(i).getCtime());
				values3.put(DataCentreBean.DATA_CLICK, "0");
				values3.put(DataCentreBean.DATA_TITLE, Database.MESSAGE_CENTER.get(i).getTitle());
				String[] ids = { id };
				DataCentreBean.getInstance().save(dbHelper, values3, ids);
			}
		}
	}

	@Override
	public boolean onDown(MotionEvent arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		Log.d("forTag", " onFling : ");
		if (!isShown) {
			if (e1.getX() - e2.getX() > 30) {// 向右滑動

				if (mViewFlipper.getDisplayedChild() == imageId.length - 1) {
					mViewFlipper.setVisibility(View.GONE);
					Editor editor = sharedViewfiper.edit();
					editor.putBoolean("flipper", true);
					editor.commit();
				} else {
					mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));
					mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
					mViewFlipper.showNext();
					return true;
				}
			} else if (e2.getX() - e1.getX() > 30) {// 向左滑動
				if (mViewFlipper.getDisplayedChild() == 0) {
					Toast.makeText(this, "親,已經是第一張了", 500).show();
				} else {
					mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in));
					mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out));
					mViewFlipper.showPrevious();
					return true;
				}
			}
		}
		return true;
	}

	@Override
	public void onLongPress(MotionEvent arg0) {}

	@Override
	public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) {
		Log.d("forTag", " onScroll : ");
		return false;
	}

	@Override
	public void onShowPress(MotionEvent arg0) {
		Log.d("forTag", " onShowPress : ");
	}

	@Override
	public boolean onSingleTapUp(MotionEvent arg0) {
		Log.d("forTag", " onSingleTapUp : ");
		return false;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		Log.d("forTag", " onTouchEvent : ");
		return this.mGestureDetector.onTouchEvent(event);
	}

	@Override
	public boolean onTouch(View arg0, MotionEvent event) {
		// TODO Auto-generated method stub
		return this.mGestureDetector.onTouchEvent(event);
	}

	//	public boolean onTouch(View view, MotionEvent event) {
	//		return this.mGestureDetector.onTouchEvent(event);
	//	}
}

問題是ViewFlipper搶了焦點了,焦點穿不下去,解決辦法是,把ViewFlipper的焦點傳遞下去:

		mViewFlipper.setOnTouchListener(new android.view.View.OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent event) {
				return mGestureDetector.onTouchEvent(event);
			}
		});
		mViewFlipper.setOnClickListener(new android.view.View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				return;
			}
		});




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章