Просмотр исходного кода

使用启动入口的方式添加有范商城入口,但是卸载有范商城图片时会卸载小绵羊

zengjiebin лет назад: 7
Родитель
Сommit
960abede83

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

@@ -207,6 +207,20 @@
             </intent-filter>
             </intent-filter>
         </activity>
         </activity>
         <activity
         <activity
+            android:name="com.sheep.gamegroup.view.activity.ActYf"
+            android:screenOrientation="portrait"
+            android:theme="@style/AppActionTheme"
+            android:label="@string/app_name_yf"
+            android:icon="@drawable/icon_yf"
+            android:enabled="false"
+            android:taskAffinity="${applicationId}.yf">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        <activity
             android:name="com.sheep.gamegroup.view.activity.MiddleSchemeAct"
             android:name="com.sheep.gamegroup.view.activity.MiddleSchemeAct"
             android:configChanges="keyboardHidden|screenSize|orientation"
             android:configChanges="keyboardHidden|screenSize|orientation"
             android:exported="true"
             android:exported="true"

+ 4 - 0
app/src/main/java/com/sheep/gamegroup/absBase/BaseActivity.java

@@ -20,6 +20,7 @@ import com.r0adkll.slidr.model.SlidrListener;
 import com.r0adkll.slidr.model.SlidrPosition;
 import com.r0adkll.slidr.model.SlidrPosition;
 import com.sheep.gamegroup.util.ActionUtil;
 import com.sheep.gamegroup.util.ActionUtil;
 import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.gamegroup.util.LogUtil;
+import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.gamegroup.view.dialog.DialogLoading;
 import com.sheep.gamegroup.view.dialog.DialogLoading;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.R;
 import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
 import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
@@ -322,6 +323,9 @@ public abstract class BaseActivity extends RxAppCompatActivity {
         }
         }
     }
     }
     private boolean isTranslucentOrFloating(){
     private boolean isTranslucentOrFloating(){
+        if(TestUtil.isDev()){
+            return false;
+        }
         boolean isTranslucentOrFloating = false;
         boolean isTranslucentOrFloating = false;
         try {
         try {
             int [] styleableRes = (int[]) Class.forName("com.android.internal.R$styleable").getField("Window").get(null);
             int [] styleableRes = (int[]) Class.forName("com.android.internal.R$styleable").getField("Window").get(null);

+ 71 - 0
app/src/main/java/com/sheep/gamegroup/util/SysAppUtil.java

@@ -3,6 +3,7 @@ package com.sheep.gamegroup.util;
 import android.app.Activity;
 import android.app.Activity;
 import android.app.Dialog;
 import android.app.Dialog;
 import android.app.PendingIntent;
 import android.app.PendingIntent;
+import android.content.ActivityNotFoundException;
 import android.content.BroadcastReceiver;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.ContentResolver;
@@ -897,6 +898,10 @@ public class SysAppUtil {
                         e.printStackTrace();
                         e.printStackTrace();
                         if(TestUtil.isDev())
                         if(TestUtil.isDev())
                             G.showToast(e);
                             G.showToast(e);
+                    } catch (ActivityNotFoundException e){
+                        if(RomUtils.checkIsMiuiRom()){
+                            skipActivity(activity, "com.miui.securitycenter", "com.miui.permcenter.MainAcitivty", null, null);
+                        }
                     } catch (Exception e){
                     } catch (Exception e){
                         e.printStackTrace();
                         e.printStackTrace();
                         if(TestUtil.isDev())
                         if(TestUtil.isDev())
@@ -1018,4 +1023,70 @@ public class SysAppUtil {
         }
         }
         return null;
         return null;
     }
     }
+
+    public static boolean skipActivity(Context context, String packageName, String className, String action, String extraPkgName){
+        Intent intent;
+        if(TextUtils.isEmpty(action))
+            intent = new Intent();
+        else
+            intent = new Intent(action);
+        if(!TextUtils.isEmpty(extraPkgName)) {
+            intent.putExtra("extra_pkgname", extraPkgName);
+        }
+        intent.setClassName(packageName, className);
+        if(QQUtil.isValidIntent(context, intent)){
+            try{
+                context.startActivity(intent);
+                if(TestUtil.isDev())
+                    G.showToast("启动成功");
+                return true;
+            } catch (Exception e) {
+                e.printStackTrace();
+                if(TestUtil.isDev())
+                    G.showToast(e);
+            }
+        } else {
+            if(TestUtil.isDev())
+                G.showToast("启动失败");
+        }
+        return false;
+    }
+
+
+
+
+
+    public static void enableComponentYf() {
+        new Thread(() -> {
+            //启用有范商城
+            ComponentName testComponent = new ComponentName(SheepApp.getInstance(), "com.sheep.gamegroup.view.activity.ActYf");
+            enableComponent(testComponent, true);
+        }).start();
+    }
+    public static boolean isEnableComponentYf() {
+        //启用有范商城
+        ComponentName testComponent = new ComponentName(SheepApp.getInstance(), "com.sheep.gamegroup.view.activity.ActYf");
+        return isEnableComponent(testComponent);
+    }
+    /**
+     * 是否已经启用组件
+     *
+     * @param componentName
+     */
+    private static boolean isEnableComponent(ComponentName componentName) {
+        PackageManager packageManager = SheepApp.getInstance().getPackageManager();
+        int state = packageManager.getComponentEnabledSetting(componentName);
+        return state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
+    }
+    /**
+     * 启用组件或者禁用组件
+     *
+     * @param componentName
+     */
+    private static void enableComponent(ComponentName componentName, boolean enable) {
+        PackageManager packageManager = SheepApp.getInstance().getPackageManager();
+        packageManager.setComponentEnabledSetting(componentName,
+                enable ?  PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+                PackageManager.DONT_KILL_APP);
+    }
 }
 }

