liuzhenxing1118 3 жил өмнө
parent
commit
db7b658a82

+ 8 - 0
app/src/main/java/com/xplora/xplauncher/activity/BaseActivity.java

@@ -6,9 +6,12 @@ import android.os.Vibrator;
 import android.view.View;
 import android.view.Window;
 import android.view.WindowManager;
+import android.widget.Toast;
 
 import androidx.annotation.Nullable;
 
+import com.xplora.xplauncher.R;
+
 public class BaseActivity extends Activity {
     public String TAG = "losion :" + getClass().getSimpleName();
     @Override
@@ -51,4 +54,9 @@ public class BaseActivity extends Activity {
         Vibrator vibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);
         vibrator.vibrate(100);
     }
+
+    public void showToast(int resId) {
+        Toast toast = Toast.makeText(this, resId, Toast.LENGTH_SHORT);
+        toast.show();
+    }
 }

+ 103 - 84
app/src/main/java/com/xplora/xplauncher/activity/MainActivity.java

@@ -13,15 +13,18 @@ import android.os.Looper;
 import android.os.Message;
 import android.os.PowerManager;
 import android.os.SystemClock;
+import android.provider.Settings;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.View;
+import android.widget.Toast;
 
 import com.xplora.xplauncher.R;
 import com.xplora.xplauncher.adapter.ContactsRecyclerAdapter;
 import com.xplora.xplauncher.adapter.RecyclerAdapter;
 import com.xplora.xplauncher.adapter.ViewPagerAdapter;
 import com.xplora.xplauncher.observer.Listener;
+import com.xplora.xplauncher.observer.SettingContentObserver;
 import com.xplora.xplauncher.utils.MetaData;
 import com.xplora.xplauncher.observer.ContactContentObserver;
 import com.xplora.xplauncher.observer.NetworkChangeReceiver;
@@ -50,8 +53,9 @@ public class MainActivity extends BaseActivity implements Listener.ButtonListene
     private TimeBroadcastReceiver mTimeReceiver = null;
     private SimStateReceiver mSimListener = null;
 
-    private ContactContentObserver mContactObserver = null;
     private RecentContentObserver mRecentObserver = null;
+    private ContactContentObserver mContactObserver = null;
+    private SettingContentObserver mSettingObserver = null;
 
     private boolean isKeyDown = false;
 
@@ -70,11 +74,7 @@ public class MainActivity extends BaseActivity implements Listener.ButtonListene
     protected void initViewBase() {
         super.initViewBase();
         initViewPager();
-        initTimeChangeBroadcast();
-        initSimStateBroadcast();
-
-        if (Macros.DEBUG_NETWORK_OBSERVER)
-            initNetworkBroadcast();
+        initObserver();
     }
 
     private void initViewPager() {
@@ -232,6 +232,34 @@ public class MainActivity extends BaseActivity implements Listener.ButtonListene
         }
     }
 
+    @Override
+    public void onClickWarningButton() {
+        //表盘界面,是否显示 warning 及状态, 0:不显示; >0 显示
+        int status = DataManager.getWarningStatus();
+        Log.d(TAG, "onClickWarningButton: " + status);
+        if (status == 0) {
+            changeWarningStatus();
+        } else {
+            String packageName = "com.xplora.xponboarding";
+            String activity = "";
+            if (status == 10) { //no sim
+                activity = packageName + ".Activity.SimInstallActivity";
+            }else if (status == 11) { //sim 未激活
+                activity = packageName + ".Activity.SimUnactivatedActivity";
+            }else if (status == 12) { //sim 被锁
+                activity = packageName + ".Activity.SimPinLockedActivity";
+            } else if (status == 2) { //esim 未激活
+                activity = packageName + ".Activity.EsimUnactivationActivity";
+            } else if (status == 1) { //手表 未激活
+                activity = packageName + ".Activity.QRActivity";
+            }
+            ComponentName component = new ComponentName(packageName, activity);
+            Intent intent = new Intent();
+            intent.setComponent(component);
+            startActivity(intent);
+        }
+    }
+
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
@@ -369,30 +397,36 @@ public class MainActivity extends BaseActivity implements Listener.ButtonListene
         homeView.setGadgetsAutoClosed();
     }
 
