1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/fxa/activities/FxAccountGetStartedActivity.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,120 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.fxa.activities; 1.9 + 1.10 +import java.util.Locale; 1.11 + 1.12 +import org.mozilla.gecko.AppConstants; 1.13 +import org.mozilla.gecko.R; 1.14 +import org.mozilla.gecko.background.common.log.Logger; 1.15 +import org.mozilla.gecko.background.fxa.FxAccountAgeLockoutHelper; 1.16 +import org.mozilla.gecko.fxa.FirefoxAccounts; 1.17 +import org.mozilla.gecko.fxa.FxAccountConstants; 1.18 +import org.mozilla.gecko.sync.Utils; 1.19 +import org.mozilla.gecko.sync.setup.activities.ActivityUtils; 1.20 +import org.mozilla.gecko.sync.setup.activities.LocaleAware; 1.21 + 1.22 +import android.accounts.AccountAuthenticatorActivity; 1.23 +import android.content.Intent; 1.24 +import android.os.Bundle; 1.25 +import android.os.SystemClock; 1.26 +import android.view.View; 1.27 +import android.view.View.OnClickListener; 1.28 +import android.widget.TextView; 1.29 + 1.30 +/** 1.31 + * Activity which displays sign up/sign in screen to the user. 1.32 + */ 1.33 +public class FxAccountGetStartedActivity extends AccountAuthenticatorActivity { 1.34 + protected static final String LOG_TAG = FxAccountGetStartedActivity.class.getSimpleName(); 1.35 + 1.36 + private static final int CHILD_REQUEST_CODE = 1; 1.37 + 1.38 + /** 1.39 + * {@inheritDoc} 1.40 + */ 1.41 + @Override 1.42 + public void onCreate(Bundle icicle) { 1.43 + Logger.setThreadLogTag(FxAccountConstants.GLOBAL_LOG_TAG); 1.44 + Logger.debug(LOG_TAG, "onCreate(" + icicle + ")"); 1.45 + 1.46 + LocaleAware.initializeLocale(getApplicationContext()); 1.47 + 1.48 + super.onCreate(icicle); 1.49 + 1.50 + setContentView(R.layout.fxaccount_get_started); 1.51 + 1.52 + linkifyOldFirefoxLink(); 1.53 + 1.54 + View button = findViewById(R.id.get_started_button); 1.55 + button.setOnClickListener(new OnClickListener() { 1.56 + @Override 1.57 + public void onClick(View v) { 1.58 + Intent intent = new Intent(FxAccountGetStartedActivity.this, FxAccountCreateAccountActivity.class); 1.59 + // Per http://stackoverflow.com/a/8992365, this triggers a known bug with 1.60 + // the soft keyboard not being shown for the started activity. Why, Android, why? 1.61 + intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 1.62 + startActivityForResult(intent, CHILD_REQUEST_CODE); 1.63 + } 1.64 + }); 1.65 + } 1.66 + 1.67 + @Override 1.68 + public void onResume() { 1.69 + super.onResume(); 1.70 + 1.71 + Intent intent = null; 1.72 + if (FxAccountAgeLockoutHelper.isLockedOut(SystemClock.elapsedRealtime())) { 1.73 + intent = new Intent(this, FxAccountCreateAccountNotAllowedActivity.class); 1.74 + } else if (FirefoxAccounts.firefoxAccountsExist(this)) { 1.75 + intent = new Intent(this, FxAccountStatusActivity.class); 1.76 + } 1.77 + 1.78 + if (intent != null) { 1.79 + this.setAccountAuthenticatorResult(null); 1.80 + setResult(RESULT_CANCELED); 1.81 + // Per http://stackoverflow.com/a/8992365, this triggers a known bug with 1.82 + // the soft keyboard not being shown for the started activity. Why, Android, why? 1.83 + intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 1.84 + this.startActivity(intent); 1.85 + this.finish(); 1.86 + } 1.87 + } 1.88 + 1.89 + /** 1.90 + * We started the CreateAccount activity for a result; this returns it to the 1.91 + * authenticator. 1.92 + */ 1.93 + @Override 1.94 + public void onActivityResult(int requestCode, int resultCode, Intent data) { 1.95 + Logger.debug(LOG_TAG, "onActivityResult: " + requestCode + ", " + resultCode); 1.96 + if (requestCode != CHILD_REQUEST_CODE) { 1.97 + super.onActivityResult(requestCode, resultCode, data); 1.98 + return; 1.99 + } 1.100 + 1.101 + this.setResult(requestCode, data); 1.102 + if (data != null) { 1.103 + this.setAccountAuthenticatorResult(data.getExtras()); 1.104 + 1.105 + // We want to drop ourselves off the back stack if the user successfully 1.106 + // created or signed in to an account. We can easily determine this by 1.107 + // checking for the presence of response data. 1.108 + this.finish(); 1.109 + } 1.110 + } 1.111 + 1.112 + protected void linkifyOldFirefoxLink() { 1.113 + TextView oldFirefox = (TextView) findViewById(R.id.old_firefox); 1.114 + String text = getResources().getString(R.string.fxaccount_getting_started_old_firefox); 1.115 + String VERSION = AppConstants.MOZ_APP_VERSION; 1.116 + String OS = AppConstants.OS_TARGET; 1.117 + 1.118 + String LOCALE = Utils.getLanguageTag(Locale.getDefault()); 1.119 + String url = getResources().getString(R.string.fxaccount_link_old_firefox, VERSION, OS, LOCALE); 1.120 + FxAccountConstants.pii(LOG_TAG, "Old Firefox url is: " + url); // Don't want to leak locale in particular. 1.121 + ActivityUtils.linkTextView(oldFirefox, text, url); 1.122 + } 1.123 +}