Merge "Listen to DisplayController for ignoreAutoRotateSettings" into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-07-29 18:05:17 +00:00
committed by Android (Google) Code Review
3 changed files with 28 additions and 12 deletions
+15 -3
View File
@@ -636,7 +636,10 @@ public class Launcher extends StatefulActivity<LauncherState>
@Override
public void onIdpChanged(boolean modelPropertiesChanged) {
initDeviceProfile(mDeviceProfile.inv);
if (!initDeviceProfile(mDeviceProfile.inv)) {
return;
}
dispatchDeviceProfileChanged();
reapplyUi();
mDragLayer.recreateControllers();
@@ -659,9 +662,17 @@ public class Launcher extends StatefulActivity<LauncherState>
mDragLayer.onOneHandedModeStateChanged(activated);
}
protected void initDeviceProfile(InvariantDeviceProfile idp) {
/**
* Returns {@code true} if a new DeviceProfile is initialized, and {@code false} otherwise.
*/
protected boolean initDeviceProfile(InvariantDeviceProfile idp) {
// Load configuration-specific DeviceProfile
mDeviceProfile = idp.getDeviceProfile(this);
DeviceProfile deviceProfile = idp.getDeviceProfile(this);
if (mDeviceProfile == deviceProfile) {
return false;
}
mDeviceProfile = deviceProfile;
if (isInMultiWindowMode()) {
mDeviceProfile = mDeviceProfile.getMultiWindowProfile(
this, getMultiWindowDisplaySize());
@@ -669,6 +680,7 @@ public class Launcher extends StatefulActivity<LauncherState>
onDeviceProfileInitiated();
mModelWriter = mModel.getWriter(getDeviceProfile().isVerticalBarLayout(), true, this);
return true;
}
public RotationHelper getRotationHelper() {
@@ -23,19 +23,21 @@ import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE;
import static com.android.launcher3.Utilities.dpiFromPx;
import static com.android.launcher3.util.window.WindowManagerProxy.MIN_TABLET_WIDTH;
import android.content.Context;
import android.content.SharedPreferences;
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.DisplayController;
import com.android.launcher3.util.UiThreadHelper;
/**
* Utility class to manage launcher rotation
*/
public class RotationHelper implements OnSharedPreferenceChangeListener,
DeviceProfile.OnDeviceProfileChangeListener {
DisplayController.DisplayInfoChangeListener {
private static final String TAG = "RotationHelper";
@@ -119,8 +121,8 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
}
@Override
public void onDeviceProfileChanged(DeviceProfile dp) {
boolean ignoreAutoRotateSettings = dp.isTablet;
public void onDisplayInfoChanged(Context context, DisplayController.Info info, int flags) {
boolean ignoreAutoRotateSettings = info.isTablet(info.realBounds);
if (mIgnoreAutoRotateSettings != ignoreAutoRotateSettings) {
setIgnoreAutoRotateSettings(ignoreAutoRotateSettings);
notifyChange();
@@ -157,8 +159,10 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
public void initialize() {
if (!mInitialized) {
mInitialized = true;
setIgnoreAutoRotateSettings(mActivity.getDeviceProfile().isTablet);
mActivity.addOnDeviceProfileChangeListener(this);
DisplayController displayController = DisplayController.INSTANCE.get(mActivity);
DisplayController.Info info = displayController.getInfo();
setIgnoreAutoRotateSettings(info.isTablet(info.realBounds));
displayController.addChangeListener(this);
notifyChange();
}
}
@@ -166,7 +170,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
public void destroy() {
if (!mDestroyed) {
mDestroyed = true;
mActivity.removeOnDeviceProfileChangeListener(this);
DisplayController.INSTANCE.get(mActivity).removeChangeListener(this);
mActivity = null;
if (mSharedPrefs != null) {
mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
@@ -278,11 +278,11 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable {
public final float fontScale;
private final int densityDpi;
public final NavigationMode navigationMode;
private final PortraitSize mScreenSizeDp;
// WindowBounds
public final WindowBounds realBounds;
public final Set<WindowBounds> supportedBounds = new ArraySet<>();
private final ArrayMap<CachedDisplayInfo, WindowBounds[]> mPerDisplayBounds =
new ArrayMap<>();
@@ -310,7 +310,7 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable {
mPerDisplayBounds.putAll(perDisplayBoundsCache);
WindowBounds[] cachedValue = mPerDisplayBounds.get(normalizedDisplayInfo);
WindowBounds realBounds = wmProxy.getRealBounds(displayInfoContext, displayInfo);
realBounds = wmProxy.getRealBounds(displayInfoContext, displayInfo);
if (cachedValue == null) {
// Unexpected normalizedDisplayInfo is found, recreate the cache
Log.e(TAG, "Unexpected normalizedDisplayInfo found, invalidating cache");