summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Shrauner <shrauner@google.com>2015-09-25 14:13:16 -0700
committerJay Shrauner <shrauner@google.com>2015-09-25 14:13:16 -0700
commit193cfc5458c5c2bb1f9800c98f179292732aa0a8 (patch)
tree7435910793f6cece645382f60800c07922b67e4e
parentc2fbff362cff30cf547248240e4e4cf2ae8a3c7d (diff)
Use TransactionSafeActivity
Remove custom visibility tracking. Bug:24294419 Change-Id: I2ef53549e7d8c07e92319bc57c4aebd05edb8ea6
-rw-r--r--src/com/android/dialer/DialtactsActivity.java24
-rw-r--r--src/com/android/dialer/calllog/CallLogActivity.java33
-rw-r--r--src/com/android/dialer/settings/AppCompatPreferenceActivity.java33
-rw-r--r--src/com/android/dialer/settings/DialerSettingsActivity.java29
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();