Merge "Preserving the homescreen rotation setting on a tablet, when the display is scaled" into ub-launcher3-calgary
This commit is contained in:
@@ -478,7 +478,7 @@ public class Launcher extends Activity
|
|||||||
IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
||||||
registerReceiver(mCloseSystemDialogsReceiver, filter);
|
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
|
// 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 the user has specifically allowed rotation.
|
||||||
if (!mRotationEnabled) {
|
if (!mRotationEnabled) {
|
||||||
@@ -1147,7 +1147,7 @@ public class Launcher extends Activity
|
|||||||
} else {
|
} else {
|
||||||
// On devices with a locked orientation, we will at least have the allow rotation
|
// On devices with a locked orientation, we will at least have the allow rotation
|
||||||
// setting.
|
// setting.
|
||||||
return !Utilities.isRotationAllowedForDevice(this);
|
return !getResources().getBoolean(R.bool.allow_rotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -265,9 +265,14 @@ public class LauncherProvider extends ContentProvider {
|
|||||||
switch (method) {
|
switch (method) {
|
||||||
case LauncherSettings.Settings.METHOD_GET_BOOLEAN: {
|
case LauncherSettings.Settings.METHOD_GET_BOOLEAN: {
|
||||||
Bundle result = new Bundle();
|
Bundle result = new Bundle();
|
||||||
result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
|
if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(arg)) {
|
||||||
Utilities.getPrefs(getContext()).getBoolean(arg, extras.getBoolean(
|
result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
|
||||||
LauncherSettings.Settings.EXTRA_DEFAULT_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;
|
return result;
|
||||||
}
|
}
|
||||||
case LauncherSettings.Settings.METHOD_SET_BOOLEAN: {
|
case LauncherSettings.Settings.METHOD_SET_BOOLEAN: {
|
||||||
|
|||||||
@@ -131,11 +131,6 @@ public final class Utilities {
|
|||||||
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
|
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
|
||||||
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
|
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 final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
|
||||||
|
|
||||||
public static boolean isPropertyEnabled(String propertyName) {
|
public static boolean isPropertyEnabled(String propertyName) {
|
||||||
@@ -143,13 +138,24 @@ public final class Utilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAllowRotationPrefEnabled(Context context) {
|
public static boolean isAllowRotationPrefEnabled(Context context) {
|
||||||
boolean allowRotationPref = getPrefs(context)
|
boolean allowRotationPref = false;
|
||||||
.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, false);
|
if (isNycOrAbove()) {
|
||||||
return sForceEnableRotation || allowRotationPref;
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isRotationAllowedForDevice(Context context) {
|
return getPrefs(context).getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, allowRotationPref);
|
||||||
return sForceEnableRotation || context.getResources().getBoolean(R.bool.allow_rotation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNycOrAbove() {
|
public static boolean isNycOrAbove() {
|
||||||
|
|||||||
Reference in New Issue
Block a user