Use only current density to check isTablet
- Removed DeviceProfile.allowRotation and use DeviceProfile.isTablet instead, which only uses current density to calculate its value - Reverted default allow_rotation preference handling to before ag/14234761 Fix: 203817448 Test: isTablet is set correctly in different screen sizes Change-Id: Ic6c8dfc774e7787f62d489ad27720a7644c1e8c7
This commit is contained in:
parent
039501f41f
commit
2998307cd6
|
@ -162,7 +162,7 @@ public class RecentsOrientedState implements
|
|||
*/
|
||||
public void setDeviceProfile(DeviceProfile deviceProfile) {
|
||||
boolean oldMultipleOrientationsSupported = isMultipleOrientationSupportedByDevice();
|
||||
setFlag(FLAG_MULTIPLE_ORIENTATION_SUPPORTED_BY_DENSITY, !deviceProfile.allowRotation);
|
||||
setFlag(FLAG_MULTIPLE_ORIENTATION_SUPPORTED_BY_DENSITY, !deviceProfile.isTablet);
|
||||
if (mListenersInitialized) {
|
||||
boolean newMultipleOrientationsSupported = isMultipleOrientationSupportedByDevice();
|
||||
// If isMultipleOrientationSupportedByDevice is changed, init or destroy listeners
|
||||
|
|
|
@ -16,13 +16,10 @@
|
|||
|
||||
package com.android.launcher3;
|
||||
|
||||
import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE;
|
||||
|
||||
import static com.android.launcher3.ResourceUtils.pxFromDp;
|
||||
import static com.android.launcher3.Utilities.dpiFromPx;
|
||||
import static com.android.launcher3.Utilities.pxFromSp;
|
||||
import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
|
||||
import static com.android.launcher3.util.WindowManagerCompat.MIN_TABLET_WIDTH;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
|
@ -64,7 +61,6 @@ public class DeviceProfile {
|
|||
public final boolean isPhone;
|
||||
public final boolean transposeLayoutWithOrientation;
|
||||
public final boolean isTwoPanels;
|
||||
public final boolean allowRotation;
|
||||
|
||||
// Device properties in current orientation
|
||||
public final boolean isLandscape;
|
||||
|
@ -244,12 +240,7 @@ public class DeviceProfile {
|
|||
availableHeightPx = windowBounds.availableSize.y;
|
||||
|
||||
mInfo = info;
|
||||
// If the device's pixel density was scaled (usually via settings for A11y), use the
|
||||
// original dimensions to determine if rotation is allowed of not.
|
||||
float originalSmallestWidth = dpiFromPx(Math.min(widthPx, heightPx), DENSITY_DEVICE_STABLE);
|
||||
allowRotation = originalSmallestWidth >= MIN_TABLET_WIDTH;
|
||||
// Tablet UI does not support emulated landscape.
|
||||
isTablet = allowRotation && info.isTablet(windowBounds);
|
||||
isTablet = info.isTablet(windowBounds);
|
||||
isPhone = !isTablet;
|
||||
isTwoPanels = isTablet && useTwoPanels;
|
||||
|
||||
|
@ -1031,7 +1022,6 @@ public class DeviceProfile {
|
|||
writer.println(prefix + "DeviceProfile:");
|
||||
writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
|
||||
|
||||
writer.println(prefix + "\tallowRotation:" + allowRotation);
|
||||
writer.println(prefix + "\tisTablet:" + isTablet);
|
||||
writer.println(prefix + "\tisPhone:" + isPhone);
|
||||
writer.println(prefix + "\ttransposeLayoutWithOrientation:"
|
||||
|
|
|
@ -49,6 +49,7 @@ import com.android.launcher3.R;
|
|||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.model.WidgetsModel;
|
||||
import com.android.launcher3.states.RotationHelper;
|
||||
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -253,12 +254,13 @@ public class SettingsActivity extends FragmentActivity
|
|||
case ALLOW_ROTATION_PREFERENCE_KEY:
|
||||
DeviceProfile deviceProfile = InvariantDeviceProfile.INSTANCE.get(
|
||||
getContext()).getDeviceProfile(getContext());
|
||||
if (deviceProfile.allowRotation) {
|
||||
if (deviceProfile.isTablet) {
|
||||
// Launcher supports rotation by default. No need to show this setting.
|
||||
return false;
|
||||
}
|
||||
// Initialize the UI once
|
||||
preference.setDefaultValue(false);
|
||||
preference.setDefaultValue(
|
||||
RotationHelper.getAllowRotationDefaultValue(deviceProfile));
|
||||
return true;
|
||||
|
||||
case FLAGS_PREFERENCE_KEY:
|
||||
|
|
|
@ -18,6 +18,10 @@ package com.android.launcher3.states;
|
|||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LOCKED;
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE;
|
||||
|
||||
import static com.android.launcher3.Utilities.dpiFromPx;
|
||||
import static com.android.launcher3.util.WindowManagerCompat.MIN_TABLET_WIDTH;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
|
@ -25,7 +29,6 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
|||
import com.android.launcher3.BaseActivity;
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.util.ActivityTracker;
|
||||
import com.android.launcher3.util.UiThreadHelper;
|
||||
|
||||
/**
|
||||
|
@ -38,6 +41,17 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
|
|||
|
||||
public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
|
||||
|
||||
/**
|
||||
* Returns the default value of {@link #ALLOW_ROTATION_PREFERENCE_KEY} preference.
|
||||
*/
|
||||
public static boolean getAllowRotationDefaultValue(DeviceProfile deviceProfile) {
|
||||
// If the device's pixel density was scaled (usually via settings for A11y), use the
|
||||
// original dimensions to determine if rotation is allowed of not.
|
||||
float originalSmallestWidth = dpiFromPx(
|
||||
Math.min(deviceProfile.widthPx, deviceProfile.heightPx), DENSITY_DEVICE_STABLE);
|
||||
return originalSmallestWidth >= MIN_TABLET_WIDTH;
|
||||
}
|
||||
|
||||
public static final int REQUEST_NONE = 0;
|
||||
public static final int REQUEST_ROTATE = 1;
|
||||
public static final int REQUEST_LOCK = 2;
|
||||
|
@ -51,7 +65,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
|
|||
|
||||
/**
|
||||
* Rotation request made by
|
||||
* {@link ActivityTracker.SchedulerCallback}.
|
||||
* {@link com.android.launcher3.util.ActivityTracker.SchedulerCallback}.
|
||||
* This supersedes any other request.
|
||||
*/
|
||||
private int mStateHandlerRequest = REQUEST_NONE;
|
||||
|
@ -84,7 +98,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
|
|||
mSharedPrefs.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
|
||||
mActivity.getDeviceProfile().allowRotation);
|
||||
getAllowRotationDefaultValue(mActivity.getDeviceProfile()));
|
||||
} else {
|
||||
if (mSharedPrefs != null) {
|
||||
mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||
|
@ -98,7 +112,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
|
|||
if (mDestroyed) return;
|
||||
boolean wasRotationEnabled = mHomeRotationEnabled;
|
||||
mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
|
||||
mActivity.getDeviceProfile().allowRotation);
|
||||
getAllowRotationDefaultValue(mActivity.getDeviceProfile()));
|
||||
if (mHomeRotationEnabled != wasRotationEnabled) {
|
||||
notifyChange();
|
||||
}
|
||||
|
@ -106,7 +120,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
|
|||
|
||||
@Override
|
||||
public void onDeviceProfileChanged(DeviceProfile dp) {
|
||||
boolean ignoreAutoRotateSettings = dp.allowRotation;
|
||||
boolean ignoreAutoRotateSettings = dp.isTablet;
|
||||
if (mIgnoreAutoRotateSettings != ignoreAutoRotateSettings) {
|
||||
setIgnoreAutoRotateSettings(ignoreAutoRotateSettings);
|
||||
notifyChange();
|
||||
|
@ -143,7 +157,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
|
|||
public void initialize() {
|
||||
if (!mInitialized) {
|
||||
mInitialized = true;
|
||||
setIgnoreAutoRotateSettings(mActivity.getDeviceProfile().allowRotation);
|
||||
setIgnoreAutoRotateSettings(mActivity.getDeviceProfile().isTablet);
|
||||
mActivity.addOnDeviceProfileChangeListener(this);
|
||||
notifyChange();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue