Skip to content

Commit 1fb8407

Browse files
amandlesamtstern
authored andcommitted
Add support for specifying a logo in the AuthMethodPickerActivity (#150)
1 parent 7550d7c commit 1fb8407

File tree

13 files changed

+118
-2
lines changed

13 files changed

+118
-2
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.content.Context;
1919
import android.content.Intent;
2020
import android.os.Bundle;
21+
import android.support.annotation.DrawableRes;
2122
import android.support.annotation.MainThread;
2223
import android.support.annotation.StringRes;
2324
import android.support.annotation.StyleRes;
@@ -78,6 +79,16 @@ public class AuthUiActivity extends Activity {
7879
@BindView(android.R.id.content)
7980
View mRootView;
8081

82+
@BindView(R.id.firebase_logo)
83+
RadioButton mFirebaseLogo;
84+
85+
@BindView(R.id.google_logo)
86+
RadioButton mGoogleLogo;
87+
88+
@BindView(R.id.no_logo)
89+
RadioButton mNoLogo;
90+
91+
8192
@Override
8293
public void onCreate(Bundle savedInstanceState) {
8394
super.onCreate(savedInstanceState);
@@ -113,6 +124,7 @@ public void signIn(View view) {
113124
startActivityForResult(
114125
AuthUI.getInstance().createSignInIntentBuilder()
115126
.setTheme(getSelectedTheme())
127+
.setLogo(getSelectedLogo())
116128
.setProviders(getSelectedProviders())
117129
.setTosUrl(getSelectedTosUrl())
118130
.build(),
@@ -160,6 +172,17 @@ private int getSelectedTheme() {
160172
return R.style.GreenTheme;
161173
}
162174

175+
@MainThread
176+
@DrawableRes
177+
private int getSelectedLogo() {
178+
if (mFirebaseLogo.isChecked()) {
179+
return R.drawable.firebase_auth_120dp;
180+
} else if (mGoogleLogo.isChecked()) {
181+
return R.drawable.logo_googleg_color_144dp;
182+
}
183+
return AuthUI.NO_LOGO;
184+
}
185+
163186
@MainThread
164187
private String[] getSelectedProviders() {
165188
ArrayList<String> selectedProviders = new ArrayList<>();
4.91 KB
Loading
3.31 KB
Loading
7.16 KB
Loading
11.4 KB
Loading
16.4 KB
Loading

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,39 @@
117117
android:text="@string/firebase_tos_label" />
118118
</RadioGroup>
119119

120+
<TextView
121+
style="@style/Base.TextAppearance.AppCompat.Subhead"
122+
android:layout_width="wrap_content"
123+
android:layout_height="wrap_content"
124+
android:layout_marginBottom="8dp"
125+
android:layout_marginTop="16dp"
126+
android:text="@string/logo_header" />
127+
128+
<RadioGroup
129+
android:layout_marginBottom="20dp"
130+
android:layout_width="wrap_content"
131+
android:layout_height="wrap_content"
132+
android:orientation="vertical">
133+
134+
<RadioButton
135+
android:id="@+id/firebase_logo"
136+
android:layout_width="wrap_content"
137+
android:layout_height="wrap_content"
138+
android:checked="true"
139+
android:text="@string/firebase_logo_label" />
140+
141+
<RadioButton
142+
android:id="@+id/google_logo"
143+
android:layout_width="wrap_content"
144+
android:layout_height="wrap_content"
145+
android:text="@string/google_logo_label" />
146+
147+
<RadioButton
148+
android:id="@+id/no_logo"
149+
android:layout_width="wrap_content"
150+
android:layout_height="wrap_content"
151+
android:text="@string/no_logo_label" />
152+
</RadioGroup>
120153
</LinearLayout>
121154

122-
</ScrollView>
155+
</ScrollView>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<string name="green_theme">Green Theme</string>
1515
<string name="purple_theme">Purple Theme</string>
1616
<string name="use_theme_header">Use theme:</string>
17+
<string name="logo_header">Logo:</string>
18+
<string name="firebase_logo_label">Firebase Auth</string>
19+
<string name="google_logo_label">Google</string>
20+
<string name="no_logo_label">None</string>
1721
<string name="auth_providers_header">Use auth providers:</string>
1822
<string name="email_label">Email</string>
1923
<string name="facebook_label">Facebook</string>

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
import android.app.Activity;
1818
import android.content.Context;
1919
import android.content.Intent;
20+
import android.support.annotation.DrawableRes;
2021
import android.support.annotation.NonNull;
2122
import android.support.annotation.Nullable;
2223
import android.support.annotation.StyleRes;
2324

2425
import com.firebase.ui.auth.provider.IDPProviderParcel;
2526
import com.firebase.ui.auth.ui.FlowParameters;
2627
import com.firebase.ui.auth.ui.ChooseAccountActivity;
28+
import com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity;
2729
import com.firebase.ui.auth.util.CredentialsApiHelper;
2830
import com.firebase.ui.auth.util.Preconditions;
2931
import com.firebase.ui.auth.util.ProviderHelper;
@@ -220,6 +222,12 @@ public class AuthUI {
220222
*/
221223
public static final String FACEBOOK_PROVIDER = "facebook";
222224

225+
/**
226+
* Default value for logo resource, omits the logo from the
227+
* {@link AuthMethodPickerActivity}
228+
*/
229+
public static final int NO_LOGO = -1;
230+
223231
/**
224232
* The set of authentication providers supported in Firebase Auth UI.
225233
*/
@@ -306,6 +314,7 @@ public static AuthUI getInstance(FirebaseApp app) {
306314
* Builder for the intent to start the user authentication flow.
307315
*/
308316
public final class SignInIntentBuilder {
317+
private int mLogo = NO_LOGO;
309318
private int mTheme = getDefaultTheme();
310319
private List<String> mProviders = Collections.singletonList(EMAIL_PROVIDER);
311320
private String mTosUrl;
@@ -325,6 +334,15 @@ public SignInIntentBuilder setTheme(@StyleRes int theme) {
325334
return this;
326335
}
327336

337+
/**
338+
* Specifies the logo to use for the {@link AuthMethodPickerActivity}. If no logo
339+
* is specified, none will be used.
340+
*/
341+
public SignInIntentBuilder setLogo(@DrawableRes int logo) {
342+
mLogo = logo;
343+
return this;
344+
}
345+
328346
/**
329347
* Specifies the terms-of-service URL for the application.
330348
*/
@@ -365,6 +383,7 @@ public Intent build() {
365383
mApp.getName(),
366384
providerInfo,
367385
mTheme,
386+
mLogo,
368387
mTosUrl));
369388
}
370389
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import android.os.Parcel;
1717
import android.os.Parcelable;
18+
import android.support.annotation.DrawableRes;
1819
import android.support.annotation.NonNull;
1920
import android.support.annotation.Nullable;
2021
import android.support.annotation.StyleRes;
@@ -39,17 +40,22 @@ public class FlowParameters implements Parcelable {
3940
@StyleRes
4041
public final int themeId;
4142

43+
@DrawableRes
44+
public final int logoId;
45+
4246
@Nullable
4347
public final String termsOfServiceUrl;
4448

4549
public FlowParameters(
4650
@NonNull String appName,
4751
@NonNull List<IDPProviderParcel> providerInfo,
4852
@StyleRes int themeId,
53+
@DrawableRes int logoId,
4954
@Nullable String termsOfServiceUrl) {
5055
this.appName = Preconditions.checkNotNull(appName, "appName cannot be null");
5156
this.providerInfo = Preconditions.checkNotNull(providerInfo, "providerInfo cannot be null");
5257
this.themeId = themeId;
58+
this.logoId = logoId;
5359
this.termsOfServiceUrl = termsOfServiceUrl;
5460
}
5561

@@ -58,6 +64,7 @@ public void writeToParcel(Parcel dest, int flags) {
5864
dest.writeString(appName);
5965
dest.writeTypedList(providerInfo);
6066
dest.writeInt(themeId);
67+
dest.writeInt(logoId);
6168
dest.writeString(termsOfServiceUrl);
6269
}
6370

@@ -73,8 +80,9 @@ public FlowParameters createFromParcel(Parcel in) {
7380
List<IDPProviderParcel> providerInfo =
7481
in.createTypedArrayList(IDPProviderParcel.CREATOR);
7582
int themeId = in.readInt();
83+
int logoId = in.readInt();
7684
String termsOfServiceUrl = in.readString();
77-
return new FlowParameters(appName, providerInfo, themeId, termsOfServiceUrl);
85+
return new FlowParameters(appName, providerInfo, themeId, logoId, termsOfServiceUrl);
7886
}
7987

8088
@Override

0 commit comments

Comments
 (0)