Use WM APIs to change rotation preference.
Bug: 5371750 Changing the system setting directly results in inconsistent behavior among the three different places where "auto-rotate" settings appear in the UI. Use the WM APIs instead. Change-Id: I1a8239af66b1cc3aeec8310383e72fc96c878d73
This commit is contained in:
@@ -35,6 +35,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemProperties;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
@@ -45,12 +46,15 @@ import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextUtils.SimpleStringSplitter;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.IWindowManager;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
@@ -72,6 +76,7 @@ import java.util.Set;
|
||||
*/
|
||||
public class AccessibilitySettings extends SettingsPreferenceFragment implements DialogCreatable,
|
||||
Preference.OnPreferenceChangeListener {
|
||||
private static final String TAG = "AccessibilitySettings";
|
||||
|
||||
private static final String DEFAULT_SCREENREADER_MARKET_LINK =
|
||||
"market://search?q=pname:com.google.android.marvin.talkback";
|
||||
@@ -230,9 +235,17 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
}
|
||||
|
||||
private void handleToggleAutoRotateScreenPreferenceClick() {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.ACCELEROMETER_ROTATION,
|
||||
(mToggleAutoRotateScreenPreference.isChecked() ? 1 : 0));
|
||||
try {
|
||||
IWindowManager wm = IWindowManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.WINDOW_SERVICE));
|
||||
if (mToggleAutoRotateScreenPreference.isChecked()) {
|
||||
wm.thawRotation();
|
||||
} else {
|
||||
wm.freezeRotation(Surface.ROTATION_0);
|
||||
}
|
||||
} catch (RemoteException exc) {
|
||||
Log.w(TAG, "Unable to save auto-rotate setting");
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeAllPreferences() {
|
||||
|
@@ -28,6 +28,7 @@ import android.database.ContentObserver;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
@@ -35,6 +36,8 @@ import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.SettingNotFoundException;
|
||||
import android.util.Log;
|
||||
import android.view.IWindowManager;
|
||||
import android.view.Surface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -230,9 +233,17 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||
if (preference == mAccelerometer) {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.ACCELEROMETER_ROTATION,
|
||||
mAccelerometer.isChecked() ? 1 : 0);
|
||||
try {
|
||||
IWindowManager wm = IWindowManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.WINDOW_SERVICE));
|
||||
if (mAccelerometer.isChecked()) {
|
||||
wm.thawRotation();
|
||||
} else {
|
||||
wm.freezeRotation(Surface.ROTATION_0);
|
||||
}
|
||||
} catch (RemoteException exc) {
|
||||
Log.w(TAG, "Unable to save auto-rotate setting");
|
||||
}
|
||||
} else if (preference == mNotificationPulse) {
|
||||
boolean value = mNotificationPulse.isChecked();
|
||||
Settings.System.putInt(getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE,
|
||||
|
Reference in New Issue
Block a user