diff options
author | Jon Miranda <jonmiranda@google.com> | 2017-09-19 14:43:17 -0700 |
---|---|---|
committer | Jon Miranda <jonmiranda@google.com> | 2017-09-19 14:43:17 -0700 |
commit | 6bed350b75ad407ba85ae15d62551194dd0a69d4 (patch) | |
tree | 363c2c2169a60199342422f1848bab283c41c2d0 /src/com/android | |
parent | d926a9316f61a7540b00ecd42acba8013e715f92 (diff) | |
download | android_packages_apps_Trebuchet-6bed350b75ad407ba85ae15d62551194dd0a69d4.tar.gz android_packages_apps_Trebuchet-6bed350b75ad407ba85ae15d62551194dd0a69d4.tar.bz2 android_packages_apps_Trebuchet-6bed350b75ad407ba85ae15d62551194dd0a69d4.zip |
Fix bug where widgets are inflated in the wrong orientation.
The bug is that in onResume, the context may tell us the wrong
orientation.
As a workaround, we store the orientation that the Launcher
is created with, and we use that orientation to check whether
we actually need to reinflate the widgets.
Bug: 64916689
Change-Id: I5194debbd217a573d1f177c31d8c0abdf9da51b5
Diffstat (limited to 'src/com/android')
6 files changed, 15 insertions, 7 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 1e12b423f..522e96a12 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -251,6 +251,10 @@ public class Launcher extends BaseActivity // Main container view and the model for the widget tray screen. @Thunk WidgetsContainerView mWidgetsView; + // 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; + // We set the state in both onCreate and then onNewIntent in some cases, which causes both // scroll issues (because the workspace may not have been measured yet) and extra work. // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. @@ -383,6 +387,7 @@ public class Launcher extends BaseActivity mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize); } + mOrientation = getResources().getConfiguration().orientation; mSharedPrefs = Utilities.getPrefs(this); mIsSafeModeEnabled = getPackageManager().isSafeMode(); mModel = app.setLauncher(this); @@ -1669,6 +1674,8 @@ public class Launcher extends BaseActivity return mSharedPrefs; } + public int getOrientation() { return mOrientation; } + @Override protected void onNewIntent(Intent intent) { long startTime = 0; diff --git a/src/com/android/launcher3/LauncherAppWidgetHostView.java b/src/com/android/launcher3/LauncherAppWidgetHostView.java index b65b74ea0..7fe130876 100644 --- a/src/com/android/launcher3/LauncherAppWidgetHostView.java +++ b/src/com/android/launcher3/LauncherAppWidgetHostView.java @@ -142,9 +142,8 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView return false; } - public boolean isReinflateRequired() { + public boolean isReinflateRequired(int orientation) { // Re-inflate is required if the orientation has changed since last inflated. - int orientation = mContext.getResources().getConfiguration().orientation; if (mPreviousOrientation != orientation) { return true; } diff --git a/src/com/android/launcher3/PendingAppWidgetHostView.java b/src/com/android/launcher3/PendingAppWidgetHostView.java index de424aba1..c2d550169 100644 --- a/src/com/android/launcher3/PendingAppWidgetHostView.java +++ b/src/com/android/launcher3/PendingAppWidgetHostView.java @@ -111,7 +111,7 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView } @Override - public boolean isReinflateRequired() { + public boolean isReinflateRequired(int orientation) { // Re inflate is required any time the widget restore status changes return mStartState != mInfo.restoreStatus; } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index f8d64984e..37ee6d751 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1213,7 +1213,7 @@ public class Workspace extends PagedView && v.getTag() instanceof LauncherAppWidgetInfo) { LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) v; - if (lahv.isReinflateRequired()) { + if (lahv.isReinflateRequired(mLauncher.getOrientation())) { // Remove and rebind the current widget (which was inflated in the wrong // orientation), but don't delete it from the database mLauncher.removeItem(lahv, info, false /* deleteFromDb */); diff --git a/src/com/android/launcher3/qsb/QsbContainerView.java b/src/com/android/launcher3/qsb/QsbContainerView.java index d26f9f646..27a07c217 100644 --- a/src/com/android/launcher3/qsb/QsbContainerView.java +++ b/src/com/android/launcher3/qsb/QsbContainerView.java @@ -36,6 +36,7 @@ import android.widget.FrameLayout; import com.android.launcher3.AppWidgetResizeFrame; import com.android.launcher3.InvariantDeviceProfile; +import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.Utilities; @@ -193,7 +194,8 @@ public class QsbContainerView extends FrameLayout { @Override public void onResume() { super.onResume(); - if (mQsb != null && mQsb.isReinflateRequired()) { + int orientation = Launcher.getLauncher(getContext()).getOrientation(); + if (mQsb != null && mQsb.isReinflateRequired(orientation)) { rebindFragment(); } } diff --git a/src/com/android/launcher3/qsb/QsbWidgetHostView.java b/src/com/android/launcher3/qsb/QsbWidgetHostView.java index 8b6fa1651..a8a41f664 100644 --- a/src/com/android/launcher3/qsb/QsbWidgetHostView.java +++ b/src/com/android/launcher3/qsb/QsbWidgetHostView.java @@ -47,9 +47,9 @@ public class QsbWidgetHostView extends AppWidgetHostView { } - public boolean isReinflateRequired() { + public boolean isReinflateRequired(int orientation) { // Re-inflate is required if the orientation has changed since last inflation. - return mPreviousOrientation != getResources().getConfiguration().orientation; + return mPreviousOrientation != orientation; } |