Wed, 31 Dec 2014 07:22:50 +0100
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 java.util.Locale; |
michael@0 | 8 | |
michael@0 | 9 | import org.mozilla.gecko.AppConstants; |
michael@0 | 10 | import org.mozilla.gecko.R; |
michael@0 | 11 | import org.mozilla.gecko.background.common.log.Logger; |
michael@0 | 12 | import org.mozilla.gecko.background.fxa.FxAccountAgeLockoutHelper; |
michael@0 | 13 | import org.mozilla.gecko.fxa.FirefoxAccounts; |
michael@0 | 14 | import org.mozilla.gecko.fxa.FxAccountConstants; |
michael@0 | 15 | import org.mozilla.gecko.sync.Utils; |
michael@0 | 16 | import org.mozilla.gecko.sync.setup.activities.ActivityUtils; |
michael@0 | 17 | import org.mozilla.gecko.sync.setup.activities.LocaleAware; |
michael@0 | 18 | |
michael@0 | 19 | import android.accounts.AccountAuthenticatorActivity; |
michael@0 | 20 | import android.content.Intent; |
michael@0 | 21 | import android.os.Bundle; |
michael@0 | 22 | import android.os.SystemClock; |
michael@0 | 23 | import android.view.View; |
michael@0 | 24 | import android.view.View.OnClickListener; |
michael@0 | 25 | import android.widget.TextView; |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * Activity which displays sign up/sign in screen to the user. |
michael@0 | 29 | */ |
michael@0 | 30 | public class FxAccountGetStartedActivity extends AccountAuthenticatorActivity { |
michael@0 | 31 | protected static final String LOG_TAG = FxAccountGetStartedActivity.class.getSimpleName(); |
michael@0 | 32 | |
michael@0 | 33 | private static final int CHILD_REQUEST_CODE = 1; |
michael@0 | 34 | |
michael@0 | 35 | /** |
michael@0 | 36 | * {@inheritDoc} |
michael@0 | 37 | */ |
michael@0 | 38 | @Override |
michael@0 | 39 | public void onCreate(Bundle icicle) { |
michael@0 | 40 | Logger.setThreadLogTag(FxAccountConstants.GLOBAL_LOG_TAG); |
michael@0 | 41 | Logger.debug(LOG_TAG, "onCreate(" + icicle + ")"); |
michael@0 | 42 | |
michael@0 | 43 | LocaleAware.initializeLocale(getApplicationContext()); |
michael@0 | 44 | |
michael@0 | 45 | super.onCreate(icicle); |
michael@0 | 46 | |
michael@0 | 47 | setContentView(R.layout.fxaccount_get_started); |
michael@0 | 48 | |
michael@0 | 49 | linkifyOldFirefoxLink(); |
michael@0 | 50 | |
michael@0 | 51 | View button = findViewById(R.id.get_started_button); |
michael@0 | 52 | button.setOnClickListener(new OnClickListener() { |
michael@0 | 53 | @Override |
michael@0 | 54 | public void onClick(View v) { |
michael@0 | 55 | Intent intent = new Intent(FxAccountGetStartedActivity.this, FxAccountCreateAccountActivity.class); |
michael@0 | 56 | // Per http://stackoverflow.com/a/8992365, this triggers a known bug with |
michael@0 | 57 | // the soft keyboard not being shown for the started activity. Why, Android, why? |
michael@0 | 58 | intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); |
michael@0 | 59 | startActivityForResult(intent, CHILD_REQUEST_CODE); |
michael@0 | 60 | } |
michael@0 | 61 | }); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | @Override |
michael@0 | 65 | public void onResume() { |
michael@0 | 66 | super.onResume(); |
michael@0 | 67 | |
michael@0 | 68 | Intent intent = null; |
michael@0 | 69 | if (FxAccountAgeLockoutHelper.isLockedOut(SystemClock.elapsedRealtime())) { |
michael@0 | 70 | intent = new Intent(this, FxAccountCreateAccountNotAllowedActivity.class); |
michael@0 | 71 | } else if (FirefoxAccounts.firefoxAccountsExist(this)) { |
michael@0 | 72 | intent = new Intent(this, FxAccountStatusActivity.class); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | if (intent != null) { |
michael@0 | 76 | this.setAccountAuthenticatorResult(null); |
michael@0 | 77 | setResult(RESULT_CANCELED); |
michael@0 | 78 | // Per http://stackoverflow.com/a/8992365, this triggers a known bug with |
michael@0 | 79 | // the soft keyboard not being shown for the started activity. Why, Android, why? |
michael@0 | 80 | intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); |
michael@0 | 81 | this.startActivity(intent); |
michael@0 | 82 | this.finish(); |
michael@0 | 83 | } |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | /** |
michael@0 | 87 | * We started the CreateAccount activity for a result; this returns it to the |
michael@0 | 88 | * authenticator. |
michael@0 | 89 | */ |
michael@0 | 90 | @Override |
michael@0 | 91 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
michael@0 | 92 | Logger.debug(LOG_TAG, "onActivityResult: " + requestCode + ", " + resultCode); |
michael@0 | 93 | if (requestCode != CHILD_REQUEST_CODE) { |
michael@0 | 94 | super.onActivityResult(requestCode, resultCode, data); |
michael@0 | 95 | return; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | this.setResult(requestCode, data); |
michael@0 | 99 | if (data != null) { |
michael@0 | 100 | this.setAccountAuthenticatorResult(data.getExtras()); |
michael@0 | 101 | |
michael@0 | 102 | // We want to drop ourselves off the back stack if the user successfully |
michael@0 | 103 | // created or signed in to an account. We can easily determine this by |
michael@0 | 104 | // checking for the presence of response data. |
michael@0 | 105 | this.finish(); |
michael@0 | 106 | } |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | protected void linkifyOldFirefoxLink() { |
michael@0 | 110 | TextView oldFirefox = (TextView) findViewById(R.id.old_firefox); |
michael@0 | 111 | String text = getResources().getString(R.string.fxaccount_getting_started_old_firefox); |
michael@0 | 112 | String VERSION = AppConstants.MOZ_APP_VERSION; |
michael@0 | 113 | String OS = AppConstants.OS_TARGET; |
michael@0 | 114 | |
michael@0 | 115 | String LOCALE = Utils.getLanguageTag(Locale.getDefault()); |
michael@0 | 116 | String url = getResources().getString(R.string.fxaccount_link_old_firefox, VERSION, OS, LOCALE); |
michael@0 | 117 | FxAccountConstants.pii(LOG_TAG, "Old Firefox url is: " + url); // Don't want to leak locale in particular. |
michael@0 | 118 | ActivityUtils.linkTextView(oldFirefox, text, url); |
michael@0 | 119 | } |
michael@0 | 120 | } |