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