version:1.0

fix:
update:更换包名
This commit is contained in:
2023-02-08 12:04:19 +08:00
parent f8b3d96ced
commit ace6008709
184 changed files with 689 additions and 7446 deletions

View File

@@ -0,0 +1,139 @@
package com.uiui.zyos.manager;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import com.tencent.mmkv.MMKV;
import com.uiui.zyos.utils.TimeUtils;
public class ConnectManager {
private static final String TAG = ConnectManager.class.getSimpleName();
public static final long ONE_MINUTES_TIME = 60 * 1000;
public static final long FIFTEEN_MINUTES_TIME = ONE_MINUTES_TIME * 15;
public static final long HALF_HOUR_TIME = FIFTEEN_MINUTES_TIME * 2;
public static final long ONE_HOUR_TIME = HALF_HOUR_TIME * 2;
public static final long SIX_HOUR_TIME = ONE_HOUR_TIME * 6;
public static final long HALF_DAY_TIME = SIX_HOUR_TIME * 2;
public static final long ONE_DAY_TIME = HALF_DAY_TIME * 2;
/*重启后连接成功的时间*/
public static final String REBOOT_LAST_ONNECT_TIME = "reboot_last_connect_time";
/*WiFi连接后连接成功的时间*/
public static final String WIFI_LAST_CONNECT_TIME = "WiFi_last_connect_time";
/*打开设备信息连接成功的时间*/
public static final String OPENINFO_LAST_ONNECT_TIME = "opneinfo_last_connect_time";
@SuppressLint("StaticFieldLeak")
private static ConnectManager sInstance;
private Context mContext;
private MMKV mMMKV = MMKV.defaultMMKV();
private ConnectManager(Context context) {
if (context == null) {
throw new RuntimeException("Context is NULL");
}
this.mContext = context;
}
public static void init(Context context) {
if (sInstance == null) {
Log.e(TAG, "init: ");
sInstance = new ConnectManager(context);
}
}
public static ConnectManager getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init ConnectManager first");
}
return sInstance;
}
public long getConnectModeTime(ConnectMode connectMode) {
long time = 0;
switch (connectMode) {
case DEFAULT:
time = 0;
break;
case ONE_MINUTE:
time = ONE_MINUTES_TIME;
break;
case FIFTEEN_MINUTES:
time = FIFTEEN_MINUTES_TIME;
break;
case HALF_HOUR:
time = HALF_HOUR_TIME;
break;
case ONE_HOUR:
time = ONE_HOUR_TIME;
break;
case SIX_HOUR:
time = SIX_HOUR_TIME;
break;
case HALF_DAY:
time = HALF_DAY_TIME;
break;
case ONE_DAY:
time = ONE_DAY_TIME;
break;
default:
}
return time;
}
public boolean isNeedConnect(String key, ConnectMode connectMode) {
long nowTime = System.currentTimeMillis();
long lastTime = mMMKV.decodeLong(key, 0);
long intervalTime = getConnectModeTime(connectMode);
//防止修改了时间一直返回false
if (lastTime > nowTime) {
return true;
}
//防止一分钟内重复请求
boolean refresh = nowTime - lastTime > intervalTime && nowTime - lastTime > ONE_MINUTES_TIME;
return refresh;
}
/**
* @return 重启后是否连接
*/
public boolean isRebootFistConnect() {
long rebootTime = mMMKV.decodeLong(REBOOT_LAST_ONNECT_TIME, 0);
//只在开机后15内连接其他情况为service重启
long time = System.currentTimeMillis() - rebootTime;
return time < 15 * 1000;
}
/**
* @return 今天WiFi连接是否有连接
*/
public boolean isWiFiFistConnect() {
long time = mMMKV.decodeLong(WIFI_LAST_CONNECT_TIME, 0);
return !TimeUtils.isTodayTime(time);
}
/**
* @return 今天打开设备信息后是否连接
*/
public boolean isOpenInfoFistConnect() {
long time = mMMKV.decodeLong(OPENINFO_LAST_ONNECT_TIME, 0);
return !TimeUtils.isTodayTime(time);
}
/**
* @param WiFiAlias
* @return 今天切换WiFi后是否连接
*/
public boolean isWiFiCutoverFistConnect(String WiFiAlias) {
long time = mMMKV.decodeLong(WiFiAlias, 0);
return !TimeUtils.isTodayTime(time);
}
}

View File

