Skip to content

Commit 98a5a6b

Browse files
author
Iain McGinniss
committed
Theming support and examples
Change-Id: Ie07522b6e9323759710038395a55929b90e50df2
1 parent ad3adac commit 98a5a6b

File tree

12 files changed

+213
-138
lines changed

12 files changed

+213
-138
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ public class AuthUiActivity extends Activity {
4646

4747
private static final int RC_SIGN_IN = 100;
4848

49+
@BindView(R.id.default_theme)
50+
RadioButton mUseDefaultTheme;
51+
4952
@BindView(R.id.green_theme)
5053
RadioButton mUseGreenTheme;
5154

52-
@BindView(R.id.blue_theme)
53-
RadioButton mUseBlueTheme;
55+
@BindView(R.id.purple_theme)
56+
RadioButton mUsePurpleTheme;
5457

5558
@BindView(R.id.email_provider)
5659
CheckBox mUseEmailProvider;
@@ -83,7 +86,7 @@ public void onCreate(Bundle savedInstanceState) {
8386
finish();
8487
}
8588

86-
setContentView(R.layout.launch_layout);
89+
setContentView(R.layout.auth_ui_layout);
8790
ButterKnife.bind(this);
8891
}
8992

@@ -128,10 +131,12 @@ private void handleSignInResponse(int resultCode, Intent data) {
128131
@MainThread
129132
@StyleRes
130133
private int getSelectedTheme() {
131-
// this can happen prior to initial layout inflation and binding,
132-
// in which case the radio button references will be null
133-
if (mUseBlueTheme == null || mUseBlueTheme.isChecked()) {
134-
return R.style.BlueTheme;
134+
if (mUseDefaultTheme.isChecked()) {
135+
return AuthUI.DEFAULT_THEME;
136+
}
137+
138+
if (mUsePurpleTheme.isChecked()) {
139+
return R.style.PurpleTheme;
135140
}
136141

137142
return R.style.GreenTheme;
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
tools:context=".auth.AuthUiActivity">
7+
8+
<LinearLayout
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:layout_marginBottom="16dp"
12+
android:layout_marginLeft="24dp"
13+
android:layout_marginRight="24dp"
14+
android:layout_marginTop="16dp"
15+
android:orientation="vertical">
16+
17+
<TextView
18+
style="@style/Base.TextAppearance.AppCompat.Headline"
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
android:layout_gravity="center_horizontal"
22+
android:drawableTop="@drawable/firebase_auth_120dp"
23+
android:text="@string/launch_title" />
24+
25+
<Button
26+
android:id="@+id/sign_in"
27+
style="@style/Widget.AppCompat.Button.Colored"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:layout_gravity="center"
31+
android:layout_margin="16dp"
32+
android:text="@string/sign_in" />
33+
34+
<TextView
35+
style="@style/Base.TextAppearance.AppCompat.Subhead"
36+
android:layout_width="wrap_content"
37+
android:layout_height="wrap_content"
38+
android:layout_marginBottom="8dp"
39+
android:text="@string/use_theme_header" />
40+
41+
<RadioGroup
42+
android:layout_width="wrap_content"
43+
android:layout_height="wrap_content"
44+
android:orientation="vertical">
45+
46+
<RadioButton
47+
android:id="@+id/default_theme"
48+
android:layout_width="wrap_content"
49+
android:layout_height="wrap_content"
50+
android:text="@string/default_theme" />
51+
52+
<RadioButton
53+
android:id="@+id/purple_theme"
54+
android:layout_width="wrap_content"
55+
android:layout_height="wrap_content"
56+
android:checked="true"
57+
android:text="@string/purple_theme" />
58+
59+
<RadioButton
60+
android:id="@+id/green_theme"
61+
android:layout_width="wrap_content"
62+
android:layout_height="wrap_content"
63+
android:text="@string/green_theme" />
64+
</RadioGroup>
65+
66+
<TextView
67+
style="@style/Base.TextAppearance.AppCompat.Subhead"
68+
android:layout_width="wrap_content"
69+
android:layout_height="wrap_content"
70+
android:layout_marginBottom="8dp"
71+
android:layout_marginTop="16dp"
72+
android:text="@string/auth_providers_header" />
73+
74+
<CheckBox
75+
android:id="@+id/email_provider"
76+
android:layout_width="wrap_content"
77+
android:layout_height="wrap_content"
78+
android:checked="true"
79+
android:text="@string/email_label" />
80+
81+
<CheckBox
82+
android:id="@+id/facebook_provider"
83+
android:layout_width="wrap_content"
84+
android:layout_height="wrap_content"
85+
android:text="@string/facebook_label" />
86+
87+
<CheckBox
88+
android:id="@+id/google_provider"
89+
android:layout_width="wrap_content"
90+
android:layout_height="wrap_content"
91+
android:text="@string/google_label" />
92+
93+
<TextView
94+
style="@style/Base.TextAppearance.AppCompat.Subhead"
95+
android:layout_width="wrap_content"
96+
android:layout_height="wrap_content"
97+
android:layout_marginBottom="8dp"
98+
android:layout_marginTop="16dp"
99+
android:text="@string/tos_header" />
100+
101+
<RadioGroup
102+
android:layout_width="wrap_content"
103+
android:layout_height="wrap_content"
104+
android:orientation="vertical">
105+
106+
<RadioButton
107+
android:id="@+id/google_tos"
108+
android:layout_width="wrap_content"
109+
android:layout_height="wrap_content"
110+
android:checked="true"
111+
android:text="@string/google_tos_label" />
112+
113+
<RadioButton
114+
android:id="@+id/firebase_tos"
115+
android:layout_width="wrap_content"
116+
android:layout_height="wrap_content"
117+
android:text="@string/firebase_tos_label" />
118+
</RadioGroup>
119+
120+
</LinearLayout>
121+
122+
</ScrollView>

app/src/main/res/layout/launch_layout.xml

Lines changed: 0 additions & 111 deletions
This file was deleted.

app/src/main/res/values-v21/styles.xml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,48 @@
11
<resources>
22

3-
<style name="AuthUIBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar" />
3+
<style name="PurpleTheme" parent="FirebaseUI">
4+
<item name="colorPrimary">@color/material_deep_purple_500</item>
5+
<item name="android:colorPrimary">@color/material_deep_purple_500</item>
46

5-
<style name="BlueTheme" parent="AuthUIBaseTheme">
6-
<item name="android:colorPrimary">@color/material_blue_500</item>
7-
<item name="android:colorAccent">@color/material_blue_a200</item>
7+
<item name="colorPrimaryDark">@color/material_deep_purple_700</item>
8+
<item name="android:colorPrimaryDark">@color/material_deep_purple_700</item>
9+
10+
<item name="colorAccent">@color/material_lime_a700</item>
11+
<item name="android:colorAccent">@color/material_lime_a700</item>
12+
13+
14+
<item name="colorControlNormal">@color/material_deep_purple_500</item>
15+
<item name="android:colorControlNormal">@color/material_deep_purple_500</item>
16+
17+
<item name="colorControlActivated">@color/material_deep_purple_a200</item>
18+
<item name="android:colorControlActivated">@color/material_deep_purple_a200</item>
19+
20+
<item name="colorControlHighlight">@color/material_lime_a700</item>
21+
<item name="android:colorControlHighlight">@color/material_lime_a700</item>
22+
23+
<item name="android:windowBackground">@color/material_purple_50</item>
824
</style>
925

10-
<style name="GreenTheme" parent="AuthUIBaseTheme">
26+
<style name="GreenTheme" parent="FirebaseUI">
27+
<item name="colorPrimary">@color/material_green_500</item>
1128
<item name="android:colorPrimary">@color/material_green_500</item>
12-
<item name="android:colorAccent">@color/material_green_a200</item>
29+
30+
<item name="android:colorPrimaryDark">@color/material_green_700</item>
31+
<item name="colorPrimaryDark">@color/material_green_700</item>
32+
33+
<item name="colorAccent">@color/material_purple_a700</item>
34+
<item name="android:colorAccent">@color/material_purple_a700</item>
35+
36+
<item name="colorControlNormal">@color/material_green_500</item>
37+
<item name="android:colorControlNormal">@color/material_green_500</item>
38+
39+
<item name="colorControlActivated">@color/material_lime_a700</item>
40+
<item name="android:colorControlActivated">@color/material_lime_a700</item>
41+
42+
<item name="colorControlHighlight">@color/material_green_a200</item>
43+
<item name="android:colorControlHighlight">@color/material_green_a200</item>
44+
45+
<item name="android:windowBackground">@color/material_green_50</item>
1346
</style>
1447

1548
<style name="WarnButton" parent="Widget.AppCompat.Button.Colored">

app/src/main/res/values/colors.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
<resources>
2-
<color name="material_blue_500">#2196F3</color>
3-
<color name="material_blue_a200">#40C4FF</color>
2+
<color name="material_deep_purple_50">#EDE7F6</color>
3+
<color name="material_deep_purple_500">#673AB7</color>
4+
<color name="material_deep_purple_700">#512DA8</color>
5+
<color name="material_deep_purple_a200">#E040FB</color>
6+
<color name="material_green_50">#E8F5E9</color>
47
<color name="material_green_500">#4CAF50</color>
8+
<color name="material_green_700">#388E3C</color>
59
<color name="material_green_a200">#69F0AE</color>
10+
11+
<color name="material_lime_50">#F9FBE7</color>
12+
<color name="material_lime_a700">#AEEA00</color>
13+
14+
<color name="material_purple_50">#F3E5F5</color>
15+
<color name="material_purple_a700">#AA00FF</color>
16+
617
<color name="material_red_a200">#FF5252</color>
718
</resources>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<eat-comment/>
1212
<string name="launch_title">Firebase Auth UI Demo</string>
1313
<string name="sign_in">Start</string>
14-
<string name="blue_theme">Blue Theme</string>
1514
<string name="green_theme">Green Theme</string>
15+
<string name="purple_theme">Purple Theme</string>
1616
<string name="use_theme_header">Use theme:</string>
1717
<string name="auth_providers_header">Use auth providers:</string>
1818
<string name="email_label">Email</string>
@@ -32,4 +32,5 @@
3232
<string name="delete_account_failed">Delete account failed 😨</string>
3333
<string name="user_profile_header">User profile:</string>
3434
<string name="profile_picture_content_desc">Profile picture</string>
35+
<string name="default_theme">Default theme</string>
3536
</resources>

0 commit comments

Comments
 (0)