Merge "Enabling fake rotation by default" into ub-launcher3-qt-dev

This commit is contained in:
Sunny Goyal
2019-05-15 18:39:37 +00:00
committed by Android (Google) Code Review
4 changed files with 46 additions and 21 deletions
+2 -1
View File
@@ -845,7 +845,8 @@ public class CellLayout extends ViewGroup implements Transposable {
* width in {@link DeviceProfile#calculateCellWidth(int, int)}.
*/
public int getUnusedHorizontalSpace() {
return getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - (mCountX * mCellWidth);
return (mRotationMode.isTransposed ? getMeasuredHeight() : getMeasuredWidth())
- getPaddingLeft() - getPaddingRight() - (mCountX * mCellWidth);
}
public Drawable getScrimBackground() {
+9 -10
View File
@@ -303,6 +303,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
LauncherAppState app = LauncherAppState.getInstance(this);
mOldConfig = new Configuration(getResources().getConfiguration());
mModel = app.setLauncher(this);
mRotationHelper = new RotationHelper(this);
InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
initDeviceProfile(idp);
idp.addOnChangeListener(this);
@@ -325,7 +326,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
setupViews();
mPopupDataProvider = new PopupDataProvider(this);
mRotationHelper = new RotationHelper(this);
mAppTransitionManager = LauncherAppTransitionManager.newInstance(this);
boolean internalStateHandled = InternalStateHandler.handleCreate(this, getIntent());
@@ -396,12 +396,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
}
}
});
if (FeatureFlags.FAKE_LANDSCAPE_UI.get()) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS;
getWindow().setAttributes(lp);
}
}
@Override
@@ -428,9 +422,13 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
super.onConfigurationChanged(newConfig);
}
private boolean supportsFakeLandscapeUI() {
return FeatureFlags.FAKE_LANDSCAPE_UI.get() && !mRotationHelper.homeScreenCanRotate();
}
@Override
protected void reapplyUi() {
if (FeatureFlags.FAKE_LANDSCAPE_UI.get()) {
public void reapplyUi() {
if (supportsFakeLandscapeUI()) {
mRotationMode = mStableDeviceProfile == null
? RotationMode.NORMAL : UiFactory.getRotationMode(mDeviceProfile);
}
@@ -486,7 +484,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize);
}
if (FeatureFlags.FAKE_LANDSCAPE_UI.get() && mDeviceProfile.isVerticalBarLayout()
if (supportsFakeLandscapeUI()
&& mDeviceProfile.isVerticalBarLayout()
&& !mDeviceProfile.isMultiWindowMode) {
mStableDeviceProfile = mDeviceProfile.inv.portraitProfile;
mRotationMode = UiFactory.getRotationMode(mDeviceProfile);
@@ -111,7 +111,7 @@ abstract class BaseFlags {
"Show chip hints and gleams on the overview screen");
public static final TogglableFlag FAKE_LANDSCAPE_UI = new TogglableFlag(
"FAKE_LANDSCAPE_UI", false,
"FAKE_LANDSCAPE_UI", true,
"Rotate launcher UI instead of using transposed layout");
public static void initialize(Context context) {
@@ -20,13 +20,16 @@ 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 android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Resources;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.UiThreadHelper;
/**
@@ -49,7 +52,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
public static final int REQUEST_ROTATE = 1;
public static final int REQUEST_LOCK = 2;
private final Activity mActivity;
private final Launcher mLauncher;
private final SharedPreferences mPrefs;
private boolean mIgnoreAutoRotateSettings;
@@ -70,13 +73,13 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
private int mLastActivityFlags = -1;
public RotationHelper(Activity activity) {
mActivity = activity;
public RotationHelper(Launcher launcher) {
mLauncher = launcher;
// On large devices we do not handle auto-rotate differently.
mIgnoreAutoRotateSettings = mActivity.getResources().getBoolean(R.bool.allow_rotation);
mIgnoreAutoRotateSettings = mLauncher.getResources().getBoolean(R.bool.allow_rotation);
if (!mIgnoreAutoRotateSettings) {
mPrefs = Utilities.getPrefs(mActivity);
mPrefs = Utilities.getPrefs(mLauncher);
mPrefs.registerOnSharedPreferenceChangeListener(this);
mAutoRotateEnabled = mPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
getAllowRotationDefaultValue());
@@ -85,11 +88,32 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
}
}
public boolean homeScreenCanRotate() {
return mIgnoreAutoRotateSettings || mAutoRotateEnabled
|| mStateHandlerRequest != REQUEST_NONE;
}
private void updateRotationAnimation() {
if (FeatureFlags.FAKE_LANDSCAPE_UI.get()) {
WindowManager.LayoutParams lp = mLauncher.getWindow().getAttributes();
lp.rotationAnimation = homeScreenCanRotate()
? WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE
: WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS;
mLauncher.getWindow().setAttributes(lp);
}
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
boolean wasRotationEnabled = mAutoRotateEnabled;
mAutoRotateEnabled = mPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
getAllowRotationDefaultValue());
notifyChange();
if (mAutoRotateEnabled != wasRotationEnabled) {
notifyChange();
updateRotationAnimation();
mLauncher.reapplyUi();
}
}
public void setStateHandlerRequest(int request) {
@@ -109,7 +133,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
// Used by tests only.
public void forceAllowRotationForTesting(boolean allowRotation) {
mIgnoreAutoRotateSettings =
allowRotation || mActivity.getResources().getBoolean(R.bool.allow_rotation);
allowRotation || mLauncher.getResources().getBoolean(R.bool.allow_rotation);
notifyChange();
}
@@ -117,6 +141,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
if (!mInitialized) {
mInitialized = true;
notifyChange();
updateRotationAnimation();
}
}
@@ -150,7 +175,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
}
if (activityFlags != mLastActivityFlags) {
mLastActivityFlags = activityFlags;
UiThreadHelper.setOrientationAsync(mActivity, activityFlags);
UiThreadHelper.setOrientationAsync(mLauncher, activityFlags);
}
}