import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
+import android.database.Cursor;
import android.location.LocationManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
public MutableLiveData<Boolean> silentState = new MutableLiveData<>();
//微聊新消息
public MutableLiveData<Boolean> icTalkMsgState = new MutableLiveData<>();
+ //震动图标
+ public MutableLiveData<Boolean> shakeValue = new MutableLiveData<>();
//
private final ExecutorService executorService;
//
private NetworkConnectChangedReceiver mNetworkChangeListener;
+ private final ContentResolver contentResolver;
private StatusBarPresenter(Context context) {
super(context);
executorService = Executors.newSingleThreadExecutor();
+ contentResolver = mContext.getContentResolver();
//监听各种状态
//需要初始化一次,然后进行监听
getWifiState();
getGpsState();
getBtState();
+ //需要监听的
getWearState();
getUnReadMsgState();
getAlarmState();
getSilentState();
checkIcTalkMsg();
checkHasMissCall();
+ observerContentChange();
+ }
+
+ private void observerContentChange() {
+ contentResolver.registerContentObserver(Uri.parse(SETTINGS + ".key_silent"), true,
+ new ContentObserver(null) {
+ @Override
+ public void onChange(boolean selfChange) {
+ ICLogger.d("on silent state update...");
+ getSilentState();
+ }
+ });
+ contentResolver.registerContentObserver(Uri.parse(SETTINGS + ".key_shake_mode"), true,
+ new ContentObserver(null) {
+ @Override
+ public void onChange(boolean selfChange) {
+ getShakeState();
+ }
+ });
+ }
+
+ private void getShakeState() {
+ executorService.execute(() -> {
+ //key_shake_mode
+ String isShake = getContent("key_shake_mode");
+ if ("1".equals(isShake)) {
+ shakeValue.postValue(Boolean.TRUE);
+ } else {
+ shakeValue.postValue(Boolean.FALSE);
+ }
+ });
+ }
+
+ private String getContent(String key) {
+ Cursor query = contentResolver.query(Uri.parse(SETTINGS), new String[]{"s_value"},
+ "s_key=?", new String[]{key}, null);
+ if (query != null) {
+ if (query.moveToNext()) {
+ String string = query.getString(0);
+ ICLogger.d("value == > " + string);
+ return string;
+ }
+ query.close();
+ }
+ return null;
}
private void checkHasMissCall() {
}
private void getSilentState() {
- // silentState.postValue(true);
+ //key_silent
+ String string = getContent("key_silent");
+ if ("1".equals(string)) {
+ silentState.postValue(Boolean.TRUE);
+ } else {
+ silentState.postValue(Boolean.FALSE);
+ }
}
private void checkIcTalkMsg() {
private View phoneView;
private View icTalkView;
private View silentIconView;
+ private View shakeView;
public StatusBarView(@NonNull Context context) {
this(context, null);
phoneView = findViewById(R.id.top_icon_phone);
icTalkView = findViewById(R.id.top_icon_ic_talk);
silentIconView = findViewById(R.id.top_icon_silent);
+ shakeView = findViewById(R.id.top_icon_ic_shake);
}
public void initPresenter(LifecycleOwner lifecycleOwner) {
});
statusBarPresenter.gpsState.observe(lifecycleOwner, isOpen -> {
//GPS定位是否打开
- locationView.setVisibility(isOpen == Boolean.TRUE? VISIBLE : GONE);
+ locationView.setVisibility(isOpen == Boolean.TRUE ? VISIBLE : GONE);
});
statusBarPresenter.icTalkMsgState.observe(lifecycleOwner, hasIcTalkMsg -> {
//是否有微聊消息
- icTalkView.setVisibility(hasIcTalkMsg== Boolean.TRUE ? VISIBLE : GONE);
+ icTalkView.setVisibility(hasIcTalkMsg == Boolean.TRUE ? VISIBLE : GONE);
});
statusBarPresenter.isWifiOpen.observe(lifecycleOwner, isWifiOpen -> {
//wifi是否打开
});
statusBarPresenter.missCallState.observe(lifecycleOwner, hasMiss -> {
//是否有未接电话
- phoneView.setVisibility(hasMiss == Boolean.TRUE? VISIBLE : GONE);
+ phoneView.setVisibility(hasMiss == Boolean.TRUE ? VISIBLE : GONE);
});
statusBarPresenter.wearState.observe(lifecycleOwner, hasWear -> {
//是否有穿戴
- wearView.setVisibility(hasWear == Boolean.TRUE? VISIBLE : GONE);
+ wearView.setVisibility(hasWear == Boolean.TRUE ? VISIBLE : GONE);
});
statusBarPresenter.msgUnReadState.observe(lifecycleOwner, hasRead -> {
//消息是否有读
- newMsgView.setVisibility(hasRead == Boolean.TRUE? VISIBLE : GONE);
+ newMsgView.setVisibility(hasRead == Boolean.TRUE ? VISIBLE : GONE);
});
statusBarPresenter.warningReadState.observe(lifecycleOwner, hasRead -> {
//警告消息是否有没阅读
- warningMsgUnReadView.setVisibility(hasRead == Boolean.TRUE? VISIBLE : GONE);
+ warningMsgUnReadView.setVisibility(hasRead == Boolean.TRUE ? VISIBLE : GONE);
});
statusBarPresenter.silentState.observe(lifecycleOwner, isSilent -> {
//是不是静音状态
- silentIconView.setVisibility(isSilent == Boolean.TRUE? VISIBLE : GONE);
+ silentIconView.setVisibility(isSilent == Boolean.TRUE ? VISIBLE : GONE);
});
statusBarPresenter.batteryLev.observe(lifecycleOwner, lev -> {
//电量还有多少
batteryView.updateCurrentLev(0);
}
});
+ statusBarPresenter.shakeValue.observe(lifecycleOwner, isShake -> {
+ if (isShake == null || isShake == Boolean.FALSE) {
+ shakeView.setVisibility(GONE);
+ } else {
+ shakeView.setVisibility(VISIBLE);
+ }
+ });
statusBarPresenter.networkTypeValue.observe(lifecycleOwner, type -> {
signalView.updateNetworkType(type);
});
android:src="@mipmap/top_icon_ic_talk_msg"
android:visibility="gone" />
+ <ImageView
+ android:id="@+id/top_icon_ic_shake"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_icon_shake"
+ android:visibility="gone" />
+
+
<ImageView
android:id="@+id/top_icon_silent"
android:layout_width="wrap_content"