Android 7.1 设置添加一级目录设置项-2

简介: Android 7.1 设置添加一级目录设置项-2

前文


Android 7.1 设置添加一级目录设置项


新增需求


新增一级项, 打开指定Activity, 如下图, 在系统下添加 定时开关机, 点击后, 打开指定app(非设置内部)

image.png


步骤


packages/apps/Settings/src/com/android/settings/Settings.java


diff --git a/packages/apps/Settings/src/com/android/settings/Settings.java b/packages/apps/Settings/src/com/android/settings/Settings.java
index 9711e4a..1cd29d0 100755
--- a/packages/apps/Settings/src/com/android/settings/Settings.java
+++ b/packages/apps/Settings/src/com/android/settings/Settings.java
@@ -28,6 +28,7 @@ public class Settings extends SettingsActivity {
     /*
     * Settings subclasses for launching independently.
     */
+    public static class TimingBootSettingsActivity extends SettingsActivity { /* empty */ }
     public static class BluetoothSettingsActivity extends SettingsActivity { /* empty */ }
     public static class WirelessSettingsActivity extends SettingsActivity { /* empty */ }
     public static class SimSettingsActivity extends SettingsActivity { /* empty */ }


新增 TimingBootSettingsActivity, 下面AndroidManifest.xml使用


packages/apps/Settings/AndroidManifest.xml


diff --git a/packages/apps/Settings/AndroidManifest.xml b/packages/apps/Settings/AndroidManifest.xml
index 6031292..a503166 100755
--- a/packages/apps/Settings/AndroidManifest.xml
+++ b/packages/apps/Settings/AndroidManifest.xml
@@ -420,6 +420,21 @@
                        android:value="com.android.settings.ApnSettings" />
         </activity>
+        <!--AnsonCode -->
+        <activity android:name="Settings$TimingBootSettingsActivity"
+                android:label="定时开关机"
+                android:icon="@drawable/ic_settings_bluetooth"
+                android:taskAffinity=""
+            >
+            <intent-filter android:priority="3">
+                <action android:name="com.android.settings.action.SETTINGS" />
+            </intent-filter>
+            <meta-data android:name="com.android.settings.category"
+                android:value="com.android.settings.category.system" />
+            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+                android:value="com.android.settings.TimingBootSettings" />
+        </activity>
+
         <activity android:name="Settings$BluetoothSettingsActivity"
                 android:label="@string/bluetooth_settings_title"
                 android:icon="@drawable/ic_settings_bluetooth"

image.png

packages/apps/Settings/src/com/android/settings/SettingsActivity.java


diff --git a/packages/apps/Settings/src/com/android/settings/SettingsActivity.java b/packages/apps/Settings/src/com/android/settings/SettingsActivity.java
index 60f6ca0..3cbd7a7 100755
--- a/packages/apps/Settings/src/com/android/settings/SettingsActivity.java
+++ b/packages/apps/Settings/src/com/android/settings/SettingsActivity.java
@@ -262,6 +262,7 @@ public class SettingsActivity extends SettingsDrawerActivity
             Settings.AccessibilitySettingsActivity.class.getName(),
             Settings.PrintSettingsActivity.class.getName(),
             Settings.PaymentSettingsActivity.class.getName(),
+            Settings.TimingBootSettingsActivity.class.getName(),
            Settings.HdmiSettingsActivity.class.getName()
     };
@@ -1037,6 +1038,18 @@ public class SettingsActivity extends SettingsDrawerActivity
     private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
             boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
         if (validate && !isValidFragment(fragmentName)) {
+            //AnsonCode 由于com.android.settings.TimingBootSettings是虚构出来的, 导致产生Invalid fragment
+            //在打开应用后, 返回, 并finish(), 让设置保持在初始界面, 否则, 重新回到设置时会显示空白的内容
+            if("com.android.settings.TimingBootSettings".equals(fragmentName)){
+                Intent tbs = new Intent();
+                tbs.setComponent(new ComponentName("com.android.timingboot", "com.android.timingboot.BootTimeSettings"));
+                tbs.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                startActivity(tbs);
+                setResult(RESULT_CANCELED, getResultIntentData());
+                finish();
+                return null;
+            } 
+            
             throw new IllegalArgumentException("Invalid fragment for this activity: "
                     + fragmentName);
         }
@@ -1169,6 +1182,11 @@ public class SettingsActivity extends SettingsDrawerActivity
                 BackupSettingsActivity.class.getName()), hasBackupActivity,
                 isAdmin || Utils.isCarrierDemoUser(this), pm);
+        //AnsonCode add TimingBoot, 使用设置项
+         setTileEnabled(new ComponentName(packageName,
+                Settings.TimingBootSettingsActivity.class.getName()),
+                true, isAdmin, pm);
+
     }


注解


注1


frameworks/base/packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java


//调用:
 TileUtils.getCategories


frameworks/base/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java


