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);
相关推荐
拭心2 小时前
Google 提供的 Android 端上大模型组件:MediaPipe LLM 介绍
android
带电的小王4 小时前
WhisperKit: Android 端测试 Whisper -- Android手机(Qualcomm GPU)部署音频大模型
android·智能手机·whisper·qualcomm
梦想平凡4 小时前
PHP 微信棋牌开发全解析:高级教程
android·数据库·oracle
元争栈道5 小时前
webview和H5来实现的android短视频(短剧)音视频播放依赖控件
android·音视频
阿甘知识库5 小时前
宝塔面板跨服务器数据同步教程:双机备份零停机
android·运维·服务器·备份·同步·宝塔面板·建站
元争栈道6 小时前
webview+H5来实现的android短视频(短剧)音视频播放依赖控件资源
android·音视频
MuYe6 小时前
Android Hook - 动态加载so库
android
居居飒7 小时前
Android学习(四)-Kotlin编程语言-for循环
android·学习·kotlin
Henry_He10 小时前
桌面列表小部件不能点击的问题分析
android
工程师老罗10 小时前
Android笔试面试题AI答之Android基础(1)
android