diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /mobile/android/services/src/main/java/org/mozilla/gecko/fxa/activities/FxAccountAbstractActivity.java | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'mobile/android/services/src/main/java/org/mozilla/gecko/fxa/activities/FxAccountAbstractActivity.java')
-rw-r--r-- | mobile/android/services/src/main/java/org/mozilla/gecko/fxa/activities/FxAccountAbstractActivity.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/activities/FxAccountAbstractActivity.java b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/activities/FxAccountAbstractActivity.java new file mode 100644 index 000000000..fc8cbf0da --- /dev/null +++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/activities/FxAccountAbstractActivity.java @@ -0,0 +1,80 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.gecko.fxa.activities; + +import android.accounts.Account; +import android.app.Activity; +import android.content.Intent; + +import org.mozilla.gecko.Locales.LocaleAwareActivity; +import org.mozilla.gecko.fxa.FirefoxAccounts; +import org.mozilla.gecko.fxa.FxAccountConstants; + +public abstract class FxAccountAbstractActivity extends LocaleAwareActivity { + private static final String LOG_TAG = FxAccountAbstractActivity.class.getSimpleName(); + + protected final boolean cannotResumeWhenAccountsExist; + protected final boolean cannotResumeWhenNoAccountsExist; + + public static final int CAN_ALWAYS_RESUME = 0; + public static final int CANNOT_RESUME_WHEN_ACCOUNTS_EXIST = 1 << 0; + public static final int CANNOT_RESUME_WHEN_NO_ACCOUNTS_EXIST = 1 << 1; + + public FxAccountAbstractActivity(int resume) { + super(); + this.cannotResumeWhenAccountsExist = 0 != (resume & CANNOT_RESUME_WHEN_ACCOUNTS_EXIST); + this.cannotResumeWhenNoAccountsExist = 0 != (resume & CANNOT_RESUME_WHEN_NO_ACCOUNTS_EXIST); + } + + /** + * Many Firefox Accounts activities shouldn't display if an account already + * exists. This function redirects as appropriate. + * + * @return true if redirected. + */ + protected boolean redirectIfAppropriate() { + if (cannotResumeWhenAccountsExist || cannotResumeWhenNoAccountsExist) { + final Account account = FirefoxAccounts.getFirefoxAccount(this); + if (cannotResumeWhenAccountsExist && account != null) { + redirectToAction(FxAccountConstants.ACTION_FXA_STATUS); + return true; + } + if (cannotResumeWhenNoAccountsExist && account == null) { + redirectToAction(FxAccountConstants.ACTION_FXA_GET_STARTED); + return true; + } + } + return false; + } + + @Override + public void onResume() { + super.onResume(); + redirectIfAppropriate(); + } + + @Override + public void onBackPressed() { + super.onBackPressed(); + overridePendingTransition(0, 0); + } + + protected void launchActivity(Class<? extends Activity> activityClass) { + Intent intent = new Intent(this, activityClass); + // Per http://stackoverflow.com/a/8992365, this triggers a known bug with + // the soft keyboard not being shown for the started activity. Why, Android, why? + intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); + } + + protected void redirectToAction(final String action) { + final Intent intent = new Intent(action); + // Per http://stackoverflow.com/a/8992365, this triggers a known bug with + // the soft keyboard not being shown for the started activity. Why, Android, why? + intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); + finish(); + } +} |