michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.fxa.activities; michael@0: michael@0: import java.util.Locale; michael@0: michael@0: import org.mozilla.gecko.AppConstants; michael@0: import org.mozilla.gecko.R; michael@0: import org.mozilla.gecko.background.common.log.Logger; michael@0: import org.mozilla.gecko.background.fxa.FxAccountAgeLockoutHelper; michael@0: import org.mozilla.gecko.fxa.FirefoxAccounts; michael@0: import org.mozilla.gecko.fxa.FxAccountConstants; michael@0: import org.mozilla.gecko.sync.Utils; michael@0: import org.mozilla.gecko.sync.setup.activities.ActivityUtils; michael@0: import org.mozilla.gecko.sync.setup.activities.LocaleAware; michael@0: michael@0: import android.accounts.AccountAuthenticatorActivity; michael@0: import android.content.Intent; michael@0: import android.os.Bundle; michael@0: import android.os.SystemClock; michael@0: import android.view.View; michael@0: import android.view.View.OnClickListener; michael@0: import android.widget.TextView; michael@0: michael@0: /** michael@0: * Activity which displays sign up/sign in screen to the user. michael@0: */ michael@0: public class FxAccountGetStartedActivity extends AccountAuthenticatorActivity { michael@0: protected static final String LOG_TAG = FxAccountGetStartedActivity.class.getSimpleName(); michael@0: michael@0: private static final int CHILD_REQUEST_CODE = 1; michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: @Override michael@0: public void onCreate(Bundle icicle) { michael@0: Logger.setThreadLogTag(FxAccountConstants.GLOBAL_LOG_TAG); michael@0: Logger.debug(LOG_TAG, "onCreate(" + icicle + ")"); michael@0: michael@0: LocaleAware.initializeLocale(getApplicationContext()); michael@0: michael@0: super.onCreate(icicle); michael@0: michael@0: setContentView(R.layout.fxaccount_get_started); michael@0: michael@0: linkifyOldFirefoxLink(); michael@0: michael@0: View button = findViewById(R.id.get_started_button); michael@0: button.setOnClickListener(new OnClickListener() { michael@0: @Override michael@0: public void onClick(View v) { michael@0: Intent intent = new Intent(FxAccountGetStartedActivity.this, FxAccountCreateAccountActivity.class); michael@0: // Per http://stackoverflow.com/a/8992365, this triggers a known bug with michael@0: // the soft keyboard not being shown for the started activity. Why, Android, why? michael@0: intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); michael@0: startActivityForResult(intent, CHILD_REQUEST_CODE); michael@0: } michael@0: }); michael@0: } michael@0: michael@0: @Override michael@0: public void onResume() { michael@0: super.onResume(); michael@0: michael@0: Intent intent = null; michael@0: if (FxAccountAgeLockoutHelper.isLockedOut(SystemClock.elapsedRealtime())) { michael@0: intent = new Intent(this, FxAccountCreateAccountNotAllowedActivity.class); michael@0: } else if (FirefoxAccounts.firefoxAccountsExist(this)) { michael@0: intent = new Intent(this, FxAccountStatusActivity.class); michael@0: } michael@0: michael@0: if (intent != null) { michael@0: this.setAccountAuthenticatorResult(null); michael@0: setResult(RESULT_CANCELED); michael@0: // Per http://stackoverflow.com/a/8992365, this triggers a known bug with michael@0: // the soft keyboard not being shown for the started activity. Why, Android, why? michael@0: intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); michael@0: this.startActivity(intent); michael@0: this.finish(); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * We started the CreateAccount activity for a result; this returns it to the michael@0: * authenticator. michael@0: */ michael@0: @Override michael@0: public void onActivityResult(int requestCode, int resultCode, Intent data) { michael@0: Logger.debug(LOG_TAG, "onActivityResult: " + requestCode + ", " + resultCode); michael@0: if (requestCode != CHILD_REQUEST_CODE) { michael@0: super.onActivityResult(requestCode, resultCode, data); michael@0: return; michael@0: } michael@0: michael@0: this.setResult(requestCode, data); michael@0: if (data != null) { michael@0: this.setAccountAuthenticatorResult(data.getExtras()); michael@0: michael@0: // We want to drop ourselves off the back stack if the user successfully michael@0: // created or signed in to an account. We can easily determine this by michael@0: // checking for the presence of response data. michael@0: this.finish(); michael@0: } michael@0: } michael@0: michael@0: protected void linkifyOldFirefoxLink() { michael@0: TextView oldFirefox = (TextView) findViewById(R.id.old_firefox); michael@0: String text = getResources().getString(R.string.fxaccount_getting_started_old_firefox); michael@0: String VERSION = AppConstants.MOZ_APP_VERSION; michael@0: String OS = AppConstants.OS_TARGET; michael@0: michael@0: String LOCALE = Utils.getLanguageTag(Locale.getDefault()); michael@0: String url = getResources().getString(R.string.fxaccount_link_old_firefox, VERSION, OS, LOCALE); michael@0: FxAccountConstants.pii(LOG_TAG, "Old Firefox url is: " + url); // Don't want to leak locale in particular. michael@0: ActivityUtils.linkTextView(oldFirefox, text, url); michael@0: } michael@0: }