diff options
author | Jay Shrauner <shrauner@google.com> | 2015-09-25 21:47:03 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-09-25 21:47:03 +0000 |
commit | 034bbc1e7c9275fdf3ac8ad29063969b6c1502ab (patch) | |
tree | 72c844aa149d118b3afe61d87a68ec67e85ba828 | |
parent | ab8c1f2c9e0d86b4d3865d24300d90db40bafdef (diff) | |
parent | 028f3e71a532ce3f94f72730f78f8c2f6b51dd53 (diff) |
am 028f3e71: Merge "Use TransactionSafeActivity" into ub-contactsdialer-a-dev
* commit '028f3e71a532ce3f94f72730f78f8c2f6b51dd53':
Use TransactionSafeActivity
4 files changed, 38 insertions, 81 deletions
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index fe828a3bb..4febd9684 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -158,8 +158,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O */ private SmartDialSearchFragment mSmartDialSearchFragment; - private boolean mIsVisible; - /** * Animation that slides in. */ @@ -564,25 +562,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } @Override - protected void onStart() { - super.onStart(); - mIsVisible = true; - } - - @Override - protected void onStop() { - mIsVisible = false; - super.onStop(); - } - - /** - * Returns true when the Activity is currently visible (between onStart and onStop). - */ - /* package */ boolean isVisible() { - return mIsVisible; - } - - @Override protected void onPause() { if (mClearSearchOnPause) { hideDialpadAndSearchUi(); @@ -596,7 +575,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O @Override protected void onSaveInstanceState(Bundle outState) { - mIsVisible = false; super.onSaveInstanceState(outState); outState.putString(KEY_SEARCH_QUERY, mSearchQuery); outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch); @@ -669,7 +647,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O @Override public boolean onMenuItemClick(MenuItem item) { - if (!isVisible()) { + if (!isSafeToCommitTransactions()) { return true; } diff --git a/src/com/android/dialer/calllog/CallLogActivity.java b/src/com/android/dialer/calllog/CallLogActivity.java index ad795f9bd..2bcd8d492 100644 --- a/src/com/android/dialer/calllog/CallLogActivity.java +++ b/src/com/android/dialer/calllog/CallLogActivity.java @@ -27,7 +27,6 @@ import android.provider.CallLog.Calls; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -40,16 +39,15 @@ import com.android.contacts.common.util.PermissionsUtil; import com.android.contacts.commonbind.analytics.AnalyticsUtil; import com.android.dialer.DialtactsActivity; import com.android.dialer.R; +import com.android.dialer.TransactionSafeActivity; -public class CallLogActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener { +public class CallLogActivity extends TransactionSafeActivity implements ViewPager.OnPageChangeListener { private ViewPager mViewPager; private ViewPagerTabs mViewPagerTabs; private ViewPagerAdapter mViewPagerAdapter; private CallLogFragment mAllCallsFragment; private CallLogFragment mMissedCallsFragment; - private boolean mIsVisible; - private String[] mTabTitles; private static final int TAB_INDEX_ALL = 0; @@ -163,31 +161,6 @@ public class CallLogActivity extends AppCompatActivity implements ViewPager.OnPa } @Override - protected void onStart() { - super.onStart(); - mIsVisible = false; - } - - @Override - protected void onStop() { - mIsVisible = false; - super.onStop(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - mIsVisible = false; - super.onSaveInstanceState(outState); - } - - /** - * Returns true when the Activity is currently visible (between onStart and onStop). - */ - /* package */ boolean isVisible() { - return mIsVisible; - } - - @Override public boolean onCreateOptionsMenu(Menu menu) { final MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.call_log_options, menu); @@ -207,7 +180,7 @@ public class CallLogActivity extends AppCompatActivity implements ViewPager.OnPa @Override public boolean onOptionsItemSelected(MenuItem item) { - if (!isVisible()) { + if (!isSafeToCommitTransactions()) { return true; } diff --git a/src/com/android/dialer/settings/AppCompatPreferenceActivity.java b/src/com/android/dialer/settings/AppCompatPreferenceActivity.java index 804d47758..4e5d9c90e 100644 --- a/src/com/android/dialer/settings/AppCompatPreferenceActivity.java +++ b/src/com/android/dialer/settings/AppCompatPreferenceActivity.java @@ -32,11 +32,14 @@ import android.view.ViewGroup; public class AppCompatPreferenceActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; + private boolean mIsSafeToCommitTransactions; + @Override protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); + mIsSafeToCommitTransactions = true; } @Override @@ -119,4 +122,34 @@ public class AppCompatPreferenceActivity extends PreferenceActivity { } return mDelegate; } + + @Override + protected void onStart() { + super.onStart(); + mIsSafeToCommitTransactions = true; + } + + @Override + protected void onResume() { + super.onResume(); + mIsSafeToCommitTransactions = true; + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mIsSafeToCommitTransactions = false; + } + + /** + * Returns true if it is safe to commit {@link FragmentTransaction}s at this time, based on + * whether {@link Activity#onSaveInstanceState} has been called or not. + * + * Make sure that the current activity calls into + * {@link super.onSaveInstanceState(Bundle outState)} (if that method is overridden), + * so the flag is properly set. + */ + public boolean isSafeToCommitTransactions() { + return mIsSafeToCommitTransactions; + } } diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java index fee0fa88e..58b0ab8e6 100644 --- a/src/com/android/dialer/settings/DialerSettingsActivity.java +++ b/src/com/android/dialer/settings/DialerSettingsActivity.java @@ -35,8 +35,6 @@ import java.util.List; public class DialerSettingsActivity extends AppCompatPreferenceActivity { protected SharedPreferences mPreferences; - private boolean mIsVisible; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -44,31 +42,6 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { } @Override - protected void onStart() { - super.onStart(); - mIsVisible = true; - } - - @Override - protected void onStop() { - mIsVisible = false; - super.onStop(); - } - - @Override - protected void onSaveInstanceState(Bundle out) { - mIsVisible = false; - super.onSaveInstanceState(out); - } - - /** - * Returns true when the Activity is currently visible (between onStart and onStop). - */ - /* package */ boolean isVisible() { - return mIsVisible; - } - - @Override public void onBuildHeaders(List<Header> target) { Header displayOptionsHeader = new Header(); displayOptionsHeader.titleRes = R.string.display_options_title; @@ -159,7 +132,7 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { @Override public void onBackPressed() { - if (!isVisible()) { + if (!isSafeToCommitTransactions()) { return; } super.onBackPressed(); |