Skip to content

Commit

Permalink
优化部分工具类
Browse files Browse the repository at this point in the history
  • Loading branch information
xuexiangjys committed Aug 8, 2019
1 parent d1d24ca commit 6d1c7e1
Show file tree
Hide file tree
Showing 12 changed files with 573 additions and 58 deletions.
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
*.iml
.gradle
.idea
/LocalRepository
/keystores
/local.properties
/.idea/workspace.xml
/.idea/caches
/.idea/codeStyles
/.idea/inspectionProfiles
/.idea/libraries
/.idea/dictionaries
/.idea/markdown-navigator
/.idea/*.xml
.DS_Store
/build
/captures
.externalNativeBuild
.externalNativeBuild
7 changes: 7 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copyright/xuexiang.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright (C) 2019 xuexiangjys([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.xuexiang.xutil.app;

import android.app.Activity;
Expand Down Expand Up @@ -167,6 +184,10 @@ public void finishAllActivity() {
}
}

public Stack<Activity> getActivityStack() {
return mActivityStack;
}

/**
* 退出
*/
Expand Down
83 changes: 75 additions & 8 deletions xutil-core/src/main/java/com/xuexiang/xutil/common/ClickUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.xuexiang.xutil.common;

import android.os.SystemClock;
import android.view.View;

import com.xuexiang.xutil.XUtil;
Expand All @@ -25,11 +26,10 @@
import java.util.TimerTask;

/**
* <pre>
* desc : 快速点击工具类
* author : xuexiang
* time : 2018/4/23 下午2:45
* </pre>
* 快速点击工具类
*
* @author xuexiang
* @since 2019-08-08 16:35
*/
public final class ClickUtils {

Expand Down Expand Up @@ -80,6 +80,40 @@ public static boolean isFastDoubleClick(View v, long intervalMillis) {
}
}

//====================多次点击==========================//

private final static int COUNTS = 5;// 点击次数
private final static long DURATION = 1000;// 规定有效时间
private static long[] mHits = new long[COUNTS];

/**
* 连续点击
*
* @param listener
*/
public static void doClick(OnContinuousClickListener listener) {
//每次点击时,数组向前移动一位
System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
//为数组最后一位赋值
mHits[mHits.length - 1] = SystemClock.uptimeMillis();
if (mHits[0] >= (SystemClock.uptimeMillis() - DURATION)) {
mHits = new long[COUNTS];//重新初始化数组
if (listener != null) {
listener.onContinuousClick();
}
}
}

/**
* 多次点击的监听
*/
public interface OnContinuousClickListener {
/**
* 多次点击
*/
void onContinuousClick();
}

/**
* 双击退出函数
*/
Expand All @@ -89,18 +123,51 @@ public static boolean isFastDoubleClick(View v, long intervalMillis) {
* 双击返回退出程序
*/
public static void exitBy2Click() {
exitBy2Click(2000, null);
}

/**
* 双击返回退出程序
*
* @param intervalMillis 按键间隔
* @param listener 退出监听
*/
public static void exitBy2Click(long intervalMillis, OnClick2ExitListener listener) {
if (!sIsExit) {
sIsExit = true; // 准备退出
ToastUtils.toast("再按一次退出程序");
if (listener != null) {
listener.onRetry();
} else {
ToastUtils.toast("再按一次退出程序");
}
Timer tExit = new Timer();
tExit.schedule(new TimerTask() {
@Override
public void run() {
sIsExit = false; // 取消退出
}
}, 2000); // 如果2秒钟内没有按下返回键,则启动定时器取消掉刚才执行的任务
}, intervalMillis); // 如果2秒钟内没有按下返回键,则启动定时器取消掉刚才执行的任务
} else {
XUtil.get().exitApp();
if (listener != null) {
listener.onExit();
} else {
XUtil.get().exitApp();
}
}
}

/**
* 点击返回退出监听
*/
public interface OnClick2ExitListener {
/**
* 再点击一次
*/
void onRetry();

/**
* 退出
*/
void onExit();
}
}
Loading

0 comments on commit 6d1c7e1

Please sign in to comment.