Skip to content

Commit cde044f

Browse files
committed
Add sign-in intent builder support for privacy policy URLS.
1 parent 251d757 commit cde044f

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

auth/src/main/java/com/firebase/ui/auth/AuthUI.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ private abstract class AuthIntentBuilder<T extends AuthIntentBuilder> {
449449
int mTheme = getDefaultTheme();
450450
List<IdpConfig> mProviders = new ArrayList<>();
451451
String mTosUrl;
452+
String mPrivacyPolicyUrl;
452453
boolean mIsSmartLockEnabled = true;
453454

454455
private AuthIntentBuilder() {}
@@ -483,6 +484,14 @@ public T setTosUrl(@Nullable String tosUrl) {
483484
return (T) this;
484485
}
485486

487+
/**
488+
* Specifies the privacy policy URL for the application.
489+
*/
490+
public T setPrivacyPolicyUrl(@Nullable String privacyPolicyUrl) {
491+
mPrivacyPolicyUrl = privacyPolicyUrl;
492+
return (T) this;
493+
}
494+
486495
/**
487496
* Specified the set of supported authentication providers. At least one provider must
488497
* be specified. There may only be one instance of each provider.
@@ -631,6 +640,7 @@ protected FlowParameters getFlowParams() {
631640
mTheme,
632641
mLogo,
633642
mTosUrl,
643+
mPrivacyPolicyUrl,
634644
mIsSmartLockEnabled,
635645
false,
636646
true,
@@ -666,6 +676,7 @@ protected FlowParameters getFlowParams() {
666676
mTheme,
667677
mLogo,
668678
mTosUrl,
679+
mPrivacyPolicyUrl,
669680
mIsSmartLockEnabled,
670681
mAllowNewEmailAccounts,
671682
false,

auth/src/main/java/com/firebase/ui/auth/ui/FlowParameters.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public class FlowParameters implements Parcelable {
4848
@Nullable
4949
public final String termsOfServiceUrl;
5050

51+
@Nullable
52+
public final String privacyPolicyUrl;
53+
5154
public final boolean smartLockEnabled;
5255

5356
public final boolean allowNewEmailAccounts;
@@ -62,6 +65,7 @@ public FlowParameters(
6265
@StyleRes int themeId,
6366
@DrawableRes int logoId,
6467
@Nullable String termsOfServiceUrl,
68+
@Nullable String privacyPolicyUrl,
6569
boolean smartLockEnabled,
6670
boolean allowNewEmailAccounts,
6771
boolean isReauth,
@@ -72,6 +76,7 @@ public FlowParameters(
7276
this.themeId = themeId;
7377
this.logoId = logoId;
7478
this.termsOfServiceUrl = termsOfServiceUrl;
79+
this.privacyPolicyUrl = privacyPolicyUrl;
7580
this.smartLockEnabled = smartLockEnabled;
7681
this.allowNewEmailAccounts = allowNewEmailAccounts;
7782
this.isReauth = isReauth;
@@ -85,6 +90,7 @@ public void writeToParcel(Parcel dest, int flags) {
8590
dest.writeInt(themeId);
8691
dest.writeInt(logoId);
8792
dest.writeString(termsOfServiceUrl);
93+
dest.writeString(privacyPolicyUrl);
8894
dest.writeInt(smartLockEnabled ? 1 : 0);
8995
dest.writeInt(allowNewEmailAccounts ? 1 : 0);
9096
dest.writeInt(isReauth ? 1 : 0);
@@ -104,6 +110,7 @@ public FlowParameters createFromParcel(Parcel in) {
104110
int themeId = in.readInt();
105111
int logoId = in.readInt();
106112
String termsOfServiceUrl = in.readString();
113+
String privacyPolicyUrl = in.readString();
107114
boolean smartLockEnabled = in.readInt() != 0;
108115
boolean allowNewEmailAccounts = in.readInt() != 0;
109116
boolean isReauth = in.readInt() != 0;
@@ -115,6 +122,7 @@ public FlowParameters createFromParcel(Parcel in) {
115122
themeId,
116123
logoId,
117124
termsOfServiceUrl,
125+
privacyPolicyUrl,
118126
smartLockEnabled,
119127
allowNewEmailAccounts,
120128
isReauth,

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import android.support.customtabs.CustomTabsIntent;
1010
import android.support.design.widget.TextInputLayout;
1111
import android.support.v4.content.ContextCompat;
12+
import android.text.SpannableString;
1213
import android.text.SpannableStringBuilder;
1314
import android.text.TextUtils;
15+
import android.text.style.ClickableSpan;
1416
import android.text.style.ForegroundColorSpan;
1517
import android.util.TypedValue;
1618
import android.view.LayoutInflater;
@@ -165,6 +167,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
165167

166168
mSaveSmartLock = mHelper.getSaveSmartLockInstance(getActivity());
167169
setUpTermsOfService();
170+
setUpPrivacyPolicy();
168171
}
169172

170173
@Override
@@ -210,6 +213,39 @@ public void onClick(View view) {
210213
});
211214
}
212215

216+
private void setUpPrivacyPolicy() {
217+
if (TextUtils.isEmpty(mHelper.getFlowParams().privacyPolicyUrl)) {
218+
return;
219+
}
220+
221+
ForegroundColorSpan foregroundColorSpan =
222+
new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.linkColor));
223+
224+
String link = getString(R.string.privacy_policy);
225+
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(link);
226+
int start = mAgreementText.length();
227+
spannableStringBuilder.setSpan(foregroundColorSpan, start, start + link.length(), 0);
228+
229+
mAgreementText.append(" and the ");
230+
mAgreementText.append(spannableStringBuilder);
231+
mAgreementText.setOnClickListener(new View.OnClickListener() {
232+
@Override
233+
public void onClick(View view) {
234+
// Getting default color
235+
TypedValue typedValue = new TypedValue();
236+
getActivity().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);
237+
@ColorInt int color = typedValue.data;
238+
239+
new CustomTabsIntent.Builder()
240+
.setToolbarColor(color)
241+
.build()
242+
.launchUrl(
243+
getActivity(),
244+
Uri.parse(mHelper.getFlowParams().privacyPolicyUrl));
245+
}
246+
});
247+
}
248+
213249
@Override
214250
public void onFocusChange(View view, boolean hasFocus) {
215251
if (hasFocus) return; // Only consider fields losing focus

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<string name="error_user_collision">An account already exists with that email address.</string>
4545
<string name="create_account_preamble">"By tapping SAVE you are indicating that you agree to the "</string>
4646
<string name="terms_of_service">Terms of Service</string>
47+
<string name="privacy_policy">Privacy Policy</string>
4748

4849
<!-- Idp/Email welcome back -->
4950
<string name="title_welcome_back_idp_prompt">@string/sign_in_default</string>

0 commit comments

Comments
 (0)