liuzhenxing1118 3 years ago
parent
commit
59907b6580

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -5,6 +5,7 @@
     android:sharedUserId="android.uid.system"
     >
 
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"
         tools:ignore="ProtectedPermissions" />
 

+ 31 - 0
app/src/main/java/com/xplora/xplauncher/activity/MainActivity.java

@@ -23,6 +23,7 @@ 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.NetworkChangeReceiver;
 import com.xplora.xplauncher.observer.RecentContentObserver;
 import com.xplora.xplauncher.observer.SettingContentObserver;
 import com.xplora.xplauncher.observer.SimStateReceiver;
@@ -71,6 +72,9 @@ public class MainActivity extends BaseActivity {
         initViewPager();
         initTimeChangeBroadcast();
         initSimStateBroadcast();
+
+        if (Macros.DEBUG_NETWORK_OBSERVER)
+            initNetworkBroadcast();
     }
 
     private void initViewPager() {
@@ -197,6 +201,11 @@ public class MainActivity extends BaseActivity {
               //添加快捷应用
                 startAppListActivity(viewIndex, appIndex);
             } else {
+                boolean isNeedActivated = DataManager.getIsAppNeedActivated(appModel);
+                int status = DataManager.getWatchStatus();
+                if (isNeedActivated && status != 0) {
+
+                }
                 startAppActivity(appModel);
             }
         }
@@ -408,6 +417,25 @@ public class MainActivity extends BaseActivity {
         });
     }
 
+    private void initNetworkBroadcast() {
+        NetworkChangeReceiver.registerObserver(new NetworkChangeReceiver.NetStateChangeObserver() {
+            @Override
+            public void onDisconnect() {
+
+            }
+
+            @Override
+            public void onMobileConnect() {
+
+            }
+
+            @Override
+            public void onWifiConnect() {
+
+            }
+        });
+    }
+
     private void registerContentObserver() {
         if (Macros.DEBUG_DATABASE)
             return;
@@ -460,6 +488,9 @@ public class MainActivity extends BaseActivity {
             mSimListener = null;
         }
 
+        if (Macros.DEBUG_NETWORK_OBSERVER)
+            NetworkChangeReceiver.unRegisterReceiver(this);
+
         if (mPagerViews.size() > 1) {
             HomePager homeView = (HomePager) mPagerViews.get(1);
             homeView.destroyView();

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

@@ -19,6 +19,7 @@ import com.xplora.xplauncher.model.ContactBean;
 import com.xplora.xplauncher.model.RecentBean;
 import com.xplora.xplauncher.utils.Constant;
 import com.xplora.xplauncher.utils.Macros;
+import com.xplora.xplauncher.utils.NetworkUtil;
 import com.xplora.xplauncher.utils.ResUtils;
 import com.xplora.xplauncher.utils.ToolsUtils;
 
@@ -368,6 +369,27 @@ public class DataManager extends Application {
         return SystemProperties.getBoolean("persist.sys.factoryimage", false);
     }
 
+    public static int getWatchStatus() {
+        int isActivated = getIsWatchActivated();
+        int networkStatus = NetworkUtil.getConnectivityStatus(sContext);
+        if (isActivated <= 0)
+            return -1;
+//        else if (networkStatus == NetworkUtil.TYPE_NOT_CONNECTED)
+//            return -2;
+        else
+            return 0;
+    }
+
+    public static boolean getIsAppNeedActivated(AppModel appModel) {
+        String[] strings = sContext.getResources().getStringArray(R.array.xp_app_need_activated);
+        for (String s: strings) {
+            if (s.equals(appModel.getPackageName())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     public static void loadWeatherIndex() {
         mWeatherIndex = 0;
     }

+ 93 - 0
app/src/main/java/com/xplora/xplauncher/observer/NetworkChangeReceiver.java

@@ -0,0 +1,93 @@
+package com.xplora.xplauncher.observer;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+
+import com.xplora.xplauncher.utils.NetworkUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class NetworkChangeReceiver extends BroadcastReceiver {
+    private List<NetStateChangeObserver> mObservers = new ArrayList<>();
+    private int mType = -1;
+    private static boolean isRegister = false;
+
+    private static class InstanceHolder {
+        private static final NetworkChangeReceiver INSTANCE = new NetworkChangeReceiver();
+    }
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+
+        if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
+            int connectivityStatus = NetworkUtil.getConnectivityStatus(context);
+            notifyObservers(connectivityStatus);
+        }
+
+    }
+
+    public static void registerReceiver(Context context) {
+        IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
+        context.registerReceiver(InstanceHolder.INSTANCE, intentFilter);
+        isRegister = true;
+    }
+
+    public static void unRegisterReceiver(Context context) {
+        if (isRegister) {
+            context.unregisterReceiver(InstanceHolder.INSTANCE);
+        }
+    }
+
+    public static void registerObserver(NetStateChangeObserver observer) {
+        if (observer == null) {
+            return;
+        }
+        if (!InstanceHolder.INSTANCE.mObservers.contains(observer)) {
+            InstanceHolder.INSTANCE.mObservers.add(observer);
+        }
+    }
+
+    public static void unRegisterObserver(NetStateChangeObserver observer) {
+        if (observer == null) {
+            return;
+        }
+        if (InstanceHolder.INSTANCE.mObservers == null) {
+            return;
+        }
+        InstanceHolder.INSTANCE.mObservers.remove(observer);
+    }
+
+    private void notifyObservers(int networkType) {
+        if (mType == networkType) {
+            return;
+        }
+        mType = networkType;
+        if (networkType == NetworkUtil.TYPE_MOBILE) {
+            for (NetStateChangeObserver observer : mObservers) {
+                observer.onMobileConnect();
+            }
+        } else if (networkType == NetworkUtil.TYPE_WIFI) {
+            for (NetStateChangeObserver observer : mObservers) {
+                observer.onWifiConnect();
+            }
+        } else {
+            for (NetStateChangeObserver observer : mObservers) {
+                observer.onDisconnect();
+            }
+        }
+    }
+
+    public interface NetStateChangeObserver {
+
+        void onDisconnect();
+
+        void onMobileConnect();
+
+        void onWifiConnect();
+    }
+}

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

@@ -5,8 +5,10 @@ public class Macros {
     //TODO:测试使用,正式版本需要关闭false
     public static boolean DEBUG = true;
 
-    public static boolean DEBUG_DATABASE = true; //模拟数据库中数据
+    public static boolean DEBUG_DATABASE = false; //模拟数据库中数据
     public static boolean DEBUG_SYSTEMPROVIDER = false; //模拟数据库中数据
 
     public static boolean DEBUG_ALL_APPS = true; //安装的应用不筛选app
+
+    public static boolean DEBUG_NETWORK_OBSERVER = false; //是否监听网络变化
 }

+ 28 - 0
app/src/main/java/com/xplora/xplauncher/utils/NetworkUtil.java

@@ -0,0 +1,28 @@
+package com.xplora.xplauncher.utils;
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+
+public class NetworkUtil {
+
+    public static final int TYPE_WIFI = 1;
+    public static final int TYPE_MOBILE = 2;
+    public static final int TYPE_NOT_CONNECTED = 0;
+
+
+    public static int getConnectivityStatus(Context context) {
+        ConnectivityManager cm = (ConnectivityManager) context
+                .getSystemService(Context.CONNECTIVITY_SERVICE);
+
+        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
+        if (null != activeNetwork) {
+            if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
+                return TYPE_WIFI;
+
+            if(activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
+                return TYPE_MOBILE;
+        }
+        return TYPE_NOT_CONNECTED;
+    }
+}

+ 6 - 0
app/src/main/res/values/arrays.xml

@@ -15,4 +15,10 @@
         <item>com.xplora.video</item>
         <item>com.xplora.voip</item>
     </string-array>
+
+    <string-array name="xp_app_need_activated">
+        <item>com.xplora.xpchat</item>
+        <item>com.xplora.xpaddfriend</item>
+        <item>com.xplora.stopwatch</item>
+    </string-array>
 </resources>