version:1.4
update:2021-10-21 10:14:40 fix: add:增加浏览器桌面检测升级,修复重复请求
This commit is contained in:
@@ -6,8 +6,10 @@ import android.content.Intent;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import com.aoleyun.sn.bean.PoweroffBean;
|
||||
import com.aoleyun.sn.service.MainService;
|
||||
|
||||
import java.text.DateFormat;
|
||||
@@ -20,10 +22,12 @@ import java.util.Date;
|
||||
* 时间管控工具类
|
||||
*/
|
||||
public class TimeUtils {
|
||||
private static final String TAG = TimeUtils.class.getSimpleName();
|
||||
private static DateFormat df = new SimpleDateFormat("HH:mm");
|
||||
public static final String START_TIME_KEY = "START_TIME";
|
||||
public static final String END_TIME_KEY = "END_TIME";
|
||||
public static long dayTime = 60 * 60 * 24 * 1000;
|
||||
public static long minuteTime = 60 * 1000;
|
||||
|
||||
public static String getNowTime() {
|
||||
long nowTime = System.currentTimeMillis();
|
||||
@@ -38,6 +42,64 @@ public class TimeUtils {
|
||||
//
|
||||
// }
|
||||
|
||||
public static boolean isShutdownTime(PoweroffBean poweroffBean) {
|
||||
int type = poweroffBean.getType();
|
||||
if (type == 1) { //单次定时关机
|
||||
return isShutdownTime(poweroffBean.getTime());
|
||||
} else if (type == 2) {//循环定时关机
|
||||
return isShutdownTime(getZeroTiemstamp() + getLoopTime(poweroffBean.getTime()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static long getZeroTiemstamp() {
|
||||
long nowTime = System.currentTimeMillis();
|
||||
long dayMillisecond = 60 * 60 * 24 * 1000;
|
||||
long zeroTime = ((nowTime) / dayMillisecond) * dayMillisecond;
|
||||
Log.e(TAG, "getZeroTiemstamp: " + zeroTime);
|
||||
return zeroTime;
|
||||
}
|
||||
|
||||
private static long getLoopTime(String timestamp) {
|
||||
//"15:34:39"
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
try {
|
||||
Date d = sdf.parse(timestamp);
|
||||
long loopTime = d.getTime();
|
||||
Log.e(TAG, "getLoopTime: LoopTime = " + loopTime);
|
||||
return loopTime;
|
||||
} catch (ParseException e) {
|
||||
Log.e(TAG, "getLoopTime: e: " + e.getStackTrace());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isShutdownTime(String timestamp) {
|
||||
//"2021-11-18 00:00:00"
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
try {
|
||||
Date d = sdf.parse(timestamp);
|
||||
long realTime = d.getTime();
|
||||
return isShutdownTime(realTime);
|
||||
} catch (ParseException e) {
|
||||
Log.e(TAG, "isShutdownTime: " + e.getStackTrace());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isShutdownTime(long timestamp) {
|
||||
long realTime = timestamp;
|
||||
long nowTime = System.currentTimeMillis();
|
||||
if (String.valueOf(timestamp).length() < String.valueOf(nowTime).length()) {
|
||||
realTime = timestamp * 1000;
|
||||
}
|
||||
if (realTime >= nowTime && realTime <= (nowTime + 1000 * 60)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static ContralTime String2ContralTime(Context context, @NonNull String timeText) {
|
||||
DateFormat df = ContralTime.getDf();
|
||||
String[] time = timeText.trim().split("-");
|
||||
@@ -157,7 +219,9 @@ public class TimeUtils {
|
||||
//开始时间大于结束时间 列 16:00-01:00
|
||||
endDate.setTime(endDate.getTime() + dayTime);
|
||||
}
|
||||
if (nowDate.getTime() >= startDate.getTime() && nowDate.getTime() <= endDate.getTime()) {
|
||||
Log.e(TAG, "inControlTime: " + (startDate.getTime() - minuteTime));
|
||||
assert nowDate != null;
|
||||
if (nowDate.getTime() <= startDate.getTime() - minuteTime || nowDate.getTime() >= endDate.getTime()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user