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.

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

mercurial