双击点击退出页面工具
来源:互联网 发布:python coroutine 编辑:程序博客网 时间:2024/05/20 18:44
在安卓中可能我们在处理返回机制的时候,不希望点击一次直接退出,而是点击两下。
下面对该场景进行封装。
public class DoubleClickExitDetector { public static String DEFAULT_HINT_MESSAGE_CHINA = "再按一次退出程序"; private int effectiveIntervalTime;// 有效的间隔时间,单位毫秒 private long lastClickTime;// 上次点击时间 private String hintMessage;// 提示消息 private Context context; /** * 创建一个双击退出识别器 * @param context Androdi上下文 * @param hintMessage 提示消息 * @param effectiveIntervalTime 有效间隔时间 */ public DoubleClickExitDetector(Context context, String hintMessage, int effectiveIntervalTime) { this.context = context; this.hintMessage = hintMessage; this.effectiveIntervalTime = effectiveIntervalTime; } /** * 创建一个双击退出识别器,有效间隔时间默认为2000毫秒 * @param context Androdi上下文 * @param hintContent 提示消息 */ public DoubleClickExitDetector(Context context, String hintContent) { this(context, hintContent, 2000); } /** * 创建一个双击退出识别器,中国环境下默认提示消息为“再按一次退出程序”,其它环境下默认提示消息为“Press again to exit the program”;有效间隔时间默认为2000毫秒 * @param context Androdi上下文 */ public DoubleClickExitDetector(Context context) { this(context,DEFAULT_HINT_MESSAGE_CHINA, 2000); } /** * 点击,你需要重写Activity的onBackPressed()方法,先调用此方法,如果返回true就执行父类的onBackPressed()方法来关闭Activity否则不执行 * @return 当两次点击时间间隔小于有效间隔时间时就会返回true,否则返回false */ public boolean click(){ long currentTime = System.currentTimeMillis(); boolean result = (currentTime-lastClickTime) < effectiveIntervalTime; lastClickTime = currentTime; if(!result){ ToastUtils.show(hintMessage); } Logger.d("result:"+result); return result; } /** * 设置有效间隔时间,单位毫秒 * @param effectiveIntervalTime 效间隔时间,单位毫秒。当两次点击时间间隔小于有效间隔时间click()方法就会返回true */ public void setEffectiveIntervalTime(int effectiveIntervalTime) { this.effectiveIntervalTime = effectiveIntervalTime; } /** * 设置提示消息 * @param hintMessage 当前点击同上次点击时间间隔大于有效间隔时间click()方法就会返回false,并且显示提示消息 */ public void setHintMessage(String hintMessage) { this.hintMessage = hintMessage; }}
阅读全文
1 0
- 双击点击退出页面工具
- 实现双击点击退出程序
- Android工具类之双击退出
- 在使用fragment的activity双击点击退出程序
- 禁止activity横屏,防止连续点击。双击退出
- Android双击退出及n次点击事件
- 双击退出
- 双击退出
- 双击退出
- 双击退出
- Silverlight页面点击按钮,退出应用程序
- 点击返回键:弹出退出的对话框和双击两次返回键,退出
- 工具类--点击返回按钮,退出
- jquery实现当前页面按钮点击全屏,点击退出全屏
- 点击弹出子页面GridView,双击选值后返回
- 双击退出、单击退出应用程序
- Notification点击跳转指定界面(APP被杀死或双击退出时唤醒,然后跳转)
- 双击回退键退出应用
- 通过Prompt实现JSBridge
- Java程序员必备的8个开发工具
- Mac 设置环境变量,并根据shell修改而修改变量的位置
- Spring的@PropertySource和@Value注解例子
- ViewCacheManager
- 双击点击退出页面工具
- 我们想把ixgbe-5.1.3和ixgbevf-4.1.2都编译进我们的内核
- Entity Framework Code First执行SQL语句、视图及存储过程
- R语言学习-一行/列转多行
- 来说说(Template Method )模版方法模式
- 以太坊 ETH各显卡算力表
- ZOJ Problem Set
- (转载)Eclipse快捷键 10个最有用的快捷键以及其他快捷用法
- Android 注解,实现动态绑定view