Android 6.0 Settings中添加虚拟键开关

  1. 添加系统默认键值
xml 复制代码
+++ b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
@@ -212,4 +212,7 @@
 
     <!-- Default for Settings.Secure.NFC_PAYMENT_COMPONENT -->
     <string name="def_nfc_payment_component"></string>
+    
+    <!--mh.modify 20190602 navigationbar switch.-->
+    <integer name="switch_navigation_bar">0</integer>
java 复制代码
+++ b/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -2646,6 +2646,9 @@ class DatabaseHelper extends SQLiteOpenHelper {
 
             loadBooleanSetting(stmt, Settings.Global.DEVICE_PROVISIONED,
                     R.bool.def_device_provisioned);
+                    
+            //mh.mmi add navbar 20190602
+            loadIntegerSetting(stmt, "switch_navigation_bar",R.integer.switch_navigation_bar);
  1. 设置中添加开关
xml 复制代码
+++ b/packages/apps/Settings/res/values-zh-rCN/strings.xml
@@ -2880,4 +2880,6 @@
     <string name="write_settings_description" msgid="6868293938839954623">"此权限允许应用修改系统设置。"</string>
     <string name="write_settings_on" msgid="8230580416068832239">"允许"</string>
     <string name="write_settings_off" msgid="5156104383386336233">"不允许"</string>  
+    <string name="switch_navigationbarview">虚拟键开关</string>
 </resources>
diff --git a/packages/apps/Settings/res/values/strings.xml b/packages/apps/Settings/res/values/strings.xml
old mode 100644
new mode 100755
index ad5ca8cbf3..d4474ab5bc

+++ b/packages/apps/Settings/res/values/strings.xml
@@ -6998,4 +6998,6 @@
     <string name="write_settings_on">Yes</string>
     <!-- Summary of app not allowed to write system settings [CHAR LIMIT=45] -->
     <string name="write_settings_off">No</string> 
+    <string name="switch_navigationbarview">Navigation key switch</string>
xml 复制代码
+++ b/packages/apps/Settings/res/xml/accessibility_settings.xml
@@ -36,6 +36,12 @@
             android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragment"
             android:key="screen_magnification_preference_screen"
             android:title="@string/accessibility_screen_magnification_title"/>
+            
+        <!-- mh.mmi -->
+        <SwitchPreference
+            android:key="switch_navigationbarview"
+            android:title="@string/switch_navigationbarview"
+            android:persistent="false"/>
java 复制代码
+++ b/packages/apps/Settings/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -187,6 +187,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
     private PreferenceCategory mServicesCategory;
     private PreferenceCategory mSystemsCategory;
 
+    private SwitchPreference mToggleNavBarPreference;//mh.mmi
     private SwitchPreference mToggleLargeTextPreference;
     private SwitchPreference mToggleHighTextContrastPreference;
     private SwitchPreference mTogglePowerButtonEndsCallPreference;
@@ -304,9 +305,20 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
             handleDisplayMagnificationPreferenceScreenClick();
             return true;
         }
+        //mh.mmi add navbar switch. 20190602
+        else if (mToggleNavBarPreference == preference) {
+            handleToggleNavBarPreferenceClick();
+        }
         return super.onPreferenceTreeClick(preferenceScreen, preference);
     }
 
+    ///mh.mmi add navbar switch. 20190602
+    private void handleToggleNavBarPreferenceClick() {
+        Settings.Global.putInt(getContentResolver(),
+                "switch_navigation_bar",
+                mToggleNavBarPreference.isChecked() ? 1 : 0);
+    }
+
     private void handleToggleLargeTextPreferenceClick() {
         /** M: MTK fix fonts problem @{ */
         float fontScale = LARGE_FONT_SCALE;
@@ -380,6 +392,10 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
         mServicesCategory = (PreferenceCategory) findPreference(SERVICES_CATEGORY);
         mSystemsCategory = (PreferenceCategory) findPreference(SYSTEM_CATEGORY);
 
+        // mh.mmi add navbar switch. 20190602
+        mToggleNavBarPreference =
+                (SwitchPreference) findPreference("switch_navigationbarview");
+        
         // Large text.
         mToggleLargeTextPreference =
                 (SwitchPreference) findPreference(TOGGLE_LARGE_TEXT_PREFERENCE);
@@ -580,6 +596,10 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
             }
             updateFontScale = mLargeFontScaleTablet;
         }
