liuzhenxing1118 3 年之前
父节点
当前提交
88631d192b

+ 2 - 13
.idea/deploymentTargetDropDown.xml

@@ -1,28 +1,17 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="deploymentTargetDropDown">
-    <runningDeviceTargetSelectedWithDropDown>
-      <Target>
-        <type value="RUNNING_DEVICE_TARGET" />
-        <deviceKey>
-          <Key>
-            <type value="VIRTUAL_DEVICE_PATH" />
-            <value value="$USER_HOME$/.android/avd/xp_360x400_API_33.avd" />
-          </Key>
-        </deviceKey>
-      </Target>
-    </runningDeviceTargetSelectedWithDropDown>
     <targetSelectedWithDropDown>
       <Target>
         <type value="QUICK_BOOT_TARGET" />
         <deviceKey>
           <Key>
             <type value="VIRTUAL_DEVICE_PATH" />
-            <value value="$USER_HOME$/.android/avd/xp_360x400_API_33.avd" />
+            <value value="$USER_HOME$/.android/avd/Pixel_XL_API_33_2.avd" />
           </Key>
         </deviceKey>
       </Target>
     </targetSelectedWithDropDown>
-    <timeTargetWasSelectedWithDropDown value="2022-08-02T11:19:36.349014Z" />
+    <timeTargetWasSelectedWithDropDown value="2022-08-06T06:29:16.293383Z" />
   </component>
 </project>

+ 62 - 58
app/src/main/java/com/xplora/xplauncher/activity/MainActivity.java

@@ -17,11 +17,16 @@ 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.data.MetaData;
+import com.xplora.xplauncher.observer.ContactContentObserver;
+import com.xplora.xplauncher.observer.RecentContentObserver;
+import com.xplora.xplauncher.observer.SettingContentObserver;
 import com.xplora.xplauncher.observer.SimStateReceiver;
 import com.xplora.xplauncher.observer.TimeBroadcastReceiver;
 import com.xplora.xplauncher.data.DataManager;
 import com.xplora.xplauncher.model.AppModel;
 import com.xplora.xplauncher.utils.Constant;
+import com.xplora.xplauncher.utils.Macros;
 import com.xplora.xplauncher.utils.ResUtils;
 
 import java.util.ArrayList;