-    // ======================== 监听数据库 =======================
-    Handler mHandler = new Handler(Looper.myLooper()) {
-        @Override
-        public void handleMessage(@NonNull Message msg) {
-            super.handleMessage(msg);
+    // ======================== 广播 =======================
+    private void initObserver() {
+        initTimeChangeBroadcast();
 
-            int primaryKey = msg.arg1;
-            if (msg.what == Constant.MSG_DB_OBSERVER_RECENT) {
-                ContactsPager contactPager = (ContactsPager)mPagerViews.get(0);
-                if (contactPager != null) {
-                    DataManager.queryRecent();
-                    contactPager.setRecentList(DataManager.mRecentBeanList);
-                }
-            } else if (msg.what == Constant.MSG_DB_OBSERVER_CONTACT) {
-                ContactsPager contactPager = (ContactsPager)mPagerViews.get(0);
-                if (contactPager != null) {
-                    DataManager.queryContacts();
-                    contactPager.setContactsList(DataManager.mContactBeanList);
-                }
-            }
+        initSimStateBroadcast();
+
+        if (Macros.DEBUG_NETWORK_OBSERVER)
+            initNetworkBroadcast();
+
+        registerContentObserver();
+    }
+
+    private void removeObserver() {
+        // 注销广播
+        if (mTimeReceiver != null) {
+            unregisterReceiver(mTimeReceiver);
+            mTimeReceiver = null;
         }
-    };
 
-    // ======================== 广播 =======================
+        if (mSimListener != null) {
+            unregisterReceiver(mSimListener);
+            mSimListener = null;
+        }
+
+        if (Macros.DEBUG_NETWORK_OBSERVER)
+            NetworkChangeReceiver.unRegisterReceiver(this);
+
+        unRegisterContentObserver();
+    }
+
     private void initTimeChangeBroadcast() {
         if (mTimeReceiver == null) {
             mTimeReceiver = new TimeBroadcastReceiver(this);
@@ -423,50 +457,14 @@ public class MainActivity extends BaseActivity implements Listener.ButtonListene
     private void initNetworkBroadcast() {
         NetworkChangeReceiver.registerObserver(new NetworkChangeReceiver.NetStateChangeObserver() {
             @Override
-            public void onDisconnect() {
-
-            }
-
+            public void onDisconnect() {}
             @Override
-            public void onMobileConnect() {
-
-            }
-
+            public void onMobileConnect() {}
             @Override
-            public void onWifiConnect() {
-
-            }
+            public void onWifiConnect() {}
         });
     }
 
-    @Override
-    public void onClickWarningButton() {
-        //表盘界面,是否显示 warning 及状态, 0:不显示; >0 显示
-        int status = DataManager.getWarningStatus();
-        Log.d(TAG, "onClickWarningButton: " + status);
-        if (status == 0) {
-            changeWarningStatus();
-        } else {
-            String packageName = "com.xplora.xponboarding";
-            String activity = "";
-            if (status == 10) { //no sim
-                activity = packageName + ".Activity.SimInstallActivity";
-            }else if (status == 11) { //sim 未激活
-                activity = packageName + ".Activity.SimUnactivatedActivity";
-            }else if (status == 12) { //sim 被锁
-                activity = packageName + ".Activity.SimPinLockedActivity";
-            } else if (status == 2) { //esim 未激活
-                activity = packageName + ".Activity.EsimUnactivationActivity";
-            } else if (status == 1) { //手表 未激活
-                activity = packageName + ".Activity.QRActivity";
-            }
-            ComponentName component = new ComponentName(packageName, activity);
-            Intent intent = new Intent();
-            intent.setComponent(component);
-            startActivity(intent);
-        }
-    }
-
     private void registerContentObserver() {
         if (!Macros.DEBUG_DATABASE_RECENT) {
             mRecentObserver = new RecentContentObserver(mHandler);
@@ -476,6 +474,11 @@ public class MainActivity extends BaseActivity implements Listener.ButtonListene
             mContactObserver = new ContactContentObserver(mHandler);
             getContentResolver().registerContentObserver(Uri.parse(MetaData.DB_CONTACTS), true, mContactObserver);
         }
+        if (!Macros.DEBUG_SYSTEMPROVIDER) {
+            mSettingObserver = new SettingContentObserver(mHandler);
+            getContentResolver().registerContentObserver(
+                    Settings.Global.getUriFor(MetaData.KEY_CLASS_DISABLE), false, mSettingObserver);
+        }
     }
 
     private void unRegisterContentObserver() {
@@ -487,6 +490,38 @@ public class MainActivity extends BaseActivity implements Listener.ButtonListene
         }
     }
 
+    // ======================== 监听数据库 =======================
+    Handler mHandler = new Handler(Looper.myLooper()) {
+        @Override
+        public void handleMessage(@NonNull Message msg) {
+            super.handleMessage(msg);
+
+            int primaryKey = msg.arg1;
+            if (msg.what == Constant.MSG_DB_OBSERVER_RECENT) {
+                ContactsPager contactPager = (ContactsPager)mPagerViews.get(0);
+                if (contactPager != null) {
+                    DataManager.queryRecent();
+                    contactPager.setRecentList(DataManager.mRecentBeanList);
+                }
+            } else if (msg.what == Constant.MSG_DB_OBSERVER_CONTACT) {
+                ContactsPager contactPager = (ContactsPager)mPagerViews.get(0);
+                if (contactPager != null) {
+                    DataManager.queryContacts();
+                    contactPager.setContactsList(DataManager.mContactBeanList);
+                }
+            } else if (msg.what == Constant.MSG_DB_OBSERVER_SETTING) {
+                int value = DataManager.getClassDisable();
+                if (value == 1) {
+                    showToast(R.string.class_disable);
+                    mViewPager.setCurrentItem(Constant.HOME_INDEX);
+                    mViewPager.setEnabled(false);
+                } else {
+                    mViewPager.setEnabled(true);
+                }
+            }
+        }
+    };
+
     @Override
     protected void onStart() {
         Log.d(TAG, "onStart: ");
@@ -500,9 +535,6 @@ public class MainActivity extends BaseActivity implements Listener.ButtonListene
 
         changeAppNameType();
         changeWarningStatus();
-
-        initTimeChangeBroadcast();
-        registerContentObserver();
     }
 
     @Override
@@ -515,32 +547,19 @@ public class MainActivity extends BaseActivity implements Listener.ButtonListene
     protected void onPause() {
         Log.d(TAG, "onPause");
         super.onPause();
-
-        unRegisterContentObserver();
     }
 
     @Override
     protected void onDestroyBase() {
         Log.d(TAG, "onDestroyBase");
         super.onDestroyBase();
-        // 注销广播
-        if (mTimeReceiver != null) {
-            unregisterReceiver(mTimeReceiver);
-            mTimeReceiver = null;
-        }
-
-        if (mSimListener != null) {
-            unregisterReceiver(mSimListener);
-            mSimListener = null;
-        }
-
-        if (Macros.DEBUG_NETWORK_OBSERVER)
-            NetworkChangeReceiver.unRegisterReceiver(this);
 
         if (mPagerViews.size() > 1) {
             HomePager homeView = (HomePager) mPagerViews.get(1);
             homeView.destroyView();
         }
+
+        removeObserver();
     }
 
     @Override

+ 6 - 0
app/src/main/java/com/xplora/xplauncher/data/DataManager.java

@@ -366,6 +366,12 @@ public class DataManager extends Application {
         return Settings.Global.getInt(sContext.getContentResolver(), MetaData.KEY_APP_NAME, 0);
     }
 
+    public static int getClassDisable() {
+        if (Macros.DEBUG_SYSTEMPROVIDER)
+            return 0;
+        return Settings.Global.getInt(sContext.getContentResolver(), MetaData.KEY_CLASS_DISABLE, 0);
+    }
+
     //是否 watch 激活
     public static int isWatchActivated() {
         int isActivated = Settings.Global.getInt(sContext.getContentResolver(), MetaData.KEY_WATCH_ACTIVATED, 0);

+ 2 - 2
app/src/main/java/com/xplora/xplauncher/utils/Macros.java

@@ -6,8 +6,8 @@ public class Macros {
     public static boolean DEBUG = true;
 
     public static boolean DEBUG_DATABASE_RECENT = true; //模拟数据库中数据
-    public static boolean DEBUG_DATABASE_CONTACT = false; //模拟数据库中数据
-    public static boolean DEBUG_SYSTEMPROVIDER = false; //模拟数据库中数据
+    public static boolean DEBUG_DATABASE_CONTACT = true; //模拟数据库中数据
+    public static boolean DEBUG_SYSTEMPROVIDER = true; //模拟数据库中数据
 
     public static boolean DEBUG_ALL_APPS = true; //安装的应用不筛选app
 

+ 1 - 0
app/src/main/java/com/xplora/xplauncher/utils/MetaData.java

@@ -20,6 +20,7 @@ public class MetaData {
     public static final String KEY_WATCH_FACE = "watch_face";
     public static final String KEY_QUICK_APP = "quick_app";
     public static final String KEY_WATCH_ACTIVATED = "active_status";
+    public static final String KEY_CLASS_DISABLE = "class_disable";
     public static final String KEY_ONBOARDING_FROM = "onboarding_from";
     public static final String KEY_RESOLUTION_PHOTO = "photo_resolution";
     public static final String KEY_RESOLUTION_VIDEO = "video_resolution";

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -11,4 +11,6 @@
     <string name="sim_status_10">No SIM</string>
     <string name="sim_status_11">SIM \nUnactivated</string>
     <string name="sim_status_12">SIM \nLocked</string>
+
+    <string name="class_disable">Class disable</string>
 </resources>