From: kfl_614 Date: Fri, 27 Nov 2020 11:28:15 +0000 (+0800) Subject: check wear state and listen wear state change. X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=fb3453ec5e1b1b1bfa5344c3e007c351bc93425c;p=launcher4.git check wear state and listen wear state change. --- diff --git a/app/src/main/java/com/ic/launcher/AnimalHeatActivity.java b/app/src/main/java/com/ic/launcher/AnimalHeatActivity.java index 99889a4..f09cca8 100644 --- a/app/src/main/java/com/ic/launcher/AnimalHeatActivity.java +++ b/app/src/main/java/com/ic/launcher/AnimalHeatActivity.java @@ -5,6 +5,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.core.view.GestureDetectorCompat; import androidx.databinding.DataBindingUtil; +import android.animation.AnimatorSet; import android.annotation.SuppressLint; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -25,6 +26,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; import android.widget.TextView; +import android.widget.Toast; import com.ic.aidl.temp.ITempAidlInterface; import com.ic.aidl.temp.ITempRemoteService; @@ -42,23 +44,25 @@ import butterknife.ButterKnife; /** * 这个是健康的界面,如果没有佩戴的话,不做检查。 - * + *

* 获取当前是否佩戴的状态key为:persist.sys.ic_antioff - * + *

* 这个是主动获取的。 - * + *

* 被动通知可以通过广播的方式监听佩戴状态的变化。 - * + *

* 广播相关的内容: - * + *

* public static String ACTION_ANTI_OFF0 = "com.ic.ACTION_ANTIOFF"; * //integer eventID =1 脱落, eventID =0 佩戴 * public static String KEY_ANTI_EVENT="eventID"; - * */ public class AnimalHeatActivity extends AppCompatActivity implements MainClockGestureDetectorImpl.OnClockGestureFlingListener { + public static final String TAG = "AnimalHeatActivity"; + public static final String ACTION_ANTI_OFF0 = "com.ic.ACTION_ANTIOFF"; + @BindString(R.string.activity_temp_tips_check) String tipsCheck; @@ -66,7 +70,7 @@ public class AnimalHeatActivity extends AppCompatActivity implements String tipsEnd; private GestureDetectorCompat gesture; - private ITempRemoteService mService; + private ITempRemoteService mService = null; private HeatHandler mHandler; // private PowerManager.WakeLock mWakeLock = null; @@ -76,18 +80,29 @@ public class AnimalHeatActivity extends AppCompatActivity implements @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - heatBinding = DataBindingUtil.setContentView(this,R.layout.activity_animal_heat); + heatBinding = DataBindingUtil.setContentView(this, R.layout.activity_animal_heat); ButterKnife.bind(this); mHandler = new HeatHandler(this); gesture = new GestureDetectorCompat(this, new MainClockGestureDetectorImpl(this)); registerBroadcast(); - bindWorkService(this); -// initWakeLock(this); + //读取佩戴值,如果没有佩戴显提示佩戴 + //接收到了佩戴的广播去获取数据 + boolean isAntiOff = SystemUtils.getSystemPropertiesBoolean("persist.sys.ic_antioff", true); + IcLog.i(TAG, "isAntiOff == > " + isAntiOff); + //如果已经佩戴了,就去获取数据 + if (!isAntiOff && mService == null) { + bindWorkService(this); + } else { + //给出UI提示 + Toast.makeText(this, getString(R.string.no_wearing_device_tips_text), + Toast.LENGTH_SHORT).show(); + } + //initWakeLock(this); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); heatBinding.setBodyTemp("--"); heatBinding.setWristTemp("--"); - boolean disablewristtemp=SystemUtils.getSystemPropertiesBoolean("persyst.sys.disableWristTemp",false); - boolean disabletempOUt=SystemUtils.getSystemPropertiesBoolean("persyst.sys.disableTempOut",true); + boolean disablewristtemp = SystemUtils.getSystemPropertiesBoolean("persyst.sys.disableWristTemp", false); + boolean disabletempOUt = SystemUtils.getSystemPropertiesBoolean("persyst.sys.disableTempOut", true); heatBinding.setDisableWristTemp(disablewristtemp); heatBinding.setDisableTempOut(disabletempOUt); } @@ -107,7 +122,7 @@ public class AnimalHeatActivity extends AppCompatActivity implements @Override protected void onDestroy() { super.onDestroy(); - IcLog.i("Temperature","Temperature Activity onDestroy"); + IcLog.i("Temperature", "Temperature Activity onDestroy"); try { mService.onStopQueryTemp(); } catch (Exception e) { @@ -116,6 +131,7 @@ public class AnimalHeatActivity extends AppCompatActivity implements // releaseWakeLock(); unbindWorkService(this); unregisterReceiver(mIntentReceiver); + unregisterReceiver(mAntiStateReceiver); } @Override @@ -147,14 +163,14 @@ public class AnimalHeatActivity extends AppCompatActivity implements return true; } - private void setTemperatureUi(int type, double temp, double animal,double tempOut) { + private void setTemperatureUi(int type, double temp, double animal, double tempOut) { DecimalFormat df = new DecimalFormat("#.0"); - switch (type){ + switch (type) { case 0: - if (heatBinding.getDisableWristTemp()){ + if (heatBinding.getDisableWristTemp()) { heatBinding.setBodyTemp(df.format(temp)); heatBinding.setTempout(df.format(tempOut)); - }else { + } else { heatBinding.setBodyTemp(df.format(animal)); heatBinding.setWristTemp(df.format(temp)); heatBinding.setTempout(df.format(tempOut)); @@ -167,7 +183,13 @@ public class AnimalHeatActivity extends AppCompatActivity implements } } + /** + * 绑定远程服务 + * + * @param context + */ private void bindWorkService(Context context) { + IcLog.i(TAG, "bind remote service.."); ServiceUtil.bindServiceUtil(context, "com.ic.action.WORK_SERVICE", connection, @@ -208,34 +230,65 @@ public class AnimalHeatActivity extends AppCompatActivity implements private ITempAidlInterface.Stub tempInterface = new ITempAidlInterface.Stub() { @Override - public void updateCurrTempValue(double value, double animal,double tempOut) throws RemoteException { - mHandler.sendMessage(obtainMessage(0, value, animal,tempOut)); + public void updateCurrTempValue(double value, double animal, double tempOut) throws RemoteException { + mHandler.sendMessage(obtainMessage(0, value, animal, tempOut)); } @Override - public void updateResultTempValue(double value, double animal,double tempOut) throws RemoteException { - mHandler.sendMessage(obtainMessage(1, value, animal,tempOut)); + public void updateResultTempValue(double value, double animal, double tempOut) throws RemoteException { + mHandler.sendMessage(obtainMessage(1, value, animal, tempOut)); } }; - private Message obtainMessage(int type, double value, double animal,double tempOut) { + private Message obtainMessage(int type, double value, double animal, double tempOut) { Message message = Message.obtain(); message.what = 1; Bundle bundle = new Bundle(); bundle.putInt("type", type); bundle.putDouble("value", value); bundle.putDouble("animal", animal); - bundle.putDouble("tempOut",tempOut); + bundle.putDouble("tempOut", tempOut); message.setData(bundle); return message; } private void registerBroadcast() { + // IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); registerReceiver(mIntentReceiver, filter); + //注册监听是否有佩戴的广播 + IntentFilter antiStateFilter = new IntentFilter(); + antiStateFilter.addAction(ACTION_ANTI_OFF0); + registerReceiver(mAntiStateReceiver, antiStateFilter); } + //integer eventID =1 脱落, eventID =0 佩戴 + public static String KEY_ANTI_EVENT = "eventID"; + public static final int STATE_ANTI_ON = 0; + public static final int STATE_ANTI_OFF = 1; + public static final int STATE_ANTI_NONE = -1; + + private BroadcastReceiver mAntiStateReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + //如果来了佩戴的广播,判断到没有绑定远程服务的话,那么就绑定吧 + int state = intent.getIntExtra(KEY_ANTI_EVENT, -1); + IcLog.i(TAG, "on AntiStateChange...." + state); + if (state == STATE_ANTI_NONE) { + IcLog.i(TAG, "state error === > " + state); + return; + } + if (state == STATE_ANTI_OFF && mService == null) { + bindWorkService(AnimalHeatActivity.this); + } else if (state == STATE_ANTI_ON) { + //脱落了,给出提示 + Toast.makeText(context, context.getString(R.string.no_wearing_device_tips_text), + Toast.LENGTH_SHORT).show(); + } + } + }; + private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 678a27d..ce9a487 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -141,4 +141,5 @@ MEASURING COMPLETE TEMPOut + 未配戴设备 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5f0af22..6a181cf 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ 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 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip