import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
-import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Handler;
import com.ic.work.hardware.BloodInfoHelper;
import com.ic.work.hardware.BloodSensorManager;
import com.ic.work.hardware.TemperatureHelper;
-import com.ic.work.utils.HardwareUtils;
import com.ic.work.utils.ICLogger;
import com.ic.work.utils.ICWorkConstants;
import com.ic.work.utils.IcLog;
import com.ic.work.utils.IcSystemProperty;
-import com.ic.work.utils.PedUtil;
-import com.ic.work.utils.SPUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
-import java.math.BigDecimal;
import java.util.concurrent.LinkedBlockingDeque;
import static com.ic.work.utils.ICWorkConstants.Jx.ACTION_AEE_HEART_RATE;
handlerThread = new HandlerThread("ic:sensor:handler");
handlerThread.start();
handler = new Handler(handlerThread.getLooper());
- observerWatchFaceActiveState();
}
- private void observerWatchFaceActiveState() {
- ICLogger.d("observerWatchFaceActiveState...");
- getContentResolver().registerContentObserver(
- Uri.parse(SETTINGS + ".watch_face_active_state"),
- true,
- contentObserver
- );
- }
-
- private final ContentObserver contentObserver = new ContentObserver(null) {
- @Override
- public void onChange(boolean selfChange) {
- handler.post(() -> {
- handleWatchFaceActiveTask();
- });
- }
- };
-
- private void handleWatchFaceActiveTask() {
- ICLogger.d("handleWatchFaceActiveTask...");
- //获取到状态
- Cursor cursor = getContentResolver().query(Uri.parse(SETTINGS),
- new String[]{"s_value"}, "s_key=?",
- new String[]{"watch_face_active_state"}, null);
- if (cursor != null) {
- try {
- if (cursor.moveToNext()) {
- String isActive = cursor.getString(0);
- boolean isActiveValue = Boolean.parseBoolean(isActive);
- //判断是否活跃
- ICLogger.d("isActiveValue == > " + isActiveValue);
- handler.removeCallbacks(checkPetCountTask);
- if (isActiveValue) {
- handler.post(checkPetCountTask);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- cursor.close();
- }
- }
- }
-
- private final Runnable checkPetCountTask = new Runnable() {
- @Override
- public void run() {
- int count = HardwareUtils.getNdkStepCountValue();
- //把count写到数据库里
- ContentValues contentValues = new ContentValues();
- contentValues.put("s_key", "sport_step_count");
- contentValues.put("s_value", count);
- getContentResolver().insert(
- Uri.parse(SensorDataService.SETTINGS), contentValues
- );
- ICLogger.d("count == > " + count);
- //更新卡路里
- BigDecimal bg = new BigDecimal(PedUtil.calcConsumeEnergy(SPUtils.getPedHeightSP(getBaseContext()),
- SPUtils.getPedWighttSP(getBaseContext()), count));
- String value = String.valueOf(bg.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
- //保存一份到数据库中
- ContentValues contentValuesCalorie = new ContentValues();
- contentValuesCalorie.put("s_key", "sport_calorie_value");
- contentValuesCalorie.put("s_value", value);
- ICLogger.d("sport_calorie_value == > " + value);
- getContentResolver().insert(Uri.parse(SensorDataService.SETTINGS), contentValuesCalorie);
- //获取步数,然后入库
- handler.removeCallbacks(this);
- handler.postDelayed(this, 1000 * 5);
- }
- };
/**
* 此方法已经是子线程了,不可以再开子线程,包括结果的处理。
public void onDestroy() {
super.onDestroy();
mTaskList.clear();
- //不再监听表盘活跃状态的变化
- getContentResolver().unregisterContentObserver(contentObserver);
powerManager = null;
EventBus.getDefault().unregister(this);
TemperatureHelper.getInstance().setTemperatureChangeListener(null);
}
}
-
private void handleBloodResult(int high, int low, int heart, int oxygen) {
HeartRate heartRate = new HeartRate(high, low, heart, oxygen);
//遍历集合,通知一次内容
sendHeartBroadcast(heart, oxygen);
}
-
//0: 家长实时检测 1:周期上报 2:手表主动检测
//这两个是掌育给过来的测试模式
//0: 家长实时检测 1:周期上报 2:手表主动检测
return super.onStartCommand(intent, flags, startId);
}
-
private void dispatchHeartRateUpdate(int high, int low, int heart, int oxygen) {
//处理一下数据
//对数据进行处理
}
}
-
private boolean hasUpdateAdjustBloodPressureValue = false;
private int bloodHighDxValue = 0;
private int bloodLowDxValue = 0;
}
bloodLowDxCursor.close();
}
-
-
}
/**
import com.ic.work.process.PedProcess;
import com.ic.work.process.TempProcess;
import com.ic.work.process.WeatherProcess;
+import com.ic.work.utils.ICLogger;
import com.ic.work.utils.IcLog;
import com.ic.work.utils.SPUtils;
import com.ic.work.weather.WeatherDBRun;
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(PedCountEvent event) {
if (pedProcess != null) {
- pedProcess.sendPedCount(event.getPedCount(),event.getCalorie());
+ pedProcess.sendPedCount(event.getPedCount(), event.getCalorie());
}
if (akProcess != null) {
sendBroadcast(pedIntent);
}
- private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
+ private final 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();
+ ICLogger.d("action == > " + action);
+ if (TextUtils.isEmpty(action)) {
return;
}
- switch (acyion) {
+ switch (action) {
case GET_PED_ACTION:
//ThreadPoolManager.getInstance().execute(new PedRunnable(mApp.getApplicationContext(), mApp.getRepository()));
- IcLog.d(TAG,"GET_PED_ACTION ");
+ IcLog.d(TAG, "GET_PED_ACTION ");
new Thread(new PedRunnable(mApp.getApplicationContext(), mApp.getRepository())).start();
break;
case Intent.ACTION_TIMEZONE_CHANGED: