import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteException;
+import android.system.Os;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import com.ic.launcher.databinding.ActivityAnimalHeatBinding;
import com.ic.launcher.listener.MainClockGestureDetectorImpl;
import com.ic.launcher.util.IcLog;
+import com.ic.launcher.util.OsUtil;
import com.ic.launcher.util.ServiceUtil;
import com.ic.launcher.util.SystemUtils;
public static final String TAG = "AnimalHeatActivity";
public static final String ACTION_ANTI_OFF0 = "com.ic.ACTION_ANTIOFF";
+ public static final String ACTION_REMOTE_WORK_SERVICE = "com.ic.action.WORK_SERVICE";
+ public static final String PACKAGE_REMOTE_WORK_SERVICE = "com.ic.temp";
+
@BindString(R.string.activity_temp_tips_check)
String tipsCheck;
registerBroadcast();
//读取佩戴值,如果没有佩戴显提示佩戴
//接收到了佩戴的广播去获取数据
+ //true表示没佩戴了,false表示有佩戴
boolean isAntiOff = SystemUtils.getSystemPropertiesBoolean("persist.sys.ic_antioff", true);
IcLog.i(TAG, "isAntiOff == > " + isAntiOff);
//如果已经佩戴了,就去获取数据
heatBinding.setCheckTips(getString(R.string.no_wearing_device_tips_text));
}
//initWakeLock(this);
+ //保持屏幕常量
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
heatBinding.setBodyTemp("--.-");
heatBinding.setWristTemp("--.-");
heatBinding.setTempout("--.-");
- boolean disablewristtemp = SystemUtils.getSystemPropertiesBoolean("persyst.sys.disableWristTemp", false);
- boolean disabletempOUt = SystemUtils.getSystemPropertiesBoolean("persyst.sys.disableTempOut", true);
- heatBinding.setDisableWristTemp(disablewristtemp);
- heatBinding.setDisableTempOut(disabletempOUt);
+ 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 onPause() {
- super.onPause();
-// IcLog.i("Temperature","Temperature Activity onPause");
-// try {
-// mService.onStopQueryTemp();
-// } catch (Exception e) {
-// IcLog.i("Temperature", e.getMessage());
-// }
- }
-
@Override
protected void onDestroy() {
super.onDestroy();
IcLog.i("Temperature", "Temperature Activity onDestroy");
try {
- mService.onStopQueryTemp();
+ //停止温度检测
+ if (mService != null) {
+ mService.onStopQueryTemp();
+ }
} catch (Exception e) {
e.printStackTrace();
//e.getMessage may be null.
}
private int currentTestType = -1;
+ //测试中
+ private static final int STATE_TESTING = 0;
+ //测试结束
+ private static final int STATE_TEST_END = 1;
private void setTemperatureUi(int type, double temp, double animal, double tempOut) {
IcLog.i(TAG, "type -- > " + type);
IcLog.i(TAG, "animal -- > " + animal);
IcLog.i(TAG, "tempOut -- > " + tempOut);
//这里有个瞬间过大的bug,人腕温不可能大于45度的。
- if (temp > 45) {
- temp = 45.0d;
- }
currentTestType = type;
- DecimalFormat df = new DecimalFormat("#.0");
+ //
switch (type) {
- case 0:
+ case STATE_TESTING:
if (heatBinding.getDisableWristTemp()) {
- heatBinding.setBodyTemp(df.format(temp));
- heatBinding.setTempout(df.format(tempOut));
+ heatBinding.setBodyTemp(OsUtil.formatTem(temp));
+ heatBinding.setTempout(OsUtil.formatTem(tempOut));
} else {
- if (".0".equals(df.format(animal))) {
- heatBinding.setBodyTemp("0.0");
- } else {
- heatBinding.setBodyTemp(df.format(animal));
- }
- heatBinding.setWristTemp(df.format(temp));
- heatBinding.setTempout(df.format(tempOut));
+ heatBinding.setBodyTemp(OsUtil.formatTem(animal));
+ heatBinding.setWristTemp(OsUtil.formatTem(temp));
+ heatBinding.setTempout(OsUtil.formatTem(tempOut));
}
break;
- case 1:
+ case STATE_TEST_END:
heatBinding.setShowLoading(false);
heatBinding.setCheckTips(tipsEnd);
break;
}
}
+
/**
* 绑定远程服务
*
private void bindWorkService(Context context) {
IcLog.i(TAG, "bind remote service..");
ServiceUtil.bindServiceUtil(context,
- "com.ic.action.WORK_SERVICE",
+ ACTION_REMOTE_WORK_SERVICE,
connection,
- "com.ic.temp");
+ PACKAGE_REMOTE_WORK_SERVICE);
}
private void unbindWorkService(Context context) {
public void onServiceConnected(ComponentName name, IBinder service) {
try {
mService = ITempRemoteService.Stub.asInterface(service);
+ //把回调接口设置给对方
mService.registerCallback(tempInterface);
+ //调用开始查询温度
mService.onStartQueryTemp();
+ //展示Loading,也 就是进度条那个
heatBinding.setShowLoading(true);
+ //设置UI正在检测中
heatBinding.setCheckTips(tipsCheck);
} catch (Exception e) {
+ e.printStackTrace();
}
}
}
};
+ /**
+ * @param type 类型,
+ * @param value 体温
+ * @param animal 腕温
+ * @param tempOut 环境温度
+ * @return
+ */
private Message obtainMessage(int type, double value, double animal, double tempOut) {
Message message = Message.obtain();
message.what = 1;
bindWorkService(AnimalHeatActivity.this);
}
- if (state == STATE_ANTI_ON && currentTestType == 1) {
+ if (state == STATE_ANTI_ON && currentTestType == STATE_TEST_END) {
//判断状态,如果已经检测完了,就显示检测完成
- heatBinding.setCheckTips(getString(R.string.activity_temp_tips_end));
+ // 按客户需求,马上进来显示检测完成,看起来不爽
+ //那就再次检测吧,底层做了处理,多次调用测试也没关系,如果判断到繁忙的话会不处理的。
+ //heatBinding.setCheckTips(getString(R.string.activity_temp_tips_end));
+
}
}
};
+ private void getRemoteData() {
+
+ if (mService == null) {
+ return;
+ }
+ try {
+ mService.onStartQueryTemp();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
- String acyion = intent.getAction();
- if (TextUtils.isEmpty(acyion)) {
+ String action = intent.getAction();
+ if (TextUtils.isEmpty(action)) {
return;
}
- switch (acyion) {
+ switch (action) {
case Intent.ACTION_CLOSE_SYSTEM_DIALOGS:
String reason = intent.getStringExtra("reason");
if ("homekey".equals(reason)) {