Skip to content

Commit f47f706

Browse files
ashwinraghavGerrit Code Review
authored andcommitted
Merge "Phone auth terms of service" into phone-auth
2 parents 2531fd2 + 97f0e06 commit f47f706

File tree

9 files changed

+169
-58
lines changed

9 files changed

+169
-58
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2017 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.firebase.ui.auth.ui;
16+
17+
import android.content.Context;
18+
import android.net.Uri;
19+
import android.support.annotation.ColorInt;
20+
import android.support.annotation.StringRes;
21+
import android.support.customtabs.CustomTabsIntent;
22+
import android.support.v4.content.ContextCompat;
23+
import android.text.SpannableStringBuilder;
24+
import android.text.style.ForegroundColorSpan;
25+
import android.util.AttributeSet;
26+
import android.util.TypedValue;
27+
import android.view.View;
28+
29+
import com.firebase.ui.auth.R;
30+
31+
/**
32+
* Text view to display terms of service before completing signup.
33+
* The view helps display TOS linking to the provided custom URI.
34+
* It handles the styling of the link and opens the uri in a CustomTabs on click.
35+
*/
36+
public class TermsTextView extends android.support.v7.widget.AppCompatTextView {
37+
public TermsTextView(Context context) {
38+
super(context);
39+
}
40+
41+
public TermsTextView(Context context, AttributeSet attrs) {
42+
super(context, attrs);
43+
}
44+
45+
public TermsTextView(Context context, AttributeSet attrs, int defStyleAttr) {
46+
super(context, attrs, defStyleAttr);
47+
}
48+
49+
/**
50+
* @param uri uri to link when the user clicks on Terms of Service
51+
* @param buttonText for the button that represents the "action" described in the terms.
52+
*/
53+
public void showTermsForUri(final Uri uri, @StringRes int buttonText) {
54+
// Format the terms interpolating the action string
55+
String buttonTextString = getContext().getString(buttonText);
56+
String preamble = getContext().getString(R.string.create_account_preamble,
57+
buttonTextString);
58+
//Apply the link color on the part of the string that links to the TOS upon clicking
59+
String link = getContext().getString(R.string.terms_of_service);
60+
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(preamble + link);
61+
int start = preamble.length();
62+
ForegroundColorSpan foregroundColorSpan =
63+
new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.linkColor));
64+
spannableStringBuilder.setSpan(foregroundColorSpan, start, start + link.length(), 0);
65+
setText(spannableStringBuilder);
66+
67+
// Open in custom tabs on click
68+
setOnClickListener(new View.OnClickListener() {
69+
@Override
70+
public void onClick(View view) {
71+
// Getting default color
72+
TypedValue typedValue = new TypedValue();
73+
getContext().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);
74+
@ColorInt int color = typedValue.data;
75+
76+
new CustomTabsIntent.Builder()
77+
.setToolbarColor(color)
78+
.build()
79+
.launchUrl(getContext(), uri);
80+
}
81+
});
82+
}
83+
}

auth/src/main/java/com/firebase/ui/auth/ui/email/RegisterEmailFragment.java

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.firebase.ui.auth.ui.FragmentBase;
2929
import com.firebase.ui.auth.ui.ImeHelper;
3030
import com.firebase.ui.auth.ui.TaskFailureLogger;
31+
import com.firebase.ui.auth.ui.TermsTextView;
3132
import com.firebase.ui.auth.ui.User;
3233
import com.firebase.ui.auth.ui.accountlink.WelcomeBackIdpPrompt;
3334
import com.firebase.ui.auth.ui.accountlink.WelcomeBackPasswordPrompt;
@@ -59,7 +60,7 @@ public class RegisterEmailFragment extends FragmentBase implements
5960
private EditText mEmailEditText;
6061
private EditText mNameEditText;
6162
private EditText mPasswordEditText;
62-
private TextView mAgreementText;
63+
private TermsTextView mAgreementText;
6364
private TextInputLayout mEmailInput;
6465
private TextInputLayout mPasswordInput;
6566

