From a8a51c836ebe5d8b65da52b84168d2b04d50ca70 Mon Sep 17 00:00:00 2001 From: ZhanGSKen Date: Thu, 27 Nov 2025 09:07:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=9B=BE=E6=A0=87=E5=A4=9A?= =?UTF-8?q?=E5=85=83=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- winboll/build.properties | 4 +- winboll/src/beta/res/values-zh/strings.xml | 3 + winboll/src/beta/res/values/strings.xml | 2 + winboll/src/beta/res/xml/shortcutsmaincn1.xml | 46 +++++ winboll/src/beta/res/xml/shortcutsmaincn2.xml | 46 +++++ winboll/src/beta/res/xml/shortcutsmainen1.xml | 46 +++++ winboll/src/main/AndroidManifest.xml | 67 ++++++- .../java/cc/winboll/studio/winboll/App.java | 13 +- .../activities/ShortcutActionActivity.java | 49 ++++++ .../studio/winboll/utils/APPPlusUtils.java | 163 ++++++++++++++++++ winboll/src/main/res/values-zh/strings.xml | 3 + winboll/src/main/res/values/strings.xml | 8 + winboll/src/main/res/xml/shortcutsmaincn1.xml | 46 +++++ winboll/src/main/res/xml/shortcutsmaincn2.xml | 46 +++++ winboll/src/main/res/xml/shortcutsmainen1.xml | 46 +++++ 15 files changed, 581 insertions(+), 7 deletions(-) create mode 100644 winboll/src/beta/res/values-zh/strings.xml create mode 100644 winboll/src/beta/res/xml/shortcutsmaincn1.xml create mode 100644 winboll/src/beta/res/xml/shortcutsmaincn2.xml create mode 100644 winboll/src/beta/res/xml/shortcutsmainen1.xml create mode 100644 winboll/src/main/java/cc/winboll/studio/winboll/activities/ShortcutActionActivity.java create mode 100644 winboll/src/main/java/cc/winboll/studio/winboll/utils/APPPlusUtils.java create mode 100644 winboll/src/main/res/values-zh/strings.xml create mode 100644 winboll/src/main/res/xml/shortcutsmaincn1.xml create mode 100644 winboll/src/main/res/xml/shortcutsmaincn2.xml create mode 100644 winboll/src/main/res/xml/shortcutsmainen1.xml diff --git a/winboll/build.properties b/winboll/build.properties index b788bb0c..894f073d 100644 --- a/winboll/build.properties +++ b/winboll/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Mon Sep 29 05:46:21 GMT 2025 +#Thu Nov 27 01:06:01 GMT 2025 stageCount=3 libraryProject= baseVersion=15.0 publishVersion=15.0.2 -buildCount=10 +buildCount=15 baseBetaVersion=15.0.3 diff --git a/winboll/src/beta/res/values-zh/strings.xml b/winboll/src/beta/res/values-zh/strings.xml new file mode 100644 index 00000000..045e125f --- /dev/null +++ b/winboll/src/beta/res/values-zh/strings.xml @@ -0,0 +1,3 @@ + + + diff --git a/winboll/src/beta/res/values/strings.xml b/winboll/src/beta/res/values/strings.xml index cec044d9..42cbd7a7 100644 --- a/winboll/src/beta/res/values/strings.xml +++ b/winboll/src/beta/res/values/strings.xml @@ -2,5 +2,7 @@ WinBoLL+ + 筋斗云★ + 金抖云☆ diff --git a/winboll/src/beta/res/xml/shortcutsmaincn1.xml b/winboll/src/beta/res/xml/shortcutsmaincn1.xml new file mode 100644 index 00000000..6b6dc9a0 --- /dev/null +++ b/winboll/src/beta/res/xml/shortcutsmaincn1.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/winboll/src/beta/res/xml/shortcutsmaincn2.xml b/winboll/src/beta/res/xml/shortcutsmaincn2.xml new file mode 100644 index 00000000..2dbb8330 --- /dev/null +++ b/winboll/src/beta/res/xml/shortcutsmaincn2.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/winboll/src/beta/res/xml/shortcutsmainen1.xml b/winboll/src/beta/res/xml/shortcutsmainen1.xml new file mode 100644 index 00000000..4684c41b --- /dev/null +++ b/winboll/src/beta/res/xml/shortcutsmainen1.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/winboll/src/main/AndroidManifest.xml b/winboll/src/main/AndroidManifest.xml index d3773024..163eb03b 100644 --- a/winboll/src/main/AndroidManifest.xml +++ b/winboll/src/main/AndroidManifest.xml @@ -23,7 +23,20 @@ + android:label="@string/app_name" + android:exported="true"> + + + + + + @@ -33,8 +46,56 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + diff --git a/winboll/src/main/java/cc/winboll/studio/winboll/App.java b/winboll/src/main/java/cc/winboll/studio/winboll/App.java index 93bd167a..1c7ecee3 100644 --- a/winboll/src/main/java/cc/winboll/studio/winboll/App.java +++ b/winboll/src/main/java/cc/winboll/studio/winboll/App.java @@ -44,9 +44,18 @@ import java.util.LinkedHashMap; import java.util.concurrent.atomic.AtomicBoolean; public class App extends GlobalApplication { - + + public static final String TAG = "App"; + + public static final String COMPONENT_EN1 = "cc.winboll.studio.winboll.MainActivityEN1"; + public static final String COMPONENT_CN1 = "cc.winboll.studio.winboll.MainActivityCN1"; + public static final String COMPONENT_CN2 = "cc.winboll.studio.winboll.MainActivityCN2"; + public static final String ACTION_SWITCHTO_EN1 = "cc.winboll.studio.winboll.App.ACTION_SWITCHTO_EN1"; + public static final String ACTION_SWITCHTO_CN1 = "cc.winboll.studio.winboll.App.ACTION_SWITCHTO_CN1"; + public static final String ACTION_SWITCHTO_CN2 = "cc.winboll.studio.winboll.App.ACTION_SWITCHTO_CN2"; + private static Handler MAIN_HANDLER = new Handler(Looper.getMainLooper()); - + @Override public void onCreate() { super.onCreate(); diff --git a/winboll/src/main/java/cc/winboll/studio/winboll/activities/ShortcutActionActivity.java b/winboll/src/main/java/cc/winboll/studio/winboll/activities/ShortcutActionActivity.java new file mode 100644 index 00000000..d906af3c --- /dev/null +++ b/winboll/src/main/java/cc/winboll/studio/winboll/activities/ShortcutActionActivity.java @@ -0,0 +1,49 @@ +package cc.winboll.studio.winboll.activities; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import cc.winboll.studio.libappbase.ToastUtils; +import cc.winboll.studio.winboll.App; +import cc.winboll.studio.winboll.R; +import cc.winboll.studio.winboll.utils.APPPlusUtils; + +/** + * @Author ZhanGSKen&豆包大模型 + * @Date 2025/11/27 09:00 + * @Describe 应用快捷方式活动类 + */ +public class ShortcutActionActivity extends Activity { + + public static final String TAG = "ShortcutActionActivity"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // 处理应用级别的切换请求 + handleSwitchRequest(); + finish(); + } + + /** + * 处理应用图标快捷菜单的请求 + */ + private void handleSwitchRequest() { + Intent intent = getIntent(); + if (intent != null && "switchto_en1".equals(intent.getDataString())) { + APPPlusUtils.switchAppLauncherToComponent(this, App.COMPONENT_EN1); + ToastUtils.show("切换至" + getString(R.string.app_name) + "图标"); + //moveTaskToBack(true); + } + if (intent != null && "switchto_cn1".equals(intent.getDataString())) { + APPPlusUtils.switchAppLauncherToComponent(this, App.COMPONENT_CN1); + ToastUtils.show("切换至" + getString(R.string.app_name_cn1) + "图标"); + //moveTaskToBack(true); + } + if (intent != null && "switchto_cn2".equals(intent.getDataString())) { + APPPlusUtils.switchAppLauncherToComponent(this, App.COMPONENT_CN2); + ToastUtils.show("切换至" + getString(R.string.app_name_cn2) + "图标"); + //moveTaskToBack(true); + } + } +} diff --git a/winboll/src/main/java/cc/winboll/studio/winboll/utils/APPPlusUtils.java b/winboll/src/main/java/cc/winboll/studio/winboll/utils/APPPlusUtils.java new file mode 100644 index 00000000..2004f939 --- /dev/null +++ b/winboll/src/main/java/cc/winboll/studio/winboll/utils/APPPlusUtils.java @@ -0,0 +1,163 @@ +package cc.winboll.studio.winboll.utils; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Build; +import android.widget.Toast; +import cc.winboll.studio.libappbase.LogUtils; +import cc.winboll.studio.winboll.App; +import cc.winboll.studio.winboll.R; + +/** + * @Author ZhanGSKen&豆包大模型 + * @Date 2025/11/27 08:56 + * @Describe APPPlusUtils + */ +public class APPPlusUtils { + public static final String TAG = "APPPlusUtils"; + + // 快捷方式配置(名称+图标,需与实际资源匹配) +// private static final String PLUS_SHORTCUT_NAME = "位置服务-Laojun"; +// private static final int PLUS_SHORTCUT_ICON = R.mipmap.ic_launcher; // Laojun 图标资源 + + /** + * 添加Plus组件与图标 + */ + public static boolean switchAppLauncherToComponent(Context context, String componentName) { + if (context == null) { + LogUtils.d(TAG, "切换失败:上下文为空"); + Toast.makeText(context, context.getString(R.string.app_name) + "图标切换失败", Toast.LENGTH_SHORT).show(); + return false; + } + + PackageManager pm = context.getPackageManager(); + + ComponentName plusComponentSwitchTo = new ComponentName(context, componentName); + ComponentName plusComponentEN1 = new ComponentName(context, App.COMPONENT_EN1); + ComponentName plusComponentCN1 = new ComponentName(context, App.COMPONENT_CN1); + ComponentName plusComponentCN2 = new ComponentName(context, App.COMPONENT_CN2); + + try { + disableComponent(pm, plusComponentEN1); + disableComponent(pm, plusComponentCN1); + disableComponent(pm, plusComponentCN2); + enableComponent(pm, plusComponentSwitchTo); + + return true; + + } catch (Exception e) { + LogUtils.e(TAG, "图标切换失败:" + e.getMessage()); + Toast.makeText(context, context.getString(R.string.app_name) + "图标切换失败" + e.getMessage(), Toast.LENGTH_SHORT).show(); + return false; + } + } + + /** + * 创建指定组件的桌面快捷方式(自动去重,兼容 Android 8.0+) + * @param component 目标组件(如 LAOJUN_ACTIVITY) + * @param name 快捷方式名称 + * @param iconRes 快捷方式图标资源ID + * @return 是否创建成功 + */ + private static boolean createComponentShortcut(Context context, ComponentName component, String name, int iconRes) { + if (context == null || component == null || name == null || iconRes == 0) { + LogUtils.d(TAG, "快捷方式创建失败:参数为空"); + return false; + } + + // Android 8.0+(API 26+):使用 ShortcutManager(系统推荐) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + try { + PackageManager pm = context.getPackageManager(); + android.content.pm.ShortcutManager shortcutManager = context.getSystemService(android.content.pm.ShortcutManager.class); + if (shortcutManager == null || !shortcutManager.isRequestPinShortcutSupported()) { + LogUtils.d(TAG, "系统不支持创建快捷方式"); + return false; + } + + // 检查是否已存在该组件的快捷方式(去重) + for (android.content.pm.ShortcutInfo info : shortcutManager.getPinnedShortcuts()) { + if (component.getClassName().equals(info.getIntent().getComponent().getClassName())) { + LogUtils.d(TAG, "快捷方式已存在:" + component.getClassName()); + return true; + } + } + + // 构建启动目标组件的意图 + Intent launchIntent = new Intent(Intent.ACTION_MAIN) + .setComponent(component) + .addCategory(Intent.CATEGORY_LAUNCHER) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + + // 构建快捷方式信息 + android.content.pm.ShortcutInfo shortcutInfo = new android.content.pm.ShortcutInfo.Builder(context, component.getClassName()) + .setShortLabel(name) + .setLongLabel(name) + .setIcon(android.graphics.drawable.Icon.createWithResource(context, iconRes)) + .setIntent(launchIntent) + .build(); + + // 请求创建快捷方式(需用户确认) + shortcutManager.requestPinShortcut(shortcutInfo, null); + return true; + + } catch (Exception e) { + LogUtils.d(TAG, "Android O+ 快捷方式创建失败:" + e.getMessage()); + return false; + } + } else { + // Android 8.0 以下:使用广播(兼容旧机型) + try { + // 构建启动目标组件的意图 + Intent launchIntent = new Intent(Intent.ACTION_MAIN) + .setComponent(component) + .addCategory(Intent.CATEGORY_LAUNCHER) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + + // 构建创建快捷方式的广播意图 + Intent installIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); + installIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent); + installIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); + installIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, + Intent.ShortcutIconResource.fromContext(context, iconRes)); + installIntent.putExtra("duplicate", false); // 禁止重复创建 + + context.sendBroadcast(installIntent); + return true; + + } catch (Exception e) { + LogUtils.d(TAG, "Android O- 快捷方式创建失败:" + e.getMessage()); + return false; + } + } + } + + /** + * 启用组件(带状态检查,避免重复操作) + */ + private static void enableComponent(PackageManager pm, ComponentName component) { + if (pm.getComponentEnabledSetting(component) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { + pm.setComponentEnabledSetting( + component, + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP | PackageManager.SYNCHRONOUS + ); + } + } + + /** + * 禁用组件(带状态检查,避免重复操作) + */ + private static void disableComponent(PackageManager pm, ComponentName component) { + if (pm.getComponentEnabledSetting(component) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { + pm.setComponentEnabledSetting( + component, + PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + PackageManager.DONT_KILL_APP | PackageManager.SYNCHRONOUS + ); + } + } +} + diff --git a/winboll/src/main/res/values-zh/strings.xml b/winboll/src/main/res/values-zh/strings.xml new file mode 100644 index 00000000..045e125f --- /dev/null +++ b/winboll/src/main/res/values-zh/strings.xml @@ -0,0 +1,3 @@ + + + diff --git a/winboll/src/main/res/values/strings.xml b/winboll/src/main/res/values/strings.xml index d9299dc4..c9677359 100644 --- a/winboll/src/main/res/values/strings.xml +++ b/winboll/src/main/res/values/strings.xml @@ -1,5 +1,13 @@ WinBoLL + 筋斗云 + 金抖云 + WinBoLL + 筋斗云 + 金抖云 + WinBoLL X + 筋斗云 X + 金抖云 X WinBoLL WinBoLL APP diff --git a/winboll/src/main/res/xml/shortcutsmaincn1.xml b/winboll/src/main/res/xml/shortcutsmaincn1.xml new file mode 100644 index 00000000..31966736 --- /dev/null +++ b/winboll/src/main/res/xml/shortcutsmaincn1.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/winboll/src/main/res/xml/shortcutsmaincn2.xml b/winboll/src/main/res/xml/shortcutsmaincn2.xml new file mode 100644 index 00000000..331ab2ec --- /dev/null +++ b/winboll/src/main/res/xml/shortcutsmaincn2.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/winboll/src/main/res/xml/shortcutsmainen1.xml b/winboll/src/main/res/xml/shortcutsmainen1.xml new file mode 100644 index 00000000..7d04b714 --- /dev/null +++ b/winboll/src/main/res/xml/shortcutsmainen1.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + +