summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/cyanogenmod/DisplayRotation.java
diff options
context:
space:
mode:
authorDvTonder <david.vantonder@gmail.com>2012-11-25 09:27:13 -0500
committerDvTonder <david.vantonder@gmail.com>2012-11-25 09:30:01 -0500
commit085edd448c091b2ee98f7ff5a87ad2e6c4c550db (patch)
treed897c499ddc0e1621752efeb1bdcf8c2b58f5f3a /src/com/android/settings/cyanogenmod/DisplayRotation.java
parent2f0ded7678df235b850339cefff1bb10021690c7 (diff)
downloadpackages_apps_settings-085edd448c091b2ee98f7ff5a87ad2e6c4c550db.zip
packages_apps_settings-085edd448c091b2ee98f7ff5a87ad2e6c4c550db.tar.gz
packages_apps_settings-085edd448c091b2ee98f7ff5a87ad2e6c4c550db.tar.bz2
Setings: Forward port Display Rotation settings
Originaly authored by Robert Burns (burnsra) Change-Id: I4f96b3f804ee4732b277c35340790f3561d69764
Diffstat (limited to 'src/com/android/settings/cyanogenmod/DisplayRotation.java')
-rw-r--r--src/com/android/settings/cyanogenmod/DisplayRotation.java147
1 files changed, 147 insertions, 0 deletions
diff --git a/src/com/android/settings/cyanogenmod/DisplayRotation.java b/src/com/android/settings/cyanogenmod/DisplayRotation.java
new file mode 100644
index 0000000..92a3f29
--- /dev/null
+++ b/src/com/android/settings/cyanogenmod/DisplayRotation.java
@@ -0,0 +1,147 @@
+/*
+ * 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 implements OnPreferenceChangeListener {
+ private static final String TAG = "DisplayRotation";
+
+ private static final String KEY_ACCELEROMETER = "accelerometer";
+ 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) {
+ boolean hasRotationLock = this.getResources().getBoolean(com.android
+ .internal.R.bool.config_hasRotationLockSwitch);
+
+ super.onCreate(savedInstanceState);
+
+ addPreferencesFromResource(R.xml.display_rotation);
+
+ PreferenceScreen prefSet = getPreferenceScreen();
+
+ mAccelerometer = (CheckBoxPreference) findPreference(KEY_ACCELEROMETER);
+ mAccelerometer.setPersistent(false);
+
+ if (hasRotationLock) {
+ mAccelerometer.setEnabled(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);
+ }
+
+ @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()));
+ }
+
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ return false;
+ }
+
+ 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 = 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;
+ if (mode == 0) {
+ mode |= ROTATION_0_MODE;
+ mRotation0Pref.setChecked(true);
+ }
+ Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(),
+ Settings.System.ACCELEROMETER_ROTATION_ANGLES, mode);
+ return true;
+ }
+
+ return super.onPreferenceTreeClick(preferenceScreen, preference);
+ }
+}