diff options
author | DvTonder <david.vantonder@gmail.com> | 2013-12-07 09:25:38 +0100 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2015-10-29 17:36:29 -0700 |
commit | f71d7438ea0b30fe08d0297b8bbb9ea68124348b (patch) | |
tree | f32110177758b46296d58f0c359dd22c2df89244 | |
parent | a284b34f11b3ad22084232950d81fb1bc68f21ce (diff) | |
download | packages_apps_Settings-f71d7438ea0b30fe08d0297b8bbb9ea68124348b.zip packages_apps_Settings-f71d7438ea0b30fe08d0297b8bbb9ea68124348b.tar.gz packages_apps_Settings-f71d7438ea0b30fe08d0297b8bbb9ea68124348b.tar.bz2 |
Settings: Forward port Display Rotation settings
Originaly authored by Robert Burns (burnsra)
Settings: Fix possible NPE in Display settings
Change-Id: I186203782aa27fb4eaa77500fecb82946bfdd173
Display : Enable rotation on large screens
The auto-rotate toggle in statusbar is no longer present, so the check
is no longer valid.
Change-Id: I0a23e251b3cb793481d14ea8ad8a9079c7c0e962
Fix the spacing between displayed rotation angles
Before: http://goo.gl/QJ7hE
After: http://goo.gl/V0alW
Change-Id: I0319f8e84e4b278b2f720cbc77cecc280c82d461
Settings: rotation settings for devices with hardware rotation lock
All settings would be disabled on devices with hardware rotation
lock due to dependency setting. Disable dependency to allow setting
swap volume and rotation degrees on those devices.
Change-Id: Iee0532902d59fa80666e17b3853db8e3d7ed5ddc
Add lockscreen rotation as an optional rotation setting (2/2)
This will allow the user to select wether or not to use the
rotation settings for the lockscreen. This is dependent
upon the rotation setting being checked.
Signed-off-by: Michael Bestas <mikeioannina@gmail.com>
Change-Id: If45c13a395e0d71b7c4cdcf484a6b8cef964ee37
JIRA: CYAN-339
Ported from cm-10.2, adjusted for 4.4
Signed-off-by: Michael Bestas <mikeioannina@gmail.com>
Change-Id: Ib239e63200fc8565c3f66969aa495f1c40908adf
-rw-r--r-- | res/values/cm_strings.xml | 11 | ||||
-rw-r--r-- | res/xml/display_rotation.xml | 53 | ||||
-rw-r--r-- | res/xml/display_settings.xml | 5 | ||||
-rw-r--r-- | src/com/android/settings/DisplaySettings.java | 109 | ||||
-rw-r--r-- | src/com/android/settings/cyanogenmod/DisplayRotation.java | 172 |
5 files changed, 348 insertions, 2 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index d827e94..58e94f6 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -459,4 +459,15 @@ <string name="auto_brightness_reset_button">Reset</string> + <!-- Display : Rotation --> + <string name="display_rotation_title">Rotation</string> + <string name="display_rotation_disabled">Disabled</string> + <string name="display_rotation_unit">degrees</string> + <string name="display_lockscreen_rotation_title">Rotate lock screen</string> + <string name="display_rotation_category_title">Rotation modes</string> + <string name="display_rotation_0_title">0 degrees</string> + <string name="display_rotation_90_title">90 degrees</string> + <string name="display_rotation_180_title">180 degrees</string> + <string name="display_rotation_270_title">270 degrees</string> + </resources> diff --git a/res/xml/display_rotation.xml b/res/xml/display_rotation.xml new file mode 100644 index 0000000..d9afb8e --- /dev/null +++ b/res/xml/display_rotation.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + android:title="@string/display_rotation_title" + xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"> + + <CheckBoxPreference + android:key="accelerometer" + android:title="@string/accelerometer_title" /> + <CheckBoxPreference + android:key="lockscreen_rotation" + android:title="@string/display_lockscreen_rotation_title" + android:dependency="accelerometer" /> + <PreferenceCategory + android:key="display_rotation_category" + android:title="@string/display_rotation_category_title" /> + <CheckBoxPreference + android:key="display_rotation_0" + android:title="@string/display_rotation_0_title" + android:layout="?android:attr/preferenceLayoutChild" + android:dependency="accelerometer" /> + <CheckBoxPreference + android:key="display_rotation_90" + android:title="@string/display_rotation_90_title" + android:layout="?android:attr/preferenceLayoutChild" + android:dependency="accelerometer" /> + <CheckBoxPreference + android:key="display_rotation_180" + android:title="@string/display_rotation_180_title" + android:layout="?android:attr/preferenceLayoutChild" + android:dependency="accelerometer" /> + <CheckBoxPreference + android:key="display_rotation_270" + android:title="@string/display_rotation_270_title" + android:layout="?android:attr/preferenceLayoutChild" + android:dependency="accelerometer" /> + + +</PreferenceScreen> diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml index 48f76bc..255348f 100644 --- a/res/xml/display_settings.xml +++ b/res/xml/display_settings.xml @@ -49,6 +49,11 @@ settings:keywords="@string/keywords_display_wallpaper" android:fragment="com.android.settings.WallpaperTypeSettings" /> + <PreferenceScreen + android:key="display_rotation" + android:fragment="com.android.settings.cyanogenmod.DisplayRotation" + android:title="@string/display_rotation_title" /> + <ListPreference android:key="screen_timeout" android:title="@string/screen_timeout" diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java index 13c1b28..8645377 100644 --- a/src/com/android/settings/DisplaySettings.java +++ b/src/com/android/settings/DisplaySettings.java @@ -16,8 +16,8 @@ */ package com.android.settings; - import com.android.internal.logging.MetricsLogger; +import android.preference.CheckBoxPreference; import com.android.internal.view.RotationPolicy; import com.android.settings.DropDownPreference.Callback; import com.android.settings.search.BaseSearchIndexProvider; @@ -44,7 +44,9 @@ import android.content.SharedPreferences; import android.hardware.Sensor; import android.hardware.SensorManager; import android.os.Build; +import android.database.ContentObserver; import android.os.Bundle; +import android.os.Handler; import android.os.RemoteException; import android.os.SystemProperties; import android.preference.ListPreference; @@ -60,6 +62,9 @@ import android.provider.Settings; import android.text.TextUtils; import android.util.Log; +import com.android.settings.DreamSettings; +import com.android.settings.Utils; +import com.android.settings.cyanogenmod.DisplayRotation; import java.util.ArrayList; import java.util.List; @@ -94,6 +99,11 @@ public class DisplaySettings extends SettingsPreferenceFragment implements private static final String KEY_COLOR_ENHANCEMENT = "color_enhancement"; private static final String KEY_TAP_TO_WAKE = "double_tap_wake_gesture"; private static final String KEY_PROXIMITY_WAKE = "proximity_on_wake"; + private static final String KEY_DISPLAY_ROTATION = "display_rotation"; + private static final String KEY_ADVANCED_DISPLAY_SETTINGS = "advanced_display_settings"; + private static final String CATEGORY_LIGHTS = "lights_prefs"; + private static final String KEY_NOTIFICATION_PULSE = "notification_pulse"; + private static final String KEY_BATTERY_LIGHT = "battery_light"; private static final String KEY_WAKE_WHEN_PLUGGED_OR_UNPLUGGED = "wake_when_plugged_or_unplugged"; private static final String CATEGORY_ADVANCED = "advanced_display_prefs"; @@ -103,6 +113,9 @@ public class DisplaySettings extends SettingsPreferenceFragment implements private static final int DLG_GLOBAL_CHANGE_WARNING = 1; private FontDialogPreference mFontSizePref; + private PreferenceScreen mNotificationPulse; + private PreferenceScreen mBatteryPulse; + private PreferenceScreen mDisplayRotationPreference; private final Configuration mCurConfig = new Configuration(); @@ -120,6 +133,22 @@ public class DisplaySettings extends SettingsPreferenceFragment implements private SwitchPreference mSunlightEnhancement; private SwitchPreference mColorEnhancement; + private ContentObserver mAccelerometerRotationObserver = + new ContentObserver(new Handler()) { + @Override + public void onChange(boolean selfChange) { + updateDisplayRotationPreferenceDescription(); + } + }; + + private final RotationPolicy.RotationPolicyListener mRotationPolicyListener = + new RotationPolicy.RotationPolicyListener() { + @Override + public void onChange() { + updateDisplayRotationPreferenceDescription(); + } + }; + @Override protected int getMetricsCategory() { return MetricsLogger.DISPLAY; @@ -133,6 +162,8 @@ public class DisplaySettings extends SettingsPreferenceFragment implements addPreferencesFromResource(R.xml.display_settings); + mDisplayRotationPreference = (PreferenceScreen) findPreference(KEY_DISPLAY_ROTATION); + mScreenSaverPreference = findPreference(KEY_SCREEN_SAVER); if (mScreenSaverPreference != null && getResources().getBoolean( @@ -147,6 +178,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements mScreenTimeoutPreference.setOnPreferenceChangeListener(this); disableUnusableTimeouts(mScreenTimeoutPreference); updateTimeoutPreferenceDescription(currentTimeout); + updateDisplayRotationPreferenceDescription(); mFontSizePref = (FontDialogPreference) findPreference(KEY_FONT_SIZE); mFontSizePref.setOnPreferenceChangeListener(this); @@ -289,6 +321,54 @@ public class DisplaySettings extends SettingsPreferenceFragment implements return res.getBoolean(com.android.internal.R.bool.config_automatic_brightness_available); } + private void updateDisplayRotationPreferenceDescription() { + if (mDisplayRotationPreference == null) { + // The preference was removed, do nothing + return; + } + + // We have a preference, lets update the summary + boolean rotationEnabled = Settings.System.getInt(getContentResolver(), + Settings.System.ACCELEROMETER_ROTATION, 0) != 0; + + if (!rotationEnabled) { + mDisplayRotationPreference.setSummary(R.string.display_rotation_disabled); + return; + } + + StringBuilder summary = new StringBuilder(); + int mode = Settings.System.getInt(getContentResolver(), + Settings.System.ACCELEROMETER_ROTATION_ANGLES, + DisplayRotation.ROTATION_0_MODE + | DisplayRotation.ROTATION_90_MODE + | DisplayRotation.ROTATION_270_MODE); + ArrayList<String> rotationList = new ArrayList<String>(); + String delim = ""; + + if ((mode & DisplayRotation.ROTATION_0_MODE) != 0) { + rotationList.add("0"); + } + if ((mode & DisplayRotation.ROTATION_90_MODE) != 0) { + rotationList.add("90"); + } + if ((mode & DisplayRotation.ROTATION_180_MODE) != 0) { + rotationList.add("180"); + } + if ((mode & DisplayRotation.ROTATION_270_MODE) != 0) { + rotationList.add("270"); + } + for (int i = 0; i < rotationList.size(); i++) { + summary.append(delim).append(rotationList.get(i)); + if ((rotationList.size() - i) > 2) { + delim = ", "; + } else { + delim = " & "; + } + } + summary.append(" " + getString(R.string.display_rotation_unit)); + mDisplayRotationPreference.setSummary(summary); + } + private void updateTimeoutPreferenceDescription(long currentTimeout) { ListPreference preference = mScreenTimeoutPreference; String summary; @@ -359,7 +439,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements @Override public void onResume() { super.onResume(); - + updateDisplayRotationPreferenceDescription(); if (mAdaptiveBacklight != null) { mAdaptiveBacklight.setChecked(AdaptiveBacklight.isEnabled()); } @@ -381,6 +461,20 @@ public class DisplaySettings extends SettingsPreferenceFragment implements mTapToWake.setChecked(TapToWake.isEnabled()); } + RotationPolicy.registerRotationPolicyListener(getActivity(), + mRotationPolicyListener); + + final ContentResolver resolver = getContentResolver(); + + // Display rotation observer + resolver.registerContentObserver( + Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), true, + mAccelerometerRotationObserver); + + if (mAdaptiveBacklight != null) { + mAdaptiveBacklight.setChecked(AdaptiveBacklight.isEnabled()); + } + // Default value for wake-on-plug behavior from config.xml boolean wakeUpWhenPluggedOrUnpluggedConfig = getResources().getBoolean( com.android.internal.R.bool.config_unplugTurnsOnScreen); @@ -393,6 +487,17 @@ public class DisplaySettings extends SettingsPreferenceFragment implements } @Override + public void onPause() { + super.onPause(); + + RotationPolicy.unregisterRotationPolicyListener(getActivity(), + mRotationPolicyListener); + + // Display rotation observer + getContentResolver().unregisterContentObserver(mAccelerometerRotationObserver); + } + + @Override public Dialog onCreateDialog(int dialogId) { if (dialogId == DLG_GLOBAL_CHANGE_WARNING) { return Utils.buildGlobalChangeWarningDialog(getActivity(), diff --git a/src/com/android/settings/cyanogenmod/DisplayRotation.java b/src/com/android/settings/cyanogenmod/DisplayRotation.java new file mode 100644 index 0000000..49cbe6c --- /dev/null +++ b/src/com/android/settings/cyanogenmod/DisplayRotation.java @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2012 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.cyanogenmod; + +import android.database.ContentObserver; +import android.os.Bundle; +import android.os.Handler; +import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceScreen; +import android.provider.Settings; + +import com.android.internal.view.RotationPolicy; +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; + +public class DisplayRotation extends SettingsPreferenceFragment { + private static final String TAG = "DisplayRotation"; + + private static final String KEY_ACCELEROMETER = "accelerometer"; + private static final String KEY_LOCKSCREEN_ROTATION = "lockscreen_rotation"; + private static final String ROTATION_0_PREF = "display_rotation_0"; + private static final String ROTATION_90_PREF = "display_rotation_90"; + private static final String ROTATION_180_PREF = "display_rotation_180"; + private static final String ROTATION_270_PREF = "display_rotation_270"; + + private CheckBoxPreference mAccelerometer; + private CheckBoxPreference mRotation0Pref; + private CheckBoxPreference mRotation90Pref; + private CheckBoxPreference mRotation180Pref; + private CheckBoxPreference mRotation270Pref; + + public static final int ROTATION_0_MODE = 1; + public static final int ROTATION_90_MODE = 2; + public static final int ROTATION_180_MODE = 4; + public static final int ROTATION_270_MODE = 8; + + private ContentObserver mAccelerometerRotationObserver = new ContentObserver(new Handler()) { + @Override + public void onChange(boolean selfChange) { + updateAccelerometerRotationCheckbox(); + } + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.display_rotation); + + PreferenceScreen prefSet = getPreferenceScreen(); + + mAccelerometer = (CheckBoxPreference) findPreference(KEY_ACCELEROMETER); + mAccelerometer.setPersistent(false); + + mRotation0Pref = (CheckBoxPreference) prefSet.findPreference(ROTATION_0_PREF); + mRotation90Pref = (CheckBoxPreference) prefSet.findPreference(ROTATION_90_PREF); + mRotation180Pref = (CheckBoxPreference) prefSet.findPreference(ROTATION_180_PREF); + mRotation270Pref = (CheckBoxPreference) prefSet.findPreference(ROTATION_270_PREF); + + int mode = Settings.System.getInt(getContentResolver(), + Settings.System.ACCELEROMETER_ROTATION_ANGLES, + ROTATION_0_MODE | ROTATION_90_MODE | ROTATION_270_MODE); + + mRotation0Pref.setChecked((mode & ROTATION_0_MODE) != 0); + mRotation90Pref.setChecked((mode & ROTATION_90_MODE) != 0); + mRotation180Pref.setChecked((mode & ROTATION_180_MODE) != 0); + mRotation270Pref.setChecked((mode & ROTATION_270_MODE) != 0); + + boolean hasRotationLock = false; +// getResources().getBoolean( +// com.android.internal.R.bool.config_hasRotationLockSwitch); + + if (hasRotationLock) { + // Disable accelerometer checkbox, but leave others enabled + mAccelerometer.setEnabled(false); + mRotation0Pref.setDependency(null); + mRotation90Pref.setDependency(null); + mRotation180Pref.setDependency(null); + mRotation270Pref.setDependency(null); + } + + final CheckBoxPreference lockScreenRotation = + (CheckBoxPreference) findPreference(KEY_LOCKSCREEN_ROTATION); + boolean canRotateLockscreen = getResources().getBoolean( + com.android.internal.R.bool.config_enableLockScreenRotation); + + if (lockScreenRotation != null && !canRotateLockscreen) { + getPreferenceScreen().removePreference(lockScreenRotation); + } + } + + @Override + public void onResume() { + super.onResume(); + + updateState(); + getContentResolver().registerContentObserver( + Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), true, + mAccelerometerRotationObserver); + } + + @Override + public void onPause() { + super.onPause(); + + getContentResolver().unregisterContentObserver(mAccelerometerRotationObserver); + } + + private void updateState() { + updateAccelerometerRotationCheckbox(); + } + + private void updateAccelerometerRotationCheckbox() { + mAccelerometer.setChecked(!RotationPolicy.isRotationLocked(getActivity())); + } + + private int getRotationBitmask() { + int mode = 0; + if (mRotation0Pref.isChecked()) { + mode |= ROTATION_0_MODE; + } + if (mRotation90Pref.isChecked()) { + mode |= ROTATION_90_MODE; + } + if (mRotation180Pref.isChecked()) { + mode |= ROTATION_180_MODE; + } + if (mRotation270Pref.isChecked()) { + mode |= ROTATION_270_MODE; + } + return mode; + } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, + Preference preference) { + if (preference == mAccelerometer) { + RotationPolicy.setRotationLockForAccessibility(getActivity(), + !mAccelerometer.isChecked()); + } else if (preference == mRotation0Pref || + preference == mRotation90Pref || + preference == mRotation180Pref || + preference == mRotation270Pref) { + int mode = getRotationBitmask(); + if (mode == 0) { + mode |= ROTATION_0_MODE; + mRotation0Pref.setChecked(true); + } + Settings.System.putInt(getActivity().getContentResolver(), + Settings.System.ACCELEROMETER_ROTATION_ANGLES, mode); + return true; + } + + return super.onPreferenceTreeClick(preferenceScreen, preference); + } +} |