@@ -102,7 +103,7 @@ public View onCreateView(LayoutInflater inflater,
102103
mEmailEditText = (EditText) v.findViewById(R.id.email);
103104
mNameEditText = (EditText) v.findViewById(R.id.name);
104105
mPasswordEditText = (EditText) v.findViewById(R.id.password);
105-
mAgreementText = (TextView) v.findViewById(R.id.create_account_text);
106+
mAgreementText = (TermsTextView) v.findViewById(R.id.create_account_text);
106107
mEmailInput = (TextInputLayout) v.findViewById(R.id.email_layout);
107108
mPasswordInput = (TextInputLayout) v.findViewById(R.id.password_layout);
108109

@@ -181,33 +182,8 @@ private void setUpTermsOfService() {
181182
if (TextUtils.isEmpty(mHelper.getFlowParams().termsOfServiceUrl)) {
182183
return;
183184
}
184-
185-
ForegroundColorSpan foregroundColorSpan =
186-
new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.linkColor));
187-
188-
String preamble = getString(R.string.create_account_preamble);
189-
String link = getString(R.string.terms_of_service);
190-
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(preamble + link);
191-
int start = preamble.length();
192-
spannableStringBuilder.setSpan(foregroundColorSpan, start, start + link.length(), 0);
193-
194-
mAgreementText.setText(spannableStringBuilder);
195-
mAgreementText.setOnClickListener(new View.OnClickListener() {
196-
@Override
197-
public void onClick(View view) {
198-
// Getting default color
199-
TypedValue typedValue = new TypedValue();
200-
getActivity().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);
201-
@ColorInt int color = typedValue.data;
202-
203-
new CustomTabsIntent.Builder()
204-
.setToolbarColor(color)
205-
.build()
206-
.launchUrl(
207-
getActivity(),
208-
Uri.parse(mHelper.getFlowParams().termsOfServiceUrl));
209-
}
210-
});
185+
mAgreementText.showTermsForUri(Uri.parse(mHelper.getFlowParams().termsOfServiceUrl),
186+
R.string.button_text_save);
211187
}
212188

213189
@Override

auth/src/main/java/com/firebase/ui/auth/ui/phone/SubmitConfirmationCodeFragment.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.firebase.ui.auth.ui.phone;
1616

1717
import android.content.Context;
18+
import android.net.Uri;
1819
import android.os.Bundle;
1920
import android.support.annotation.NonNull;
2021
import android.support.annotation.Nullable;
@@ -33,6 +34,7 @@
3334
import com.firebase.ui.auth.ui.ExtraConstants;
3435
import com.firebase.ui.auth.ui.FlowParameters;
3536
import com.firebase.ui.auth.ui.FragmentBase;
37+
import com.firebase.ui.auth.ui.TermsTextView;
3638