+ 9 - 31
app/src/main/java/com/sheep/gamegroup/util/TestUtil.java

@@ -731,6 +731,12 @@ public class TestUtil {
     private static void testSkip(Activity activity) {
     private static void testSkip(Activity activity) {
         CharSequence charSequence = StringUtils.getCopyText();
         CharSequence charSequence = StringUtils.getCopyText();
         if(charSequence == null){
         if(charSequence == null){
+// 快捷方式权限设置界面
+//        com.miui.securitycenter;com.miui.permcenter.permissions.PermissionAppsEditorActivity
+// 权限设置界面
+//        com.miui.securitycenter;com.miui.permcenter.permissions.AppPermissionsTabActivity
+// 安全中心
+//        com.miui.securitycenter;com.miui.permcenter.MainAcitivty
             G.showToast("请在粘贴板中复现内容,格式如下:com.miui.securitycenter;com.miui.permcenter.permissions.AppPermissionsTabActivity");
             G.showToast("请在粘贴板中复现内容,格式如下:com.miui.securitycenter;com.miui.permcenter.permissions.AppPermissionsTabActivity");
         } else {
         } else {
             String copyText = charSequence.toString();
             String copyText = charSequence.toString();
@@ -741,46 +747,18 @@ public class TestUtil {
                     PackageUtil.startApp(activity, items[0]);
                     PackageUtil.startApp(activity, items[0]);
                     break;
                     break;
                 case 2:
                 case 2:
-                    startActivity(activity, items[0], items[1], null, null);
+                    SysAppUtil.skipActivity(activity, items[0], items[1], null, null);
                     break;
                     break;
                 case 3:
                 case 3:
-                    startActivity(activity, items[0], items[1], items[2], null);
+                    SysAppUtil.skipActivity(activity, items[0], items[1], items[2], null);
                     break;
                     break;
                 case 4:
                 case 4:
-                    startActivity(activity, items[0], items[1], items[3], items[4]);
+                    SysAppUtil.skipActivity(activity, items[0], items[1], items[3], items[4]);
                     break;
                     break;
             }
             }
         }
         }
     }
     }
 
 
