Don't reset message view when becoming active again.

- We used to (re-)load the content on every onStart(),
  which is called too when coming back from other actibities.
  So if you go home and come back with the task switcher,
  all state get reset, including webview zoom/pan and the current tab.

- Introduce a new flag, mLoadWhenResumed, to tell if we really need to
  load a message.

Also:
- Start loading a message in onResume() rather than onStart()
  to keep it consistent with other fragments.

Bug 3215269

Change-Id: I1cc6e12c3cc3c08065da3696603a3247f341469a
This commit is contained in:
Makoto Onuki 2010-11-19 15:03:37 -08:00
parent 00fb407689
commit 4c9e1a3fde
3 changed files with 31 additions and 20 deletions

View File

@ -88,7 +88,7 @@ public class MessageFileViewFragment extends MessageViewFragmentBase {
synchronized (mLock) {
mFileEmailUri = fileEmailUri;
}
openMessageIfStarted();
loadMessageIfResumed();
}
@Override

View File

@ -220,7 +220,7 @@ public class MessageViewFragment extends MessageViewFragmentBase {
synchronized (mLock) {
mMessageIdToOpen = messageId;
}
openMessageIfStarted();
loadMessageIfResumed();
}
@Override

View File

@ -147,7 +147,8 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
// contains the HTML content as set in WebView.
private String mHtmlTextWebView;
private boolean mStarted;
private boolean mResumed;
private boolean mLoadWhenResumed;
private boolean mIsMessageLoadedForTest;
@ -347,10 +348,6 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
Log.d(Email.LOG_TAG, "MessageViewFragment onStart");
}
super.onStart();
mStarted = true;
if (isMessageSpecified()) {
openMessageIfStarted();
}
}
@Override
@ -360,17 +357,17 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
}
super.onResume();
// Dynamic configuration of WebView
WebSettings.TextSize textZoom;
switch (Preferences.getPreferences(mContext).getTextZoom()) {
case Preferences.TEXT_ZOOM_TINY: textZoom = WebSettings.TextSize.SMALLEST; break;
case Preferences.TEXT_ZOOM_SMALL: textZoom = WebSettings.TextSize.SMALLER; break;
case Preferences.TEXT_ZOOM_NORMAL: textZoom = WebSettings.TextSize.NORMAL; break;
case Preferences.TEXT_ZOOM_LARGE: textZoom = WebSettings.TextSize.LARGER; break;
case Preferences.TEXT_ZOOM_HUGE: textZoom = WebSettings.TextSize.LARGEST; break;
default: textZoom = WebSettings.TextSize.NORMAL; break;
mResumed = true;
if (isMessageSpecified()) {
if (mLoadWhenResumed) {
loadMessageIfResumed();
} else {
// This means, the user comes back from other (full-screen) activities.
// In this case we've already loaded the content, so don't load it again,
// which results in resetting all view state, including WebView zoom/pan
// and the current tab.
}
}
mMessageContentView.getSettings().setTextSize(textZoom);
}
@Override
@ -378,6 +375,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Email.LOG_TAG, "MessageViewFragment onPause");
}
mResumed = false;
super.onPause();
}
@ -386,7 +384,6 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Email.LOG_TAG, "MessageViewFragment onStop");
}
mStarted = false;
super.onStop();
}
@ -464,10 +461,12 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
resetView();
}
protected final void openMessageIfStarted() {
if (!mStarted) {
protected final void loadMessageIfResumed() {
if (!mResumed) {
mLoadWhenResumed = true;
return;
}
mLoadWhenResumed = false;
cancelAllTasks();
resetView();
mLoadMessageTask = new LoadMessageTask(true);
@ -481,6 +480,18 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
mMessageContentView.getSettings().setBlockNetworkLoads(true);
mMessageContentView.scrollTo(0, 0);
mMessageContentView.loadUrl("file:///android_asset/empty.html");
// Dynamic configuration of WebView
WebSettings.TextSize textZoom;
switch (Preferences.getPreferences(mContext).getTextZoom()) {
case Preferences.TEXT_ZOOM_TINY: textZoom = WebSettings.TextSize.SMALLEST; break;
case Preferences.TEXT_ZOOM_SMALL: textZoom = WebSettings.TextSize.SMALLER; break;
case Preferences.TEXT_ZOOM_NORMAL: textZoom = WebSettings.TextSize.NORMAL; break;
case Preferences.TEXT_ZOOM_LARGE: textZoom = WebSettings.TextSize.LARGER; break;
case Preferences.TEXT_ZOOM_HUGE: textZoom = WebSettings.TextSize.LARGEST; break;
default: textZoom = WebSettings.TextSize.NORMAL; break;
}
mMessageContentView.getSettings().setTextSize(textZoom);
}
mAttachmentsScroll.scrollTo(0, 0);
mInviteScroll.scrollTo(0, 0);