init
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.uiuipad.find;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
|
||||
assertEquals("com.uiuipad.find", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
134
app/src/main/AndroidManifest.xml
Normal file
134
app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,134 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.uiuipad.find"
|
||||
android:sharedUserId="android.uid.system">
|
||||
|
||||
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.MASTER_CLEAR" />
|
||||
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.ACTION_SCREEN_ON" />
|
||||
<uses-permission android:name="android.permission.ACTION_SCREEN_OFF" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
||||
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
|
||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.GET_TASKS" />
|
||||
<uses-permission android:name="android.permission.REORDER_TASKS" />
|
||||
|
||||
|
||||
<!-- 百度 -->
|
||||
|
||||
<!-- 这个权限用于进行网络定位 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<!-- 这个权限用于访问GPS定位 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<!-- 用于访问wifi网络信息,wifi信息会用于进行网络定位 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<!-- 获取运营商信息,用于支持提供运营商信息相关的接口 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<!-- 这个权限用于获取wifi的获取权限,wifi信息会用来进行网络定位 -->
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<!-- 写入扩展存储,向扩展卡写入数据,用于写入离线定位数据 -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<!-- 访问网络,网络定位需要上网 -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!-- 允许挂载和反挂载文件系统可移动存储 -->
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
|
||||
<!-- 允许程序读取底层系统日志文件 -->
|
||||
<uses-permission android:name="android.permission.READ_LOGS" />
|
||||
<!-- 允许访问振动设备 -->
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<!-- 允许使用PowerManager的 WakeLocks保持进程在休眠时从屏幕消失 -->
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<!-- 允许程序读取或写入系统设置 -->
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
<!-- android 9.0上使用前台服务,需要添加权限 -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<!-- 用于读取手机当前的状态 -->
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<!-- 读取缓存数据 -->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<!-- 获取模拟定位信息 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
|
||||
<uses-permission
|
||||
android:name="android.permission.PACKAGE_USAGE_STATS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
|
||||
|
||||
<application
|
||||
android:name=".base.BaseApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".activity.MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
|
||||
<!-- 声明service组件 -->
|
||||
<service
|
||||
android:name="com.baidu.location.f"
|
||||
android:enabled="true"
|
||||
android:process=":remote" />
|
||||
|
||||
<!-- 消息接收监听器 (用户可自主扩展) -->
|
||||
<receiver
|
||||
android:name=".push.alipush.AliyunMessageReceiver"
|
||||
android:exported="false"> <!-- 为保证receiver安全,建议设置不可导出,如需对其他应用开放可通过android:permission进行限制 -->
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.push2.action.NOTIFICATION_OPENED" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.push2.action.NOTIFICATION_REMOVED" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.sdk.android.push.RECEIVE" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name=".push.alipush.AliMessageIntentService"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.push2.action.NOTIFICATION_OPENED" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.push2.action.NOTIFICATION_REMOVED" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.sdk.android.push.RECEIVE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<!-- 请填写你自己的- appKey -->
|
||||
<meta-data
|
||||
android:name="com.alibaba.app.appkey"
|
||||
android:value="333853534" />
|
||||
<!-- 请填写你自己的appSecret -->
|
||||
<meta-data
|
||||
android:name="com.alibaba.app.appsecret"
|
||||
android:value="a5ebaf63c0d74b3dbd470e419cac7f05" />
|
||||
|
||||
<!-- AK鉴权 -->
|
||||
<meta-data
|
||||
android:name="com.baidu.lbsapi.API_KEY"
|
||||
android:value="rAN40nR4GDgBBbm5C5xbjasptzyMKTSS" />
|
||||
<!-- http://lbsyun.baidu.com/apiconsole/key -->
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.uiuipad.find.activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.uiuipad.find.R;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
129
app/src/main/java/com/uiuipad/find/base/BaseActivity.java
Normal file
129
app/src/main/java/com/uiuipad/find/base/BaseActivity.java
Normal file
@@ -0,0 +1,129 @@
|
||||
package com.uiuipad.find.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.ContentView;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.trello.rxlifecycle4.LifecycleProvider;
|
||||
import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
|
||||
import com.uiuipad.find.R;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity implements LifecycleProvider<ActivityEvent> {
|
||||
public final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
|
||||
|
||||
public BaseActivity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@ContentView
|
||||
public BaseActivity(@LayoutRes int contentLayoutId) {
|
||||
super(contentLayoutId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final Observable<ActivityEvent> lifecycle() {
|
||||
return lifecycleSubject.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull ActivityEvent event) {
|
||||
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindToLifecycle() {
|
||||
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
// StatusBarUtil.init(this);
|
||||
UltimateBarX.statusBar(this)
|
||||
.transparent()
|
||||
.colorRes(R.color.colorPrimaryDark)
|
||||
// .light(true)
|
||||
.apply();
|
||||
UltimateBarX.navigationBar(this)
|
||||
.transparent()
|
||||
.colorRes(R.color.colorPrimaryDark)
|
||||
// .light(true)
|
||||
.apply();
|
||||
setContentView(this.getLayoutId());
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置布局
|
||||
*/
|
||||
public abstract int getLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
public abstract void initView();
|
||||
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
public abstract void initData();
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
lifecycleSubject.onNext(ActivityEvent.START);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
lifecycleSubject.onNext(ActivityEvent.RESUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onPause() {
|
||||
lifecycleSubject.onNext(ActivityEvent.PAUSE);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStop() {
|
||||
lifecycleSubject.onNext(ActivityEvent.STOP);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onDestroy() {
|
||||
lifecycleSubject.onNext(ActivityEvent.DESTROY);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
123
app/src/main/java/com/uiuipad/find/base/BaseApplication.java
Normal file
123
app/src/main/java/com/uiuipad/find/base/BaseApplication.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package com.uiuipad.find.base;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.sdk.android.push.CloudPushService;
|
||||
import com.alibaba.sdk.android.push.CommonCallback;
|
||||
import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiuipad.find.BuildConfig;
|
||||
import com.uiuipad.find.manager.MapManager;
|
||||
import com.uiuipad.find.push.PushManager;
|
||||
import com.uiuipad.find.util.Utils;
|
||||
|
||||
public class BaseApplication extends Application {
|
||||
private static final String TAG = BaseApplication.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (!BuildConfig.DEBUG) {
|
||||
catchException();
|
||||
}
|
||||
String rootDir = MMKV.initialize(this);
|
||||
Log.i(TAG, "mmkv root: " + rootDir);
|
||||
|
||||
PushManager.init(this);
|
||||
MapManager.init(this);
|
||||
aliyunPushInit();
|
||||
}
|
||||
|
||||
private void catchException() {
|
||||
Thread.setDefaultUncaughtExceptionHandler(
|
||||
new Thread.UncaughtExceptionHandler() {
|
||||
@Override
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
Log.e("捕获异常子线程:", Thread.currentThread().getName() +
|
||||
"在:" + e.getStackTrace()[0].getClassName());
|
||||
}
|
||||
}
|
||||
);
|
||||
//下面是新增方法!
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
Looper.loop(); //会先执行这个方法,然后在执行下面的异常捕获方法!
|
||||
} catch (Exception e) {
|
||||
Log.e("捕获异常主线程:", Thread.currentThread().getName() +
|
||||
"在:" + e.getStackTrace()[0].getClassName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void aliyunPushInit() {
|
||||
PushServiceFactory.init(this);
|
||||
final CloudPushService pushService = PushServiceFactory.getCloudPushService();
|
||||
pushService.setLogLevel(CloudPushService.LOG_DEBUG);
|
||||
pushService.register(this, new CommonCallback() {
|
||||
@Override
|
||||
public void onSuccess(String response) {
|
||||
Log.e("AliyunPush", "init cloudchannel success");
|
||||
Log.e("AliyunPush", "init cloudchannel success " + pushService.getDeviceId());
|
||||
String sn = Utils.getSerial();
|
||||
Log.e(TAG, "AliyunPush: sn=" + sn);
|
||||
if (TextUtils.isEmpty(sn)) {
|
||||
return;
|
||||
}
|
||||
pushService.bindAccount(sn, new CommonCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s) {
|
||||
Log.e("AliyunPush", "bind account " + sn + " success\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(String errorCode, String errorMsg) {
|
||||
Log.e("AliyunPush", "bind account " + sn + " failed." +
|
||||
"errorCode: " + errorCode + ", errorMsg:" + errorMsg);
|
||||
}
|
||||
});
|
||||
pushService.addAlias(sn, new CommonCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s) {
|
||||
Log.e("AliyunPush", "add alias " + sn + " success\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(String errorCode, String errorMsg) {
|
||||
Log.e("AliyunPush", "add alias " + sn + " failed." +
|
||||
"errorCode: " + errorCode + ", errorMsg:" + errorMsg + "\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(String errorCode, String errorMessage) {
|
||||
Log.e("AliyunPush", "init cloudchannel failed -- errorcode:" + errorCode + " -- errorMessage:" + errorMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrimMemory(int level) {
|
||||
super.onTrimMemory(level);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.uiuipad.find.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.ContentView;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.trello.rxlifecycle4.LifecycleProvider;
|
||||
import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
|
||||
public abstract class BaseLifecycleActivity extends AppCompatActivity implements LifecycleProvider<ActivityEvent> {
|
||||
public final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
|
||||
|
||||
public BaseLifecycleActivity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@ContentView
|
||||
public BaseLifecycleActivity(@LayoutRes int contentLayoutId) {
|
||||
super(contentLayoutId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final Observable<ActivityEvent> lifecycle() {
|
||||
return lifecycleSubject.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull ActivityEvent event) {
|
||||
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindToLifecycle() {
|
||||
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
setContentView(this.getLayoutId());
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置布局
|
||||
*/
|
||||
public abstract int getLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
public abstract void initView();
|
||||
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
public abstract void initData();
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
lifecycleSubject.onNext(ActivityEvent.START);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
lifecycleSubject.onNext(ActivityEvent.RESUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onPause() {
|
||||
lifecycleSubject.onNext(ActivityEvent.PAUSE);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStop() {
|
||||
lifecycleSubject.onNext(ActivityEvent.STOP);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onDestroy() {
|
||||
lifecycleSubject.onNext(ActivityEvent.DESTROY);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
129
app/src/main/java/com/uiuipad/find/base/BaseLightActivity.java
Normal file
129
app/src/main/java/com/uiuipad/find/base/BaseLightActivity.java
Normal file
@@ -0,0 +1,129 @@
|
||||
package com.uiuipad.find.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.ContentView;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.trello.rxlifecycle4.LifecycleProvider;
|
||||
import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
|
||||
import com.uiuipad.find.R;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
|
||||
public abstract class BaseLightActivity extends AppCompatActivity implements LifecycleProvider<ActivityEvent> {
|
||||
public final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
|
||||
|
||||
public BaseLightActivity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@ContentView
|
||||
public BaseLightActivity(@LayoutRes int contentLayoutId) {
|
||||
super(contentLayoutId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final Observable<ActivityEvent> lifecycle() {
|
||||
return lifecycleSubject.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull ActivityEvent event) {
|
||||
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindToLifecycle() {
|
||||
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
// StatusBarUtil.init(this);
|
||||
UltimateBarX.statusBar(this)
|
||||
.transparent()
|
||||
.colorRes(R.color.colorPrimaryDark)
|
||||
.light(true)
|
||||
.apply();
|
||||
UltimateBarX.navigationBar(this)
|
||||
.transparent()
|
||||
.colorRes(R.color.colorPrimaryDark)
|
||||
.light(true)
|
||||
.apply();
|
||||
setContentView(this.getLayoutId());
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置布局
|
||||
*/
|
||||
public abstract int getLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
public abstract void initView();
|
||||
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
public abstract void initData();
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
lifecycleSubject.onNext(ActivityEvent.START);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
lifecycleSubject.onNext(ActivityEvent.RESUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onPause() {
|
||||
lifecycleSubject.onNext(ActivityEvent.PAUSE);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStop() {
|
||||
lifecycleSubject.onNext(ActivityEvent.STOP);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onDestroy() {
|
||||
lifecycleSubject.onNext(ActivityEvent.DESTROY);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.uiuipad.find.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.ContentView;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.trello.rxlifecycle4.LifecycleProvider;
|
||||
import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
public abstract class BaseLightLifecycleActivity extends AppCompatActivity implements LifecycleProvider<ActivityEvent> {
|
||||
public final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
|
||||
|
||||
public BaseLightLifecycleActivity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@ContentView
|
||||
public BaseLightLifecycleActivity(@LayoutRes int contentLayoutId) {
|
||||
super(contentLayoutId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final Observable<ActivityEvent> lifecycle() {
|
||||
return lifecycleSubject.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull ActivityEvent event) {
|
||||
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindToLifecycle() {
|
||||
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
setContentView(this.getLayoutId());
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置布局
|
||||
*/
|
||||
public abstract int getLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
public abstract void initView();
|
||||
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
public abstract void initData();
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
lifecycleSubject.onNext(ActivityEvent.START);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
lifecycleSubject.onNext(ActivityEvent.RESUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onPause() {
|
||||
lifecycleSubject.onNext(ActivityEvent.PAUSE);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStop() {
|
||||
lifecycleSubject.onNext(ActivityEvent.STOP);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onDestroy() {
|
||||
lifecycleSubject.onNext(ActivityEvent.DESTROY);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.uiuipad.find.base;
|
||||
|
||||
public interface BasePresenter<V extends BaseView> {
|
||||
void attachView(V view);
|
||||
|
||||
void detachView();
|
||||
}
|
||||
4
app/src/main/java/com/uiuipad/find/base/BaseView.java
Normal file
4
app/src/main/java/com/uiuipad/find/base/BaseView.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.uiuipad.find.base;
|
||||
|
||||
public interface BaseView {
|
||||
}
|
||||
145
app/src/main/java/com/uiuipad/find/bean/MapBean.java
Normal file
145
app/src/main/java/com/uiuipad/find/bean/MapBean.java
Normal file
@@ -0,0 +1,145 @@
|
||||
package com.uiuipad.find.bean;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class MapBean implements Serializable {
|
||||
private static final long serialVersionUID = -4356064111098876676L;
|
||||
|
||||
double longitude;
|
||||
double latitude;
|
||||
String adcode;
|
||||
String address;
|
||||
String city;
|
||||
String cityCode;
|
||||
String country;
|
||||
String countryCode;
|
||||
String district;
|
||||
String province;
|
||||
String street;
|
||||
String streetNumber;
|
||||
String town;
|
||||
String locationDescribe;
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public String getAdcode() {
|
||||
return adcode;
|
||||
}
|
||||
|
||||
public void setAdcode(String adcode) {
|
||||
this.adcode = adcode;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getCityCode() {
|
||||
return cityCode;
|
||||
}
|
||||
|
||||
public void setCityCode(String cityCode) {
|
||||
this.cityCode = cityCode;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getCountryCode() {
|
||||
return countryCode;
|
||||
}
|
||||
|
||||
public void setCountryCode(String countryCode) {
|
||||
this.countryCode = countryCode;
|
||||
}
|
||||
|
||||
public String getDistrict() {
|
||||
return district;
|
||||
}
|
||||
|
||||
public void setDistrict(String district) {
|
||||
this.district = district;
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getStreetNumber() {
|
||||
return streetNumber;
|
||||
}
|
||||
|
||||
public void setStreetNumber(String streetNumber) {
|
||||
this.streetNumber = streetNumber;
|
||||
}
|
||||
|
||||
public String getTown() {
|
||||
return town;
|
||||
}
|
||||
|
||||
public void setTown(String town) {
|
||||
this.town = town;
|
||||
}
|
||||
|
||||
public String getLocationDescribe() {
|
||||
return locationDescribe;
|
||||
}
|
||||
|
||||
public void setLocationDescribe(String locationDescribe) {
|
||||
this.locationDescribe = locationDescribe;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
11
app/src/main/java/com/uiuipad/find/comm/CommonConfig.java
Normal file
11
app/src/main/java/com/uiuipad/find/comm/CommonConfig.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.uiuipad.find.comm;
|
||||
|
||||
public class CommonConfig {
|
||||
public static final String MMKV_ID = "InterProcessKV";
|
||||
|
||||
public static final String MAP_LOCATION_JSON_KEY = "MAPLOCATION_JSON_STRING";
|
||||
public static final String MAP_LONGITUDE_KEY = "map_longitude_key";
|
||||
public static final String MAP_LATITUDE_KEY = "map_latitude_key";
|
||||
public static final String MAP_ADDRESS_KEY = "map_address_key";
|
||||
public static final String MAP_ERROR_KEY = "map_error_key";
|
||||
}
|
||||
144
app/src/main/java/com/uiuipad/find/gson/GsonUtils.java
Normal file
144
app/src/main/java/com/uiuipad/find/gson/GsonUtils.java
Normal file
@@ -0,0 +1,144 @@
|
||||
package com.uiuipad.find.gson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class GsonUtils {
|
||||
//https://blog.csdn.net/zte1055889498/article/details/122400299
|
||||
|
||||
public static JsonObject getJsonObject(String jsonString) {
|
||||
JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
private static final Gson gson;
|
||||
|
||||
static {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
builder.registerTypeAdapterFactory(new NullStringToEmptyAdapterFactory());
|
||||
builder.registerTypeAdapter(Integer.class, new IntegerDefault0Adapter());
|
||||
builder.registerTypeAdapter(int.class, new IntegerDefault0Adapter());
|
||||
builder.disableHtmlEscaping();
|
||||
builder.enableComplexMapKeySerialization();
|
||||
// builder.excludeFieldsWithoutExposeAnnotation();
|
||||
builder.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
gson = builder.create();
|
||||
}
|
||||
|
||||
public static Type makeJavaType(Type rawType, Type... typeArguments) {
|
||||
return TypeToken.getParameterized(rawType, typeArguments).getType();
|
||||
}
|
||||
|
||||
public static String toString(Object value) {
|
||||
if (Objects.isNull(value)) {
|
||||
return null;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return (String) value;
|
||||
}
|
||||
return toJSONString(value);
|
||||
}
|
||||
|
||||
public static String toJSONString(Object value) {
|
||||
return gson.toJson(value);
|
||||
}
|
||||
|
||||
public static String toPrettyString(Object value) {
|
||||
return gson.newBuilder().setPrettyPrinting().create().toJson(value);
|
||||
}
|
||||
|
||||
public static JsonElement fromJavaObject(Object value) {
|
||||
JsonElement result = null;
|
||||
if (Objects.nonNull(value) && (value instanceof String)) {
|
||||
result = parseObject((String) value);
|
||||
} else {
|
||||
result = gson.toJsonTree(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static JsonElement parseObject(String content) {
|
||||
return JsonParser.parseString(content);
|
||||
}
|
||||
|
||||
public static JsonElement getJsonElement(JsonObject node, String name) {
|
||||
return node.get(name);
|
||||
}
|
||||
|
||||
public static JsonElement getJsonElement(JsonArray node, int index) {
|
||||
return node.get(index);
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(JsonElement node, Class<T> clazz) {
|
||||
return gson.fromJson(node, clazz);
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(JsonElement node, Type type) {
|
||||
return gson.fromJson(node, type);
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(JsonElement node, TypeToken<?> typeToken) {
|
||||
return toJavaObject(node, typeToken.getType());
|
||||
}
|
||||
|
||||
public static <E> List<E> toJavaList(JsonElement node, Class<E> clazz) {
|
||||
return toJavaObject(node, makeJavaType(List.class, clazz));
|
||||
}
|
||||
|
||||
public static List<Object> toJavaList(JsonElement node) {
|
||||
return toJavaObject(node, new TypeToken<List<Object>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public static <V> Map<String, V> toJavaMap(JsonElement node, Class<V> clazz) {
|
||||
return toJavaObject(node, makeJavaType(Map.class, String.class, clazz));
|
||||
}
|
||||
|
||||
public static Map<String, Object> toJavaMap(JsonElement node) {
|
||||
return toJavaObject(node, new TypeToken<Map<String, Object>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(String content, Class<T> clazz) {
|
||||
JsonObject jsonObject = getJsonObject(content);
|
||||
String jsonString = jsonObject.toString();
|
||||
return gson.fromJson(jsonString, clazz);
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(String content, Type type) {
|
||||
return gson.fromJson(content, type);
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(String content, TypeToken<?> typeToken) {
|
||||
return toJavaObject(content, typeToken.getType());
|
||||
}
|
||||
|
||||
public static <E> List<E> toJavaList(String content, Class<E> clazz) {
|
||||
return toJavaObject(content, makeJavaType(List.class, clazz));
|
||||
}
|
||||
|
||||
public static List<Object> toJavaList(String content) {
|
||||
return toJavaObject(content, new TypeToken<List<Object>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public static <V> Map<String, V> toJavaMap(String content, Class<V> clazz) {
|
||||
return toJavaObject(content, makeJavaType(Map.class, String.class, clazz));
|
||||
}
|
||||
|
||||
public static Map<String, Object> toJavaMap(String content) {
|
||||
return toJavaObject(content, new TypeToken<Map<String, Object>>() {
|
||||
}.getType());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.uiuipad.find.gson;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class IntegerDefault0Adapter implements JsonSerializer<Integer>, JsonDeserializer<Integer> {
|
||||
@Override
|
||||
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
try {
|
||||
if (json.getAsString().equals("")) {
|
||||
return 0;
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
try {
|
||||
return json.getAsInt();
|
||||
} catch (NumberFormatException e) {
|
||||
throw new JsonSyntaxException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.uiuipad.find.gson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.TypeAdapterFactory;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class NullStringToEmptyAdapterFactory<T> implements TypeAdapterFactory {
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||
|
||||
Class<T> rawType = (Class<T>) type.getRawType();
|
||||
if (rawType != String.class) {
|
||||
return null;
|
||||
}
|
||||
return (TypeAdapter<T>) new StringAdapter();
|
||||
}
|
||||
|
||||
public static class StringAdapter extends TypeAdapter<String> {
|
||||
@Override
|
||||
public String read(JsonReader reader) throws IOException {
|
||||
if (reader.peek() == JsonToken.NULL) {
|
||||
reader.nextNull();
|
||||
return "";
|
||||
}
|
||||
return reader.nextString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter writer, String value) throws IOException {
|
||||
if (value == null) {
|
||||
writer.nullValue();
|
||||
return;
|
||||
}
|
||||
writer.value(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
222
app/src/main/java/com/uiuipad/find/manager/MapManager.java
Normal file
222
app/src/main/java/com/uiuipad/find/manager/MapManager.java
Normal file
@@ -0,0 +1,222 @@
|
||||
package com.uiuipad.find.manager;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.location.BDAbstractLocationListener;
|
||||
import com.baidu.location.BDLocation;
|
||||
import com.baidu.location.LocationClient;
|
||||
import com.baidu.location.LocationClientOption;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiuipad.find.bean.MapBean;
|
||||
import com.uiuipad.find.comm.CommonConfig;
|
||||
import com.uiuipad.find.gson.GsonUtils;
|
||||
|
||||
public class MapManager {
|
||||
private static final String TAG = MapManager.class.getSimpleName();
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static MapManager sInstance;
|
||||
private Context mContext;
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private LocationClient mLocationClient = null;
|
||||
private LocationClientOption mOption;
|
||||
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private MapManager(Context context) {
|
||||
this.mContext = context;
|
||||
Settings.Secure.putString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+gps");
|
||||
initAmap();
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("Context is NULL");
|
||||
}
|
||||
if (sInstance == null) {
|
||||
sInstance = new MapManager(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static MapManager getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init MapManager first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void initAmap() {
|
||||
if (mLocationClient == null) {
|
||||
mLocationClient = new LocationClient(mContext);
|
||||
}
|
||||
Settings.Secure.putString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+gps");
|
||||
mLocationClient.setLocOption(getDefaultLocationClientOption());
|
||||
mLocationClient.registerLocationListener(mListener);
|
||||
mLocationClient.stop();
|
||||
mLocationClient.start();
|
||||
}
|
||||
|
||||
public LocationClient getLocationClient() {
|
||||
if (mLocationClient == null) {
|
||||
initAmap();
|
||||
}
|
||||
return mLocationClient;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @return DefaultLocationClientOption 默认O设置
|
||||
*/
|
||||
public LocationClientOption getDefaultLocationClientOption() {
|
||||
if (mOption == null) {
|
||||
mOption = new LocationClientOption();
|
||||
mOption.setCoorType("bd09ll"); // 可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
|
||||
mOption.setScanSpan(0); // 可选,默认0,即仅定位一次,设置发起连续定位请求的间隔需要大于等于1000ms才是有效的
|
||||
mOption.setIsNeedAddress(true); // 可选,设置是否需要地址信息,默认不需要
|
||||
mOption.setIsNeedLocationDescribe(true); // 可选,设置是否需要地址描述
|
||||
mOption.setNeedDeviceDirect(false); // 可选,设置是否需要设备方向结果
|
||||
mOption.setLocationNotify(false); // 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
|
||||
mOption.setIgnoreKillProcess(true); // 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop
|
||||
mOption.setIsNeedLocationDescribe(true); // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation
|
||||
mOption.setIsNeedLocationPoiList(true); // 可选,默认false,设置是否需要POI结果,可以在BDLocation
|
||||
mOption.SetIgnoreCacheException(false); // 可选,默认false,设置是否收集CRASH信息,默认收集
|
||||
mOption.setLocationMode(LocationClientOption.LocationMode.Battery_Saving); // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备,模糊
|
||||
mOption.setIsNeedAltitude(false); // 可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用
|
||||
// 可选,设置首次定位时选择定位速度优先还是定位准确性优先,默认为速度优先
|
||||
// mOption.setFirstLocType(LocationClientOption.FirstLocType.SPEED_IN_FIRST_LOC);
|
||||
}
|
||||
return mOption;
|
||||
}
|
||||
|
||||
/*****
|
||||
*
|
||||
* 定位结果回调,重写onReceiveLocation方法,可以直接拷贝如下代码到自己工程中修改
|
||||
*
|
||||
*/
|
||||
private BDAbstractLocationListener mListener = new BDAbstractLocationListener() {
|
||||
|
||||
/**
|
||||
* 定位请求回调函数
|
||||
* @param location 定位结果
|
||||
*/
|
||||
@Override
|
||||
public void onReceiveLocation(BDLocation location) {
|
||||
if (null != location) {
|
||||
switch (location.getLocType()) {
|
||||
case BDLocation.TypeGpsLocation:// GPS定位结果
|
||||
case BDLocation.TypeNetWorkLocation:// 网络定位结果
|
||||
case BDLocation.TypeOffLineLocation:// 离线定位结果
|
||||
Log.e(TAG, "onLocationChanged: " + "定位成功");
|
||||
Log.e(TAG, "onLocationChanged: longitude = " + location.getLongitude());
|
||||
Log.e(TAG, "onLocationChanged: latitude = " + location.getLatitude());
|
||||
Log.e(TAG, "onLocationChanged: " + location.getAddrStr() + location.getLocationDescribe());
|
||||
mMMKV.encode(CommonConfig.MAP_ADDRESS_KEY, location.getAddrStr() + location.getLocationDescribe());
|
||||
mMMKV.encode(CommonConfig.MAP_LONGITUDE_KEY, location.getLongitude());
|
||||
mMMKV.encode(CommonConfig.MAP_LATITUDE_KEY, location.getLatitude());
|
||||
mMMKV.encode(CommonConfig.MAP_ERROR_KEY, "-");
|
||||
saveMapResult(location);
|
||||
break;
|
||||
case BDLocation.TypeServerError:
|
||||
Log.e(TAG, "onReceiveLocation: " + "服务端网络定位失败");
|
||||
mMMKV.encode(CommonConfig.MAP_ERROR_KEY, "服务端网络定位失败,可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com,会有人追查原因");
|
||||
break;
|
||||
case BDLocation.TypeNetWorkException:
|
||||
Log.e(TAG, "onReceiveLocation: " + "网络不同导致定位失败,请检查网络是否通畅");
|
||||
mMMKV.encode(CommonConfig.MAP_ERROR_KEY, "网络不同导致定位失败,请检查网络是否通畅");
|
||||
break;
|
||||
case BDLocation.TypeCriteriaException:
|
||||
Log.e(TAG, "onReceiveLocation: " + "无法获取有效定位依据导致定位失败");
|
||||
mMMKV.encode(CommonConfig.MAP_ERROR_KEY, "无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
Log.e(TAG, "AmapAddress: " + mMMKV.decodeString(CommonConfig.MAP_ADDRESS_KEY, "-"));
|
||||
Log.e(TAG, "AmapError: " + mMMKV.decodeString(CommonConfig.MAP_ERROR_KEY, "-"));
|
||||
Settings.Secure.putString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-network");
|
||||
Settings.Secure.putString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-gps");
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.ASSISTED_GPS_ENABLED, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectHotSpotMessage(String s, int i) {
|
||||
super.onConnectHotSpotMessage(s, i);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调定位诊断信息,开发者可以根据相关信息解决定位遇到的一些问题
|
||||
* @param locType 当前定位类型
|
||||
* @param diagnosticType 诊断类型(1~9)
|
||||
* @param diagnosticMessage 具体的诊断信息释义
|
||||
*/
|
||||
@Override
|
||||
public void onLocDiagnosticMessage(int locType, int diagnosticType, String diagnosticMessage) {
|
||||
super.onLocDiagnosticMessage(locType, diagnosticType, diagnosticMessage);
|
||||
// int tag = 2;
|
||||
StringBuffer sb = new StringBuffer(256);
|
||||
sb.append("诊断结果: ");
|
||||
if (locType == BDLocation.TypeNetWorkLocation) {
|
||||
if (diagnosticType == 1) {
|
||||
sb.append("网络定位成功,没有开启GPS,建议打开GPS会更好");
|
||||
sb.append("\n" + diagnosticMessage);
|
||||
} else if (diagnosticType == 2) {
|
||||
sb.append("网络定位成功,没有开启Wi-Fi,建议打开Wi-Fi会更好");
|
||||
sb.append("\n" + diagnosticMessage);
|
||||
}
|
||||
} else if (locType == BDLocation.TypeOffLineLocationFail) {
|
||||
if (diagnosticType == 3) {
|
||||
sb.append("定位失败,请您检查您的网络状态");
|
||||
sb.append("\n" + diagnosticMessage);
|
||||
}
|
||||
} else if (locType == BDLocation.TypeCriteriaException) {
|
||||
if (diagnosticType == 4) {
|
||||
sb.append("定位失败,无法获取任何有效定位依据");
|
||||
sb.append("\n" + diagnosticMessage);
|
||||
} else if (diagnosticType == 5) {
|
||||
sb.append("定位失败,无法获取有效定位依据,请检查运营商网络或者Wi-Fi网络是否正常开启,尝试重新请求定位");
|
||||
sb.append(diagnosticMessage);
|
||||
} else if (diagnosticType == 6) {
|
||||
sb.append("定位失败,无法获取有效定位依据,请尝试插入一张sim卡或打开Wi-Fi重试");
|
||||
sb.append("\n" + diagnosticMessage);
|
||||
} else if (diagnosticType == 7) {
|
||||
sb.append("定位失败,飞行模式下无法获取有效定位依据,请关闭飞行模式重试");
|
||||
sb.append("\n" + diagnosticMessage);
|
||||
} else if (diagnosticType == 9) {
|
||||
sb.append("定位失败,无法获取任何有效定位依据");
|
||||
sb.append("\n" + diagnosticMessage);
|
||||
}
|
||||
} else if (locType == BDLocation.TypeServerError) {
|
||||
if (diagnosticType == 8) {
|
||||
sb.append("定位失败,请确认您定位的开关打开状态,是否赋予APP定位权限");
|
||||
sb.append("\n" + diagnosticMessage);
|
||||
}
|
||||
}
|
||||
Log.e(TAG, "onLocationChanged: " + "定位失败");
|
||||
mMMKV.encode(CommonConfig.MAP_ERROR_KEY, sb.toString());
|
||||
Log.e(TAG, "onLocDiagnosticMessage: " + sb);
|
||||
}
|
||||
};
|
||||
|
||||
private void saveMapResult(BDLocation bdLocation) {
|
||||
MapBean mapBean = new MapBean();
|
||||
mapBean.setLongitude(bdLocation.getLongitude());
|
||||
mapBean.setLatitude(bdLocation.getLatitude());
|
||||
mapBean.setAdcode(bdLocation.getAdCode());
|
||||
mapBean.setAddress(bdLocation.getAddrStr());
|
||||
mapBean.setCity(bdLocation.getCity());
|
||||
mapBean.setCityCode(bdLocation.getCityCode());
|
||||
mapBean.setCountry(bdLocation.getCountry());
|
||||
mapBean.setCountryCode(bdLocation.getCountryCode());
|
||||
mapBean.setDistrict(bdLocation.getDistrict());
|
||||
mapBean.setProvince(bdLocation.getProvince());
|
||||
mapBean.setStreet(bdLocation.getStreet());
|
||||
mapBean.setStreetNumber(bdLocation.getStreetNumber());
|
||||
mapBean.setTown(bdLocation.getTown());
|
||||
mapBean.setLocationDescribe(bdLocation.getLocationDescribe());
|
||||
|
||||
mMMKV.encode(CommonConfig.MAP_LOCATION_JSON_KEY, GsonUtils.toJSONString(mapBean));
|
||||
}
|
||||
}
|
||||
49
app/src/main/java/com/uiuipad/find/push/PushManager.java
Normal file
49
app/src/main/java/com/uiuipad/find/push/PushManager.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.uiuipad.find.push;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiuipad.find.comm.CommonConfig;
|
||||
|
||||
public class PushManager {
|
||||
private static final String TAG = PushManager.class.getSimpleName();
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static PushManager sInstance;
|
||||
private Context mContext;
|
||||
private ContentResolver mResolver;
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private PushManager(Context context) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("Context is NULL");
|
||||
}
|
||||
this.mContext = context;
|
||||
this.mResolver = context.getContentResolver();
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new PushManager(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static PushManager getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init PushManager first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
|
||||
public void setPushContent(String title, String extras) {
|
||||
switch (title) {
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.uiuipad.find.push.alipush;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.sdk.android.push.AliyunMessageIntentService;
|
||||
import com.alibaba.sdk.android.push.notification.CPushMessage;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liyazhou on 17/8/22.
|
||||
* 为避免推送广播被系统拦截的小概率事件,我们推荐用户通过IntentService处理消息互调,接入步骤:
|
||||
* 1. 创建IntentService并继承AliyunMessageIntentService
|
||||
* 2. 覆写相关方法,并在Manifest的注册该Service
|
||||
* 3. 调用接口CloudPushService.setPushIntentService
|
||||
* 详细用户可参考:https://help.aliyun.com/document_detail/30066.html#h2-2-messagereceiver-aliyunmessageintentservice
|
||||
*/
|
||||
|
||||
public class AliMessageIntentService extends AliyunMessageIntentService {
|
||||
private static final String TAG = AliyunMessageIntentService.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* 推送通知的回调方法
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
protected void onNotification(Context context, String title, String summary, Map<String, String> extraMap) {
|
||||
Log.i(TAG, "收到一条推送通知 : " + title + ", summary:" + summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送消息的回调方法
|
||||
*
|
||||
* @param context
|
||||
* @param cPushMessage
|
||||
*/
|
||||
@Override
|
||||
protected void onMessage(Context context, CPushMessage cPushMessage) {
|
||||
Log.i(TAG, "收到一条推送消息 : " + cPushMessage.getTitle() + ", content:" + cPushMessage.getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从通知栏打开通知的扩展处理
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationOpened(Context context, String title, String summary, String extraMap) {
|
||||
Log.i(TAG, "onNotificationOpened : " + " : " + title + " : " + summary + " : " + extraMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无动作通知点击回调。当在后台或阿里云控制台指定的通知动作为无逻辑跳转时,通知点击回调为onNotificationClickedWithNoAction而不是onNotificationOpened
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationClickedWithNoAction(Context context, String title, String summary, String extraMap) {
|
||||
Log.i(TAG, "onNotificationClickedWithNoAction : " + " : " + title + " : " + summary + " : " + extraMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知删除回调
|
||||
*
|
||||
* @param context
|
||||
* @param messageId
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationRemoved(Context context, String messageId) {
|
||||
Log.i(TAG, "onNotificationRemoved : " + messageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用处于前台时通知到达回调。注意:该方法仅对自定义样式通知有效,相关详情请参考https://help.aliyun.com/document_detail/30066.html#h3-3-4-basiccustompushnotification-api
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
* @param openType
|
||||
* @param openActivity
|
||||
* @param openUrl
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationReceivedInApp(Context context, String title, String summary, Map<String, String> extraMap, int openType, String openActivity, String openUrl) {
|
||||
Log.i(TAG, "onNotificationReceivedInApp : " + " : " + title + " : " + summary + " " + extraMap + " : " + openType + " : " + openActivity + " : " + openUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.uiuipad.find.push.alipush;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.sdk.android.push.MessageReceiver;
|
||||
import com.alibaba.sdk.android.push.notification.CPushMessage;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.uiuipad.find.push.PushManager;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: 正纬
|
||||
* @since: 15/4/9
|
||||
* @version: 1.1
|
||||
* @feature: 用于接收推送的通知和消息
|
||||
*/
|
||||
public class AliyunMessageReceiver extends MessageReceiver {
|
||||
// 消息接收部分的LOG_TAG
|
||||
public static final String TAG = AliyunMessageReceiver.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* 推送通知的回调方法
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
public void onNotification(Context context, String title, String summary, Map<String, String> extraMap) {
|
||||
// TODO 处理推送通知
|
||||
if (null != extraMap) {
|
||||
for (Map.Entry<String, String> entry : extraMap.entrySet()) {
|
||||
Log.i(TAG, "@Get diy param : Key=" + entry.getKey() + " , Value=" + entry.getValue());
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "@收到通知 && 自定义消息为空");
|
||||
}
|
||||
Log.i(TAG, "收到一条推送通知 : " + title + ", summary:" + summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用处于前台时通知到达回调。注意:该方法仅对自定义样式通知有效,相关详情请参考https://help.aliyun.com/document_detail/30066.html?spm=5176.product30047.6.620.wjcC87#h3-3-4-basiccustompushnotification-api
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
* @param openType
|
||||
* @param openActivity
|
||||
* @param openUrl
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationReceivedInApp(Context context, String title, String summary, Map<String, String> extraMap, int openType, String openActivity, String openUrl) {
|
||||
Log.i(TAG, "onNotificationReceivedInApp : " + " : " + title + " : " + summary + " " + extraMap + " : " + openType + " : " + openActivity + " : " + openUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送消息的回调方法
|
||||
*
|
||||
* @param context
|
||||
* @param cPushMessage
|
||||
*/
|
||||
@Override
|
||||
public void onMessage(Context context, CPushMessage cPushMessage) {
|
||||
Log.e(TAG, "收到一条推送消息 : " + cPushMessage.getTitle() + ", content:" + cPushMessage.getContent());
|
||||
String title = cPushMessage.getTitle();
|
||||
String content = cPushMessage.getContent();
|
||||
JsonObject extrasJson = JsonParser.parseString(content).getAsJsonObject();
|
||||
String extras = "";
|
||||
if (extrasJson.get("extras") != null) {
|
||||
extras = extrasJson.get("extras").toString();
|
||||
}
|
||||
PushManager.getInstance().setPushContent(title, extras);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从通知栏打开通知的扩展处理
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
public void onNotificationOpened(Context context, String title, String summary, String extraMap) {
|
||||
Log.i(TAG, "onNotificationOpened : " + " : " + title + " : " + summary + " : " + extraMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知删除回调
|
||||
*
|
||||
* @param context
|
||||
* @param messageId
|
||||
*/
|
||||
@Override
|
||||
public void onNotificationRemoved(Context context, String messageId) {
|
||||
Log.i(TAG, "onNotificationRemoved : " + messageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无动作通知点击回调。当在后台或阿里云控制台指定的通知动作为无逻辑跳转时,通知点击回调为onNotificationClickedWithNoAction而不是onNotificationOpened
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param summary
|
||||
* @param extraMap
|
||||
*/
|
||||
@Override
|
||||
protected void onNotificationClickedWithNoAction(Context context, String title, String summary, String extraMap) {
|
||||
Log.i(TAG, "onNotificationClickedWithNoAction : " + " : " + title + " : " + summary + " : " + extraMap);
|
||||
}
|
||||
}
|
||||
36
app/src/main/java/com/uiuipad/find/util/Utils.java
Normal file
36
app/src/main/java/com/uiuipad/find/util/Utils.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.uiuipad.find.util;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class Utils {
|
||||
|
||||
/**
|
||||
* 获取设备序列号
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@SuppressLint({"MissingPermission", "NewApi"})
|
||||
public static String getSerial() {
|
||||
// return JGYUtils.getInstance().getIMEI();
|
||||
String serial = "unknown";
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {//9.0+
|
||||
serial = Build.getSerial();
|
||||
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {//8.0+
|
||||
serial = Build.SERIAL;
|
||||
} else {//8.0-
|
||||
Class<?> c = Class.forName("android.os.SystemProperties");
|
||||
Method get = c.getMethod("get", String.class);
|
||||
serial = (String) get.invoke(c, "ro.serialno");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("e", "读取设备序列号异常:" + e.toString());
|
||||
}
|
||||
return serial;
|
||||
}
|
||||
}
|
||||
18
app/src/main/res/layout/activity_main.xml
Normal file
18
app/src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.7 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
6
app/src/main/res/values/colors.xml
Normal file
6
app/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#6200EE</color>
|
||||
<color name="colorPrimaryDark">#3700B3</color>
|
||||
<color name="colorAccent">#03DAC5</color>
|
||||
</resources>
|
||||
3
app/src/main/res/values/strings.xml
Normal file
3
app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">设备查找</string>
|
||||
</resources>
|
||||
11
app/src/main/res/values/styles.xml
Normal file
11
app/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
17
app/src/test/java/com/uiuipad/find/ExampleUnitTest.java
Normal file
17
app/src/test/java/com/uiuipad/find/ExampleUnitTest.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.uiuipad.find;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user