Merge "Get home rotation default value from DisplayController Info in case DeviceProfile is not updated." into tm-qpr-dev am: 618df8b34e

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/20712705

Change-Id: I857c8bc25dc82cf03192bda451bd699db0818448
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Pat Manning
2022-12-15 20:47:02 +00:00
committed by Automerger Merge Worker
2 changed files with 14 additions and 14 deletions
@@ -53,6 +53,7 @@ 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 com.android.launcher3.util.DisplayController;
import java.util.Collections;
import java.util.List;
@@ -267,15 +268,14 @@ public class SettingsActivity extends FragmentActivity
return !WidgetsModel.GO_DISABLE_NOTIFICATION_DOTS;
case ALLOW_ROTATION_PREFERENCE_KEY:
DeviceProfile deviceProfile = InvariantDeviceProfile.INSTANCE.get(
getContext()).getDeviceProfile(getContext());
if (deviceProfile.isTablet) {
DisplayController.Info info = InvariantDeviceProfile.INSTANCE.get(
getContext()).getDeviceProfile(getContext()).getDisplayInfo();
if (info.isTablet(info.realBounds)) {
// Launcher supports rotation by default. No need to show this setting.
return false;
}
// Initialize the UI once
preference.setDefaultValue(
RotationHelper.getAllowRotationDefaultValue(deviceProfile));
preference.setDefaultValue(RotationHelper.getAllowRotationDefaultValue(info));
return true;
case FLAGS_PREFERENCE_KEY:
@@ -35,7 +35,6 @@ import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.util.DisplayController;
@@ -50,11 +49,11 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
/**
* Returns the default value of {@link #ALLOW_ROTATION_PREFERENCE_KEY} preference.
*/
public static boolean getAllowRotationDefaultValue(DeviceProfile deviceProfile) {
public static boolean getAllowRotationDefaultValue(DisplayController.Info 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(deviceProfile.widthPx, deviceProfile.heightPx), DENSITY_DEVICE_STABLE);
float originalSmallestWidth = dpiFromPx(Math.min(info.currentSize.x, info.currentSize.y),
DENSITY_DEVICE_STABLE);
return originalSmallestWidth >= MIN_TABLET_WIDTH;
}
@@ -99,7 +98,8 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
new Handler(UI_HELPER_EXECUTOR.getLooper(), this::setOrientationAsync);
}
private void setIgnoreAutoRotateSettings(boolean ignoreAutoRotateSettings) {
private void setIgnoreAutoRotateSettings(boolean ignoreAutoRotateSettings,
DisplayController.Info info) {
// On large devices we do not handle auto-rotate differently.
mIgnoreAutoRotateSettings = ignoreAutoRotateSettings;
if (!mIgnoreAutoRotateSettings) {
@@ -108,7 +108,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
mSharedPrefs.registerOnSharedPreferenceChangeListener(this);
}
mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
getAllowRotationDefaultValue(mActivity.getDeviceProfile()));
getAllowRotationDefaultValue(info));
} else {
if (mSharedPrefs != null) {
mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
@@ -122,7 +122,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
if (mDestroyed || mIgnoreAutoRotateSettings) return;
boolean wasRotationEnabled = mHomeRotationEnabled;
mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
getAllowRotationDefaultValue(mActivity.getDeviceProfile()));
getAllowRotationDefaultValue(mActivity.getDeviceProfile().getDisplayInfo()));
if (mHomeRotationEnabled != wasRotationEnabled) {
notifyChange();
}
@@ -132,7 +132,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
public void onDisplayInfoChanged(Context context, DisplayController.Info info, int flags) {
boolean ignoreAutoRotateSettings = info.isTablet(info.realBounds);
if (mIgnoreAutoRotateSettings != ignoreAutoRotateSettings) {
setIgnoreAutoRotateSettings(ignoreAutoRotateSettings);
setIgnoreAutoRotateSettings(ignoreAutoRotateSettings, info);
notifyChange();
}
}
@@ -169,7 +169,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
mInitialized = true;
DisplayController displayController = DisplayController.INSTANCE.get(mActivity);
DisplayController.Info info = displayController.getInfo();
setIgnoreAutoRotateSettings(info.isTablet(info.realBounds));
setIgnoreAutoRotateSettings(info.isTablet(info.realBounds), info);
displayController.addChangeListener(this);
notifyChange();
}