-    //
-    private static boolean startActivity(Context context, String packageName, String className, String action, String extraPkgName){
-        Intent intent;
-        if(TextUtils.isEmpty(action))
-            intent = new Intent();
-        else
-            intent = new Intent(action);
-//        intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionAppsEditorActivity");//快捷方式权限设置界面
-//        intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsTabActivity");
-        if(!TextUtils.isEmpty(extraPkgName)) {
-            intent.putExtra("extra_pkgname", extraPkgName);
-        }
-        intent.setClassName(packageName, className);
-        if(QQUtil.isValidIntent(context, intent)){
-            try{
-                context.startActivity(intent);
-                G.showToast("启动成功");
-                return true;
-            } catch (Exception e) {
-                e.printStackTrace();
-                G.showToast(e);
-            }
-        } else {
-            G.showToast("启动失败");
-        }
-        return false;
-    }
-
 
 
     /**
     /**
      * 测试设备信息
      * 测试设备信息

+ 6 - 3
app/src/main/java/com/sheep/gamegroup/view/activity/ActWebX5.java

@@ -130,12 +130,15 @@ public class ActWebX5 extends BaseActWeb {
     private void checkWebParams(WebParams webParams) {
     private void checkWebParams(WebParams webParams) {
         if(webParams.getUrl().startsWith(Config.YF_SHOP_HOME_SHEEP.split("\\?")[0]) || webParams.getUrl().startsWith(Config.YF_SHOP_HOME_SHEEP_TEST.split("\\?")[0])) {//检测是否是有范商城地址
         if(webParams.getUrl().startsWith(Config.YF_SHOP_HOME_SHEEP.split("\\?")[0]) || webParams.getUrl().startsWith(Config.YF_SHOP_HOME_SHEEP_TEST.split("\\?")[0])) {//检测是否是有范商城地址
             boolean isIgnore = SpUtils.getAsBoolean(KEY_IGNORE_ADD_YOU_FAN_LAUNCHER, false);
             boolean isIgnore = SpUtils.getAsBoolean(KEY_IGNORE_ADD_YOU_FAN_LAUNCHER, false);
-            boolean hasShortcut = SysAppUtil.hasShortcut(SheepApp.getInstance(), Config.YF_SHOP_NAME);
-            if (!hasShortcut && !isIgnore && !CommonUtil.getInstance().hasYouFanLauncher()) {//未忽略并且没有添加有范商品入口
+//            boolean hasShortcut = SysAppUtil.hasShortcut(SheepApp.getInstance(), Config.YF_SHOP_NAME);
+//            boolean isShow = !hasShortcut && !isIgnore && !CommonUtil.getInstance().hasYouFanLauncher();//未忽略并且没有添加有范商品入口
+            boolean isShow = !isIgnore && !SysAppUtil.isEnableComponentYf();
+            if (isShow) {
                 ViewUtil.showMsgDialog(this, new DialogConfig().setTitle("温馨提示")
                 ViewUtil.showMsgDialog(this, new DialogConfig().setTitle("温馨提示")
                         .setMsg("亲,喜欢的话,就添加一个商城的桌面快捷入口吧!(点击否将不再提示)")
                         .setMsg("亲,喜欢的话,就添加一个商城的桌面快捷入口吧!(点击否将不再提示)")
                         .setBtnLeftText("否").setBtnLeftOnClickListener(view -> SpUtils.putAsBoolean(KEY_IGNORE_ADD_YOU_FAN_LAUNCHER, true))
                         .setBtnLeftText("否").setBtnLeftOnClickListener(view -> SpUtils.putAsBoolean(KEY_IGNORE_ADD_YOU_FAN_LAUNCHER, true))
-                        .setBtnRightText("是").setBtnRightOnClickListener(view -> CommonUtil.getInstance().addYouFanLauncher()));
+//                        .setBtnRightText("是").setBtnRightOnClickListener(view -> CommonUtil.getInstance().addYouFanLauncher()));
+                        .setBtnRightText("是").setBtnRightOnClickListener(view -> SysAppUtil.enableComponentYf()));
             }
             }
         }
         }
     }
     }

+ 1 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/ActWebX5YF.java

@@ -10,6 +10,7 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
  * Created by realicing on 2019/3/20.
  * Created by realicing on 2019/3/20.
  * realicing@sina.com
  * realicing@sina.com
  * 有范商城h5
  * 有范商城h5
+ * 快捷入口方式来实现,但是问题很多,暂时用ActYf来替代该功能
  */
  */
 public class ActWebX5YF extends ActWebX5 {
 public class ActWebX5YF extends ActWebX5 {
     public static final String KEY_HAS_YOU_FAN_LAUNCHER = "has_you_fan_launcher";
     public static final String KEY_HAS_YOU_FAN_LAUNCHER = "has_you_fan_launcher";

+ 22 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/ActYf.java

@@ -0,0 +1,22 @@
+package com.sheep.gamegroup.view.activity;
+
+import com.sheep.gamegroup.model.entity.WebParams;
+import com.sheep.gamegroup.util.DataUtil;
+import com.sheep.jiuyan.samllsheep.Config;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+
+/**
+ * Created by realicing on 2019/4/8.
+ * realicing@sina.com
+ * 有范商城入口;
+ * 直接添加入口方式来实现
+ */
+public class ActYf  extends ActWebX5 {
+    @Override
+    public void initWebParams() {
+        DataUtil.putAsBoolean(ActWebX5YF.KEY_HAS_YOU_FAN_LAUNCHER, true);
+
+        String url = SheepApp.getInstance().getConnectAddress().getYfShotHomeSheep();
+        webParams = new WebParams(url, Config.YF_SHOP_NAME).tokenFirstUpperCase();
+    }
+}

BIN
app/src/main/res/drawable/icon_yf_small.png


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

@@ -225,4 +225,6 @@
 
 
 
 
     <string name="to_exchange">去兑换</string>
     <string name="to_exchange">去兑换</string>
+
+    <string name="app_name_yf">有范商城</string>
 </resources>
 </resources>