add cut listener.
authorTrillGates <williamtrillgates@gmail.com>
Fri, 17 Sep 2021 12:52:50 +0000 (20:52 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Fri, 17 Sep 2021 12:52:50 +0000 (20:52 +0800)
app/src/main/java/com/ic/launcher/presenter/StatusBarBasePresenter.java
app/src/main/java/com/ic/launcher/utils/SystemUtils.java
app/src/main/java/com/ic/launcher/view/StatusBarView.java

index d94deb5..a047db7 100644 (file)
@@ -40,7 +40,9 @@ public class StatusBarBasePresenter extends BasePresenter {
     //网络类型
     public MutableLiveData<String> networkTypeValue = new MutableLiveData<>();
     //未佩戴状态
-    public MutableLiveData<Boolean> wearState = new MutableLiveData<>();
+    public MutableLiveData<Boolean> wearStateValue = new MutableLiveData<>();
+    //剪断状态
+    public MutableLiveData<Boolean> cutStateValue = new MutableLiveData<>();
 
     private Handler handler;
     private TelephonyManager mTelephony;
@@ -141,6 +143,7 @@ public class StatusBarBasePresenter extends BasePresenter {
                 }
                 //获取佩戴状态
                 getWearState();
+                getCutState();
                 getConnectionState();
                 handler.postDelayed(this, 3000);
             }
@@ -148,13 +151,24 @@ public class StatusBarBasePresenter extends BasePresenter {
     }
 
     private void getWearState() {
-        boolean isAntiOff = SystemUtils.getSystemPropertiesBoolean("persist.sys.ic_antioff",
-                false);
-        if (isAntiOff) {
+        String isAntiOff = SystemUtils.getSystemPropertiesString("persist.sys.ic_antioff", "");
+        ICLogger.d("isAntiOff ==> " + isAntiOff);
+        if ("true".equals(isAntiOff)) {
             //未佩戴
-            wearState.postValue(Boolean.FALSE);
+            wearStateValue.postValue(Boolean.FALSE);
+        } else {
+            wearStateValue.postValue(Boolean.TRUE);
+        }
+    }
+
+    private void getCutState() {
+        String isAntiOff = SystemUtils.getSystemPropertiesString("persist.sys.ic_cutoff", "");
+        ICLogger.d("isAntiOff ==> " + isAntiOff);
+        if ("true".equals(isAntiOff)) {
+            //剪断了
+            cutStateValue.postValue(Boolean.TRUE);
         } else {
-            wearState.postValue(Boolean.TRUE);
+            cutStateValue.postValue(Boolean.FALSE);
         }
     }
 
index d95ee57..99b759e 100644 (file)
@@ -124,17 +124,17 @@ public class SystemUtils {
     }
 
 
-    public static String getSystemPropertiesString(String prop, String defaultvlaue){
-        String ret=defaultvlaue;
+    public static String getSystemPropertiesString(String prop, String defaultValue){
+        String ret=defaultValue;
         String temp=getSystemProperties(prop);
         if (!temp.trim().isEmpty()){
             ret = temp;
         }
         return ret;
     }
-    public static boolean getSystemPropertiesBoolean(String prop, boolean defaultvlaue){
+    public static boolean getSystemPropertiesBoolean(String prop, boolean defaultValue){
 
-        boolean ret=defaultvlaue;
+        boolean ret=defaultValue;
         String temp=getSystemProperties(prop);
         if (!temp.trim().isEmpty()){
             if( temp.trim().equals("true")) {
index 7bda6fb..a777380 100644 (file)
@@ -103,8 +103,12 @@ public class StatusBarView extends FrameLayout {
             //是否有未接电话
             phoneView.setVisibility(hasMiss == Boolean.TRUE ? VISIBLE : GONE);
         });
-        statusBarPresenter.wearState.observe(lifecycleOwner, hasWear -> {
+        statusBarPresenter.wearStateValue.observe(lifecycleOwner, hasWear -> {
             //是否有穿戴
+            wearView.setVisibility(hasWear == Boolean.TRUE ? GONE : VISIBLE);
+        });
+        statusBarPresenter.cutStateValue.observe(lifecycleOwner, hasWear -> {
+            //是否剪断,如果没有剪断,则会显示图标,如果剪断了,那么就没有图标了
             wearView.setVisibility(hasWear == Boolean.TRUE ? VISIBLE : GONE);
         });
         statusBarPresenter.msgUnReadState.observe(lifecycleOwner, hasRead -> {