您的位置:首页 > 移动开发 > Android开发

android ViewFlipper制作,OnGestureListener手势监听不灵敏问题

2013-10-31 19:31 507 查看
项目须有需要做一个新功能引导采用了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;
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