listen wear state.
authorTrillGates <williamtrillgates@gmail.com>
Thu, 15 Jul 2021 07:29:09 +0000 (15:29 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Thu, 15 Jul 2021 07:29:09 +0000 (15:29 +0800)
app/src/main/java/com/ic/launcher/presenter/StatusBarBasePresenter.java
app/src/main/java/com/ic/launcher/presenter/StatusBarPresenter.java
app/src/main/java/com/ic/launcher/view/MarqueeView.java
app/src/main/res/mipmap-mdpi/top_icon_new_msg.png

index 76d139e..e400456 100644 (file)
@@ -35,6 +35,8 @@ public class StatusBarBasePresenter extends BasePresenter {
     public MutableLiveData<Boolean> isServerConnected = new MutableLiveData<>();
     //网络类型
     public MutableLiveData<String> networkTypeValue = new MutableLiveData<>();
+    //未佩戴状态
+    public MutableLiveData<Boolean> wearState = new MutableLiveData<>();
 
     private Handler handler;
     private TelephonyManager mTelephony;
@@ -115,12 +117,25 @@ public class StatusBarBasePresenter extends BasePresenter {
                     getSignalStrength();
                     queryPhoneNetworkTypeResId(mTelephony);
                 }
+                //获取佩戴状态
+                getWearState();
                 getConnectionState();
                 handler.postDelayed(this, 3000);
             }
         });
     }
 
+    private void getWearState() {
+        boolean isAntiOff = SystemUtils.getSystemPropertiesBoolean("persist.sys.ic_antioff",
+                false);
+        if (isAntiOff) {
+            //未佩戴
+            wearState.postValue(Boolean.FALSE);
+        } else {
+            wearState.postValue(Boolean.TRUE);
+        }
+    }
+
     private int mOldSimCardState = -1;
 
     private boolean querySimCardState() {
index a540245..04ceed4 100644 (file)
@@ -32,8 +32,6 @@ public class StatusBarPresenter extends StatusBarBasePresenter {
     public MutableLiveData<Boolean> gpsState = new MutableLiveData<>();
     //蓝牙状态
     public MutableLiveData<Boolean> btState = new MutableLiveData<>();
-    //未佩戴状态
-    public MutableLiveData<Boolean> wearState = new MutableLiveData<>();
     //未读预警消息
     public MutableLiveData<Boolean> warningReadState = new MutableLiveData<>();
     //开启闹钟提示
@@ -65,7 +63,6 @@ public class StatusBarPresenter extends StatusBarBasePresenter {
         getGpsState();
         getBtState();
         //需要监听的
-        getWearState();
         getUnReadMsgState();
         getAlarmState();
         getWarningMsgReadState();
@@ -169,10 +166,6 @@ public class StatusBarPresenter extends StatusBarBasePresenter {
         //  msgUnReadState.postValue(true);
     }
 
-    private void getWearState() {
-        // wearState.postValue(true);
-    }
-
     private void getBtState() {
         //蓝牙
         IntentFilter btFilter = new IntentFilter();
index 247928b..3145be3 100644 (file)
@@ -41,7 +41,7 @@ public class MarqueeView extends ViewGroup {
         public int bottom = 0;
     }
 
-    private int margin = 0;
+    private int margin = 1;
 
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@@ -57,7 +57,10 @@ public class MarqueeView extends ViewGroup {
             item.measure(widthSpec, heightMeasureSpec);
             //ICLogger.d("item.getMeasuredWidth() == > " + item.getMeasuredWidth());
             //设置孩子的位置,从0开始
-            item.setTag(new Position(totalWidth, 0, totalWidth + item.getMeasuredWidth(), item.getMeasuredHeight()));
+            item.setTag(new Position(totalWidth,
+                    0,
+                    totalWidth + item.getMeasuredWidth(),
+                    item.getMeasuredHeight()));
             totalWidth += item.getMeasuredWidth() + margin * 2;
         }
         int parentWidth = MeasureSpec.makeMeasureSpec(totalWidth, MeasureSpec.EXACTLY);
index 07612a7..88dd329 100644 (file)
Binary files a/app/src/main/res/mipmap-mdpi/top_icon_new_msg.png and b/app/src/main/res/mipmap-mdpi/top_icon_new_msg.png differ