update:2021.01.27

fix:修复应用安装信息上传
add:时间管控,顶部app管控
This commit is contained in:
2021-01-27 16:11:05 +08:00
parent 5428846475
commit 32a61c38c3
29 changed files with 1579 additions and 306 deletions

View File

@@ -0,0 +1,172 @@
package com.info.sn.utils;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.info.sn.service.InitJpushServer;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class TimeUtils {
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 String getNowTime() {
long nowTime = System.currentTimeMillis();
DateFormat df = ContralTime.getDf();
return df.format(nowTime);
}
// public static boolean CurrentInTimeScope(ContralTime contralTime) {
// boolean result = true;
// final long aDayInMillis = 1000 * 60 * 60 * 24;
// long currentTimeMillis = System.currentTimeMillis();
//
// }
public static ContralTime String2ContralTime(Context context, @NonNull String timeText) {
DateFormat df = ContralTime.getDf();
String[] time = timeText.trim().split("-");
if (time.length != 2) {
throw new RuntimeException("Time format error!");
}
try {
SPUtils.put(context, START_TIME_KEY, time[0].trim());
SPUtils.put(context, END_TIME_KEY, time[1].trim());
Date startDate = df.parse(time[0].trim());
Date endDate = df.parse(time[1].trim());
ContralTime contralTime = new ContralTime();
// if (date1.getTime() < date2.getTime()) {
contralTime.setStartTime(df.format(startDate));
contralTime.setEndTime(df.format(endDate));
// } else {
// contralTime.setStartTime(df.format(date2));
// contralTime.setEndTime(df.format(date1));
// }
return contralTime;
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
public static ContralTime getDefaltContralTime(Context context) {
String startTime = (String) SPUtils.get(context, START_TIME_KEY, "00:00");
String endTime = (String) SPUtils.get(context, END_TIME_KEY, "00:00");
if (null == startTime || null == endTime || (startTime.equals("00:00") && endTime.equals("00:00"))) {
return null;
} else {
try {
Date startDate = df.parse(startTime.trim());
Date endDate = df.parse(endTime.trim());
ContralTime contralTime = new ContralTime();
contralTime.setStartTime(df.format(startDate));
contralTime.setEndTime(df.format(endDate));
return contralTime;
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
}
public static void setEmpty(Context context) {
SPUtils.put(context, START_TIME_KEY, "00:00");
SPUtils.put(context, END_TIME_KEY, "00:00");
Intent intent = new Intent();
intent.setAction(InitJpushServer.TimeChangedReceiver.ACTION_UPDATE);
context.sendBroadcast(intent);
}
public static class ContralTime {
//format HH:mm
static String startTime;
static String endTime;
public ContralTime() {
}
public ContralTime(String startT, String endT) {
startTime = startT;
endTime = endT;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startT) {
startTime = startT;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endT) {
endTime = endT;
}
public static DateFormat getDf() {
return df;
}
public static void setDf(DateFormat d) {
df = d;
}
public String getNowTimeString(long time) {
return df.format(new Date(time));
}
public boolean inControlTime(long time) {
return inControlTime(df.format(new Date(time)));
}
public boolean inControlTime(String time) {
if (TextUtils.isEmpty(time)) {
throw new RuntimeException("Time is empty");
} else {
if (!time.contains(":")) {
throw new RuntimeException("Time format error");
}
}
try {
Date startDate = df.parse(startTime);
Date endDate = df.parse(endTime);
Date nowDate = df.parse(time);
if (startDate.getTime() > endDate.getTime()) {
//开始时间大于结束时间 列 1600-0100
endDate.setTime(endDate.getTime() + dayTime);
}
if (nowDate.getTime() >= startDate.getTime() && nowDate.getTime() <= endDate.getTime()) {
return true;
} else {
return false;
}
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
@NonNull
@Override
public String toString() {
return startTime + "\t-\t" + endTime;
}
}
}