@@ -0,0 +1,12 @@
package com.uiui.zyos.manager;
public enum ConnectMode {
DEFAULT,
ONE_MINUTE,
FIFTEEN_MINUTES,
HALF_HOUR,
ONE_HOUR,
SIX_HOUR,
HALF_DAY,
ONE_DAY,
}

View File

@@ -0,0 +1,165 @@
package com.uiui.zyos.manager;
import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tencent.mmkv.MMKV;
import com.uiui.zyos.bean.MapBean;
import com.uiui.zyos.config.CommonConfig;
import com.uiui.zyos.disklrucache.CacheHelper;
import com.uiui.sn.IGetInfoInterface;
import java.lang.reflect.Type;
public class RemoteManager {
private static final String TAG = RemoteManager.class.getSimpleName();
@SuppressLint("StaticFieldLeak")
private static RemoteManager sInstance;
private Context mContext;
private MMKV mMMKV = MMKV.defaultMMKV();
private CacheHelper mCacheHelper;
private IGetInfoInterface getInfoInterface;
private ServiceConnection mIGetInfoConnection;
private RemoteManager(Context context) {
if (context == null) {
throw new RuntimeException("Context is NULL");
}
this.mContext = context;
this.mCacheHelper = new CacheHelper(context);
mIGetInfoConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.e(TAG, "onServiceConnected: mIGetInfoConnection");
getInfoInterface = IGetInfoInterface.Stub.asInterface(service);
getLocation();
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.e(TAG, "onServiceDisconnected: mIGetInfoConnection");
getInfoInterface = null;
bindInfoService();
}
};
bindInfoService();
}
public static void init(Context context) {
if (sInstance == null) {
Log.e(TAG, "init: ");
sInstance = new RemoteManager(context);
}
}
public static RemoteManager getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init RemoteManager first");
}
return sInstance;
}
private void bindInfoService() {
if (getInfoInterface == null) {
//这是连接aidl服务的代码
Intent intent = new Intent();
intent.setAction("com.uiui.sn.IGetInfoInterface");
intent.setPackage("com.uiui.sn");
intent.setComponent(new ComponentName("com.uiui.sn", "com.uiui.sn.service.RemoteService"));
mContext.bindService(intent, mIGetInfoConnection, Context.BIND_AUTO_CREATE);
}
}
public void getLocation() {
if (getInfoInterface != null) {
try {
String jsonString = getInfoInterface.getMapResult();
mMMKV.encode(CommonConfig.MAP_LOCATION_JSON_KEY, jsonString);
} catch (Exception e) {
Log.e(TAG, "getMapResult: " + e.getMessage());
}
} else {
bindInfoService();
}
}
public MapBean getMapBean() {
String jsonString = mMMKV.decodeString(CommonConfig.MAP_LOCATION_JSON_KEY);
if (TextUtils.isEmpty(jsonString)) {
return null;
} else {
Gson gson = new Gson();
Type type = new TypeToken<MapBean>() {
}.getType();
MapBean mapBean = gson.fromJson(jsonString, type);
mMMKV.encode(CommonConfig.MAP_ADDRESS_KEY, mapBean.getAddress() + mapBean.getLocationDescribe());
mMMKV.encode(CommonConfig.MAP_LONGITUDE_KEY, mapBean.getLongitude());
mMMKV.encode(CommonConfig.MAP_LATITUDE_KEY, mapBean.getLatitude());
return mapBean;
}
}
public String getCity() {
MapBean mapBean = getMapBean();
if (mapBean == null) {
getLocation();
return "北京";
} else {
return mapBean.getCity();
}
}
public String getCityDistrict() {
MapBean mapBean = getMapBean();
if (mapBean == null) {
getLocation();
return "北京";
} else {
return mapBean.getCity() + "\t" + mapBean.getDistrict();
}
}
public double getLongitude() {
MapBean mapBean = getMapBean();
if (mapBean == null) {
getLocation();
return 0.0;
} else {
return mapBean.getLongitude();
}
}
public double getLatitude() {
MapBean mapBean = getMapBean();
if (mapBean == null) {
getLocation();
return 0.0;
} else {
return mapBean.getLatitude();
}
}
public String getLocationTude() {
MapBean mapBean = getMapBean();
if (mapBean == null) {
getLocation();
return "0.0";
} else {
return mapBean.getLongitude() + "," + mapBean.getLatitude();
}
}
}