+        
+        ///mh.mmi add navbar switch. 20190602
+        mToggleNavBarPreference.setChecked(Settings.Global.getInt(getContentResolver(),
+                "switch_navigation_bar", 0) == 1);
 
         mToggleLargeTextPreference.setChecked(mCurConfig.fontScale == updateFontScale);
         /** @} */
  1. 监听数据库变化
java 复制代码
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -668,6 +668,43 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
 
         mScreenPinningRequest = new ScreenPinningRequest(mContext);
     }
+    
+    ///mh.modify start 2019.6.2
+    class NavBarChangeContentObserver extends ContentObserver{
+ 
+        public NavBarChangeContentObserver() {
+            super(new Handler());
+        }
+ 
+        @Override
+        public void onChange(boolean selfChange) {
+            super.onChange(selfChange);
+            boolean isShownav = Settings.Global.getInt(mContext.getContentResolver(), "switch_navigation_bar", 0) != 0;
+            android.util.Log.d("mh.log", "isShownav:"+isShownav);
+            if (isShownav) {
+                if (mNavigationBarView == null) {
+                    addNarBar();
+                }
+                if (mNavigationBarView != null) {
+                    checkBarMode(MODE_TRANSLUCENT, mNavigationBarWindowState, mNavigationBarView.getBarTransitions(), false);
+                }
+            } else {
+                if (mNavigationBarView != null) {
+                    mWindowManager.removeView(mNavigationBarView);
+                    mNavigationBarView = null;
+                }
+            }
+        }
+    }
+    private void addNarBar() {
+        if (mNavigationBarView == null) {
+            mNavigationBarView = (NavigationBarView) View.inflate(mContext, R.layout.navigation_bar, null);
+            mNavigationBarView.setDisabledFlags(mDisabled1);
+            mNavigationBarView.setBar(this);
+            prepareNavigationBarView();
+        }
+        mWindowManager.addView(mNavigationBarView, getNavigationBarLayoutParams());
+    }
+    
+    ///mh.modify end 2019.6.2

@@ -1246,7 +1248,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
     // For small-screen devices (read: phones) that lack hardware navigation buttons
     private void addNavigationBar() {
         if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + mNavigationBarView);
-        if (mNavigationBarView == null) return;
+        if (mNavigationBarView == null) {
+            Settings.Global.putInt(mContext.getContentResolver(), "switch_navigation_bar", 0);
+            return;
+        }
 
         prepareNavigationBarView();
 
     // ================================================================================
     // Constructing the view
@@ -698,6 +735,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
 
         mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar);
         mStatusBarView.setBar(this);
              
+        ///mh.mmi add navbar 20190602
+        NavBarChangeContentObserver mNavContentObserver = new NavBarChangeContentObserver();
+        mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor("switch_navigation_bar"),true,mNavContentObserver);
 
         PanelHolder holder = (PanelHolder) mStatusBarWindow.findViewById(R.id.panel_holder);
         mStatusBarView.setPanelHolder(holder);
相关推荐
Winston Wood4 分钟前
Perfetto学习大全
android·性能优化·perfetto
Dnelic-3 小时前
【单元测试】【Android】JUnit 4 和 JUnit 5 的差异记录
android·junit·单元测试·android studio·自学笔记
Eastsea.Chen5 小时前
MTK Android12 user版本MtkLogger
android·framework
长亭外的少年13 小时前
Kotlin 编译失败问题及解决方案:从守护进程到 Gradle 配置
android·开发语言·kotlin
建群新人小猿15 小时前
会员等级经验问题
android·开发语言·前端·javascript·php
1024小神16 小时前
tauri2.0版本开发苹果ios和安卓android应用,环境搭建和最后编译为apk
android·ios·tauri
兰琛16 小时前
20241121 android中树结构列表(使用recyclerView实现)
android·gitee
Y多了个想法17 小时前
RK3568 android11 适配敦泰触摸屏 FocalTech-ft5526
android·rk3568·触摸屏·tp·敦泰·focaltech·ft5526
NotesChapter18 小时前
Android吸顶效果,并有着ViewPager左右切换
android
_祝你今天愉快19 小时前
分析android :The binary version of its metadata is 1.8.0, expected version is 1.5.
android