@Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: isMOtionActionUp = false; if (clickType == ConstantUtil.NoClick) { clickType = ConstantUtil.SingleClick; // 开启线程 if (mClickThread != null) { mClickThread = null; } mClickThread = new ClickTThread(); mClickThread.start(); } else if (clickType == ConstantUtil.SingleClick) { clickType = ConstantUtil.DoubleClick; } else { clickType = ConstantUtil.InvalidClick; } break; case MotionEvent.ACTION_MOVE: clickType = ConstantUtil.NoClick; break; case MotionEvent.ACTION_UP: isMOtionActionUp = true; break; } return true; } /** * 点击的类型 */ private int clickType = ConstantUtil.NoClick; /** * 释放手指 */ private boolean isMOtionActionUp = false; private ClickTThread mClickThread; static class myHandler extends Handler { } private myHandler mHandler = new myHandler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub switch (msg.what) { default: break; case ConstantUtil.mClickTThreadStop: if (isMOtionActionUp) { switch (clickType) { default: System.out.println("InvalidClick"); break; case ConstantUtil.NoClick: System.out.println("NoClick"); break; case ConstantUtil.SingleClick: System.out.println("SingleClick"); break; case ConstantUtil.DoubleClick: System.out.println("DoubleClick"); break; } } else if (clickType == ConstantUtil.SingleClick) { // 超时间没有释放手指并且只点击一次的被视为长按 System.out.println("LongClick"); } System.out.println("AppIcon position is " + row + " row " + column + " column."); // 超时间清除点击事件 clickType = ConstantUtil.NoClick; break; } } }; /** * 第一次点击时启动该线程,在规定时间后判断点击的次数(可用定时器实现该功能) * * @author zoipuus * */ private class ClickTThread extends Thread { @Override public void run() { // TODO Auto-generated method stub try { sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } mHandler.obtainMessage(ConstantUtil.mClickTThreadStop) .sendToTarget(); } }
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