mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 1056225 - Part 2: Lift onConfigurationChanged to HomeFragment. r=margaret
I took the most commented version. There are two things to note here: * Several panels did not define onConfigurationChanged. It's not clear if these panels didn't need it (after some analysis?) or if they just didn't copy-paste thoroughly. This version is always safe, if inefficient, and I've commented to say as much. * The order of operations for the Bookmarks panel may be delicate. I did not preserve the original order (save stack first, then detach and attach); it appears to not be necessary to save the stack first, because the configuration change is completed before the containing Activity is restarted (and the stack is restored). I tested that the folder stack was preserved across device rotations locally.
This commit is contained in:
parent
7b23628793
commit
da294de55b
@ -140,23 +140,10 @@ public class BookmarksPanel extends HomeFragment {
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
// Reattach the fragment, forcing a reinflation of its view.
|
||||
// We use commitAllowingStateLoss() instead of commit() here to avoid
|
||||
// an IllegalStateException. If the phone is rotated while Fennec
|
||||
// is in the background, onConfigurationChanged() is fired.
|
||||
// onConfigurationChanged() is called before onResume(), so
|
||||
// using commit() would throw an IllegalStateException since it can't
|
||||
// be used between the Activity's onSaveInstanceState() and
|
||||
// onResume().
|
||||
if (isVisible()) {
|
||||
// The parent stack is saved just so that the folder state can be
|
||||
// restored on rotation.
|
||||
mSavedParentStack = mListAdapter.getParentStack();
|
||||
|
||||
getFragmentManager().beginTransaction()
|
||||
.detach(this)
|
||||
.attach(this)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ import org.mozilla.gecko.util.UiAsyncTask;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@ -143,19 +142,6 @@ public class DynamicPanel extends HomeFragment {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
// Detach and reattach the fragment as the layout changes.
|
||||
if (isVisible()) {
|
||||
getFragmentManager().beginTransaction()
|
||||
.detach(this)
|
||||
.attach(this)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
@ -272,9 +272,35 @@ abstract class HomeFragment extends Fragment {
|
||||
loadIfVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a configuration change by detaching and re-attaching.
|
||||
* <p>
|
||||
* A HomeFragment only needs to handle onConfiguration change (i.e.,
|
||||
* re-attach) if its UI needs to change (i.e., re-inflate layouts, use
|
||||
* different styles, etc) for different device orientations. Handling
|
||||
* configuration changes in all HomeFragments will simply cause some
|
||||
* redundant re-inflations on device rotation. This slight inefficiency
|
||||
* avoids potentially not handling a needed onConfigurationChanged in a
|
||||
* subclass.
|
||||
*/
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
// Reattach the fragment, forcing a re-inflation of its view.
|
||||
// We use commitAllowingStateLoss() instead of commit() here to avoid
|
||||
// an IllegalStateException. If the phone is rotated while Fennec
|
||||
// is in the background, onConfigurationChanged() is fired.
|
||||
// onConfigurationChanged() is called before onResume(), so
|
||||
// using commit() would throw an IllegalStateException since it can't
|
||||
// be used between the Activity's onSaveInstanceState() and
|
||||
// onResume().
|
||||
if (isVisible()) {
|
||||
getFragmentManager().beginTransaction()
|
||||
.detach(this)
|
||||
.attach(this)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
|
||||
void setCanLoadHint(boolean canLoadHint) {
|
||||
|
@ -17,7 +17,6 @@ import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
||||
@ -112,19 +111,6 @@ public class ReadingListPanel extends HomeFragment {
|
||||
mEmptyView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
// Detach and reattach the fragment as the layout changes.
|
||||
if (isVisible()) {
|
||||
getFragmentManager().beginTransaction()
|
||||
.detach(this)
|
||||
.attach(this)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
@ -27,7 +27,6 @@ import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.database.MatrixCursor.RowBuilder;
|
||||
@ -48,6 +47,7 @@ import android.widget.TextView;
|
||||
public class RecentTabsPanel extends HomeFragment
|
||||
implements NativeEventListener {
|
||||
// Logging tag name
|
||||
@SuppressWarnings("unused")
|
||||
private static final String LOGTAG = "GeckoRecentTabsPanel";
|
||||
|
||||
// Cursor loader ID for the loader that loads recent tabs
|
||||
@ -181,19 +181,6 @@ public class RecentTabsPanel extends HomeFragment
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("ClosedTabs:StopNotifications", null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
// Detach and reattach the fragment as the layout changes.
|
||||
if (isVisible()) {
|
||||
getFragmentManager().beginTransaction()
|
||||
.detach(this)
|
||||
.attach(this)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
@ -35,7 +35,6 @@ import org.mozilla.gecko.util.ThreadUtils;
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
@ -213,19 +212,6 @@ public class TopSitesPanel extends HomeFragment {
|
||||
mGridAdapter = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
// Detach and reattach the fragment as the layout changes.
|
||||
if (isVisible()) {
|
||||
getFragmentManager().beginTransaction()
|
||||
.detach(this)
|
||||
.attach(this)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
Loading…
Reference in New Issue
Block a user