--- /dev/null
+*.iml
+.gradle
+/local.properties
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+.DS_Store
+/build
+/captures
+.externalNativeBuild
+.cxx
--- /dev/null
+<component name="ProjectCodeStyleConfiguration">
+ <code_scheme name="Project" version="173">
+ <codeStyleSettings language="XML">
+ <indentOptions>
+ <option name="CONTINUATION_INDENT_SIZE" value="4" />
+ </indentOptions>
+ <arrangement>
+ <rules>
+ <section>
+ <rule>
+ <match>
+ <AND>
+ <NAME>xmlns:android</NAME>
+ <XML_ATTRIBUTE />
+ <XML_NAMESPACE>^$</XML_NAMESPACE>
+ </AND>
+ </match>
+ </rule>
+ </section>
+ <section>
+ <rule>
+ <match>
+ <AND>
+ <NAME>xmlns:.*</NAME>
+ <XML_ATTRIBUTE />
+ <XML_NAMESPACE>^$</XML_NAMESPACE>
+ </AND>
+ </match>
+ <order>BY_NAME</order>
+ </rule>
+ </section>
+ <section>
+ <rule>
+ <match>
+ <AND>
+ <NAME>.*:id</NAME>
+ <XML_ATTRIBUTE />
+ <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
+ </AND>
+ </match>
+ </rule>
+ </section>
+ <section>
+ <rule>
+ <match>
+ <AND>
+ <NAME>.*:name</NAME>
+ <XML_ATTRIBUTE />
+ <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
+ </AND>
+ </match>
+ </rule>
+ </section>
+ <section>
+ <rule>
+ <match>
+ <AND>
+ <NAME>name</NAME>
+ <XML_ATTRIBUTE />
+ <XML_NAMESPACE>^$</XML_NAMESPACE>
+ </AND>
+ </match>
+ </rule>
+ </section>
+ <section>
+ <rule>
+ <match>
+ <AND>
+ <NAME>style</NAME>
+ <XML_ATTRIBUTE />
+ <XML_NAMESPACE>^$</XML_NAMESPACE>
+ </AND>
+ </match>
+ </rule>
+ </section>
+ <section>
+ <rule>
+ <match>
+ <AND>
+ <NAME>.*</NAME>
+ <XML_ATTRIBUTE />
+ <XML_NAMESPACE>^$</XML_NAMESPACE>
+ </AND>
+ </match>
+ <order>BY_NAME</order>
+ </rule>
+ </section>
+ <section>
+ <rule>
+ <match>
+ <AND>
+ <NAME>.*</NAME>
+ <XML_ATTRIBUTE />
+ <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
+ </AND>
+ </match>
+ <order>ANDROID_ATTRIBUTE_ORDER</order>
+ </rule>
+ </section>
+ <section>
+ <rule>
+ <match>
+ <AND>
+ <NAME>.*</NAME>
+ <XML_ATTRIBUTE />
+ <XML_NAMESPACE>.*</XML_NAMESPACE>
+ </AND>
+ </match>
+ <order>BY_NAME</order>
+ </rule>
+ </section>
+ </rules>
+ </arrangement>
+ </codeStyleSettings>
+ </code_scheme>
+</component>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="GradleSettings">
+ <option name="linkedExternalProjectsSettings">
+ <GradleProjectSettings>
+ <compositeConfiguration>
+ <compositeBuild compositeDefinitionSource="SCRIPT" />
+ </compositeConfiguration>
+ <option name="distributionType" value="DEFAULT_WRAPPED" />
+ <option name="externalProjectPath" value="$PROJECT_DIR$" />
+ <option name="resolveModulePerSourceSet" value="false" />
+ <option name="testRunner" value="PLATFORM" />
+ </GradleProjectSettings>
+ </option>
+ </component>
+</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <output url="file://$PROJECT_DIR$/build/classes" />
+ </component>
+ <component name="ProjectType">
+ <option name="id" value="Android" />
+ </component>
+</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="RunConfigurationProducerService">
+ <option name="ignoredProducers">
+ <set>
+ <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
+ <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
+ <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
+ </set>
+ </option>
+ </component>
+</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
+ <mapping directory="$PROJECT_DIR$/IcWorkService" vcs="Git" />
+ </component>
+</project>
\ No newline at end of file
--- /dev/null
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 29
+ buildToolsVersion "29.0.2"
+ defaultConfig {
+ applicationId "com.ic.work"
+ minSdkVersion 19
+ targetSdkVersion 29
+ versionCode 1
+ versionName "1.0"
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ }
+
+ //使用JDK1.8
+ compileOptions {
+ targetCompatibility JavaVersion.VERSION_1_8
+ sourceCompatibility JavaVersion.VERSION_1_8
+ }
+
+
+ sourceSets {
+ main {
+ jni.srcDirs = []
+ manifest.srcFile 'src/main/AndroidManifest.xml'
+ java.srcDirs = ['src/main/java', 'src/main/aidl']
+ resources.srcDirs = ['src/main/java', 'src/main/aidl']
+ aidl.srcDirs = ['src/main/aidl']
+ res.srcDirs = ['src/main/res']
+ assets.srcDirs = ['src/main/assets']
+ }
+ }
+
+ signingConfigs {
+ key {
+ storeFile file("EQC_G5.jks")
+ storePassword "123456"
+ keyAlias "watch_g5"
+ keyPassword "123456"
+ }
+ }
+
+ buildTypes {
+ release {
+ zipAlignEnabled true // zip 对齐优化
+ shrinkResources true // 移除未使用的资源文件
+ signingConfig signingConfigs.key
+ minifyEnabled true
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ renderscriptDebuggable = false
+ debuggable = false
+ jniDebuggable = false
+ manifestPlaceholders = [:]
+ }
+
+ debug {
+ signingConfig signingConfigs.key
+ }
+ }
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ implementation 'androidx.appcompat:appcompat:1.1.0'
+ implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+
+ implementation 'com.amap.api:location:4.8.0'
+
+ implementation 'org.greenrobot:eventbus:3.2.0'
+
+ implementation 'com.squareup.okio:okio:2.4.3'
+
+ implementation 'com.alibaba:fastjson:1.2.61'
+
+ implementation "androidx.room:room-runtime:2.2.5"
+ annotationProcessor "androidx.room:room-compiler:2.2.5"
+
+ implementation 'com.jakewharton.threetenabp:threetenabp:1.2.2'
+}
--- /dev/null
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
--- /dev/null
+package com.ic.work;
+
+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.ic.work", appContext.getPackageName());
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.ic.work">
+
+ <!-- 这个权限用于进行网络定位-->
+ <uses-permission android:name="android.permission.ACCESS_COARSE_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.READ_PHONE_STATE" />
+ <!-- 写入扩展存储,向扩展卡写入数据,用于写入离线定位数据-->
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+ <!-- 访问网络,网络定位需要上网-->
+ <uses-permission android:name="android.permission.INTERNET" />
+ <!-- SD卡读取权限,用户写入离线定位数据-->
+ <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
+
+ <uses-permission android:name="android.permission.WRITE_SETTINGS" />
+
+ <!--用于申请调用A-GPS模块-->
+ <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
+
+
+ <application
+ android:name=".WorkServiceApp"
+ android:allowBackup="true"
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:roundIcon="@mipmap/ic_launcher_round"
+ android:supportsRtl="true"
+ android:theme="@style/AppTheme">
+
+ <meta-data
+ android:name="com.amap.api.v2.apikey"
+ android:value="80c129088f7bbe251a846d645ee8360a" />
+
+
+ <service
+ android:name=".WorkService"
+ android:process=":remote"
+ android:enabled="true"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="com.ic.action.WORK_SERVICE" />
+ </intent-filter>
+ </service>
+
+ <activity android:name=".MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <service android:name="com.amap.api.location.APSService" />
+ </application>
+
+</manifest>
\ No newline at end of file
--- /dev/null
+package com.ic.aidl.blood;
+
+public class BloodState {
+
+ public static final int BLOOD_NULL_TIPS = -1;
+ public static final int BLOOD_NOT_DEVICE = 1001;
+
+ public static final int BLOOD_PLEASE_QUIET = 1002;
+ public static final int BLOOD_START_CHECK= 1003;
+
+ public static final int BLOOD_NOT_WEAR=1004;
+ public static final int BLOOD_ING_CHECK=1005;
+
+ public static final int BLOOD_STOP_CHECK=1006;
+ public static final int BLOOD_NOT_DATA_CHECK=1007;
+}
--- /dev/null
+// IWeatherAidlInterface.aidl
+package com.ic.aidl.blood;
+
+// Declare any non-default types here with import statements
+
+interface IBloodAidlInterface {
+ /**
+ * Demonstrates some basic types that you can use as parameters
+ * and return values in AIDL.
+ */
+
+ void updateBloodCheckResult(int high,int low,int heart);
+ void updateBloodCheckTips(int top,int bottom);
+}
--- /dev/null
+// IWeatherRemoteService.aidl
+package com.ic.aidl.blood;
+
+// Declare any non-default types here with import statements
+
+import com.ic.aidl.blood.IBloodAidlInterface;
+
+interface IBloodRemoteService {
+ /**
+ * Demonstrates some basic types that you can use as parameters
+ * and return values in AIDL.
+ */
+ void registerCallback(IBloodAidlInterface cb);
+ void unregisterCallback(IBloodAidlInterface cb);
+
+ void startCheckBlood();
+ void stopCheckBlood();
+}
--- /dev/null
+// IWeatherAidlInterface.aidl
+package com.ic.aidl.ped;
+
+// Declare any non-default types here with import statements
+import com.ic.aidl.ped.RecordParcelable;
+
+interface IPedAidlInterface {
+ /**
+ * Demonstrates some basic types that you can use as parameters
+ * and return values in AIDL.
+ */
+ void updatePedCount(int count);
+ void updatePedRecord(in List<RecordParcelable> record);
+
+}
--- /dev/null
+// IWeatherRemoteService.aidl
+package com.ic.aidl.ped;
+
+// Declare any non-default types here with import statements
+
+import com.ic.aidl.ped.IPedAidlInterface;
+
+interface IPedRemoteService {
+ /**
+ * Demonstrates some basic types that you can use as parameters
+ * and return values in AIDL.
+ */
+ void registerCallback(IPedAidlInterface cb);
+ void unregisterCallback(IPedAidlInterface cb);
+
+ void queryPedCount();
+ void queryPedRecord();
+ void syncPedHeightSetting(int height);
+ void syncPedWeightSetting(int weight);
+}
--- /dev/null
+package com.ic.aidl.ped;
+
+parcelable RecordParcelable;
\ No newline at end of file
--- /dev/null
+package com.ic.aidl.ped;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class RecordParcelable implements Parcelable {
+ private int number;
+ private String distance;
+ private String calorie;
+ private String date;
+
+ public RecordParcelable() {
+ number = 0;
+ distance = null;
+ calorie = null;
+ date = "";
+ }
+
+ public RecordParcelable(int number, String distance, String calorie, String date) {
+ this.number = number;
+ this.distance = distance;
+ this.calorie = calorie;
+ this.date = date;
+ }
+
+ public RecordParcelable(Parcel p) {
+ this.number = p.readInt();
+ this.distance = p.readString();
+ this.calorie = p.readString();
+ this.date = p.readString();
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(number);
+ dest.writeString(distance);
+ dest.writeString(calorie);
+ dest.writeString(date);
+ }
+
+ public static final Parcelable.Creator<RecordParcelable> CREATOR
+ = new Parcelable.Creator<RecordParcelable>() {
+ public RecordParcelable createFromParcel(Parcel in) {
+ return new RecordParcelable(in);
+ }
+
+ public RecordParcelable[] newArray(int size) {
+ return new RecordParcelable[size];
+ }
+ };
+
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+ public String getDistance() {
+ return distance;
+ }
+
+ public void setDistance(String distance) {
+ this.distance = distance;
+ }
+
+ public String getCalorie() {
+ return calorie;
+ }
+
+ public void setCalorie(String calorie) {
+ this.calorie = calorie;
+ }
+
+ public String getDate() {
+ return date;
+ }
+
+ public void setDate(String date) {
+ this.date = date;
+ }
+}
--- /dev/null
+// IWeatherAidlInterface.aidl
+package com.ic.aidl.weather;
+
+// Declare any non-default types here with import statements
+import com.ic.aidl.weather.WeatherParcelable;
+
+interface IWeatherAidlInterface {
+ /**
+ * Demonstrates some basic types that you can use as parameters
+ * and return values in AIDL.
+ */
+ void updateCurrWeather(in WeatherParcelable weather);
+
+}
--- /dev/null
+// IWeatherRemoteService.aidl
+package com.ic.aidl.weather;
+
+// Declare any non-default types here with import statements
+
+import com.ic.aidl.weather.IWeatherAidlInterface;
+
+interface IWeatherRemoteService {
+ /**
+ * Demonstrates some basic types that you can use as parameters
+ * and return values in AIDL.
+ */
+ void registerCallback(IWeatherAidlInterface cb);
+ void unregisterCallback(IWeatherAidlInterface cb);
+
+ void queryWeatherInfo();
+}
--- /dev/null
+package com.ic.aidl.weather;
+
+parcelable WeatherParcelable;
\ No newline at end of file
--- /dev/null
+package com.ic.aidl.weather;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class WeatherParcelable implements Parcelable {
+ private String city;
+ private String statusDay; // 白天状态,如:晴
+ private String statusNight; // 晚上状态
+ private String figureDay; // 状态索引
+ private String figureNight;
+ private String temperatureDay; // 白天温度 或 最低温度
+ private String temperatureNight; // 晚上温度 或 最低温度
+ private String updateTime; // 更新时间
+
+ public WeatherParcelable() {
+ city = "";
+ statusDay = "";
+ statusNight = "";
+ figureDay = "";
+ figureNight = "";
+ temperatureDay = "";
+ temperatureNight = "";
+ updateTime = "";
+ }
+
+ public WeatherParcelable(String city,
+ String statusDay, String statusNight,
+ String figureDay, String figureNight,
+ String temperatureDay, String temperatureNight,
+ String updateTime) {
+ this.city = city;
+ this.statusDay = statusDay;
+ this.statusNight = statusNight;
+ this.figureDay = figureDay;
+ this.figureNight =figureNight;
+ this.temperatureDay = temperatureDay;
+ this.temperatureNight = temperatureNight;
+ this.updateTime =updateTime;
+ }
+
+ public WeatherParcelable(Parcel p) {
+ this.city = p.readString();
+ this.statusDay = p.readString();
+ this.statusNight = p.readString();
+ this.figureDay = p.readString();
+ this.figureNight = p.readString();
+ this.temperatureDay = p.readString();
+ this.temperatureNight = p.readString();
+ this.updateTime = p.readString();
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(city);
+ dest.writeString(statusDay);
+ dest.writeString(statusNight);
+ dest.writeString(figureDay);
+ dest.writeString(figureNight);
+ dest.writeString(temperatureDay);
+ dest.writeString(temperatureNight);
+ dest.writeString(updateTime);
+ }
+
+ public static final Creator<WeatherParcelable> CREATOR
+ = new Creator<WeatherParcelable>() {
+ public WeatherParcelable createFromParcel(Parcel in) {
+ return new WeatherParcelable(in);
+ }
+
+ public WeatherParcelable[] newArray(int size) {
+ return new WeatherParcelable[size];
+ }
+ };
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getStatusDay() {
+ return statusDay;
+ }
+
+ public void setStatusDay(String statusDay) {
+ this.statusDay = statusDay;
+ }
+
+ public String getStatusNight() {
+ return statusNight;
+ }
+
+ public void setStatusNight(String statusNight) {
+ this.statusNight = statusNight;
+ }
+
+ public String getFigureDay() {
+ return figureDay;
+ }
+
+ public void setFigureDay(String figureDay) {
+ this.figureDay = figureDay;
+ }
+
+ public String getFigureNight() {
+ return figureNight;
+ }
+
+ public void setFigureNight(String figureNight) {
+ this.figureNight = figureNight;
+ }
+
+ public String getTemperatureDay() {
+ return temperatureDay;
+ }
+
+ public void setTemperatureDay(String temperatureDay) {
+ this.temperatureDay = temperatureDay;
+ }
+
+ public String getTemperatureNight() {
+ return temperatureNight;
+ }
+
+ public void setTemperatureNight(String temperatureNight) {
+ this.temperatureNight = temperatureNight;
+ }
+
+ public String getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(String updateTime) {
+ this.updateTime = updateTime;
+ }
+}
--- /dev/null
+package com.ic.jni;
+
+
+public class ICJniUtils {
+
+ public ICJniUtils(){
+
+ }
+
+ static {
+ System.loadLibrary("ICJniUtils");
+ }
+
+ /***************计步控制************************************/
+ /*运行此函数清除 系统计步为0*/
+ public static native int resetStepCount();
+
+ /*获取当前步数*/
+ public static native int getStepCount();
+ /*开启计步 不必判断返回值*/
+ public static native int enablePedometer();
+ /*停止计步 不必判断返回值*/
+ public static native int disablePedometer();
+
+ /*检测计步当前是否开启 1开启,0 关闭*/
+ public static native int isPedometerEnabled();
+
+ /*保存当前步数(getStepCount取得的值)到磁盘 不必判断返回值*/
+ public static native int saveStepCount();
+
+ /*恢复保存时的步数数据,下次getStepCount会在恢复的值上增加 不必判断返回值*/
+ public static native int recoverStepCount();
+
+
+ /******心率,血压****************************************/
+ /*检查 PPG硬件是否存在,返回 1 存在,0 不存在*/
+ public static native int isPPGavailable();
+
+ /*开启心率血压检测*/
+ public static native int enablePPG();
+
+ /*停止心率血压检测*/
+ public static native int disablePPG();
+ /*返回 心率值 每分钟跳动次数, 通过这个心率>0 判断是否已经有检测结果,
+ 有就可以直接通过getHighBloodPressure 和 getLowBloodPressure 获取血压高压低压值*/
+ public static native int getPPG();
+ /* 返回PPG 运行状态, 0 停止, 1,运行中*/
+ public static native int isPPGStarted();
+ /*返回是否佩戴 0 未佩戴,1 佩戴*/
+ public static native int isWeared();
+
+ /*获取血压高压值*/
+ public static native int getHighBloodPressure();
+
+ /*获取血压低压值*/
+ public static native int getLowBloodPressure();
+
+ /*获取血氧值*/
+ public static native int getSPO2();
+}
--- /dev/null
+package com.ic.work;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.os.Bundle;
+import android.widget.Button;
+
+import com.ic.work.utils.IcLog;
+import com.ic.work.utils.PedUtil;
+import com.ic.work.utils.ServiceUtil;
+
+import org.threeten.bp.OffsetDateTime;
+import org.threeten.bp.format.DateTimeFormatter;
+
+import java.math.BigDecimal;
+
+public class MainActivity extends AppCompatActivity {
+ private static final String TAG="MainActivity";
+
+ private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ Button mBt = (Button) findViewById(R.id.start_service_bt);
+ mBt.setOnClickListener(view -> {
+ ServiceUtil.startServiceUtil(getApplicationContext(),
+ "com.ic.action.WORK_SERVICE",
+ getPackageName());
+ });
+
+ OffsetDateTime today = OffsetDateTime.now();
+ IcLog.i(TAG,today.format(formatter));
+
+ BigDecimal bg = new BigDecimal(PedUtil.calcDistanceBySteps(170, 1000));
+ IcLog.i(TAG,""+bg.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
+ }
+}
--- /dev/null
+package com.ic.work;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+public class ThreadPoolManager {
+ private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
+
+ private static ThreadPoolManager mInstance;
+
+ private ThreadPoolExecutor mTheadPool;
+
+ public static final synchronized ThreadPoolManager getInstance() {
+ if (mInstance == null) {
+ mInstance = new ThreadPoolManager();
+ }
+ return mInstance;
+ }
+
+ private ThreadPoolManager() {
+ mTheadPool = new ThreadPoolExecutor(
+ 0,
+ CPU_COUNT * 2 + 1,
+ 120L, TimeUnit.SECONDS,
+ new SynchronousQueue<Runnable>());
+ }
+
+ public void execute(Runnable runnable) {
+ if (runnable == null)
+ return;
+
+ mTheadPool.execute(runnable);
+ }
+
+ /**
+ * 从线程池中移除任务
+ */
+ public void remove(Runnable runnable) {
+ if (runnable == null)
+ return;
+
+ mTheadPool.remove(runnable);
+ }
+}
--- /dev/null
+package com.ic.work;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+
+import com.ic.work.event.BloodCheckResultEvent;
+import com.ic.work.event.BloodCheckTipsEvent;
+import com.ic.work.event.LocationResultEvent;
+import com.ic.work.event.PedCountEvent;
+import com.ic.work.event.PedRecordResultEvent;
+import com.ic.work.event.PedSettingEvent;
+import com.ic.work.event.WeatherAgainEvent;
+import com.ic.work.event.WeatherResultEvent;
+import com.ic.work.process.BloodProcess;
+import com.ic.work.process.PedProcess;
+import com.ic.work.process.WeatherProcess;
+import com.ic.work.utils.IcLog;
+import com.ic.work.utils.SPUtils;
+import com.ic.work.weather.WeatherHelper;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
+
+public class WorkService extends Service {
+
+ private static final String TAG = "WorkService";
+
+ private WeatherProcess weatherProcess;
+ private BloodProcess bloodProcess;
+ private PedProcess pedProcess;
+
+ private WeatherHelper mWeatherHelper;
+
+ private WorkServiceApp mApp;
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ if (intent != null) {
+ int reqType = intent.getIntExtra("REQ_TYPE", -1);
+ IcLog.i(TAG,"Bind reqType"+reqType);
+ switch (reqType) {
+ case 101:
+ //天气
+ return weatherProcess.getWeatherBinder();
+ case 102:
+ //血压
+ return bloodProcess.getBloodBinder();
+ case 103:
+ //计步
+ return pedProcess.getPedBinder();
+ default:
+ return null;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mApp = (WorkServiceApp) getApplication();
+
+ weatherProcess = new WeatherProcess(mApp);
+ bloodProcess = new BloodProcess();
+
+ pedProcess = new PedProcess(
+ (WorkServiceApp) getApplication(),
+ SPUtils.getPedHeightSP(getApplicationContext()),
+ SPUtils.getPedWighttSP(getApplicationContext()));
+
+ mWeatherHelper = new WeatherHelper();
+
+ EventBus.getDefault().register(this);
+
+ mWeatherHelper.startLocation(getApplicationContext());
+
+ IcLog.i(TAG, "work service is start");
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ IcLog.i(TAG,"WorkService onStartCommand");
+ return super.onStartCommand(intent, flags, startId);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ IcLog.i(TAG,"WorkService onDestroy");
+ bloodProcess = null;
+
+ mApp = null;
+ EventBus.getDefault().unregister(this);
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void onMessageEvent(LocationResultEvent event) {
+ mWeatherHelper.queryWeatherServerInfo(mApp.getWeatherRepository(),event.getmCity());
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void onMessageEvent(BloodCheckTipsEvent event) {
+ if (bloodProcess != null) {
+ bloodProcess.sendBloodCheckTips(event.getTopTips(),
+ event.getBottomTips());
+ }
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void onMessageEvent(BloodCheckResultEvent event) {
+ if (bloodProcess != null) {
+ bloodProcess.sendBloodCheckResult(event.getHigh(),
+ event.getLow(), event.getHeart());
+ }
+
+ //发送一次广播给 心率 launcher
+ sendHeartBroadcast(event.getHeart());
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void onMessageEvent(PedSettingEvent event) {
+
+ if(pedProcess != null){
+ return;
+ }
+
+ switch (event.getType()){
+ case 1:
+ int height = event.getValue();
+ SPUtils.setPedHeightSP(getApplicationContext(),height);
+ pedProcess.updateHeight(height);
+ break;
+ case 2:
+ int weight = event.getValue();
+ SPUtils.setPedWighttSP(getApplicationContext(),weight);
+ pedProcess.updateWeight(weight);
+ break;
+ }
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void onMessageEvent(PedRecordResultEvent event) {
+ if(pedProcess != null){
+ pedProcess.sendPedRecord(event.getRecordList());
+ }
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void onMessageEvent(PedCountEvent event) {
+ if(pedProcess != null){
+ pedProcess.sendPedCount(event.getPedCount());
+ }
+
+ //发送一次广播给launcher
+ sendPedCountBroadcast(event.getPedCount());
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void onMessageEvent(WeatherResultEvent event) {
+ if(weatherProcess != null){
+ weatherProcess.sendCurrWeather(event.getParcelable());
+ }
+ }
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void onMessageEvent(WeatherAgainEvent event) {
+ if(mWeatherHelper != null){
+ mWeatherHelper.startLocation(getApplicationContext());
+ }
+ }
+
+ private void sendPedCountBroadcast(int count){
+ Intent pedIntent = new Intent();
+ pedIntent.setAction("com.ic.action.PED_COUNT");
+ pedIntent.putExtra("PED_COUNT",count);
+ sendBroadcast(pedIntent);
+ }
+
+ private void sendHeartBroadcast(int count){
+ Intent pedIntent = new Intent();
+ pedIntent.setAction("com.ic.action.BLOOD_HEART");
+ pedIntent.putExtra("BLOOD_HEART",count);
+ sendBroadcast(pedIntent);
+ }
+
+}
--- /dev/null
+package com.ic.work;
+
+import android.app.Application;
+
+import com.ic.work.db.AppDatabase;
+import com.ic.work.db.PedInjection;
+import com.ic.work.db.WeatherInjection;
+import com.ic.work.utils.IcLog;
+import com.jakewharton.threetenabp.AndroidThreeTen;
+
+public class WorkServiceApp extends Application {
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ IcLog.setLogHead("IcWorkService");
+
+ AndroidThreeTen.init(this);
+ }
+
+ public AppDatabase getDatabase() {
+ return AppDatabase.getInstance(this);
+ }
+
+ public PedInjection getRepository() {
+ return PedInjection.getInstance(getDatabase());
+ }
+
+ public WeatherInjection getWeatherRepository() {
+ return WeatherInjection.getInstance(getDatabase());
+ }
+}
\ No newline at end of file
--- /dev/null
+package com.ic.work.db;
+
+import android.content.Context;
+
+import androidx.room.Database;
+import androidx.room.Room;
+import androidx.room.RoomDatabase;
+import androidx.room.TypeConverters;
+
+import com.ic.work.db.dao.PedDao;
+import com.ic.work.db.dao.WeatherDao;
+import com.ic.work.db.entity.PedEntity;
+import com.ic.work.db.entity.WeatherEntity;
+
+@Database(entities = {PedEntity.class, WeatherEntity.class}, version = 2,exportSchema = false)
+@TypeConverters(TiviTypeConverters.class)
+public abstract class AppDatabase extends RoomDatabase {
+
+ private static AppDatabase sInstance;
+
+ public static final String DATABASE_NAME = "ic-work-db";
+
+ public abstract PedDao loadPedDao();
+ public abstract WeatherDao loadWeatherDao();
+
+ public static AppDatabase getInstance(final Context context) {
+ if (sInstance == null) {
+ synchronized (AppDatabase.class) {
+ if (sInstance == null) {
+ sInstance = buildDatabase(context.getApplicationContext());
+ }
+ }
+ }
+ return sInstance;
+ }
+
+ private static AppDatabase buildDatabase(final Context appContext) {
+ return Room.databaseBuilder(appContext, AppDatabase.class, DATABASE_NAME).build();
+ }
+}
--- /dev/null
+package com.ic.work.db;
+
+import android.content.Context;
+
+import com.ic.work.db.dao.PedDao;
+import com.ic.work.db.entity.PedEntity;
+
+import org.threeten.bp.LocalDate;
+import org.threeten.bp.OffsetDateTime;
+
+import java.util.Date;
+import java.util.List;
+
+public class PedInjection {
+
+ private static PedInjection sInstance;
+
+ private final AppDatabase mDatabase;
+
+ private PedInjection(final AppDatabase database) {
+ mDatabase = database;
+ }
+
+ public static PedInjection getInstance(final AppDatabase database) {
+ if (sInstance == null) {
+ synchronized (PedInjection.class) {
+ if (sInstance == null) {
+ sInstance = new PedInjection(database);
+ }
+ }
+ }
+ return sInstance;
+ }
+
+ private PedDao getPedDao() {
+ return mDatabase.loadPedDao();
+ }
+
+ public List<PedEntity> queryDBPedDate(LocalDate date) {
+ return getPedDao().loadDatePedList(date);
+ }
+
+ public void insertDBPedDate(PedEntity entity) {
+ getPedDao().insertPedEntity(entity);
+ }
+
+ public void updateDBPedDate(PedEntity entity) {
+ getPedDao().updatePedEntity(entity.getId(),
+ entity.getPedNumber(),
+ entity.getPedDistance(),
+ entity.getPedDistance());
+ }
+
+ public int queryDBPedCount() {
+ return getPedDao().queryCountPed();
+ }
+
+ public List<PedEntity> queryDBPedAllList() {
+ return getPedDao().loadAllDatePedList();
+ }
+
+ public List<PedEntity> queryDBPedOldestList() {
+ return getPedDao().loadOldestDatePedList();
+ }
+
+ public void deletePedEntity(int id) {
+ getPedDao().deletePedEntity(id);
+ }
+}
--- /dev/null
+package com.ic.work.db;
+
+import android.text.TextUtils;
+
+import androidx.room.TypeConverter;
+
+import org.threeten.bp.LocalDate;
+import org.threeten.bp.format.DateTimeFormatter;
+
+public class TiviTypeConverters {
+
+ private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
+
+ @TypeConverter
+ public static LocalDate toLocalDate(String value) {
+ if (TextUtils.isEmpty(value)) {
+ return null;
+ }
+ return formatter.parse(value,LocalDate.FROM);
+ }
+
+ @TypeConverter
+ public static String fromLocalDate(LocalDate date) {
+ if (date == null) {
+ return null;
+ }
+ return date.format(formatter);
+ }
+}
--- /dev/null
+package com.ic.work.db;
+
+import com.ic.work.db.dao.WeatherDao;
+import com.ic.work.db.entity.WeatherEntity;
+
+import org.threeten.bp.LocalDate;
+import org.threeten.bp.OffsetDateTime;
+
+import java.util.List;
+
+public class WeatherInjection {
+
+ private static WeatherInjection sInstance;
+
+ private final AppDatabase mDatabase;
+
+ private WeatherInjection(final AppDatabase database) {
+ mDatabase = database;
+ }
+
+ public static WeatherInjection getInstance(final AppDatabase database) {
+ if (sInstance == null) {
+ synchronized (PedInjection.class) {
+ if (sInstance == null) {
+ sInstance = new WeatherInjection(database);
+ }
+ }
+ }
+ return sInstance;
+ }
+
+ private WeatherDao getWeatherDao() {
+ return mDatabase.loadWeatherDao();
+ }
+
+ public List<WeatherEntity> queryDBWeatherDate(LocalDate date) {
+ return getWeatherDao().loadAllDateWeatherList(date);
+ }
+
+ public void deleteDBWeatherDate() {
+ getWeatherDao().deleteWeatherList();
+ }
+
+ public void insertWeatherEntity(WeatherEntity entity){
+ getWeatherDao().insertWeatherEntity(entity);
+ }
+}
--- /dev/null
+package com.ic.work.db.dao;
+
+import androidx.room.Dao;
+import androidx.room.Insert;
+import androidx.room.Query;
+
+import com.ic.work.db.entity.PedEntity;
+
+import org.threeten.bp.LocalDate;
+import org.threeten.bp.OffsetDateTime;
+
+import java.util.List;
+
+@Dao
+public interface PedDao {
+
+ //查询时间对应的记录,可能为空。
+ @Query("SELECT * FROM icPedDb WHERE pedDate = :currDate ")
+ List<PedEntity> loadDatePedList(LocalDate currDate);
+
+ @Query("SELECT COUNT(id) FROM icPedDb")
+ int queryCountPed();
+
+ @Query("SELECT * FROM icPedDb ORDER BY datetime(pedDate) limit 1")
+ List<PedEntity> loadOldestDatePedList();
+
+ @Query("SELECT * FROM icPedDb")
+ List<PedEntity> loadAllDatePedList();
+
+ @Insert
+ void insertPedEntity(PedEntity entity);
+
+ //更新记录
+ @Query("UPDATE icPedDb SET pedNumber = :number , pedDistance = :distance , pedCalorie = :calorie WHERE id = :id")
+ void updatePedEntity(int id, int number, float distance, float calorie);
+
+ @Query("DELETE FROM icPedDb WHERE id = :id")
+ void deletePedEntity(int id);
+}
--- /dev/null
+package com.ic.work.db.dao;
+
+import androidx.room.Dao;
+import androidx.room.Insert;
+import androidx.room.Query;
+
+import com.ic.work.db.entity.WeatherEntity;
+
+import org.threeten.bp.LocalDate;
+import org.threeten.bp.OffsetDateTime;
+
+import java.util.List;
+
+@Dao
+public interface WeatherDao {
+
+ @Query("SELECT * FROM icWeatherDb WHERE updateTime= :currDate")
+ List<WeatherEntity> loadAllDateWeatherList(LocalDate currDate);
+
+ @Query("DELETE from icWeatherDb")
+ void deleteWeatherList();
+
+ @Insert
+ void insertWeatherEntity(WeatherEntity entity);
+}
--- /dev/null
+package com.ic.work.db.entity;
+
+import androidx.room.Entity;
+import androidx.room.Index;
+import androidx.room.PrimaryKey;
+
+import org.threeten.bp.LocalDate;
+import org.threeten.bp.OffsetDateTime;
+
+@Entity(tableName = "icPedDb",
+ indices = {@Index("id")})
+public class PedEntity {
+ @PrimaryKey(autoGenerate = true)
+ private int id;
+ private int pedNumber;
+ private float pedDistance;
+ private float pedCalorie;
+ private LocalDate pedDate;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getPedNumber() {
+ return pedNumber;
+ }
+
+ public void setPedNumber(int pedNumber) {
+ this.pedNumber = pedNumber;
+ }
+
+ public float getPedDistance() {
+ return pedDistance;
+ }
+
+ public void setPedDistance(float pedDistance) {
+ this.pedDistance = pedDistance;
+ }
+
+ public float getPedCalorie() {
+ return pedCalorie;
+ }
+
+ public void setPedCalorie(float pedCalorie) {
+ this.pedCalorie = pedCalorie;
+ }
+
+ public LocalDate getPedDate() {
+ return pedDate;
+ }
+
+ public void setPedDate(LocalDate pedDate) {
+ this.pedDate = pedDate;
+ }
+}
--- /dev/null
+package com.ic.work.db.entity;
+
+import androidx.room.Entity;
+import androidx.room.Index;
+import androidx.room.PrimaryKey;
+
+import org.threeten.bp.LocalDate;
+
+@Entity(tableName = "icWeatherDb",
+ indices = {@Index("id")})
+public class WeatherEntity {
+ @PrimaryKey(autoGenerate = true)
+ private int id;
+ private String city;
+ private String statusDay; // 白天状态,如:晴
+ private String statusNight; // 晚上状态
+ private String figureDay; // 状态索引
+ private String figureNight;
+ private String temperatureDay; // 白天温度 或 最低温度
+ private String temperatureNight; // 晚上温度 或 最低温度
+ private LocalDate updateTime; // 更新时间
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getStatusDay() {
+ return statusDay;
+ }
+
+ public void setStatusDay(String statusDay) {
+ this.statusDay = statusDay;
+ }
+
+ public String getStatusNight() {
+ return statusNight;
+ }
+
+ public void setStatusNight(String statusNight) {
+ this.statusNight = statusNight;
+ }
+
+ public String getFigureDay() {
+ return figureDay;
+ }
+
+ public void setFigureDay(String figureDay) {
+ this.figureDay = figureDay;
+ }
+
+ public String getFigureNight() {
+ return figureNight;
+ }
+
+ public void setFigureNight(String figureNight) {
+ this.figureNight = figureNight;
+ }
+
+ public String getTemperatureDay() {
+ return temperatureDay;
+ }
+
+ public void setTemperatureDay(String temperatureDay) {
+ this.temperatureDay = temperatureDay;
+ }
+
+ public String getTemperatureNight() {
+ return temperatureNight;
+ }
+
+ public void setTemperatureNight(String temperatureNight) {
+ this.temperatureNight = temperatureNight;
+ }
+
+ public LocalDate getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(LocalDate updateTime) {
+ this.updateTime = updateTime;
+ }
+}
--- /dev/null
+package com.ic.work.event;
+
+public class BloodCheckResultEvent {
+ private int high;
+ private int low;
+ private int heart;
+
+
+ public BloodCheckResultEvent(int high, int low, int heart) {
+ this.high = high;
+ this.low = low;
+ this.heart = heart;
+ }
+
+ public int getHigh() {
+ return high;
+ }
+
+ public int getLow() {
+ return low;
+ }
+
+ public int getHeart() {
+ return heart;
+ }
+
+}
--- /dev/null
+package com.ic.work.event;
+
+public class BloodCheckTipsEvent {
+ private int topTips;
+ private int bottomTips;
+
+ public BloodCheckTipsEvent(int topTips, int bottomTips) {
+ this.topTips = topTips;
+ this.bottomTips = bottomTips;
+ }
+
+ public int getTopTips() {
+ return topTips;
+ }
+
+ public void setTopTips(int topTips) {
+ this.topTips = topTips;
+ }
+
+ public int getBottomTips() {
+ return bottomTips;
+ }
+
+ public void setBottomTips(int bottomTips) {
+ this.bottomTips = bottomTips;
+ }
+}
--- /dev/null
+package com.ic.work.event;
+
+public class LocationResultEvent {
+
+ private String mCity;
+
+ public LocationResultEvent(String city) {
+ this.mCity = city;
+ }
+
+ public String getmCity() {
+ return mCity;
+ }
+}
--- /dev/null
+package com.ic.work.event;
+
+public class PedCountEvent {
+ private int pedCount;
+
+ public PedCountEvent(int count) {
+ this.pedCount = count;
+ }
+
+ public int getPedCount() {
+ return pedCount;
+ }
+}
--- /dev/null
+package com.ic.work.event;
+
+import com.ic.aidl.ped.RecordParcelable;
+
+import java.util.List;
+
+public class PedRecordResultEvent {
+ private List<RecordParcelable> recordList;
+
+ public List<RecordParcelable> getRecordList() {
+ return recordList;
+ }
+
+ public PedRecordResultEvent(List<RecordParcelable> recordList) {
+ this.recordList = recordList;
+ }
+}
--- /dev/null
+package com.ic.work.event;
+
+public class PedSettingEvent {
+ private int type;
+ private int value;
+
+ public PedSettingEvent(int type, int value) {
+ this.type = type;
+ this.value = value;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public int getValue() {
+ return value;
+ }
+}
--- /dev/null
+package com.ic.work.event;
+
+public class WeatherAgainEvent {
+}
--- /dev/null
+package com.ic.work.event;
+
+import com.ic.aidl.weather.WeatherParcelable;
+
+public class WeatherResultEvent {
+ private WeatherParcelable parcelable;
+
+ public WeatherResultEvent(WeatherParcelable parcelable) {
+ this.parcelable = parcelable;
+ }
+
+ public WeatherParcelable getParcelable() {
+ return parcelable;
+ }
+}
--- /dev/null
+package com.ic.work.hardware;
+
+import com.ic.work.event.BloodCheckResultEvent;
+import com.ic.work.event.BloodCheckTipsEvent;
+import com.ic.work.utils.HardwareUtils;
+import com.ic.work.utils.IcLog;
+
+import org.greenrobot.eventbus.EventBus;
+
+import static com.ic.aidl.blood.BloodState.BLOOD_ING_CHECK;
+import static com.ic.aidl.blood.BloodState.BLOOD_NOT_DATA_CHECK;
+import static com.ic.aidl.blood.BloodState.BLOOD_NOT_DEVICE;
+import static com.ic.aidl.blood.BloodState.BLOOD_NOT_WEAR;
+import static com.ic.aidl.blood.BloodState.BLOOD_NULL_TIPS;
+import static com.ic.aidl.blood.BloodState.BLOOD_PLEASE_QUIET;
+import static com.ic.aidl.blood.BloodState.BLOOD_START_CHECK;
+import static com.ic.aidl.blood.BloodState.BLOOD_STOP_CHECK;
+
+public class BloodRunnable implements Runnable{
+
+ private static final String TAG="BloodRunnable";
+
+ @Override
+ public void run() {
+ int ndkHeart = 0;
+ int ndkHigh = 0;
+ int ndkLow = 0;
+ int count = 0;
+
+ if (HardwareUtils.isPPGavailable()) {
+ sendTipsEventBus(BLOOD_NULL_TIPS,BLOOD_NOT_DEVICE);
+ return;
+ }
+
+ //开启
+ HardwareUtils.onNdkEnablePPG();
+
+ sendTipsEventBus(BLOOD_PLEASE_QUIET,BLOOD_START_CHECK);
+
+ try {
+ while (!Thread.currentThread().isInterrupted()) {
+ ndkHeart = HardwareUtils.getNdkPPGValue();
+ if (HardwareUtils.isWeared()) {
+ //未佩戴
+ sendTipsEventBus(BLOOD_NULL_TIPS,BLOOD_NOT_WEAR);
+ if (count > 15) break;
+ count++;
+ } else {
+ if (ndkHeart > 0) {
+ //佩戴好,并且已经或到心率的值,则获取低压和高压的值
+ ndkHigh = HardwareUtils.getNdkHighBloodValue();
+ ndkLow = HardwareUtils.getNdkLowBloodValue();
+ //跳出循环,不在获取
+ break;
+ } else {
+ //正在测量中,请稍等
+ sendTipsEventBus(BLOOD_PLEASE_QUIET,BLOOD_ING_CHECK);
+ }
+ }
+
+ Thread.sleep(1000);
+ }
+
+ if (count > 15 || ndkHeart == 0) {
+ sendTipsEventBus(BLOOD_STOP_CHECK, BLOOD_NOT_DATA_CHECK);
+ } else {
+ EventBus.getDefault().post(new BloodCheckResultEvent(ndkHigh,ndkLow,ndkHeart));
+ }
+
+ HardwareUtils.onNdkDisablePPG();
+
+ } catch (InterruptedException e) {
+ IcLog.e(TAG, "Stop Get Heart Value");
+ }finally {
+ HardwareUtils.onNdkDisablePPG();
+ }
+ }
+
+ private void sendTipsEventBus(int top,int bottom){
+ EventBus.getDefault().post(new BloodCheckTipsEvent(top, bottom));
+ }
+}
--- /dev/null
+package com.ic.work.hardware;
+
+import com.ic.aidl.ped.RecordParcelable;
+import com.ic.work.db.PedInjection;
+import com.ic.work.db.entity.PedEntity;
+import com.ic.work.event.PedRecordResultEvent;
+
+import org.greenrobot.eventbus.EventBus;
+import org.threeten.bp.format.DateTimeFormatter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PedRecordRunnable implements Runnable {
+ private PedInjection mPedDb;
+
+ private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
+
+ public PedRecordRunnable(PedInjection pedDB) {
+ mPedDb = pedDB;
+ }
+
+ @Override
+ public void run() {
+ List<PedEntity> query = mPedDb.queryDBPedAllList();
+ List<RecordParcelable> recordList = new ArrayList<>();
+ for (int i=0; i< query.size(); i++){
+ RecordParcelable recordP = new RecordParcelable();
+ recordP.setNumber(query.get(i).getPedNumber());
+ recordP.setCalorie(String.valueOf(query.get(i).getPedCalorie()));
+ recordP.setDistance(String.valueOf(query.get(i).getPedDistance()));
+ recordP.setDate(query.get(i).getPedDate().format(formatter));
+
+ recordList.add(recordP);
+ }
+
+ //发送数据到主线程
+ EventBus.getDefault().post(new PedRecordResultEvent(recordList));
+ }
+}
--- /dev/null
+package com.ic.work.hardware;
+
+import com.ic.work.db.PedInjection;
+import com.ic.work.db.entity.PedEntity;
+import com.ic.work.event.PedCountEvent;
+import com.ic.work.utils.HardwareUtils;
+import com.ic.work.utils.IcLog;
+import com.ic.work.utils.PedUtil;
+
+import org.greenrobot.eventbus.EventBus;
+import org.threeten.bp.LocalDate;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+public class PedRunnable implements Runnable {
+
+ private static final String TAG = "PedRunnable";
+
+ private PedInjection mPedDb;
+
+ private int mHeight;
+ private int mWeight;
+
+ public PedRunnable(PedInjection pedDB, int height, int weight) {
+ mPedDb = pedDB;
+ mHeight = height;
+ mWeight = weight;
+ }
+
+ public void setHeight(int mHeight) {
+ this.mHeight = mHeight;
+ }
+
+ public void setWeight(int mWeight) {
+ this.mWeight = mWeight;
+ }
+
+ @Override
+ public void run() {
+ //1.先获取一次当前的计步数
+ int currCount = HardwareUtils.getNdkStepCountValue();
+ IcLog.i(TAG, "Ped Count" + currCount);
+
+ int size = mPedDb.queryDBPedCount();
+ if (size == 0) {
+ //如果数据库中无记录,把当前数据插入到数据库中
+ insertDBPedEntity(currCount, LocalDate.now(),size);
+ } else {
+ //2.去查询数据中是否有当天的记录。
+ List<PedEntity> todayPed = mPedDb.queryDBPedDate(LocalDate.now());
+ if (todayPed != null && todayPed.size() > 0) {
+ //3.如果数据中有当天的数据,并更新数据
+ if (currCount > 0 && currCount > todayPed.get(0).getPedNumber()) {
+ todayPed.get(0).setPedNumber(currCount);
+ updateDBPedEntity(todayPed.get(0));
+ }
+ } else {
+ //4.如果数据库中没有当天的数据,则把当前的数据更新前一天的数据中
+ // 并且重置计步,并在数据库中新建一条数据
+ //重置计步
+ HardwareUtils.resetNdkStepCountValue();
+ //获取前一天的数据
+ List<PedEntity> beforePed = mPedDb.queryDBPedDate(LocalDate.now().minusDays(1));
+ if (beforePed != null && beforePed.size() > 0) {
+ beforePed.get(0).setPedNumber(currCount);
+ updateDBPedEntity(beforePed.get(0));
+
+ insertDBPedEntity(0, LocalDate.now(),size);
+ //发送给主线程。主线更新数据UI
+ EventBus.getDefault().post(new PedCountEvent(0));
+ return;
+ } else {
+ //如果没有前一天没有数据。则直接 插入今天的数据
+ insertDBPedEntity(currCount, LocalDate.now(),size);
+ }
+ }
+ }
+
+ //发送给主线程。主线更新数据UI
+ EventBus.getDefault().post(new PedCountEvent(currCount));
+ }
+
+ private PedEntity createEntity(int number, LocalDate date) {
+
+ PedEntity entity = new PedEntity();
+ entity.setPedNumber(number);
+ entity.setPedDistance(getDistanceValue(number));
+ entity.setPedCalorie(getCalorieValue(number));
+ entity.setPedDate(date);
+
+ return entity;
+ }
+
+ private void insertDBPedEntity(int number, LocalDate date,int size) {
+ //判断 size 超过
+ if(size >= 60){
+ //删除一条最早的数据
+ List<PedEntity> entities = mPedDb.queryDBPedOldestList();
+ if(entities != null && entities.size() == 1){
+ mPedDb.deletePedEntity(entities.get(0).getId());
+ }
+ }
+ mPedDb.insertDBPedDate(createEntity(number, date));
+ }
+
+ private void updateDBPedEntity(PedEntity entity) {
+ int number = entity.getPedNumber();
+ entity.setPedDistance(getDistanceValue(number));
+ entity.setPedCalorie(getCalorieValue(number));
+ mPedDb.updateDBPedDate(entity);
+ }
+
+ private float getCalorieValue(int number) {
+ BigDecimal bg = new BigDecimal(PedUtil.calcConsumeEnergy(mHeight, mWeight, number));
+ return bg.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
+ }
+
+ private float getDistanceValue(int number) {
+ BigDecimal bg = new BigDecimal(PedUtil.calcDistanceBySteps(mHeight, number));
+ return bg.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
+ }
+}
--- /dev/null
+package com.ic.work.process;
+
+import android.os.IBinder;
+import android.os.RemoteCallbackList;
+import android.os.RemoteException;
+
+import com.ic.aidl.blood.IBloodAidlInterface;
+import com.ic.aidl.blood.IBloodRemoteService;
+import com.ic.work.ThreadPoolManager;
+import com.ic.work.hardware.BloodRunnable;
+import com.ic.work.utils.IcLog;
+
+
+public class BloodProcess {
+ private static final String TAG = "BloodProcess";
+
+ private RemoteCallbackList<IBloodAidlInterface> mCallbacks = new RemoteCallbackList<>();
+
+ private BloodRunnable mBloodRun;
+
+ public BloodProcess() {
+ mBloodRun = new BloodRunnable();
+ }
+
+ public IBinder getBloodBinder() {
+ return bloodBinder;
+ }
+
+ private IBloodRemoteService.Stub bloodBinder = new IBloodRemoteService.Stub() {
+ @Override
+ public void registerCallback(IBloodAidlInterface cb) throws RemoteException {
+ if (cb != null) {
+ mCallbacks.register(cb);
+ }
+ }
+
+ @Override
+ public void unregisterCallback(IBloodAidlInterface cb) throws RemoteException {
+ if (cb != null) {
+ mCallbacks.unregister(cb);
+ }
+ }
+
+ @Override
+ public void startCheckBlood() throws RemoteException {
+ ThreadPoolManager.getInstance().execute(mBloodRun);
+ }
+
+ @Override
+ public void stopCheckBlood() throws RemoteException {
+ ThreadPoolManager.getInstance().remove(mBloodRun);
+ }
+ };
+
+ public void sendBloodCheckResult(int heih, int low, int heart) {
+ int N = 0;
+ try {
+ N = mCallbacks.beginBroadcast();
+ for (int i = 0; i < N; i++) {
+ mCallbacks.getBroadcastItem(i).updateBloodCheckResult(heih, low, heart);
+ }
+ } catch (NullPointerException e) {
+ IcLog.e(TAG, e.getMessage());
+ } catch (RemoteException er) {
+ IcLog.e(TAG, er.getMessage());
+ } finally {
+ try {
+ if (N > 0) {
+ mCallbacks.finishBroadcast();
+ }
+ } catch (IllegalArgumentException ll) {
+ IcLog.e(TAG, ll.getMessage());
+ }
+ }
+ }
+
+ public void sendBloodCheckTips(int top, int bottom) {
+ int N = 0;
+ try {
+ N = mCallbacks.beginBroadcast();
+ for (int i = 0; i < N; i++) {
+ mCallbacks.getBroadcastItem(i).updateBloodCheckTips(top, bottom);
+ }
+ } catch (NullPointerException e) {
+ IcLog.e(TAG, e.getMessage());
+ } catch (RemoteException er) {
+ IcLog.e(TAG, er.getMessage());
+ } finally {
+ try {
+ if (N > 0) {
+ mCallbacks.finishBroadcast();
+ }
+ } catch (IllegalArgumentException ll) {
+ IcLog.e(TAG, ll.getMessage());
+ }
+ }
+ }
+}
--- /dev/null
+package com.ic.work.process;
+
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.RemoteCallbackList;
+import android.os.RemoteException;
+
+import com.ic.aidl.ped.IPedAidlInterface;
+import com.ic.aidl.ped.IPedRemoteService;
+import com.ic.aidl.ped.RecordParcelable;
+import com.ic.work.ThreadPoolManager;
+import com.ic.work.WorkServiceApp;
+import com.ic.work.event.PedSettingEvent;
+import com.ic.work.hardware.PedRecordRunnable;
+import com.ic.work.hardware.PedRunnable;
+import com.ic.work.utils.IcLog;
+
+import org.greenrobot.eventbus.EventBus;
+
+import java.util.List;
+
+public class PedProcess {
+ private static final String TAG = "PedProcess";
+
+ private RemoteCallbackList<IPedAidlInterface> mCallbacks = new RemoteCallbackList<>();
+
+ private PedRunnable mPedRun;
+ private PedRecordRunnable mRecordRun;
+
+ public PedProcess(WorkServiceApp app, int height, int weight) {
+ mPedRun = new PedRunnable(app.getRepository(), height, weight);
+ mRecordRun = new PedRecordRunnable(app.getRepository());
+ }
+
+ public IBinder getPedBinder() {
+ return pedBinder;
+ }
+
+ private IPedRemoteService.Stub pedBinder = new IPedRemoteService.Stub() {
+ @Override
+ public void registerCallback(IPedAidlInterface cb) throws RemoteException {
+ if (cb != null) {
+ mCallbacks.register(cb);
+ }
+ }
+
+ @Override
+ public void unregisterCallback(IPedAidlInterface cb) throws RemoteException {
+ if (cb != null) {
+ mCallbacks.unregister(cb);
+ }
+ }
+
+ @Override
+ public void queryPedCount() throws RemoteException {
+ ThreadPoolManager.getInstance().execute(mPedRun);
+ }
+
+ @Override
+ public void queryPedRecord() throws RemoteException {
+ ThreadPoolManager.getInstance().execute(mRecordRun);
+ }
+
+ @Override
+ public void syncPedHeightSetting(int height) throws RemoteException {
+ EventBus.getDefault().post(new PedSettingEvent(1, height));
+ }
+
+ @Override
+ public void syncPedWeightSetting(int weight) throws RemoteException {
+ EventBus.getDefault().post(new PedSettingEvent(2, weight));
+ }
+ };
+
+ public void updateHeight(int height){
+ mPedRun.setHeight(height);
+ }
+
+ public void updateWeight(int weight){
+ mPedRun.setWeight(weight);
+ }
+
+ public void sendPedCount(int count) {
+ int N = 0;
+ try {
+ N = mCallbacks.beginBroadcast();
+ for (int i = 0; i < N; i++) {
+ mCallbacks.getBroadcastItem(i).updatePedCount(count);
+ }
+ } catch (NullPointerException e) {
+ IcLog.e(TAG, e.getMessage());
+ } catch (RemoteException er) {
+ IcLog.e(TAG, er.getMessage());
+ } finally {
+ try {
+ if (N > 0) {
+ mCallbacks.finishBroadcast();
+ }
+ } catch (IllegalArgumentException ll) {
+ IcLog.e(TAG, ll.getMessage());
+ }
+ }
+ }
+
+ public void sendPedRecord(List<RecordParcelable> record) {
+ int N = 0;
+ try {
+ N = mCallbacks.beginBroadcast();
+ for (int i = 0; i < N; i++) {
+ mCallbacks.getBroadcastItem(i).updatePedRecord(record);
+ }
+ } catch (NullPointerException e) {
+ IcLog.e(TAG, e.getMessage());
+ } catch (RemoteException er) {
+ IcLog.e(TAG, er.getMessage());
+ } finally {
+ try {
+ if (N > 0) {
+ mCallbacks.finishBroadcast();
+ }
+ } catch (IllegalArgumentException ll) {
+ IcLog.e(TAG, ll.getMessage());
+ }
+ }
+ }
+}
--- /dev/null
+package com.ic.work.process;
+
+import android.os.IBinder;
+import android.os.RemoteCallbackList;
+import android.os.RemoteException;
+
+import com.ic.aidl.weather.IWeatherAidlInterface;
+import com.ic.aidl.weather.IWeatherRemoteService;
+import com.ic.aidl.weather.WeatherParcelable;
+import com.ic.work.ThreadPoolManager;
+import com.ic.work.WorkServiceApp;
+import com.ic.work.utils.IcLog;
+import com.ic.work.weather.WeatherDBRun;
+
+public class WeatherProcess {
+
+ private static final String TAG = "WeatherProcess";
+
+ private RemoteCallbackList<IWeatherAidlInterface> mCallbacks = new RemoteCallbackList<>();
+
+ private WeatherDBRun weatherRun;
+
+ public WeatherProcess(WorkServiceApp app) {
+ weatherRun = new WeatherDBRun(app.getWeatherRepository());
+ }
+
+ public IBinder getWeatherBinder(){
+ return weatherBinder;
+ }
+
+ private IWeatherRemoteService.Stub weatherBinder = new IWeatherRemoteService.Stub() {
+ @Override
+ public void registerCallback(IWeatherAidlInterface cb) throws RemoteException {
+ if (cb != null) {
+ mCallbacks.register(cb);
+ }
+ }
+
+ @Override
+ public void unregisterCallback(IWeatherAidlInterface cb) throws RemoteException {
+ if (cb != null) {
+ mCallbacks.unregister(cb);
+ }
+ }
+
+ @Override
+ public void queryWeatherInfo() throws RemoteException {
+ ThreadPoolManager.getInstance().execute(weatherRun);
+ }
+ };
+
+ public void sendCurrWeather(WeatherParcelable parcelable) {
+ int N = 0;
+ try {
+ N = mCallbacks.beginBroadcast();
+ for (int i = 0; i < N; i++) {
+ mCallbacks.getBroadcastItem(i).updateCurrWeather(parcelable);
+ }
+ } catch (NullPointerException e) {
+ IcLog.e(TAG, e.getMessage());
+ } catch (RemoteException er) {
+ IcLog.e(TAG, er.getMessage());
+ } finally {
+ try {
+ if (N > 0) {
+ mCallbacks.finishBroadcast();
+ }
+ } catch (IllegalArgumentException ll) {
+ IcLog.e(TAG, ll.getMessage());
+ }
+ }
+ }
+}
--- /dev/null
+package com.ic.work.utils;
+
+import android.os.Handler;
+import android.os.Looper;
+
+import androidx.annotation.NonNull;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+public class AppExecutors {
+
+ private final Executor mDiskIO;
+
+ private final Executor mNetworkIO;
+
+ private final Executor mMainThread;
+
+ private AppExecutors(Executor diskIO, Executor networkIO, Executor mainThread) {
+ this.mDiskIO = diskIO;
+ this.mNetworkIO = networkIO;
+ this.mMainThread = mainThread;
+ }
+
+ public AppExecutors() {
+ this(Executors.newSingleThreadExecutor(), Executors.newFixedThreadPool(3),
+ new MainThreadExecutor());
+ }
+
+ public Executor diskIO() {
+ return mDiskIO;
+ }
+
+ public Executor networkIO() {
+ return mNetworkIO;
+ }
+
+ public Executor mainThread() {
+ return mMainThread;
+ }
+
+ private static class MainThreadExecutor implements Executor {
+ private Handler mainThreadHandler = new Handler(Looper.getMainLooper());
+
+ @Override
+ public void execute(@NonNull Runnable command) {
+ mainThreadHandler.post(command);
+ }
+ }
+}
--- /dev/null
+package com.ic.work.utils;
+
+import com.ic.jni.ICJniUtils;
+
+public class HardwareUtils {
+
+ private static final String TAG = "HardwareUtils";
+
+ public static boolean isPPGavailable() {
+ try {
+ return ICJniUtils.isPPGavailable() == 0;
+ } catch (Exception e) {
+ IcLog.e(TAG, e.getMessage());
+ return true;
+ }
+ }
+
+ public static void onNdkEnablePPG() {
+ try {
+ ICJniUtils.enablePPG();
+ } catch (Exception e) {
+ IcLog.e(TAG, e.getMessage());
+ }
+ }
+
+ public static void onNdkDisablePPG() {
+ try {
+ ICJniUtils.disablePPG();
+ } catch (Exception e) {
+ IcLog.e(TAG, e.getMessage());
+ }
+ }
+
+ public static boolean isWeared() {
+ try {
+ return ICJniUtils.isWeared() == 0;
+ } catch (Exception e) {
+ IcLog.e(TAG, e.getMessage());
+ return true;
+ }
+ }
+
+ public static int getNdkPPGValue() {
+ try {
+ return ICJniUtils.getPPG();
+ } catch (Exception e) {
+ IcLog.e(TAG, e.getMessage());
+ return 0;
+ }
+ }
+
+ public static int getNdkHighBloodValue() {
+ try {
+ return ICJniUtils.getHighBloodPressure();
+ } catch (Exception e) {
+ IcLog.e(TAG, e.getMessage());
+ return 0;
+ }
+ }
+
+ public static int getNdkLowBloodValue() {
+ try {
+ return ICJniUtils.getLowBloodPressure();
+ } catch (Exception e) {
+ IcLog.e(TAG, e.getMessage());
+ return 0;
+ }
+ }
+
+ public static int getNdkStepCountValue() {
+ try {
+ return ICJniUtils.getStepCount();
+ } catch (Exception e) {
+ IcLog.e(TAG, e.getMessage());
+ return 0;
+ }
+ }
+
+ public static int resetNdkStepCountValue() {
+ try {
+ return ICJniUtils.resetStepCount();
+ } catch (Exception e) {
+ IcLog.e(TAG, e.getMessage());
+ return 0;
+ }
+ }
+}
--- /dev/null
+package com.ic.work.utils;
+
+import android.util.Log;
+
+import com.ic.work.BuildConfig;
+
+/**
+ * @author RyanLee
+ * @date 2018/2/2
+ */
+
+public class IcLog {
+
+ private static final String DOT = ".";
+ private static boolean isDebug = BuildConfig.DEBUG;
+ private static String tagHead = "";
+
+ public static void v(String tag, String msg) {
+ if (isDebug) {
+ Log.v(mergeHeadTag(tag), msg);
+ }
+ }
+
+ public static void d(String tag, String msg) {
+ if (isDebug) {
+ Log.d(mergeHeadTag(tag), msg);
+ }
+ }
+
+ public static void i(String tag, String msg) {
+ if (isDebug) {
+ Log.i(mergeHeadTag(tag), msg);
+ }
+ }
+
+ public static void w(String tag, String msg) {
+ if (isDebug) {
+ Log.w(mergeHeadTag(tag), msg);
+ }
+ }
+
+ public static void e(String tag, String msg) {
+ if (isDebug) {
+ Log.e(mergeHeadTag(tag), msg);
+ }
+ }
+
+ public static void setDebug(boolean debug) {
+ isDebug = debug;
+ }
+
+ public static void setLogHead(String head) {
+ tagHead = head + DOT;
+ }
+
+ private static String mergeHeadTag(final String tag) {
+ return tagHead + tag;
+ }
+}
--- /dev/null
+package com.ic.work.utils;
+
+public class PedUtil {
+
+ private static final float LB_KG_CONVERSION_RATE = 0.45359237f;
+ private static final float KM_TO_MILE_CONVERSION_RATE = 0.62147119f;
+ private static final float INCH_CM_CONVERSION_RATE = 2.54f;
+ private static final int FOOT_INCH_CONVERSION_RATE = 12;
+
+ //根据身高、步数计算路程
+ public static float calcDistanceBySteps(int height, int steps) {
+ float var = 0f;
+ if (height < 154) {
+ var = (float) 16 / 42;
+ } else if (height > 174) {
+ var = (float) 17 / 42;
+ } else {
+ var = (float) 11 / 28;
+ }
+
+ return (steps * height * var + height / 7) / 100000; // km
+ }
+
+ public static float calcConsumeEnergy(int height, int weight, int steps) {
+ float consumeEnergy = 0f;
+ if (steps > 0) {
+ consumeEnergy = (0.53f * height + 0.58f * weight + 0.04f * steps) - 135;
+ consumeEnergy = (int) (consumeEnergy * 10) / 10f;
+ consumeEnergy = Math.max(consumeEnergy, 0.1f);
+ }
+ return consumeEnergy;
+ }
+
+ //单位转换 Inch 英寸 -> cm
+ public static float inchToCm(float inch) {
+ return (inch * INCH_CM_CONVERSION_RATE);
+ }
+
+ //单位转换 km -> mile 英里
+ public static float kmToMile(float km) {
+ return (km * KM_TO_MILE_CONVERSION_RATE);
+ }
+
+ //单位转换 kg -> lb 磅
+ public static float kgTolb(float kg) {
+ return (kg / LB_KG_CONVERSION_RATE);
+ }
+
+ //单位转换 lb 磅 -> kg
+ public static float lbTokg(float lb) {
+ return (lb * LB_KG_CONVERSION_RATE);
+ }
+}
--- /dev/null
+package com.ic.work.utils;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+
+public class SPUtils {
+
+ private static final String Ped_Height = "Ped_Height";
+ private static final String Ped_Weight = "Ped_Weight";
+
+ public static SharedPreferences getSP(Context context) {
+ return context.getSharedPreferences("IcPedSet", Context.MODE_PRIVATE);
+ }
+
+ public static int getPedHeightSP(Context context) {
+ return getSP(context).getInt(Ped_Height, 170);
+ }
+
+ public static int getPedWighttSP(Context context) {
+ return getSP(context).getInt(Ped_Weight, 75);
+ }
+
+ public static void setPedHeightSP(Context context,int height) {
+ SharedPreferences.Editor editor = getSP(context).edit();
+ if (editor != null) {
+ editor.putInt(Ped_Weight, height);
+ editor.apply();
+ }
+ }
+
+ public static void setPedWighttSP(Context context,int weight) {
+ SharedPreferences.Editor editor = getSP(context).edit();
+ if (editor != null) {
+ editor.putInt(Ped_Weight, weight);
+ editor.apply();
+ }
+ }
+}
--- /dev/null
+package com.ic.work.utils;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+
+import java.util.List;
+
+public class ServiceUtil {
+
+ public static void startServiceUtil(Context context , String serviceAction, String packageName) {
+ Intent intent = getExplicitIntent(context, new Intent(serviceAction));
+ if(intent != null){
+ intent.setPackage(packageName);
+ context.startService(intent);
+ }
+ }
+
+ public static void bindServiceUtil(Context context , String action, ServiceConnection connection,int type) {
+ Intent in = getExplicitIntent(context, new Intent(action));
+ if(in != null){
+ in.putExtra("REQ_TYPE",type);
+ context.bindService(in, connection, 0);
+ }
+ }
+
+ private static Intent getExplicitIntent(Context context, Intent impl) {
+ List<ResolveInfo> resolveInfo = context.getPackageManager().queryIntentServices(impl, 0);
+
+ if (resolveInfo.size() != 1) return null;
+
+ Intent intent = new Intent(impl);
+ ServiceInfo info = resolveInfo.get(0).serviceInfo;
+ if (info == null) return null;
+ intent.setComponent(new ComponentName(info.packageName, info.name));
+
+ return intent;
+ }
+}
--- /dev/null
+package com.ic.work.weather;
+
+import android.content.Context;
+
+import com.amap.api.location.AMapLocationClient;
+import com.amap.api.location.AMapLocationClientOption;
+import com.amap.api.location.AMapLocationListener;
+import com.ic.work.event.LocationResultEvent;
+import com.ic.work.utils.IcLog;
+
+import org.greenrobot.eventbus.EventBus;
+
+public class LocationHelper {
+
+ private static final String TAG ="LocationHelper";
+
+ public AMapLocationClient mLocationClient;
+
+ public LocationHelper(Context context) {
+ mLocationClient = new AMapLocationClient(context);
+ //定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
+ AMapLocationListener mLocationListener = aMapLocation -> {
+ if (aMapLocation != null) {
+ if (aMapLocation.getErrorCode() == 0) {
+ IcLog.i(TAG,"Loaction City:"+aMapLocation.getCity());
+ EventBus.getDefault().post(new LocationResultEvent(aMapLocation.getCity()));
+ } else {
+ //定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
+ IcLog.e(TAG, "location Error, ErrCode:"
+ + aMapLocation.getErrorCode() + ", errInfo:"
+ + aMapLocation.getErrorInfo());
+ EventBus.getDefault().post(new LocationResultEvent(""));
+ }
+ }
+ };
+ mLocationClient.setLocationListener(mLocationListener);
+ mLocationClient.setLocationOption(getDefaultOption());
+ }
+
+ public void startLocationService(){
+ if(mLocationClient != null){
+ mLocationClient.startLocation();
+ }
+ }
+
+ public void stopLocationService(){
+ if(mLocationClient != null){
+ mLocationClient.stopLocation();
+ mLocationClient.onDestroy();
+
+ mLocationClient = null;
+ }
+ }
+
+ private AMapLocationClientOption getDefaultOption() {
+ AMapLocationClientOption mOption = new AMapLocationClientOption();
+
+ // 高德地图默认值
+ mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
+ mOption.setGpsFirst(false);//可选,设置是否gps优先,只在高精度模式下有效。默认关闭
+ mOption.setHttpTimeOut(30000);//可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效
+ mOption.setInterval(2000);//可选,设置定位间隔。默认为2秒
+ mOption.setNeedAddress(true);//可选,设置是否返回逆地理地址信息。默认是true
+ mOption.setOnceLocation(false);//可选,设置是否单次定位。默认是false
+ mOption.setOnceLocationLatest(false);//可选,设置是否等待wifi刷新,默认为false.如果设置为true,会自动变为单次定位,持续定位时不要使用
+ AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);//可选, 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
+ mOption.setSensorEnable(false);//可选,设置是否使用传感器。默认是false
+ mOption.setWifiScan(true); //可选,设置是否开启wifi扫描。默认为true,如果设置为false会同时停止主动刷新,停止以后完全依赖于系统刷新,定位位置可能存在误差
+ mOption.setLocationCacheEnable(true); //可选,设置是否使用缓存定位,默认为true
+
+
+ // 自定义
+ mOption.setHttpTimeOut(10000);
+ mOption.setInterval(10000);
+
+ // 一次定位设置
+ // 该方法默认为false。
+ mOption.setOnceLocation(true);
+ // 关闭缓存机制
+ mOption.setLocationCacheEnable(false);
+
+ return mOption;
+ }
+
+}
--- /dev/null
+package com.ic.work.weather;
+
+import com.ic.aidl.weather.WeatherParcelable;
+import com.ic.work.db.WeatherInjection;
+import com.ic.work.db.entity.WeatherEntity;
+import com.ic.work.event.WeatherAgainEvent;
+import com.ic.work.event.WeatherResultEvent;
+
+import org.greenrobot.eventbus.EventBus;
+import org.threeten.bp.LocalDate;
+import org.threeten.bp.OffsetDateTime;
+import org.threeten.bp.format.DateTimeFormatter;
+
+import java.util.List;
+
+public class WeatherDBRun implements Runnable {
+
+ private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
+
+ private WeatherInjection weatherDb;
+
+ public WeatherDBRun(WeatherInjection weather){
+ this.weatherDb = weather;
+ }
+
+ @Override
+ public void run() {
+
+ List<WeatherEntity> weatherList = weatherDb.queryDBWeatherDate(LocalDate.now());
+ if(weatherList == null || weatherList.size() ==0){
+ //通知主线程 开始定位 并通过Socket 获取天气
+ EventBus.getDefault().post(new WeatherAgainEvent());
+ //删除表中所有数据
+ weatherDb.deleteDBWeatherDate();
+ }else {
+ WeatherEntity entity = weatherList.get(0);
+
+ WeatherParcelable parcelable = new WeatherParcelable();
+ parcelable.setCity(entity.getCity());
+ parcelable.setFigureDay(entity.getFigureDay());
+ parcelable.setFigureNight(entity.getFigureNight());
+ parcelable.setStatusDay(entity.getStatusDay());
+ parcelable.setStatusNight(entity.getStatusNight());
+ parcelable.setTemperatureDay(entity.getTemperatureDay());
+ parcelable.setTemperatureNight(entity.getTemperatureNight());
+ parcelable.setUpdateTime(entity.getUpdateTime().format(formatter));
+
+ //通知主线程 更新UI
+ EventBus.getDefault().post(new WeatherResultEvent(parcelable));
+ }
+ }
+}
--- /dev/null
+package com.ic.work.weather;
+
+import android.content.Context;
+import android.text.TextUtils;
+
+import com.alibaba.fastjson.JSONObject;
+import com.ic.work.ThreadPoolManager;
+import com.ic.work.db.WeatherInjection;
+import com.ic.work.weather.melon.SocketThread;
+
+public class WeatherHelper {
+
+ private LocationHelper mLocation = null;
+
+ public void startLocation(Context context) {
+ mLocation = new LocationHelper(context);
+ mLocation.startLocationService();
+ }
+
+ private void stopLocation() {
+ if (mLocation != null) {
+ mLocation.stopLocationService();
+ mLocation = null;
+ }
+ }
+
+
+ public void queryWeatherServerInfo(WeatherInjection weatherDb,String city) {
+
+ stopLocation();
+
+ if(TextUtils.isEmpty(city)){
+ return;
+ }
+
+ final String serverHost = "118.190.120.79";
+ final int port = 11645;
+
+ JSONObject paramJson = new JSONObject();
+ paramJson.put("cmd", "getserviceip");
+ paramJson.put("channel", "西瓜皮-西瓜皮");
+ final String param = paramJson.toJSONString();
+
+ SocketThread socket = new SocketThread(weatherDb,serverHost, port, param,city);
+ ThreadPoolManager.getInstance().execute(socket);
+ }
+}
--- /dev/null
+package com.ic.work.weather.melon;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.ic.aidl.weather.WeatherParcelable;
+import com.ic.work.BuildConfig;
+import com.ic.work.db.WeatherInjection;
+import com.ic.work.db.entity.WeatherEntity;
+import com.ic.work.event.WeatherResultEvent;
+import com.ic.work.utils.IcLog;
+
+import org.greenrobot.eventbus.EventBus;
+import org.threeten.bp.LocalDate;
+import org.threeten.bp.OffsetDateTime;
+import org.threeten.bp.format.DateTimeFormatter;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+public class SocketThread implements Runnable {
+ private static final String TAG = "SocketThread";
+
+ private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
+
+ private String mIp;
+ private int mPort;
+ private String param;
+
+ private String mCity;
+
+ private SocketUtils mSocketUtils;
+
+ private WeatherInjection weatherInjection;
+
+ public SocketThread(WeatherInjection weatherDb, String ip, int port, String param, String city) {
+ mSocketUtils = new SocketUtils();
+
+ weatherInjection = weatherDb;
+
+ this.mIp = ip;
+ this.mPort = port;
+ this.param = param;
+ this.mCity = city;
+ }
+
+ @Override
+ public void run() {
+
+ byte[] response = null;
+ int count = 0;
+ boolean isQueryWeather = false;
+
+ while (true) {
+ count++;
+
+ try {
+ mSocketUtils.connectSocket(mIp, mPort);
+ mSocketUtils.write(param.getBytes(UTF_8));
+ response = mSocketUtils.read();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ mSocketUtils.disconnect();
+ }
+
+ if (response != null || count == 3) {
+ if (response != null) {
+ if (!isQueryWeather) {
+ parseWeatherServerInfo(new String(response, UTF_8));
+ count = 0;
+ isQueryWeather = true;
+ response=null;
+ continue;
+ } else {
+ parseWeatherJSONString(new String(response, UTF_8));
+ }
+ }
+ break;
+ }
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ break;
+ }
+ }
+ }
+
+
+ private void parseWeatherServerInfo(String stringJson) {
+ IcLog.i(TAG, stringJson);
+
+ JSONObject responseJsonObj = JSONObject.parseObject(stringJson);
+ JSONObject serverInfo = responseJsonObj.getJSONObject("result");
+ mIp = serverInfo.getString("weather_ip");
+ mPort = serverInfo.getIntValue("weather_port");
+
+ JSONObject paramJson = new JSONObject();
+ paramJson.put("cmd", "getheweatherbycity");
+ paramJson.put("city", transformCityName(mCity));
+ param = paramJson.toJSONString();
+ }
+
+ private void parseWeatherJSONString(String stringJson) {
+ IcLog.i(TAG, "Response is weather" + stringJson);
+
+ JSONObject responseJsonObj = JSONObject.parseObject(stringJson);
+ JSONArray jsonArray = responseJsonObj.getJSONArray("HeWeather data service 3.0");
+ if (jsonArray.size() > 0) {
+ JSONObject jsonObjectRoot = jsonArray.getJSONObject(0);
+ String stringStatus = jsonObjectRoot.getString("status");
+ if (stringStatus.equalsIgnoreCase("ok")) {
+ JSONArray jsonObjectForecast = jsonObjectRoot.getJSONArray("daily_forecast");
+
+ JSONObject fJson = jsonObjectForecast.getJSONObject(0);
+
+ JSONObject jObjectCond = fJson.getJSONObject("cond");
+ JSONObject jObjectTemp = fJson.getJSONObject("tmp");
+
+ WeatherParcelable weather = new WeatherParcelable();
+ WeatherEntity db = new WeatherEntity();
+ weather.setCity(mCity);
+ db.setCity(mCity);
+
+ weather.setStatusDay(jObjectCond.getString("txt_d")); // 白天天气描述
+ db.setStatusDay(weather.getStatusDay());
+ weather.setStatusNight(jObjectCond.getString("txt_n")); // 夜间天气描述
+ db.setStatusNight(weather.getStatusNight());
+
+ weather.setFigureDay(jObjectCond.getString("code_d")); // 天气索引
+ db.setFigureDay(weather.getFigureDay());
+ weather.setFigureNight(jObjectCond.getString("code_n"));
+ db.setFigureNight(weather.getFigureNight());
+
+ weather.setTemperatureDay(jObjectTemp.getString("min")); // 白天温度-对应“和风天气”的最低温度
+ db.setTemperatureDay(weather.getTemperatureDay());
+ weather.setTemperatureNight(jObjectTemp.getString("max")); // 夜间温度-对应“和风天气”的最高温度
+ db.setTemperatureNight(weather.getTemperatureNight());
+
+ weather.setUpdateTime(LocalDate.now().format(formatter));
+ db.setUpdateTime(LocalDate.now());
+
+ if (BuildConfig.DEBUG) {
+ StringBuffer stringBuffer = new StringBuffer();
+ stringBuffer.append(weather.getStatusDay()).append("-").append(weather.getStatusNight())
+ .append("|")
+ .append(weather.getTemperatureDay()).append("-").append(weather.getTemperatureNight())
+ .append("|")
+ .append(weather.getUpdateTime());
+ IcLog.i(TAG, "Response is weather:" + stringBuffer.toString());
+ }
+
+ EventBus.getDefault().post(new WeatherResultEvent(weather));
+ //插入数据库
+ weatherInjection.deleteDBWeatherDate();
+ weatherInjection.insertWeatherEntity(db);
+ }
+ }
+ }
+
+ private static String transformCityName(String cityName) {
+ String retValue = cityName;
+ if (cityName != null && !cityName.isEmpty()) {
+ if (retValue.endsWith("地区")) {
+ retValue = retValue.substring(0, retValue.length() - 2);
+ } else if (retValue.endsWith("市") || retValue.endsWith("县") || retValue.endsWith("州") || retValue.endsWith("盟")
+ || retValue.endsWith("区")) {
+ retValue = retValue.substring(0, retValue.length() - 1);
+ }
+ }
+
+ return retValue;
+ }
+}
--- /dev/null
+package com.ic.work.weather.melon;
+
+import java.io.IOException;
+import java.net.Socket;
+
+import okio.BufferedSink;
+import okio.BufferedSource;
+import okio.Okio;
+
+public class SocketUtils {
+ private Socket socket;
+ private BufferedSource source;
+ private BufferedSink sink;
+
+ public void connectSocket(String host,int port) throws IOException {
+ socket = new Socket(host,port);
+ socket.setSoTimeout(15000);
+ sink = Okio.buffer(Okio.sink(socket.getOutputStream()));
+ source = Okio.buffer(Okio.source(socket.getInputStream()));
+ }
+
+ public void write(byte[] param) throws IOException {
+ sink.writeInt(param.length);
+ sink.write(param);
+ sink.flush();
+ }
+
+ public byte[] read() throws IOException {
+ int byteCount = source.readInt();
+ if (byteCount>10485760){
+ throw new RuntimeException("超出最大可接收字节数"+byteCount);
+ }
+ return source.readByteArray(byteCount);
+ }
+
+ public void disconnect() {
+ if (socket!=null){
+ try {
+ socket.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }finally {
+ socket = null;
+ sink = null;
+ source = null;
+ }
+ }
+ }
+}
--- /dev/null
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:aapt="http://schemas.android.com/aapt"
+ android:width="108dp"
+ android:height="108dp"
+ android:viewportWidth="108"
+ android:viewportHeight="108">
+ <path
+ android:fillType="evenOdd"
+ android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
+ android:strokeWidth="1"
+ android:strokeColor="#00000000">
+ <aapt:attr name="android:fillColor">
+ <gradient
+ android:endX="78.5885"
+ android:endY="90.9159"
+ android:startX="48.7653"
+ android:startY="61.0927"
+ android:type="linear">
+ <item
+ android:color="#44000000"
+ android:offset="0.0" />
+ <item
+ android:color="#00000000"
+ android:offset="1.0" />
+ </gradient>
+ </aapt:attr>
+ </path>
+ <path
+ android:fillColor="#FFFFFF"
+ android:fillType="nonZero"
+ android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
+ android:strokeWidth="1"
+ android:strokeColor="#00000000" />
+</vector>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="108dp"
+ android:height="108dp"
+ android:viewportWidth="108"
+ android:viewportHeight="108">
+ <path
+ android:fillColor="#008577"
+ android:pathData="M0,0h108v108h-108z" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M9,0L9,108"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M19,0L19,108"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M29,0L29,108"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M39,0L39,108"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M49,0L49,108"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M59,0L59,108"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M69,0L69,108"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M79,0L79,108"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M89,0L89,108"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M99,0L99,108"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M0,9L108,9"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M0,19L108,19"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M0,29L108,29"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M0,39L108,39"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M0,49L108,49"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M0,59L108,59"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M0,69L108,69"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M0,79L108,79"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M0,89L108,89"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M0,99L108,99"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M19,29L89,29"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M19,39L89,39"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M19,49L89,49"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M19,59L89,59"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M19,69L89,69"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M19,79L89,79"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M29,19L29,89"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M39,19L39,89"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M49,19L49,89"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M59,19L59,89"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M69,19L69,89"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+ <path
+ android:fillColor="#00000000"
+ android:pathData="M79,19L79,89"
+ android:strokeWidth="0.8"
+ android:strokeColor="#33FFFFFF" />
+</vector>
--- /dev/null
+<?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=".MainActivity">
+
+
+ <Button
+ android:id="@+id/start_service_bt"
+ android:layout_width="140dp"
+ android:layout_height="80dp"
+ android:text="启动服务"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+ <background android:drawable="@drawable/ic_launcher_background" />
+ <foreground android:drawable="@drawable/ic_launcher_foreground" />
+</adaptive-icon>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+ <background android:drawable="@drawable/ic_launcher_background" />
+ <foreground android:drawable="@drawable/ic_launcher_foreground" />
+</adaptive-icon>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <color name="colorPrimary">#008577</color>
+ <color name="colorPrimaryDark">#00574B</color>
+ <color name="colorAccent">#D81B60</color>
+</resources>
--- /dev/null
+<resources>
+ <string name="app_name">IcWorkService</string>
+</resources>
--- /dev/null
+<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>
--- /dev/null
+package com.ic.work;
+
+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);
+ }
+}
\ No newline at end of file
--- /dev/null
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ google()
+ jcenter()
+
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:3.5.2'
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ google()
+ jcenter()
+
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
--- /dev/null
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx1536m
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app's APK
+# https://developer.android.com/topic/libraries/support-library/androidx-rn
+android.useAndroidX=true
+# Automatically convert third-party libraries to use AndroidX
+android.enableJetifier=true
+
--- /dev/null
+#Thu Mar 19 15:54:09 CST 2020
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
--- /dev/null
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
--- /dev/null
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
--- /dev/null
+include ':app'
+rootProject.name='IcWorkService'