- 添加系统默认键值
+++ b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
@@ -212,4 +212,7 @@
<string name="def_nfc_payment_component"></string>
+
+
+ <integer name="switch_navigation_bar">0</integer>
+++ 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);
+
+
+ loadIntegerSetting(stmt, "switch_navigation_bar",R.integer.switch_navigation_bar);
- 设置中添加开关
+++ 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>
<string name="write_settings_off">No</string>
+ <string name="switch_navigationbarview">Navigation key switch</string>
+++ 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"/>
+
+
+ <SwitchPreference
+ android:key="switch_navigationbarview"
+ android:title="@string/switch_navigationbarview"
+ android:persistent="false"/>
+++ 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;
private SwitchPreference mToggleLargeTextPreference;
private SwitchPreference mToggleHighTextContrastPreference;
private SwitchPreference mTogglePowerButtonEndsCallPreference;
@@ -304,9 +305,20 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
handleDisplayMagnificationPreferenceScreenClick();
return true;
}
+
+ else if (mToggleNavBarPreference == preference) {
+ handleToggleNavBarPreferenceClick();
+ }
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
+
+ private void handleToggleNavBarPreferenceClick() {
+ Settings.Global.putInt(getContentResolver(),
+ "switch_navigation_bar",
+ mToggleNavBarPreference.isChecked() ? 1 : 0);
+ }
+
private void handleToggleLargeTextPreferenceClick() {
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);
+
+ mToggleNavBarPreference =
+ (SwitchPreference) findPreference("switch_navigationbarview");
+
mToggleLargeTextPreference =
(SwitchPreference) findPreference(TOGGLE_LARGE_TEXT_PREFERENCE);
@@ -580,6 +596,10 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
}
updateFontScale = mLargeFontScaleTablet;
}
+
+
+ mToggleNavBarPreference.setChecked(Settings.Global.getInt(getContentResolver(),
+ "switch_navigation_bar", 0) == 1);
mToggleLargeTextPreference.setChecked(mCurConfig.fontScale == updateFontScale);
- 监听数据库变化
+++ 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);
}
+
+
+ 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());
+ }
+
+
@@ -1246,7 +1248,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
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();
@@ -698,6 +735,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar);
mStatusBarView.setBar(this);
+
+ 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);