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
This commit is contained in:
Sunny Goyal
2016-02-23 14:49:22 -08:00
parent 1e41c08fa3
commit 58b53b5dff
4 changed files with 30 additions and 27 deletions
+18 -15
View File
@@ -141,27 +141,30 @@ public final class Utilities {
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
// 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) {