public static List<DashboardCategory> getCategories(Context context,
            HashMap<Pair<String, String>, Tile> cache) {
        final long startTime = System.currentTimeMillis();
        boolean setup = Global.getInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0)
                != 0;
        ArrayList<Tile> tiles = new ArrayList<>();
        UserManager userManager = UserManager.get(context);
        for (UserHandle user : userManager.getUserProfiles()) {
            // TODO: Needs much optimization, too many PM queries going on here.
            if (user.getIdentifier() == ActivityManager.getCurrentUser()) {
                // Only add Settings for this user.
                getTilesForAction(context, user, SETTINGS_ACTION, cache, null, tiles, true);
                getTilesForAction(context, user, OPERATOR_SETTINGS, cache,
                        OPERATOR_DEFAULT_CATEGORY, tiles, false);
                getTilesForAction(context, user, MANUFACTURER_SETTINGS, cache,
                        MANUFACTURER_DEFAULT_CATEGORY, tiles, false);
            }
            if (setup) {
                getTilesForAction(context, user, EXTRA_SETTINGS_ACTION, cache, null, tiles, false);
            }
        }
        boolean isSupportBluetooth = "true".equals(SystemProperties.get("ro.rk.bt_enable"));
        HashMap<String, DashboardCategory> categoryMap = new HashMap<>();
        for (Tile tile : tiles) {
            DashboardCategory category = categoryMap.get(tile.category);
            if (category == null) {
                category = createCategory(context, tile.category);
                if (category == null) {
                    Log.w(LOG_TAG, "Couldn't find category " + tile.category);
                    continue;
                }
                categoryMap.put(category.key, category);
            }
            Intent tileIntent = tile.intent;
            if(!isSupportBluetooth && tileIntent != null && tileIntent.toString().contains("com.android.settings/.Settings$BluetoothSettingsActivity"))
                continue;
            category.addTile(tile);
        }
        ArrayList<DashboardCategory> categories = new ArrayList<>(categoryMap.values());
        for (DashboardCategory category : categories) {
            Collections.sort(category.tiles, TILE_COMPARATOR);
        }
        Collections.sort(categories, CATEGORY_COMPARATOR);
        if (DEBUG_TIMING) Log.d(LOG_TAG, "getCategories took "
                + (System.currentTimeMillis() - startTime) + " ms");
        return categories;
    }
相关文章
|
5月前
|
XML API Android开发
码农之重学安卓:利用androidx.preference 快速创建一、二级设置菜单(demo)
本文介绍了如何使用androidx.preference库快速创建具有一级和二级菜单的Android设置界面的步骤和示例代码。
154 1
码农之重学安卓:利用androidx.preference 快速创建一、二级设置菜单(demo)
|
4月前
|
Android开发
Android经典实战之Textview文字设置不同颜色、下划线、加粗、超链接等效果
本文介绍了 `SpannableString` 在 Android 开发中的强大功能,包括如何在单个字符串中应用多种样式,如颜色、字体大小、风格等,并提供了详细代码示例,展示如何设置文本颜色、添加点击事件等,助你实现丰富文本效果。
335 3
|
5月前
|
Android开发
Android在rootdir根目录创建自定义目录和挂载点的方法
本文介绍了在Android高通平台的根目录下创建自定义目录和挂载点的方法,通过修改Android.mk文件并使用`LOCAL_POST_INSTALL_CMD`变量在编译过程中添加目录,最终在ramdisk.img的系统根路径下成功创建了`/factory/bin`目录。
251 1
|
5月前
|
Java 网络安全 开发工具
UNITY与安卓⭐一、Android Studio初始设置
UNITY与安卓⭐一、Android Studio初始设置
|
6月前
|
XML Android开发 数据格式
Android 中如何设置activity的启动动画,让它像dialog一样从底部往上出来
在 Android 中实现 Activity 的对话框式过渡动画:从底部滑入与从顶部滑出。需定义两个 XML 动画文件 `activity_slide_in.xml` 和 `activity_slide_out.xml`,分别控制 Activity 的进入与退出动画。使用 `overridePendingTransition` 方法在启动 (`startActivity`) 或结束 (`finish`) Activity 时应用这些动画。为了使前 Activity 保持静止,可定义 `no_animation.xml` 并在启动新 Activity 时仅设置新 Activity 的进入动画。
156 12
|
4月前
|
图形学 iOS开发 Android开发
从Unity开发到移动平台制胜攻略:全面解析iOS与Android应用发布流程,助你轻松掌握跨平台发布技巧,打造爆款手游不是梦——性能优化、广告集成与内购设置全包含
【8月更文挑战第31天】本书详细介绍了如何在Unity中设置项目以适应移动设备,涵盖性能优化、集成广告及内购功能等关键步骤。通过具体示例和代码片段,指导读者完成iOS和Android应用的打包与发布,确保应用顺利上线并获得成功。无论是性能调整还是平台特定的操作,本书均提供了全面的解决方案。
163 0
|
5月前
|
开发工具 Android开发
Android项目架构设计问题之外部客户方便地设置回调如何解决
Android项目架构设计问题之外部客户方便地设置回调如何解决
35 0
|
5月前
|
数据可视化 Java 数据挖掘
Android项目架构设计问题之设置RecyclerView的LayoutManager如何解决
Android项目架构设计问题之设置RecyclerView的LayoutManager如何解决
41 0
|
6月前
|
Java Android开发
android 设置系统时间的流程
android 设置系统时间的方法
455 2
|
7月前
|
Android开发
Android Studio(2022.3.1)设置阿里云源-新旧版本
Android Studio(2022.3.1)设置阿里云源-新旧版本
1304 1