@@ -29,16 +34,19 @@ import java.util.List;
 
 public class MainActivity extends BaseActivity {
     private int mCurrentPagerIndex = Constant.HOME_INDEX;
-    private int mAppTitleStatus = 1;
+    private int mAppNameType = 1;
     private int mDeleteBtnStatus = 0;
 
-
     private final List<View> mPagesDatas = new ArrayList<>();
     private final List<Object> mPagerViews = new ArrayList<>();
     private ViewPager mViewPager = null;
     private ViewPagerAdapter mViewPagerAdapter = null;
     private TimeBroadcastReceiver mTimeReceiver = null;
 
+    private ContactContentObserver mContactObserver = null;
+    private RecentContentObserver mRecentObserver = null;
+    private SettingContentObserver mSettingbserver = null;
+
     @Override
     protected void onCreateBase() {
         setContentView(R.layout.activity_main);
@@ -47,9 +55,7 @@ public class MainActivity extends BaseActivity {
     @Override
     protected void initDataBase() {
         super.initDataBase();
-
-        //监听数据库
-        DataManager.registerContentObserver(new RecentContentObserver(mHandler), new ContactContentObserver(mHandler), new SettingContentObserver(mHandler));
+        mAppNameType = DataManager.getAppNameType();
     }
 
     @Override
@@ -98,7 +104,7 @@ public class MainActivity extends BaseActivity {
             List<AppModel> appsList = new ArrayList<>();
             appsList = DataManager.getQuickAppsWithIndex(i);
 
-            BasePager appsPager = new AppsPager(this, appsList, Constant.E_PAGER_TYPE.COMMON,i, mAppTitleStatus, mDeleteBtnStatus, onAppItemOnClickListener);
+            BasePager appsPager = new AppsPager(this, appsList, Constant.E_PAGER_TYPE.COMMON,i, mAppNameType, mDeleteBtnStatus, onAppItemOnClickListener);
             appsPager.mBaseView.setOnClickListener(new AppsPagerOnClickListener());
             appsPager.mBaseView.setOnLongClickListener(new AppsPagerOnClickListener());
 
@@ -109,7 +115,7 @@ public class MainActivity extends BaseActivity {
 
     private void initInstalledAppsPager() {
         List<AppModel> installedApps = DataManager.getInstalledApps();
-        BasePager appsPager = new AppsPager(this, installedApps, Constant.E_PAGER_TYPE.APPLIST, 0, mAppTitleStatus, mDeleteBtnStatus, onAppItemOnClickListener);
+        BasePager appsPager = new AppsPager(this, installedApps, Constant.E_PAGER_TYPE.APPLIST, 0, mAppNameType, mDeleteBtnStatus, onAppItemOnClickListener);
         appsPager.mBaseView.setOnClickListener(new AppsPagerOnClickListener());
         appsPager.mBaseView.setOnLongClickListener(new AppsPagerOnClickListener());
 
@@ -300,61 +306,35 @@ public class MainActivity extends BaseActivity {
     }
 
     // ======================== 监听数据库 =======================
-    public class RecentContentObserver extends ContentObserver {
-        public RecentContentObserver(Handler handler) {
-            super(handler);
-        }
-
-        @Override
-        public void onChange(boolean selfChange) {
-            ContactsPager contactPager = (ContactsPager)mPagerViews.get(0);
-            if (contactPager != null) {
-                DataManager.queryRecent();
-                contactPager.setRecentList(DataManager.mRecentBeanList);
-            }
-            super.onChange(selfChange);
-        }
-    }
-
-    public class ContactContentObserver extends ContentObserver {
-        public ContactContentObserver(Handler handler) {
-            super(handler);
-        }
-
-        @Override
-        public void onChange(boolean selfChange) {
-            ContactsPager contactPager = (ContactsPager)mPagerViews.get(0);
-            if (contactPager != null) {
-                DataManager.queryContacts();
-                contactPager.setContactsList(DataManager.mContactBeanList);
-            }
-            super.onChange(selfChange);
-        }
-    }
-
-    public class SettingContentObserver extends ContentObserver {
-        public SettingContentObserver(Handler handler) {
-            super(handler);
-        }
-
-        @Override
-        public void onChange(boolean selfChange) {
-            DataManager.loadSetting();
-            //刷新app标题
-            for (int i = 2; i < mPagerViews.size(); i++) {
-                AppsPager pager = (AppsPager)mPagerViews.get(i);
-                pager.refreshAppTitleStatus(DataManager.getAppTitleType());
-            }
-            //刷新表盘
-            changeFace(DataManager.getFaceIndex());
-            super.onChange(selfChange);
-        }
-    }
-
     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 type = DataManager.getAppNameType();
+                if (type == mAppNameType)
+                    return;
+                mAppNameType = type;
+                //刷新app标题
+                for (int i = 2; i < mPagerViews.size(); i++) {
+                    AppsPager pager = (AppsPager)mPagerViews.get(i);
+                    pager.refreshAppTitleStatus(mAppNameType);
+                }
+            }
         }
     };
 
@@ -388,16 +368,40 @@ public class MainActivity extends BaseActivity {
         });
     }
 
+    private void registerContentObserver() {
+        mRecentObserver = new RecentContentObserver(mHandler);
+        mContactObserver = new ContactContentObserver(mHandler);
+        mSettingbserver = new SettingContentObserver(mHandler);
+
+        getContentResolver().registerContentObserver(MetaData.TABLE_URI_RECENT, true, mRecentObserver);
+        getContentResolver().registerContentObserver(MetaData.TABLE_URI_CONTACT, true, mContactObserver);
+        getContentResolver().registerContentObserver(MetaData.TABLE_URI_SETTING, true, mSettingbserver);
+    }
+
+    private void unRegisterContentObserver() {
+        getContentResolver().unregisterContentObserver(mContactObserver);
+        getContentResolver().unregisterContentObserver(mRecentObserver);
+        getContentResolver().unregisterContentObserver(mSettingbserver);
+    }
+
     @Override
     protected void onResume() {
         super.onResume();
 
         initTimeChangeBroadcast();
+
+        if (!Macros.DEBUG_DATABASE) {
+            registerContentObserver();
+        }
     }
 
     @Override
     protected void onPause() {
         super.onPause();
+
+        if (!Macros.DEBUG_DATABASE) {
+            unRegisterContentObserver();
+        }
     }
 
     @Override

+ 51 - 60
app/src/main/java/com/xplora/xplauncher/data/DataManager.java

@@ -8,6 +8,7 @@ import android.content.pm.ResolveInfo;
 import android.database.ContentObserver;
 import android.graphics.Bitmap;
 import android.graphics.drawable.Drawable;
+import android.provider.Settings;
 import android.telephony.TelephonyManager;
 import android.widget.ImageView;
 
@@ -25,9 +26,8 @@ import java.util.List;
 public class DataManager extends Application {
     public static Context sContext;
     private static int mFaceIndex = 0;
-    private static int mAppName = 0; //是否显示 app 名称
+    private static int mAppNameType = 0; //是否显示 app 名称
     private static int mWeatherIndex = 0;
-    private static int mDeleteStatus = 0;
     private static List<AppModel> mInstalledAppsList = new ArrayList<>();
     private static List<AppModel> mQuickAppsList = new ArrayList<>(Constant.COUNT_QUICK_APP);
     public static List<ContactBean> mContactBeanList = new ArrayList<>();
@@ -45,18 +45,10 @@ public class DataManager extends Application {
         List<AppModel> appModelList = loadInstalledApps();
         mInstalledAppsList = sortAppList(appModelList);
 
-        loadSetting();
+        loadQuickApps();
         loadWeatherIndex();
     }
 
-    public static void registerContentObserver(ContentObserver recentObserver, ContentObserver contactObserver, ContentObserver settingObserver) {
-        if (Macros.DEBUG)
-            return;
-        sContext.getContentResolver().registerContentObserver(MetaData.TABLE_URI_RECENT, true, recentObserver);
-        sContext.getContentResolver().registerContentObserver(MetaData.TABLE_URI_CONTACT, true, contactObserver);
-        sContext.getContentResolver().registerContentObserver(MetaData.TABLE_URI_SETTING, true, settingObserver);
-    }
-
     public static List<AppModel> loadInstalledApps() {
         PackageManager pm = sContext.getPackageManager();
         Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
@@ -97,38 +89,41 @@ public class DataManager extends Application {
         }
     }
 
-    public static void loadSetting() {
-        if (Macros.DEBUG) {
-            loadQuickApps("");
+    public static void loadQuickApps() {
+        if (Macros.DEBUG_DATABASE) {
+            presetQuickApps();
+            return;
+        }
+        String quickContent = Settings.Global.getString(sContext.getContentResolver(), MetaData.KEY_QUICK_APP);
+        if (quickContent.isEmpty()) {
+            //如果快捷应用为空,预置
+            presetQuickApps();
+            saveQuickApps();
         } else {
-            List dataList = DatabaseHelper.querySetting(sContext);
-            mFaceIndex = (int)dataList.get(0);
-            mAppName = (int)dataList.get(1);
-            String quickContent = (String)dataList.get(2);
             loadQuickApps(quickContent);
         }
     }
 
-    public static void loadQuickApps(String quickContent) {
-        if (Macros.DEBUG) {
-            for (int i = 0; i < Constant.COUNT_QUICK_APP; i++) {
-                if (mInstalledAppsList.size() > i) {
-                    mQuickAppsList.add(mInstalledAppsList.get(i).copy());
-                } else {
-                    AppModel model = new AppModel();
-                    mQuickAppsList.add(model);
+    private static void loadQuickApps(String quickContent) {
+        String[] quickList = quickContent.split(";");
+        for (int i = 0; i < Constant.COUNT_QUICK_APP; i++) {
+            if (i < quickList.length) {
+                AppModel model = getAppModel(quickList[i]);
+                if (model != null) {
+                    mQuickAppsList.add(model.copy());
+                    continue;
                 }
             }
-        } else {
-            String[] quickList = quickContent.split(";");
-            for (int i = 0; i < Constant.COUNT_QUICK_APP; i++) {
-                if (i < quickList.length) {
-                    AppModel model = getAppModel(quickList[i]);
-                    if (model != null) {
-                        mQuickAppsList.add(model.copy());
-                        continue;
-                    }
-                }
+            AppModel model = new AppModel();
+            mQuickAppsList.add(model);
+        }
+    }
+
+    public static void presetQuickApps() {
+        for (int i = 0; i < Constant.COUNT_QUICK_APP; i++) {
+            if (mInstalledAppsList.size() > i) {
+                mQuickAppsList.add(mInstalledAppsList.get(i).copy());
+            } else {
                 AppModel model = new AppModel();
                 mQuickAppsList.add(model);
             }
@@ -143,14 +138,19 @@ public class DataManager extends Application {
 
     public static void replaceQuickApps(int viewIndex, int appIndex, AppModel appModel) {
         mQuickAppsList.set(viewIndex * (Constant.COUNT_VIEW_APP) + appIndex, appModel.copy());
+        saveQuickApps();
+    }
 
+    public static void saveQuickApps() {
+        if (Macros.DEBUG_DATABASE)
+            return;
         //保存数据库
         StringBuilder s = new StringBuilder();
         for (AppModel model: mQuickAppsList) {
-             s.append(model.getPackageName()).append(";");
+            s.append(model.getPackageName()).append(";");
         }
-        if (!Macros.DEBUG) {
-            DatabaseHelper.update(sContext, MetaData.KEY_SETTING_QUICKAPP, s.toString());
+        if (!Macros.DEBUG_DATABASE) {
+            Settings.Global.putString(sContext.getContentResolver(), MetaData.KEY_QUICK_APP, s.toString());
         }
     }
 
@@ -285,19 +285,22 @@ public class DataManager extends Application {
         return status == TelephonyManager.SIM_STATE_PUK_REQUIRED;
     }
 
-    public static void loadFaceIndex() {
-        mFaceIndex = 0;
-    }
-
     public static int getFaceIndex() {
-        return mFaceIndex;
+        if (Macros.DEBUG_DATABASE)
+            return 0;
+        return Settings.Global.getInt(sContext.getContentResolver(), MetaData.KEY_WATCH_FACE, 0);
     }
 
     public static void setFaceIndex(int index) {
-        mFaceIndex = index;
-        if (!Macros.DEBUG) {
-            DatabaseHelper.update(sContext, MetaData.KEY_SETTING_WATCHFACE, String.valueOf(index));
-        }
+        if (Macros.DEBUG_DATABASE)
+            return;
+        Settings.Global.putInt(sContext.getContentResolver(), MetaData.KEY_WATCH_FACE, index);
+    }
+
+    public static int getAppNameType() {
+        if (Macros.DEBUG_DATABASE)
+            return 0;
+        return Settings.Global.getInt(sContext.getContentResolver(), MetaData.KEY_APP_NAME, 0);
     }
 
     public static void loadWeatherIndex() {
@@ -312,18 +315,6 @@ public class DataManager extends Application {
         return 6;
     }
 
-    public static int getAppTitleType() {
-        return 0;
-    }
-
-    public static int getDeleteStatus() {
-        return mDeleteStatus;
-    }
-
-    public static void setDeleteStatus(int status) {
-        mDeleteStatus = status;
-    }
-
     public static void setImageView(ImageView imageView, String imagePath, int resId, int defaultId) {
         if (resId > 0) {
             imageView.setImageResource(resId);

+ 7 - 0
app/src/main/java/com/xplora/xplauncher/data/MetaData.java

@@ -24,4 +24,11 @@ public class MetaData {
     public static final String KEY_SETTING_WATCHFACE = "watch_face";
     public static final String KEY_SETTING_APPNAME = "app_name";
     public static final String KEY_SETTING_QUICKAPP = "quick_app";
+
+    //KEY
+    public static final String KEY_APP_NAME = "app_name";
+    public static final String KEY_WATCH_FACE = "watch_face";
+    public static final String KEY_QUICK_APP = "quick_app";
+    public static final String KEY_RESOLUTION_PHOTO = "photo_resolution";
+    public static final String KEY_RESOLUTION_VIDEO = "video_resolution";
 }

+ 32 - 0
app/src/main/java/com/xplora/xplauncher/observer/ContactContentObserver.java

@@ -0,0 +1,32 @@
+package com.xplora.xplauncher.observer;
+
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Handler;
+
+import com.xplora.xplauncher.utils.Constant;
+
+public class ContactContentObserver extends ContentObserver {
+    private static Handler mHandler = null;
+
+    public ContactContentObserver(Handler handler) {
+        super(handler);
+        mHandler = handler;
+    }
+
+    @Override
+    public void onChange(boolean selfChange, Uri uri) {
+        android.util.Log.d("xplauncher", "onChange :" + uri);
+        super.onChange(selfChange, uri);
+
+        if (uri == null)
+            return;
+
+        mHandler.postDelayed(new Runnable() {
+            @Override
+            public void run() {
+                mHandler.sendEmptyMessage(Constant.MSG_DB_OBSERVER_CONTACT);
+            }
+        }, 10);
+    }
+}

+ 32 - 0
app/src/main/java/com/xplora/xplauncher/observer/RecentContentObserver.java

@@ -0,0 +1,32 @@
+package com.xplora.xplauncher.observer;
+
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Handler;
+
+import com.xplora.xplauncher.utils.Constant;
+
+public class RecentContentObserver extends ContentObserver {
+    private static Handler mHandler = null;
+
+    public RecentContentObserver(Handler handler) {
+        super(handler);
+        mHandler = handler;
+    }
+
+    @Override
+    public void onChange(boolean selfChange, Uri uri) {
+        android.util.Log.d("xplauncher", "onChange :" + uri);
+        super.onChange(selfChange, uri);
+
+        if (uri == null)
+            return;
+
+        mHandler.postDelayed(new Runnable() {
+            @Override
+            public void run() {
+                mHandler.sendEmptyMessage(Constant.MSG_DB_OBSERVER_RECENT);
+            }
+        }, 10);
+    }
+}

+ 32 - 0
app/src/main/java/com/xplora/xplauncher/observer/SettingContentObserver.java

@@ -0,0 +1,32 @@
+package com.xplora.xplauncher.observer;
+
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Handler;
+
+import com.xplora.xplauncher.utils.Constant;
+
+public class SettingContentObserver extends ContentObserver {
+    private static Handler mHandler = null;
+
+    public SettingContentObserver(Handler handler) {
+        super(handler);
+        mHandler = handler;
+    }
+
+    @Override
+    public void onChange(boolean selfChange, Uri uri) {
+        android.util.Log.d("xplauncher", "onChange :" + uri);
+        super.onChange(selfChange, uri);
+
+        if (uri == null)
+            return;
+
+        mHandler.postDelayed(new Runnable() {
+            @Override
+            public void run() {
+                mHandler.sendEmptyMessage(Constant.MSG_DB_OBSERVER_SETTING);
+            }
+        }, 10);
+    }
+}

+ 4 - 0
app/src/main/java/com/xplora/xplauncher/utils/Constant.java

@@ -25,6 +25,10 @@ public class Constant {
     public static String INTENT_PAGER_INDEX = "intent_pager_index";
     public static String INTENT_ITEM_INDEX = "intent_item_index";
 
+    public final static int MSG_DB_OBSERVER_CONTACT = 1001;//数据库监控
+    public final static int MSG_DB_OBSERVER_RECENT = 1002;//数据库监控
+    public final static int MSG_DB_OBSERVER_SETTING = 3000;//数据库监控
+
     public final static String DB_CONTENT_URI = "content://com.xplora .WatchCommonProvider/";
     public final static String DB_CONTACTS = DB_CONTENT_URI + "contact";