mobile/android/base/fxa/activities/FxAccountStatusActivity.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.fxa.activities;
michael@0 6
michael@0 7 import org.mozilla.gecko.background.common.log.Logger;
michael@0 8 import org.mozilla.gecko.fxa.FirefoxAccounts;
michael@0 9 import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
michael@0 10 import org.mozilla.gecko.sync.setup.activities.LocaleAware.LocaleAwareFragmentActivity;
michael@0 11
michael@0 12 import android.accounts.Account;
michael@0 13 import android.annotation.TargetApi;
michael@0 14 import android.app.ActionBar;
michael@0 15 import android.content.Intent;
michael@0 16 import android.os.Build;
michael@0 17 import android.os.Bundle;
michael@0 18 import android.view.MenuItem;
michael@0 19
michael@0 20 /**
michael@0 21 * Activity which displays account status.
michael@0 22 */
michael@0 23 public class FxAccountStatusActivity extends LocaleAwareFragmentActivity {
michael@0 24 private static final String LOG_TAG = FxAccountStatusActivity.class.getSimpleName();
michael@0 25
michael@0 26 protected FxAccountStatusFragment statusFragment;
michael@0 27
michael@0 28 @Override
michael@0 29 protected void onCreate(Bundle savedInstanceState) {
michael@0 30 super.onCreate(savedInstanceState);
michael@0 31
michael@0 32 // Display the fragment as the content.
michael@0 33 statusFragment = new FxAccountStatusFragment();
michael@0 34 getSupportFragmentManager()
michael@0 35 .beginTransaction()
michael@0 36 .replace(android.R.id.content, statusFragment)
michael@0 37 .commit();
michael@0 38
michael@0 39 maybeSetHomeButtonEnabled();
michael@0 40 }
michael@0 41
michael@0 42 /**
michael@0 43 * Sufficiently recent Android versions need additional code to receive taps
michael@0 44 * on the status bar to go "up". See <a
michael@0 45 * href="http://stackoverflow.com/a/8953148">this stackoverflow answer</a> for
michael@0 46 * more information.
michael@0 47 */
michael@0 48 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
michael@0 49 protected void maybeSetHomeButtonEnabled() {
michael@0 50 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
michael@0 51 Logger.debug(LOG_TAG, "Not enabling home button; version too low.");
michael@0 52 return;
michael@0 53 }
michael@0 54 final ActionBar actionBar = getActionBar();
michael@0 55 if (actionBar != null) {
michael@0 56 Logger.debug(LOG_TAG, "Enabling home button.");
michael@0 57 actionBar.setHomeButtonEnabled(true);
michael@0 58 return;
michael@0 59 }
michael@0 60 Logger.debug(LOG_TAG, "Not enabling home button.");
michael@0 61 }
michael@0 62
michael@0 63 @Override
michael@0 64 public void onResume() {
michael@0 65 super.onResume();
michael@0 66
michael@0 67 final AndroidFxAccount fxAccount = getAndroidFxAccount();
michael@0 68 if (fxAccount == null) {
michael@0 69 Logger.warn(LOG_TAG, "Could not get Firefox Account.");
michael@0 70
michael@0 71 // Gracefully redirect to get started.
michael@0 72 Intent intent = new Intent(this, FxAccountGetStartedActivity.class);
michael@0 73 // Per http://stackoverflow.com/a/8992365, this triggers a known bug with
michael@0 74 // the soft keyboard not being shown for the started activity. Why, Android, why?
michael@0 75 intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
michael@0 76 startActivity(intent);
michael@0 77
michael@0 78 setResult(RESULT_CANCELED);
michael@0 79 finish();
michael@0 80 return;
michael@0 81 }
michael@0 82 statusFragment.refresh(fxAccount);
michael@0 83 }
michael@0 84
michael@0 85 /**
michael@0 86 * Helper to fetch (unique) Android Firefox Account if one exists, or return null.
michael@0 87 */
michael@0 88 protected AndroidFxAccount getAndroidFxAccount() {
michael@0 89 Account account = FirefoxAccounts.getFirefoxAccount(this);
michael@0 90 if (account == null) {
michael@0 91 return null;
michael@0 92 }
michael@0 93 return new AndroidFxAccount(this, account);
michael@0 94 }
michael@0 95
michael@0 96 @Override
michael@0 97 public boolean onOptionsItemSelected(MenuItem item) {
michael@0 98 int itemId = item.getItemId();
michael@0 99 switch (itemId) {
michael@0 100 case android.R.id.home:
michael@0 101 finish();
michael@0 102 return true;
michael@0 103 }
michael@0 104 return super.onOptionsItemSelected(item);
michael@0 105 }
michael@0 106 }

mercurial