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
This commit is contained in:
Jon Miranda
2017-09-19 14:43:17 -07:00
parent d926a9316f
commit 6bed350b75
6 changed files with 15 additions and 7 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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 */);

View File

@@ -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();
}
}

View File

@@ -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;
}