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;
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;
/**
* 这个是健康的界面,如果没有佩戴的话,不做检查。
- *
+ * <p>
* 获取当前是否佩戴的状态key为:persist.sys.ic_antioff
- *
+ * <p>
* 这个是主动获取的。
- *
+ * <p>
* 被动通知可以通过广播的方式监听佩戴状态的变化。
- *
+ * <p>
* 广播相关的内容:
- *
+ * <p>
* 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;
String tipsEnd;
private GestureDetectorCompat gesture;
- private ITempRemoteService mService;
+ private ITempRemoteService mService = null;
private HeatHandler mHandler;
// private PowerManager.WakeLock mWakeLock = null;
@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);
}
@Override
protected void onDestroy() {
super.onDestroy();
- IcLog.i("Temperature","Temperature Activity onDestroy");
+ IcLog.i("Temperature", "Temperature Activity onDestroy");
try {
mService.onStopQueryTemp();
} catch (Exception e) {
// releaseWakeLock();
unbindWorkService(this);
unregisterReceiver(mIntentReceiver);
+ unregisterReceiver(mAntiStateReceiver);
}
@Override
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));
}
}
+ /**
+ * 绑定远程服务
+ *
+ * @param context
+ */
private void bindWorkService(Context context) {
+ IcLog.i(TAG, "bind remote service..");
ServiceUtil.bindServiceUtil(context,
"com.ic.action.WORK_SERVICE",
connection,
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) {