3739
/**
3840
* Display confirmation code to verify phone numbers input in {{@link VerifyPhoneNumberFragment}}
@@ -49,6 +51,7 @@ public class SubmitConfirmationCodeFragment extends FragmentBase {
4951
Button mSubmitConfirmationButton;
5052
CustomCountDownTimer mCountdownTimer;
5153
PhoneVerificationActivity mVerifier;
54+
TermsTextView mAgreementText;
5255
long mMillisUntilFinished;
5356
private String EXTRA_MILLIS_UNTIL_FINISHED = "EXTRA_MILLIS_UNTIL_FINISHED";
5457

@@ -72,11 +75,12 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
7275
View v = inflater.inflate(R.layout.confirmation_code_layout, container, false);
7376
FragmentActivity parentActivity = getActivity();
7477

75-
this.mEditPhoneTextView = (TextView) v.findViewById(R.id.edit_phone_number);
76-
this.mCountDownTextView = (TextView) v.findViewById(R.id.ticker);
77-
this.mResendCodeTextView = (TextView) v.findViewById(R.id.resend_code);
78+
mEditPhoneTextView = (TextView) v.findViewById(R.id.edit_phone_number);
79+
mCountDownTextView = (TextView) v.findViewById(R.id.ticker);
80+
mResendCodeTextView = (TextView) v.findViewById(R.id.resend_code);
7881
mConfirmationCodeEditText = (SpacedEditText) v.findViewById(R.id.confirmation_code);
79-
this.mSubmitConfirmationButton = (Button) v.findViewById(R.id.submit_confirmation_code);
82+
mSubmitConfirmationButton = (Button) v.findViewById(R.id.submit_confirmation_code);
83+
mAgreementText = (TermsTextView) v.findViewById(R.id.create_account_tos);
8084

8185
final String phoneNumber = getArguments().getString(ExtraConstants.EXTRA_PHONE);
8286

@@ -86,7 +90,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
8690
setupCountDown(RESEND_WAIT_MILLIS);
8791
setupSubmitConfirmationCodeButton();
8892
setupResendConfirmationCodeTextView(phoneNumber);
89-
93+
setUpTermsOfService();
9094
return v;
9195
}
9296

@@ -218,6 +222,14 @@ private void cancelTimer() {
218222
}
219223
}
220224

225+
private void setUpTermsOfService() {
226+
if (TextUtils.isEmpty(mHelper.getFlowParams().termsOfServiceUrl)) {
227+
return;
228+
}
229+
mAgreementText.showTermsForUri(Uri.parse(mHelper.getFlowParams().termsOfServiceUrl),
230+
R.string.continue_phone_login);
231+
}
232+
221233
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
222234
CustomCountDownTimer getmCountdownTimer() {
223235
return mCountdownTimer;

auth/src/main/java/com/firebase/ui/auth/ui/phone/VerifyPhoneNumberFragment.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class VerifyPhoneNumberFragment extends FragmentBase implements View.OnCl
5757
TextView errorEditText;
5858
Button sendCodeButton;
5959
PhoneVerificationActivity mVerifier;
60+
TextView mSmsTermsText;
6061

6162
private static final int RC_PHONE_HINT = 22;
6263

@@ -83,15 +84,23 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
8384
mPhoneEditText = (EditText) v.findViewById(R.id.phone_number);
8485
errorEditText = (TextView) v.findViewById(R.id.phone_number_error);
8586
sendCodeButton = (Button) v.findViewById(R.id.send_code);
87+
mSmsTermsText = (TextView) v.findViewById(R.id.send_sms_tos);
8688

8789
FragmentActivity parentActivity = getActivity();
8890
parentActivity.setTitle(getString(R.string.verify_phone_number_title));
8991
setUpCountrySpinner();
9092
setupSendCodeButton();
93+
setupTerms();
9194

9295
return v;
9396
}
9497

98+
private void setupTerms() {
99+
final String verifyPhoneButtonText = getString(R.string.verify_phone_number);
100+
final String terms = getString(R.string.sms_terms_of_service, verifyPhoneButtonText);
101+
mSmsTermsText.setText(terms);
102+
}
103+
95104
@Override
96105
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
97106
super.onActivityCreated(savedInstanceState);

auth/src/main/res/layout/confirmation_code_layout.xml

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,48 @@
5454
android:layout_below="@id/confirmation_code"
5555
android:text="@string/continue_phone_login" />
5656

57-
<TextView
58-
android:id="@+id/ticker"
59-
style="@style/FirebaseUI.Text.T08"
57+
<LinearLayout
58+
android:id="@+id/resend_code_layout"
6059
android:layout_width="match_parent"
61-
android:layout_height="wrap_content"
62-
android:layout_below="@+id/submit_confirmation_code"
63-
android:enabled="false"
64-
android:gravity="center"
65-
android:paddingTop="16dp"
66-
android:textAppearance="?android:attr/textAppearanceMedium"
67-
android:textColor="?attr/android:textColorSecondary"
68-
tools:ignore="SelectableText" />
60+
android:layout_height="match_parent"
61+
android:layout_below="@id/submit_confirmation_code"
62+
android:orientation="vertical">
63+
<TextView
64+
android:id="@+id/ticker"
65+
style="@style/FirebaseUI.Text.T08"
66+
tools:text = "Resend in 0:01"
67+
android:layout_width="match_parent"
68+
android:layout_height="wrap_content"
69+
android:enabled="false"
70+
android:gravity="center"
71+
android:paddingTop="16dp"
72+
android:textAppearance="?android:attr/textAppearanceMedium"
73+
android:textColor="?attr/android:textColorSecondary"
74+
tools:ignore="SelectableText" />
6975

70-
<TextView
71-
android:id="@+id/resend_code"
72-
style="@style/FirebaseUI.Text.T08"
76+
<TextView
77+
android:id="@+id/resend_code"
78+
style="@style/FirebaseUI.Text.T08"
79+
tools:text = "Resend code"
80+
android:layout_width="match_parent"
81+
android:layout_height="wrap_content"
82+
android:gravity="center"
83+
android:paddingTop="16dp"
84+
android:text="@string/resend_code"
85+
android:textAppearance="?android:attr/textAppearanceMedium"
86+
android:textColor="@color/linkColor"
87+
android:visibility="gone" />
88+
</LinearLayout>
89+
90+
<com.firebase.ui.auth.ui.TermsTextView
91+
android:id="@+id/create_account_tos"
92+
style="@style/FirebaseUI.Text.BodyText"
7393
android:layout_width="match_parent"
7494
android:layout_height="wrap_content"
75-
android:layout_below="@+id/submit_confirmation_code"
76-
android:gravity="center"
77-
android:paddingTop="16dp"
78-
android:text="@string/resend_code"
79-
android:textAppearance="?android:attr/textAppearanceMedium"
80-
android:textColor="@color/linkColor"
81-
android:visibility="gone" />
82-
95+
android:layout_marginTop="@dimen/field_padding_vert"
96+
android:textIsSelectable="false"
97+
android:layout_below="@id/resend_code_layout"
98+
tools:text="@string/create_account_preamble"/>
8399
</RelativeLayout>
84100

85101
</ScrollView>

auth/src/main/res/layout/phone_layout.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,14 @@
3939
android:layout_alignParentRight="true"
4040
android:layout_below="@id/phone_number_error"
4141
android:text="@string/verify_phone_number"/>
42+
43+
<TextView
44+
android:id="@+id/send_sms_tos"
45+
style="@style/FirebaseUI.Text.BodyText"
46+
android:layout_width="match_parent"
47+
android:layout_height="wrap_content"
48+
android:layout_below="@id/send_code"
49+
android:textColor="?android:textColorTertiary"
50+
android:layout_marginTop="@dimen/field_padding_vert"/>
4251
</RelativeLayout>
4352
</ScrollView>

auth/src/main/res/layout/register_email_layout.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
</android.support.design.widget.TextInputLayout>
6767

68-
<TextView
68+
<com.firebase.ui.auth.ui.TermsTextView
6969
android:id="@+id/create_account_text"
7070
style="@style/FirebaseUI.Text.BodyText"
7171
android:layout_width="match_parent"

auth/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</plurals>
4646
<string name="email_account_creation_error" translation_description="Inline error for signup failure">Email account registration unsuccessful</string>
4747
<string name="error_user_collision" translation_description="Inline error when user signs up using an existing email account">An account already exists with that email address.</string>
48-
<string name="create_account_preamble" translation_description="Terms of service preamble">"By tapping SAVE you are indicating that you agree to the "</string>
48+
<string name="create_account_preamble" translation_description="Terms of service preamble">"By tapping &quot;%1$s&quot; you are indicating that you agree to the "</string>
4949
<string name="terms_of_service" translation_description="Link text to web url containing the app's terms of service">Terms of Service</string>
5050

5151
<!-- Idp/Email welcome back -->
@@ -104,4 +104,5 @@
104104
<string name="resend_code" translation_description="Link text to resend verification sms">Resend Code</string>
105105
<string name="verify_phone_number" translation_description="Button text to submit confirmation code and complete phone verification">Verify Phone Number</string>
106106
<string name="continue_phone_login" translation_description="Button text to submit phone number and send sms">Continue</string>
107+
<string name="sms_terms_of_service" translation_description="Fine print warning displayed below Verify Phone Number button" >By tapping &quot;%1$s&quot;, an SMS may be sent. Message &amp; data rates may apply.</string>
107108
</resources>

auth/src/main/res/values/styles.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@
109109
<item name="android:layout_gravity">center_horizontal</item>
110110
</style>
111111

112+
<style name="FirebaseUI.SMSTermsText" parent="FirebaseUI.Text.BodyText">
113+
<item name="android:layout_width">match_parent</item>
114+
<item name="android:textColor">?android:textColorTertiary</item>
115+
</style>
116+
112117
<style name="FirebaseUI.TextInputEditText">
113118
<item name="android:textSize">16sp</item>
114119
<item name="android:layout_width">match_parent</item>

0 commit comments

Comments
 (0)