Use WindowManagerProxy.getRotation to determine if rotation has changed
- Follow-up of http://ag/19559863 as Config diff on windowConfiguration does not work on 3P Launcher, so diff WindowManagerProxy.getRotation instead - Also centralized Configuration diff logic into StatefulActivity Bug: 240730723 Test: manual on 90/180 degree rotation in Launcher, RecentsActivity and 3P Launcher Change-Id: Ib368ed5d749841a6873a03e2644608ff68885922
This commit is contained in:
@@ -15,10 +15,14 @@
|
||||
*/
|
||||
package com.android.launcher3.statemanager;
|
||||
|
||||
import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
|
||||
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
|
||||
|
||||
import static com.android.launcher3.LauncherState.FLAG_CLOSE_POPUPS;
|
||||
import static com.android.launcher3.LauncherState.FLAG_NON_INTERACTIVE;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -31,6 +35,7 @@ import com.android.launcher3.LauncherRootView;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.statemanager.StateManager.AtomicAnimationFactory;
|
||||
import com.android.launcher3.statemanager.StateManager.StateHandler;
|
||||
import com.android.launcher3.util.window.WindowManagerProxy;
|
||||
import com.android.launcher3.views.BaseDragLayer;
|
||||
|
||||
import java.util.List;
|
||||
@@ -48,6 +53,17 @@ public abstract class StatefulActivity<STATE_TYPE extends BaseState<STATE_TYPE>>
|
||||
|
||||
private LauncherRootView mRootView;
|
||||
|
||||
protected Configuration mOldConfig;
|
||||
private int mOldRotation;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mOldConfig = new Configuration(getResources().getConfiguration());
|
||||
mOldRotation = WindowManagerProxy.INSTANCE.get(this).getRotation(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create handlers to control the property changes for this activity
|
||||
*/
|
||||
@@ -198,5 +214,21 @@ public abstract class StatefulActivity<STATE_TYPE extends BaseState<STATE_TYPE>>
|
||||
* Handles configuration change when system calls {@link #onConfigurationChanged}, or on other
|
||||
* situations that configuration might change.
|
||||
*/
|
||||
public void handleConfigurationChanged(Configuration newConfig) {}
|
||||
public void handleConfigurationChanged(Configuration newConfig) {
|
||||
int diff = newConfig.diff(mOldConfig);
|
||||
int rotation = WindowManagerProxy.INSTANCE.get(this).getRotation(this);
|
||||
if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0
|
||||
|| rotation != mOldRotation) {
|
||||
onHandleConfigurationChanged();
|
||||
}
|
||||
|
||||
mOldConfig.setTo(newConfig);
|
||||
mOldRotation = rotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logic for when device configuration changes (rotation, screen size change, multi-window,
|
||||
* etc.)
|
||||
*/
|
||||
protected abstract void onHandleConfigurationChanged();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user