From 58b53b5dff703285229fd024fdd882c1606df1a9 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 23 Feb 2016 14:49:22 -0800 Subject: [PATCH] Preserving the homescreen rotation setting on a tablet, when the display is scaled Bug: 27040652 Change-Id: I07f5e02443379ac5b877f72d33cedf4f2feca926 Conflicts: src/com/android/launcher3/Utilities.java --- .../launcher3/WallpaperPickerActivity.java | 7 +--- src/com/android/launcher3/Launcher.java | 6 ++-- .../android/launcher3/LauncherProvider.java | 11 +++++-- src/com/android/launcher3/Utilities.java | 33 ++++++++++--------- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java index 5d41238434..4998bf4b73 100644 --- a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java +++ b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java @@ -1195,11 +1195,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { @Override public boolean enableRotation() { - // Check if rotation is enabled for this device. - if (Utilities.isRotationAllowedForDevice(getContext())) - return true; - - // Check if the user has specifically enabled rotation via preferences. - return Utilities.isAllowRotationPrefEnabled(getApplicationContext(), true); + return true; } } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 40c5bd69eb..5d53fd0159 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -488,11 +488,11 @@ public class Launcher extends Activity IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); registerReceiver(mCloseSystemDialogsReceiver, filter); - mRotationEnabled = Utilities.isRotationAllowedForDevice(getApplicationContext()); + mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation); // In case we are on a device with locked rotation, we should look at preferences to check // if the user has specifically allowed rotation. if (!mRotationEnabled) { - mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext(), false); + mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext()); } // On large interfaces, or on devices that a user has specifically enabled screen rotation, @@ -1205,7 +1205,7 @@ public class Launcher extends Activity } else { // On devices with a locked orientation, we will at least have the allow rotation // setting. - return !Utilities.isRotationAllowedForDevice(this); + return !getResources().getBoolean(R.bool.allow_rotation); } } diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 0947709170..7c4b78d0be 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -268,9 +268,14 @@ public class LauncherProvider extends ContentProvider { switch (method) { case LauncherSettings.Settings.METHOD_GET_BOOLEAN: { Bundle result = new Bundle(); - result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, - Utilities.getPrefs(getContext()).getBoolean(arg, extras.getBoolean( - LauncherSettings.Settings.EXTRA_DEFAULT_VALUE))); + if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(arg)) { + result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, + Utilities.isAllowRotationPrefEnabled(getContext())); + } else { + result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, + Utilities.getPrefs(getContext()).getBoolean(arg, extras.getBoolean( + LauncherSettings.Settings.EXTRA_DEFAULT_VALUE))); + } return result; } case LauncherSettings.Settings.METHOD_SET_BOOLEAN: { diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index e3b450bb08..271e581f01 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -141,27 +141,30 @@ public final class Utilities { CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS, new LinkedBlockingQueue()); - // To turn on these properties, type - // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS] - private static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate"; - private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY); - public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation"; public static boolean isPropertyEnabled(String propertyName) { return Log.isLoggable(propertyName, Log.VERBOSE); } - public static boolean isAllowRotationPrefEnabled(Context context, boolean multiProcess) { - SharedPreferences sharedPrefs = context.getSharedPreferences( - LauncherFiles.SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE | (multiProcess ? - Context.MODE_MULTI_PROCESS : 0)); - boolean allowRotationPref = sharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, false); - return sForceEnableRotation || allowRotationPref; - } - - public static boolean isRotationAllowedForDevice(Context context) { - return sForceEnableRotation || context.getResources().getBoolean(R.bool.allow_rotation); + public static boolean isAllowRotationPrefEnabled(Context context) { + boolean allowRotationPref = false; + if (isNycOrAbove()) { + // If the device was scaled, used the original dimensions to determine if rotation + // is allowed of not. + try { + // TODO: Use the actual field when the API is finalized. + int originalDensity = + DisplayMetrics.class.getField("DENSITY_DEVICE_STABLE").getInt(null); + Resources res = context.getResources(); + int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp + * res.getDisplayMetrics().densityDpi / originalDensity; + allowRotationPref = originalSmallestWidth >= 600; + } catch (Exception e) { + // Ignore + } + } + return getPrefs(context).getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, allowRotationPref); } public static Bitmap createIconBitmap(Cursor c, int iconIndex, Context context) {