Skip to content

Commit e3d32ac

Browse files
authored
Polish custom layout implementation (#1513)
1 parent eb031c7 commit e3d32ac

File tree

14 files changed

+565
-125
lines changed

14 files changed

+565
-125
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dependencies {
5454
// demonstrative purposes, and you may find them useful in your own apps; YMMV.
5555
implementation(Config.Libs.Misc.permissions)
5656
implementation(Config.Libs.Misc.butterKnife)
57+
implementation(Config.Libs.Support.constraint)
5758
annotationProcessor(Config.Libs.Misc.butterKnifeCompiler)
5859
debugImplementation(Config.Libs.Misc.leakCanary)
5960
debugImplementation(Config.Libs.Misc.leakCanaryFragments)

app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.google.firebase.auth.FirebaseAuth;
5050

5151
import java.util.ArrayList;
52-
import java.util.Arrays;
5352
import java.util.List;
5453

5554
import butterknife.BindView;
@@ -79,6 +78,9 @@ public class AuthUiActivity extends AppCompatActivity {
7978
@BindView(R.id.phone_provider) CheckBox mUsePhoneProvider;
8079
@BindView(R.id.anonymous_provider) CheckBox mUseAnonymousProvider;
8180

81+
@BindView(R.id.default_layout) RadioButton mDefaultLayout;
82+
@BindView(R.id.custom_layout) RadioButton mCustomLayout;
83+
8284
@BindView(R.id.default_theme) RadioButton mDefaultTheme;
8385
@BindView(R.id.green_theme) RadioButton mGreenTheme;
8486
@BindView(R.id.purple_theme) RadioButton mPurpleTheme;
@@ -187,6 +189,24 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
187189
mUseEmailLinkProvider.setChecked(false);
188190
mUseEmailProvider.setChecked(true);
189191

192+
// The custom layout in this app only supports Email and Google providers.
193+
mCustomLayout.setOnCheckedChangeListener(new OnCheckedChangeListener() {
194+
@Override
195+
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
196+
if (checked) {
197+
mUseGoogleProvider.setChecked(true);
198+
mUseEmailProvider.setChecked(true);
199+
200+
mUseFacebookProvider.setChecked(false);
201+
mUseTwitterProvider.setChecked(false);
202+
mUseGitHubProvider.setChecked(false);
203+
mUseEmailLinkProvider.setChecked(false);
204+
mUsePhoneProvider.setChecked(false);
205+
mUseAnonymousProvider.setChecked(false);
206+
}
207+
}
208+
});
209+
190210
if (ConfigurationUtils.isGoogleMisconfigured(this)
191211
|| ConfigurationUtils.isFacebookMisconfigured(this)
192212
|| ConfigurationUtils.isTwitterMisconfigured(this)
@@ -241,6 +261,18 @@ public Intent buildSignInIntent(@Nullable String link) {
241261
.setIsSmartLockEnabled(mEnableCredentialSelector.isChecked(),
242262
mEnableHintSelector.isChecked());
243263

264+
if (mCustomLayout.isChecked()) {
265+
AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout
266+
.Builder(R.layout.auth_method_picker_custom_layout)
267+
.setGoogleButtonId(R.id.custom_google_signin_button)
268+
.setEmailButtonId(R.id.custom_email_signin_clickable_text)
269+
.setTosAndPrivacyPolicyId(R.id.custom_tos_pp)
270+
.build();
271+
272+
builder.setTheme(R.style.CustomTheme);
273+
builder.setAuthMethodPickerLayout(customLayout);
274+
}
275+
244276
if (getSelectedTosUrl() != null && getSelectedPrivacyPolicyUrl() != null) {
245277
builder.setTosAndPrivacyPolicyUrls(
246278
getSelectedTosUrl(),
@@ -260,32 +292,6 @@ public Intent buildSignInIntent(@Nullable String link) {
260292
return builder.build();
261293
}
262294

263-
@OnClick(R.id.customised_sign_in)
264-
public void signInCustomLayout() {
265-
AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout
266-
.Builder(R.layout.auth_method_picker_custom_layout)
267-
.setupGoogleButtonId(R.id.custom_google_signin_button)
268-
.setupEmailButtonId(R.id.custom_email_signin_clickable_text)
269-
.build();
270-
271-
//For now we only test Google and Email
272-
List<IdpConfig> availableProviders = Arrays.asList(
273-
new AuthUI.IdpConfig.GoogleBuilder()
274-
.setScopes(getGoogleScopes())
275-
.build(),
276-
new IdpConfig.EmailBuilder()
277-
.setRequireName(mRequireName.isChecked())
278-
.setAllowNewAccounts(mAllowNewEmailAccounts.isChecked())
279-
.build());
280-
281-
startActivityForResult(
282-
AuthUI.getInstance().createSignInIntentBuilder()
283-
.setAvailableProviders(availableProviders)
284-
.setAuthMethodPickerLayout(customLayout)
285-
.build(),
286-
RC_SIGN_IN);
287-
}
288-
289295
@OnClick(R.id.sign_in_silent)
290296
public void silentSignIn() {
291297
AuthUI.getInstance().silentSignIn(this, getSelectedProviders())
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<gradient
4+
android:startColor="#7986cb"
5+
android:endColor="#7e57c2"
6+
android:angle="270"/>
7+
</shape>
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:background="@drawable/custom_bg_gradient">
8+
9+
<android.support.constraint.Guideline
10+
android:id="@+id/guideline"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:orientation="vertical"
14+
app:layout_constraintGuide_percent="0.4" />
15+
16+
<ImageView
17+
android:id="@+id/custom_logo"
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:layout_marginStart="16dp"
21+
android:layout_marginLeft="16dp"
22+
android:layout_marginEnd="16dp"
23+
android:layout_marginRight="16dp"
24+
android:layout_marginBottom="8dp"
25+
android:src="@mipmap/ic_launcher_foreground"
26+
app:layout_constraintBottom_toTopOf="@+id/custom_subheader"
27+
app:layout_constraintEnd_toStartOf="@+id/guideline"
28+
app:layout_constraintHorizontal_bias="0.5"
29+
app:layout_constraintStart_toStartOf="parent"
30+
app:layout_constraintTop_toTopOf="@+id/header_idp_choice"
31+
app:layout_constraintVertical_bias="0.0"
32+
app:layout_constraintVertical_chainStyle="packed"
33+
tools:ignore="ContentDescription" />
34+
35+
<TextView
36+
android:id="@+id/custom_subheader"
37+
android:layout_width="wrap_content"
38+
android:layout_height="wrap_content"
39+
android:layout_marginStart="16dp"
40+
android:layout_marginLeft="16dp"
41+
android:layout_marginEnd="16dp"
42+
android:layout_marginRight="16dp"
43+
android:layout_marginBottom="8dp"
44+
android:text="@string/custom_layout_subheader"
45+
android:textColor="#FFFFFF"
46+
app:layout_constraintTop_toBottomOf="@+id/custom_logo"
47+
app:layout_constraintBottom_toTopOf="@+id/custom_tos_pp"
48+
app:layout_constraintEnd_toEndOf="@+id/guideline"
49+
app:layout_constraintHorizontal_bias="0.5"
50+
app:layout_constraintStart_toStartOf="parent" />
51+
52+
53+
<!-- Horiz line, left of provider header -->
54+
<FrameLayout
55+
android:id="@+id/header_idp_wing_left"
56+
style="@style/CustomWingOuter"
57+
app:layout_constraintBottom_toBottomOf="@+id/header_idp_choice"
58+
app:layout_constraintEnd_toStartOf="@+id/header_idp_choice"
59+
app:layout_constraintStart_toEndOf="@+id/guideline"
60+
app:layout_constraintTop_toTopOf="@+id/header_idp_choice">
61+
62+
<View style="@style/CustomWingInner" />
63+
64+
</FrameLayout>
65+
66+
<TextView
67+
android:id="@+id/header_idp_choice"
68+
android:layout_width="wrap_content"
69+
android:layout_height="wrap_content"
70+
android:text="@string/custom_layout_idp_header"
71+
android:textAllCaps="true"
72+
android:textColor="#FFFFFF"
73+
app:layout_constraintVertical_chainStyle="packed"
74+
app:layout_constraintBottom_toTopOf="@+id/custom_google_signin_button"
75+
app:layout_constraintEnd_toStartOf="@+id/header_idp_wing_right"
76+
app:layout_constraintHorizontal_bias="0.5"
77+
app:layout_constraintStart_toEndOf="@+id/header_idp_wing_left"
78+
app:layout_constraintTop_toTopOf="parent" />
79+
80+
<!-- Horiz line, right of provider header -->
81+
<FrameLayout
82+
android:id="@+id/header_idp_wing_right"
83+
style="@style/CustomWingOuter"
84+
app:layout_constraintBottom_toBottomOf="@+id/header_idp_choice"
85+
app:layout_constraintEnd_toEndOf="parent"
86+
app:layout_constraintStart_toEndOf="@+id/header_idp_choice"
87+
app:layout_constraintTop_toTopOf="@+id/header_idp_choice">
88+
89+
<View style="@style/CustomWingInner" />
90+
91+
</FrameLayout>
92+
93+
<!--
94+
NOTE: This sample app uses this class from the FirebaseUI library to show the Google Sign
95+
in button. However this button is NOT considered part of the public API and you should not
96+
use it in your own app.
97+
-->
98+
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton xmlns:android="http://schemas.android.com/apk/res/android"
99+
android:id="@+id/custom_google_signin_button"
100+
style="@style/FirebaseUI.Button.AccountChooser.GoogleButton"
101+
android:layout_width="wrap_content"
102+
android:layout_height="wrap_content"
103+
android:layout_marginTop="32dp"
104+
android:text="@string/fui_sign_in_with_google"
105+
app:layout_constraintBottom_toTopOf="@+id/header_email"
106+
app:layout_constraintEnd_toEndOf="parent"
107+
app:layout_constraintHorizontal_bias="0.5"
108+
app:layout_constraintStart_toStartOf="@+id/guideline"
109+
app:layout_constraintTop_toBottomOf="@+id/header_idp_choice" />
110+
111+
<!-- Horiz line, left of email header -->
112+
<FrameLayout
113+
android:id="@+id/header_email_wing_left"
114+
style="@style/CustomWingOuter"
115+
app:layout_constraintBottom_toBottomOf="@+id/header_email"
116+
app:layout_constraintEnd_toStartOf="@+id/header_email"
117+
app:layout_constraintStart_toEndOf="@+id/guideline"
118+
app:layout_constraintTop_toTopOf="@+id/header_email">
119+
120+
<View style="@style/CustomWingInner" />
121+
122+
</FrameLayout>
123+
124+
<TextView
125+
android:id="@+id/header_email"
126+
android:layout_width="wrap_content"
127+
android:layout_height="wrap_content"
128+
android:layout_marginTop="32dp"
129+
android:text="@string/custom_layout_email_header"
130+
android:textAllCaps="true"
131+
android:textColor="#FFFFFF"
132+
app:layout_constraintBottom_toTopOf="@+id/custom_email_signin_clickable_text"
133+
app:layout_constraintEnd_toStartOf="@+id/header_email_wing_right"
134+
app:layout_constraintHorizontal_bias="0.5"
135+
app:layout_constraintStart_toEndOf="@+id/header_email_wing_left"
136+
app:layout_constraintTop_toBottomOf="@+id/custom_google_signin_button" />
137+
138+
<!-- Horiz line, right of email header -->
139+
<FrameLayout
140+
android:id="@+id/header_email_wing_right"
141+
style="@style/CustomWingOuter"
142+
app:layout_constraintBottom_toBottomOf="@+id/header_email"
143+
app:layout_constraintEnd_toEndOf="parent"
144+
app:layout_constraintStart_toEndOf="@+id/header_email"
145+
app:layout_constraintTop_toTopOf="@+id/header_email">
146+
147+
<View style="@style/CustomWingInner" />
148+
149+
</FrameLayout>
150+
151+
<TextView
152+
android:id="@+id/custom_email_signin_clickable_text"
153+
android:layout_width="wrap_content"
154+
android:layout_height="wrap_content"
155+
android:layout_marginStart="16dp"
156+
android:layout_marginLeft="16dp"
157+
android:layout_marginTop="32dp"
158+
android:layout_marginEnd="16dp"
159+
android:layout_marginRight="16dp"
160+
android:layout_marginBottom="8dp"
161+
android:clickable="true"
162+
android:focusable="true"
163+
android:text="@string/custom_layout_email_click_text"
164+
android:textColor="#FFFFFF"
165+
android:textStyle="bold"
166+
app:layout_constraintBottom_toBottomOf="parent"
167+
app:layout_constraintEnd_toEndOf="parent"
168+
app:layout_constraintHorizontal_bias="0.5"
169+
app:layout_constraintStart_toEndOf="@+id/guideline"
170+
app:layout_constraintTop_toBottomOf="@+id/header_email" />
171+
172+
<TextView
173+
android:id="@+id/custom_tos_pp"
174+
android:layout_width="0dp"
175+
android:layout_height="wrap_content"
176+
android:layout_margin="16dp"
177+
android:layout_marginStart="8dp"
178+
android:layout_marginLeft="8dp"
179+
android:layout_marginEnd="8dp"
180+
android:layout_marginRight="8dp"
181+
android:gravity="center_horizontal"
182+
android:textColor="#FFFFFF"
183+
app:layout_constraintTop_toBottomOf="@+id/custom_subheader"
184+
app:layout_constraintBottom_toBottomOf="parent"
185+
app:layout_constraintEnd_toStartOf="@+id/guideline"
186+
app:layout_constraintHorizontal_bias="0.5"
187+
app:layout_constraintStart_toStartOf="parent"
188+
tools:text="Terms of Service and Privacy Policy" />
189+
190+
</android.support.constraint.ConstraintLayout>

0 commit comments

Comments
 (0)