diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2018-01-31 15:18:11 -0800 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2018-01-31 15:20:30 -0800 |
commit | f8d56fc8a1402c53e26b434f6737d01cf87cda51 (patch) | |
tree | fdd19c5f01eede72baba12773436c5503fdd8d0a /src/com/android/launcher3 | |
parent | 260fec1b24a1172bd8db7174b33584f5eed524b0 (diff) | |
download | android_packages_apps_Trebuchet-f8d56fc8a1402c53e26b434f6737d01cf87cda51.tar.gz android_packages_apps_Trebuchet-f8d56fc8a1402c53e26b434f6737d01cf87cda51.tar.bz2 android_packages_apps_Trebuchet-f8d56fc8a1402c53e26b434f6737d01cf87cda51.zip |
Initial changes for handling configuration changes dynamically
Bug: 71709920
Change-Id: I88cf2229dea28d01c13a5a76d2290e91b07d095e
Diffstat (limited to 'src/com/android/launcher3')
12 files changed, 119 insertions, 59 deletions
diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java index cc6a58f9a..a3fe89a5f 100644 --- a/src/com/android/launcher3/DropTargetBar.java +++ b/src/com/android/launcher3/DropTargetBar.java @@ -111,6 +111,7 @@ public class DropTargetBar extends FrameLayout lp.topMargin += grid.edgeMarginPx; lp.height = grid.dropTargetBarSizePx; + lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; } setLayoutParams(lp); for (ButtonDropTarget button : mDropTargets) { diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java index 9d2bb070e..03043f245 100644 --- a/src/com/android/launcher3/Hotseat.java +++ b/src/com/android/launcher3/Hotseat.java @@ -28,12 +28,10 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewDebug; import android.view.ViewGroup; -import android.view.ViewGroup.LayoutParams; import android.widget.FrameLayout; import android.widget.TextView; import com.android.launcher3.config.FeatureFlags; -import com.android.launcher3.logging.UserEventDispatcher; import com.android.launcher3.logging.UserEventDispatcher.LogContainerProvider; import com.android.launcher3.userevent.nano.LauncherLogProto.Action; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; diff --git a/src/com/android/launcher3/InsettableFrameLayout.java b/src/com/android/launcher3/InsettableFrameLayout.java index baf3328ea..1db1fc000 100644 --- a/src/com/android/launcher3/InsettableFrameLayout.java +++ b/src/com/android/launcher3/InsettableFrameLayout.java @@ -38,10 +38,6 @@ public class InsettableFrameLayout extends FrameLayout implements Insettable { @Override public void setInsets(Rect insets) { - // If the insets haven't changed, this is a no-op. Avoid unnecessary layout caused by - // modifying child layout params. - if (insets.equals(mInsets)) return; - final int n = getChildCount(); for (int i = 0; i < n; i++) { final View child = getChildAt(i); diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 85443ed9e..8ef1da9b7 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -16,6 +16,8 @@ package com.android.launcher3; +import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; +import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; @@ -53,7 +55,9 @@ import android.content.IntentFilter; import android.content.IntentSender; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.database.sqlite.SQLiteDatabase; import android.graphics.Point; import android.graphics.PointF; @@ -215,6 +219,7 @@ public class Launcher extends BaseActivity @Thunk static final int NEW_APPS_ANIMATION_DELAY = 500; private LauncherAppTransitionManager mAppTransitionManager; + private Configuration mOldConfig; @Thunk Workspace mWorkspace; private View mLauncherView; @@ -237,10 +242,6 @@ public class Launcher extends BaseActivity // UI and state for the overview panel private ViewGroup mOverviewPanel; - // We need to store the orientation Launcher was created with, due to a bug (b/64916689) - // that results in widgets being inflated in the wrong orientation. - private int mOrientation; - @Thunk boolean mWorkspaceLoading = true; private OnResumeCallback mOnResumeCallback; @@ -310,17 +311,9 @@ public class Launcher extends BaseActivity TraceHelper.partitionSection("Launcher-onCreate", "super call"); LauncherAppState app = LauncherAppState.getInstance(this); + mOldConfig = new Configuration(getResources().getConfiguration()); + initDeviceProfile(app.getInvariantDeviceProfile()); - // Load configuration-specific DeviceProfile - mDeviceProfile = app.getInvariantDeviceProfile().getDeviceProfile(this); - if (isInMultiWindowModeCompat()) { - Display display = getWindowManager().getDefaultDisplay(); - Point mwSize = new Point(); - display.getSize(mwSize); - mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize); - } - - mOrientation = getResources().getConfiguration().orientation; mSharedPrefs = Utilities.getPrefs(this); mIsSafeModeEnabled = getPackageManager().isSafeMode(); mModel = app.setLauncher(this); @@ -393,7 +386,7 @@ public class Launcher extends BaseActivity ? SCREEN_ORIENTATION_UNSPECIFIED : SCREEN_ORIENTATION_NOSENSOR); setContentView(mLauncherView); - ((LauncherRootView) mLauncherView).dispatchInsets(); + getRootView().dispatchInsets(); // Listen for broadcasts IntentFilter filter = new IntentFilter(); @@ -405,10 +398,7 @@ public class Launcher extends BaseActivity getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW, Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText)); - mAppTransitionManager = Utilities.getOverrideObject(LauncherAppTransitionManager.class, - this, R.string.app_transition_manager_class); - - mAppTransitionManager.registerRemoteAnimations(); + mAppTransitionManager = LauncherAppTransitionManager.newInstance(this); if (mLauncherCallbacks != null) { mLauncherCallbacks.onCreate(savedInstanceState); @@ -418,6 +408,45 @@ public class Launcher extends BaseActivity } @Override + public void onConfigurationChanged(Configuration newConfig) { + int diff = newConfig.diff(mOldConfig); + if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) { + mUserEventDispatcher = null; + initDeviceProfile(mDeviceProfile.inv); + + // Re create transition manager as it may rely on the device profile. + // TODO: Remove any dynamic states from this class. + mAppTransitionManager = LauncherAppTransitionManager.newInstance(this); + + // TODO: Link these to the callbacks + mAllAppsController.onDeviceProfileChanged(mDeviceProfile); + mDragLayer.setup(this, mDragController); + + // TODO: Clear all-apps recycler view pools + + getRootView().dispatchInsets(); + getStateManager().reapplyState(); + + // TODO: We can probably avoid rebind when only screen size changed. + mModel.startLoader(mWorkspace.getNextPage()); + } + + mOldConfig.setTo(newConfig); + super.onConfigurationChanged(newConfig); + } + + private void initDeviceProfile(InvariantDeviceProfile idp) { + // Load configuration-specific DeviceProfile + mDeviceProfile = idp.getDeviceProfile(this); + if (isInMultiWindowModeCompat()) { + Display display = getWindowManager().getDefaultDisplay(); + Point mwSize = new Point(); + display.getSize(mwSize); + mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize); + } + } + + @Override public void onThemeChanged() { recreate(); } @@ -1216,7 +1245,7 @@ public class Launcher extends BaseActivity return mSharedPrefs; } - public int getOrientation() { return mOrientation; } + public int getOrientation() { return mOldConfig.orientation; } @Override protected void onNewIntent(Intent intent) { diff --git a/src/com/android/launcher3/LauncherAppTransitionManager.java b/src/com/android/launcher3/LauncherAppTransitionManager.java index 9d68dc9e8..be2dc54ed 100644 --- a/src/com/android/launcher3/LauncherAppTransitionManager.java +++ b/src/com/android/launcher3/LauncherAppTransitionManager.java @@ -18,6 +18,7 @@ package com.android.launcher3; import android.app.ActivityOptions; +import android.content.Context; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -28,6 +29,11 @@ import android.view.View; */ public class LauncherAppTransitionManager { + public static LauncherAppTransitionManager newInstance(Context context) { + return Utilities.getOverrideObject(LauncherAppTransitionManager.class, + context, R.string.app_transition_manager_class); + } + public Bundle getDefaultActivityLaunchOptions(Launcher launcher, View v) { if (Utilities.ATLEAST_MARSHMALLOW) { int left = 0, top = 0; @@ -58,7 +64,4 @@ public class LauncherAppTransitionManager { public Bundle getActivityLaunchOptions(Launcher launcher, View v) { return getDefaultActivityLaunchOptions(launcher, v); } - - public void registerRemoteAnimations() { - } } diff --git a/src/com/android/launcher3/LauncherRootView.java b/src/com/android/launcher3/LauncherRootView.java index 18d52343c..fc4de2d32 100644 --- a/src/com/android/launcher3/LauncherRootView.java +++ b/src/com/android/launcher3/LauncherRootView.java @@ -89,13 +89,17 @@ public class LauncherRootView extends InsettableFrameLayout { @Override public void setInsets(Rect insets) { - super.setInsets(insets); + // If the insets haven't changed, this is a no-op. Avoid unnecessary layout caused by + // modifying child layout params. + if (!insets.equals(mInsets)) { + super.setInsets(insets); + } setBackground(insets.top == 0 ? null : Themes.getAttrDrawable(getContext(), R.attr.workspaceStatusBarScrim)); } public void dispatchInsets() { - fitSystemWindows(mInsets); + super.setInsets(mInsets); } @Override diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index dc3de18d5..19df17ecf 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -307,19 +307,24 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, mAH[i].padding.left = mAH[i].padding.right = leftRightPadding; mAH[i].applyPadding(); } + + ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams(); if (grid.isVerticalBarLayout()) { - ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams(); mlp.leftMargin = insets.left; mlp.topMargin = insets.top; mlp.rightMargin = insets.right; - setLayoutParams(mlp); setPadding(grid.workspacePadding.left, 0, grid.workspacePadding.right, 0); } else { - View navBarBg = findViewById(R.id.nav_bar_bg); - ViewGroup.LayoutParams navBarBgLp = navBarBg.getLayoutParams(); - navBarBgLp.height = insets.bottom; - navBarBg.setLayoutParams(navBarBgLp); + mlp.leftMargin = mlp.rightMargin = mlp.topMargin = 0; + setPadding(0, 0, 0, 0); } + setLayoutParams(mlp); + + View navBarBg = findViewById(R.id.nav_bar_bg); + ViewGroup.LayoutParams navBarBgLp = navBarBg.getLayoutParams(); + navBarBgLp.height = insets.bottom; + navBarBg.setLayoutParams(navBarBgLp); + InsettableFrameLayout.dispatchInsets(this, insets); } diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java index dadc6cd0b..4292f654c 100644 --- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java +++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java @@ -2,6 +2,7 @@ package com.android.launcher3.allapps; import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN; import static com.android.launcher3.anim.Interpolators.LINEAR; +import static com.android.launcher3.util.SystemUiController.UI_STATE_ALL_APPS; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -10,6 +11,7 @@ import android.util.Property; import android.view.View; import android.view.animation.Interpolator; +import com.android.launcher3.DeviceProfile; import com.android.launcher3.Hotseat; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; @@ -59,7 +61,7 @@ public class AllAppsTransitionController private final Launcher mLauncher; private final boolean mIsDarkTheme; - private final boolean mIsVerticalLayout; + private boolean mIsVerticalLayout; // Animation in this class is controlled by a single variable {@link mProgress}. // Visually, it represents top y coordinate of the all apps container if multiplied with @@ -80,7 +82,7 @@ public class AllAppsTransitionController mProgress = 1f; mIsDarkTheme = Themes.getAttrBoolean(mLauncher, R.attr.isMainColorDark); - mIsVerticalLayout = mLauncher.getDeviceProfile().isVerticalBarLayout(); + onDeviceProfileChanged(mLauncher.getDeviceProfile()); } public float getShiftRange() { @@ -93,6 +95,10 @@ public class AllAppsTransitionController mAppsView.setVisibility(View.VISIBLE); } + public void onDeviceProfileChanged(DeviceProfile profile) { + mIsVerticalLayout = profile.isVerticalBarLayout(); + } + /** * Note this method should not be called outside this class. This is public because it is used * in xml-based animations which also handle updating the appropriate UI. @@ -125,13 +131,15 @@ public class AllAppsTransitionController // status bar. boolean forceChange = shiftCurrent <= mShiftRange / 4; if (forceChange) { - mLauncher.getSystemUiController().updateUiState( - SystemUiController.UI_STATE_ALL_APPS, !mIsDarkTheme); + mLauncher.getSystemUiController().updateUiState(UI_STATE_ALL_APPS, !mIsDarkTheme); } else { - mLauncher.getSystemUiController().updateUiState( - SystemUiController.UI_STATE_ALL_APPS, 0); + mLauncher.getSystemUiController().updateUiState(UI_STATE_ALL_APPS, 0); } - + } else { + mAppsView.setAlpha(1); + mLauncher.getHotseat().setTranslationY(0); + mLauncher.getWorkspace().getPageIndicator().setTranslationY(0); + mLauncher.getSystemUiController().updateUiState(UI_STATE_ALL_APPS, 0); } } diff --git a/src/com/android/launcher3/pageindicators/WorkspacePageIndicator.java b/src/com/android/launcher3/pageindicators/WorkspacePageIndicator.java index 3e4bd3100..ee4e4ee9d 100644 --- a/src/com/android/launcher3/pageindicators/WorkspacePageIndicator.java +++ b/src/com/android/launcher3/pageindicators/WorkspacePageIndicator.java @@ -271,6 +271,7 @@ public class WorkspacePageIndicator extends PageIndicator implements Insettable, setOnClickListener(this); } else { + lp.leftMargin = lp.rightMargin = 0; lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; lp.height = grid.pageIndicatorSizePx; lp.bottomMargin = grid.hotseatBarSizePx + insets.bottom; diff --git a/src/com/android/launcher3/views/AllAppsScrim.java b/src/com/android/launcher3/views/AllAppsScrim.java index 662f99c05..0ef9c8f23 100644 --- a/src/com/android/launcher3/views/AllAppsScrim.java +++ b/src/com/android/launcher3/views/AllAppsScrim.java @@ -50,12 +50,13 @@ public class AllAppsScrim extends View implements OnChangeListener, Insettable { private final Rect mDrawRect = new Rect(); private final Rect mPadding = new Rect(); private final Rect mInsets = new Rect(); - private final DeviceProfile mGrid; + private final float mRadius; - private final int mMinAlpha; - private final int mAlphaRange; private final int mScrimColor; + private int mMinAlpha; + private int mAlphaRange; + private final float mShadowBlur; private final Bitmap mShadowBitmap; @@ -82,16 +83,21 @@ public class AllAppsScrim extends View implements OnChangeListener, Insettable { mRadius = getResources().getDimension(R.dimen.all_apps_scrim_radius); mShadowBlur = getResources().getDimension(R.dimen.all_apps_scrim_blur); - Launcher launcher = Launcher.getLauncher(context); - mGrid = launcher.getDeviceProfile(); - mFillAlpha = mMinAlpha = mGrid.isVerticalBarLayout() - ? MIN_ALPHA_LANDSCAPE : MIN_ALPHA_PORTRAIT; - mAlphaRange = MAX_ALPHA - mMinAlpha; + initDefaults(); + mFillAlpha = mMinAlpha; mShadowBitmap = generateShadowBitmap(); updateColors(mWallpaperColorInfo); } + private DeviceProfile initDefaults() { + DeviceProfile grid = Launcher.getLauncher(getContext()).getDeviceProfile(); + mMinAlpha = grid.isVerticalBarLayout() + ? MIN_ALPHA_LANDSCAPE : MIN_ALPHA_PORTRAIT; + mAlphaRange = MAX_ALPHA - mMinAlpha; + return grid; + } + private Bitmap generateShadowBitmap() { float curveBot = mRadius + mShadowBlur; @@ -191,29 +197,32 @@ public class AllAppsScrim extends View implements OnChangeListener, Insettable { @Override public void setInsets(Rect insets) { mInsets.set(insets); - if (mGrid.isVerticalBarLayout()) { - mPadding.set(mGrid.workspacePadding); + DeviceProfile grid = initDefaults(); + if (grid.isVerticalBarLayout()) { + mPadding.set(grid.workspacePadding); mPadding.bottom = 0; mPadding.left += mInsets.left; mPadding.top = mInsets.top; mPadding.right += mInsets.right; + setDrawRegion(0); } else { + mPadding.setEmpty(); float scrimMargin = getResources().getDimension(R.dimen.all_apps_scrim_margin); - setDrawRegion(mGrid.hotseatBarSizePx + insets.bottom + scrimMargin); + setDrawRegion(grid.hotseatBarSizePx + insets.bottom + scrimMargin); } - updateDrawRect(); + updateDrawRect(grid); invalidate(); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); - updateDrawRect(); + updateDrawRect(Launcher.getLauncher(getContext()).getDeviceProfile()); } - private void updateDrawRect() { + private void updateDrawRect(DeviceProfile grid) { mDrawRect.bottom = getHeight(); - if (mGrid.isVerticalBarLayout()) { + if (grid.isVerticalBarLayout()) { mDrawRect.left = (int) (mPadding.left - mShadowBlur - 0.5f); mDrawRect.right = (int) (getWidth() - mPadding.right + 0.5f); } else { diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java index fa8271438..b22509ce3 100644 --- a/src/com/android/launcher3/widget/BaseWidgetSheet.java +++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java @@ -113,6 +113,10 @@ abstract class BaseWidgetSheet extends AbstractSlideInView protected void onCloseComplete() { super.onCloseComplete(); + clearNavBarColor(); + } + + protected void clearNavBarColor() { mLauncher.getSystemUiController().updateUiState( SystemUiController.UI_STATE_WIDGET_BOTTOM_SHEET, 0); } diff --git a/src/com/android/launcher3/widget/WidgetsFullSheet.java b/src/com/android/launcher3/widget/WidgetsFullSheet.java index a1bfe8849..d62a90964 100644 --- a/src/com/android/launcher3/widget/WidgetsFullSheet.java +++ b/src/com/android/launcher3/widget/WidgetsFullSheet.java @@ -100,6 +100,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet mRecyclerView.getPaddingRight(), insets.bottom); if (insets.bottom > 0) { setupNavBarColor(); + } else { + clearNavBarColor(); } requestLayout(); } |