diff --git a/powerbell/build.properties b/powerbell/build.properties index b709c835..c8fc7bb2 100644 --- a/powerbell/build.properties +++ b/powerbell/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Tue Nov 25 13:28:22 GMT 2025 +#Wed Nov 26 08:17:33 GMT 2025 stageCount=8 libraryProject= baseVersion=15.11 publishVersion=15.11.7 -buildCount=2 +buildCount=10 baseBetaVersion=15.11.8 diff --git a/powerbell/src/beta/AndroidManifest.xml b/powerbell/src/beta/AndroidManifest.xml index b3f7ebf6..43d1ccfb 100644 --- a/powerbell/src/beta/AndroidManifest.xml +++ b/powerbell/src/beta/AndroidManifest.xml @@ -6,31 +6,6 @@ tools:replace="android:icon" android:icon="@drawable/ic_launcher_beta"> - - - - - - - - - - - - - - - diff --git a/powerbell/src/beta/res/values-zh/string.xml b/powerbell/src/beta/res/values-zh/string.xml index 8abb2278..633b11b7 100644 --- a/powerbell/src/beta/res/values-zh/string.xml +++ b/powerbell/src/beta/res/values-zh/string.xml @@ -1,6 +1,7 @@ - 泡额呗额☆ + 能源钟★ + 泡额呗额☆ diff --git a/powerbell/src/beta/res/xml/shortcutsmaincn1.xml b/powerbell/src/beta/res/xml/shortcutsmaincn1.xml new file mode 100644 index 00000000..d2297b89 --- /dev/null +++ b/powerbell/src/beta/res/xml/shortcutsmaincn1.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/powerbell/src/beta/res/xml/shortcutsmaincn2.xml b/powerbell/src/beta/res/xml/shortcutsmaincn2.xml new file mode 100644 index 00000000..1bf9db12 --- /dev/null +++ b/powerbell/src/beta/res/xml/shortcutsmaincn2.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/powerbell/src/beta/res/xml/shortcutsmainen1.xml b/powerbell/src/beta/res/xml/shortcutsmainen1.xml new file mode 100644 index 00000000..d56a42ef --- /dev/null +++ b/powerbell/src/beta/res/xml/shortcutsmainen1.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/powerbell/src/main/AndroidManifest.xml b/powerbell/src/main/AndroidManifest.xml index f4ccdf5e..dcc07343 100644 --- a/powerbell/src/main/AndroidManifest.xml +++ b/powerbell/src/main/AndroidManifest.xml @@ -66,6 +66,82 @@ android:usesCleartextTraffic="true" tools:ignore="GoogleAppIndexingWarning"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/App.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/App.java index 6d285616..5bd248ce 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/App.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/App.java @@ -13,7 +13,14 @@ import java.io.File; public class App extends GlobalApplication { public static final String TAG = "GlobalApplication"; - + + public static final String COMPONENT_EN1 = "cc.winboll.studio.powerbell.MainActivityEN1"; + public static final String COMPONENT_CN1 = "cc.winboll.studio.powerbell.MainActivityCN1"; + public static final String COMPONENT_CN2 = "cc.winboll.studio.powerbell.MainActivityCN2"; + public static final String ACTION_SWITCHTO_EN1 = "cc.winboll.studio.powerbell.App.ACTION_SWITCHTO_EN1"; + public static final String ACTION_SWITCHTO_CN1 = "cc.winboll.studio.powerbell.App.ACTION_SWITCHTO_CN1"; + public static final String ACTION_SWITCHTO_CN2 = "cc.winboll.studio.powerbell.App.ACTION_SWITCHTO_CN2"; + // 数据配置存储工具 static AppConfigUtils _mAppConfigUtils; static AppCacheUtils _mAppCacheUtils; diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java index 0a299231..ea23ddf5 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java @@ -1,13 +1,11 @@ package cc.winboll.studio.powerbell; -import android.Manifest; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Intent; import android.database.Cursor; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.provider.MediaStore; import android.view.KeyEvent; @@ -15,8 +13,6 @@ import android.view.Menu; import android.view.MenuItem; import android.widget.RelativeLayout; import androidx.appcompat.widget.Toolbar; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; import cc.winboll.studio.libaes.views.ADsBannerView; import cc.winboll.studio.libappbase.LogActivity; import cc.winboll.studio.libappbase.LogUtils; @@ -27,6 +23,7 @@ import cc.winboll.studio.powerbell.activities.ClearRecordActivity; import cc.winboll.studio.powerbell.activities.WinBoLLActivity; import cc.winboll.studio.powerbell.beans.BackgroundPictureBean; import cc.winboll.studio.powerbell.fragments.MainViewFragment; +import cc.winboll.studio.powerbell.unittest.MainUnitTestActivity; import cc.winboll.studio.powerbell.utils.BackgroundPictureUtils; /** @@ -113,7 +110,7 @@ public class MainActivity extends WinBoLLActivity { } showFragment(mMainViewFragment); } - + @Override protected void onDestroy() { super.onDestroy(); @@ -227,6 +224,9 @@ public class MainActivity extends WinBoLLActivity { public boolean onCreateOptionsMenu(Menu menu) { mMenu = menu; getMenuInflater().inflate(R.menu.toolbar_main, mMenu); + if (App.isDebugging()) { + getMenuInflater().inflate(R.menu.toolbar_unittest, mMenu); + } return true; } @@ -244,6 +244,8 @@ public class MainActivity extends WinBoLLActivity { startActivity(new Intent(this, BackgroundPictureActivity.class)); } else if (menuItemId == R.id.action_log) { LogActivity.startLogActivity(this); + } else if (menuItemId == R.id.action_unittestactivity) { + startActivity(new Intent(this, MainUnitTestActivity.class)); } return true; } diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/ShortcutActionActivity.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/ShortcutActionActivity.java new file mode 100644 index 00000000..c22978d1 --- /dev/null +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/ShortcutActionActivity.java @@ -0,0 +1,49 @@ +package cc.winboll.studio.powerbell.activities; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import cc.winboll.studio.libappbase.ToastUtils; +import cc.winboll.studio.powerbell.R; +import cc.winboll.studio.powerbell.utils.APPPlusUtils; +import cc.winboll.studio.powerbell.App; + +/** + * @Author ZhanGSKen&豆包大模型 + * @Date 2025/11/15 13:45 + * @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/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/APPPlusUtils.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/APPPlusUtils.java new file mode 100644 index 00000000..162c5ea0 --- /dev/null +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/APPPlusUtils.java @@ -0,0 +1,164 @@ +package cc.winboll.studio.powerbell.utils; + +/** + * @Author ZhanGSKen&豆包大模型 + * @Date 2025/11/26 15:54 + * @Describe 应用图标切换工具类(启用组件时创建对应快捷方式) + */ +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.powerbell.App; +import cc.winboll.studio.powerbell.MainActivity; +import cc.winboll.studio.powerbell.R; + +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/powerbell/src/main/res/menu/toolbar_main.xml b/powerbell/src/main/res/menu/toolbar_main.xml index 5ef6f1b5..ca34fb1a 100644 --- a/powerbell/src/main/res/menu/toolbar_main.xml +++ b/powerbell/src/main/res/menu/toolbar_main.xml @@ -9,9 +9,6 @@ - diff --git a/powerbell/src/main/res/menu/toolbar_unittest.xml b/powerbell/src/main/res/menu/toolbar_unittest.xml new file mode 100644 index 00000000..a1347d3c --- /dev/null +++ b/powerbell/src/main/res/menu/toolbar_unittest.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/powerbell/src/main/res/values-zh/strings.xml b/powerbell/src/main/res/values-zh/strings.xml index 97869d5a..f4f9435d 100644 --- a/powerbell/src/main/res/values-zh/strings.xml +++ b/powerbell/src/main/res/values-zh/strings.xml @@ -1,6 +1,7 @@ - 泡额呗额 + 能源钟 + 泡额呗额 一个接收手机电量信息的应用,当电量值达到设定范围时会提醒用户。 本应用崩溃了,作者水平有限,敬请谅解! Main View diff --git a/powerbell/src/main/res/values/strings.xml b/powerbell/src/main/res/values/strings.xml index 1b7491c8..771ee1c0 100644 --- a/powerbell/src/main/res/values/strings.xml +++ b/powerbell/src/main/res/values/strings.xml @@ -1,9 +1,17 @@ PowerBell + 能源钟 + 泡额呗额 PowerBell A mobile app that receives battery level information from a phone and alerts the user when the battery level reaches a predefined range. This application has crashed, the author level is limited, please understand! + PowerBell + 能源钟 + 泡额呗额 + PowerBell + 能源钟 + 泡额呗额 Main View About Battery Report @@ -11,6 +19,7 @@ Change Picture Developer View Log View + Debug Activity Clean Log Source View Message master switch diff --git a/powerbell/src/main/res/xml/shortcutsmaincn1.xml b/powerbell/src/main/res/xml/shortcutsmaincn1.xml new file mode 100644 index 00000000..c06e0572 --- /dev/null +++ b/powerbell/src/main/res/xml/shortcutsmaincn1.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/powerbell/src/main/res/xml/shortcutsmaincn2.xml b/powerbell/src/main/res/xml/shortcutsmaincn2.xml new file mode 100644 index 00000000..b0633cd2 --- /dev/null +++ b/powerbell/src/main/res/xml/shortcutsmaincn2.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/powerbell/src/main/res/xml/shortcutsmainen1.xml b/powerbell/src/main/res/xml/shortcutsmainen1.xml new file mode 100644 index 00000000..7d04b714 --- /dev/null +++ b/powerbell/src/main/res/xml/shortcutsmainen1.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/powerbell/src/stage/AndroidManifest.xml b/powerbell/src/stage/AndroidManifest.xml index e5c042d2..76f080d1 100644 --- a/powerbell/src/stage/AndroidManifest.xml +++ b/powerbell/src/stage/AndroidManifest.xml @@ -4,31 +4,6 @@ - - - - - - - - - - - - - - -