Skip to content

Commit 1a09a75

Browse files
authored
Merge pull request #2 from JosefHruska/master
FirebaseUI fork
2 parents 2153c44 + 9cd9d55 commit 1a09a75

32 files changed

+405
-138
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
!.idea/codeStyleSettings.xml
66
.DS_Store
77
build
8-
google-services.json
8+
google-services.json

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
<!-- Auth UI demo -->
3535
<activity
3636
android:name=".auth.AuthUiActivity"
37+
android:theme="@style/AppTheme.NoActionbar"
3738
android:label="@string/name_auth_ui"/>
3839
<activity
3940
android:name=".auth.SignedInActivity"
41+
android:theme="@style/AppTheme.NoActionbar"
4042
android:label="@string/name_auth_ui"/>
4143

4244
<!-- Storage UI demo-->

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
<item name="colorAccent">@color/colorAccent</item>
77
</style>
88

9+
<style name="AppTheme.NoActionbar">
10+
<item name="windowActionBar">false</item>
11+
<item name="windowNoTitle">true</item>
12+
</style>
13+
914
<style name="PurpleTheme" parent="FirebaseUI">
1015
<item name="colorPrimary">@color/material_deep_purple_500</item>
1116
<item name="colorPrimaryDark">@color/material_deep_purple_700</item>

auth/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,24 @@
3737
<activity
3838
android:name=".ui.email.RegisterEmailActivity"
3939
android:label="@string/sign_in_default"
40+
android:windowSoftInputMode="adjustResize|stateAlwaysVisible"
4041
android:exported="false"/>
4142

4243
<activity
4344
android:name=".ui.accountlink.WelcomeBackIdpPrompt"
4445
android:label="@string/title_welcome_back_idp_prompt"
46+
android:windowSoftInputMode="adjustResize"
4547
android:exported="false"/>
4648

4749
<activity
4850
android:name=".ui.accountlink.WelcomeBackPasswordPrompt"
4951
android:label="@string/title_welcome_back_password_prompt"
52+
android:windowSoftInputMode="adjustResize"
5053
android:exported="false"/>
5154

5255
<activity
5356
android:name=".ui.idp.AuthMethodPickerActivity"
57+
android:theme="@style/FirebaseUI.NoActionBar"
5458
android:label="@string/default_toolbar_title"
5559
android:exported="false"/>
5660

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import android.os.Bundle;
1818
import android.support.annotation.RestrictTo;
19+
import android.view.MenuItem;
1920

2021
@SuppressWarnings("Registered")
2122
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@@ -27,4 +28,12 @@ protected void onCreate(Bundle savedInstance) {
2728
mActivityHelper.configureTheme();
2829
}
2930

31+
@Override
32+
public boolean onOptionsItemSelected(MenuItem item) {
33+
switch (item.getItemId()) {
34+
case android.R.id.home:
35+
onBackPressed();
36+
}
37+
return true;
38+
}
3039
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@
99
import android.support.annotation.Nullable;
1010
import android.support.annotation.RestrictTo;
1111
import android.support.design.widget.TextInputLayout;
12+
import android.support.v4.content.ContextCompat;
13+
import android.text.Editable;
1214
import android.text.TextUtils;
15+
import android.text.TextWatcher;
1316
import android.util.Log;
17+
import android.view.KeyEvent;
1418
import android.view.LayoutInflater;
1519
import android.view.View;
1620
import android.view.ViewGroup;
21+
import android.view.inputmethod.EditorInfo;
1722
import android.widget.EditText;
23+
import android.widget.TextView;
1824

1925
import com.firebase.ui.auth.R;
2026
import com.firebase.ui.auth.ui.ExtraConstants;
@@ -106,6 +112,21 @@ public View onCreateView(LayoutInflater inflater,
106112
mEmailFieldValidator = new EmailFieldValidator(mEmailLayout);
107113
mEmailLayout.setOnClickListener(this);
108114
mEmailEditText.setOnClickListener(this);
115+
checkEmailValid();
116+
mEmailEditText.addTextChangedListener(textListener);
117+
118+
// If we press enter on soft-keyboard it simulates finish button click
119+
mEmailEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
120+
@Override
121+
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
122+
if (actionId == EditorInfo.IME_ACTION_DONE && getView() != null) {
123+
onClick(getView().findViewById(R.id.button_next));
124+
return true;
125+
} else {
126+
return false;
127+
}
128+
}
129+
});
109130

110131
// "Next" button
111132
v.findViewById(R.id.button_next).setOnClickListener(this);
@@ -231,6 +252,16 @@ private void showEmailAutoCompleteHint() {
231252
}
232253
}
233254

255+
private void checkEmailValid() {
256+
if (getView() != null && mEmailFieldValidator != null) {
257+
if (!mEmailFieldValidator.isValid(mEmailEditText.getText().toString())) {
258+
getView().findViewById(R.id.button_next).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.sign_up_disabled));
259+
} else {
260+
getView().findViewById(R.id.button_next).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.authui_colorAccent));
261+
}
262+
}
263+
}
264+
234265
private PendingIntent getEmailHintIntent() {
235266
GoogleApiClient client = new GoogleApiClient.Builder(getContext())
236267
.addApi(Auth.CREDENTIALS_API)
@@ -264,4 +295,21 @@ public void onClick(View view) {
264295
mEmailLayout.setError(null);
265296
}
266297
}
298+
299+
TextWatcher textListener = new TextWatcher() {
300+
@Override
301+
public void afterTextChanged(Editable s) {
302+
}
303+
304+
@Override
305+
public void beforeTextChanged(CharSequence s, int start,
306+
int count, int after) {
307+
}
308+
309+
@Override
310+
public void onTextChanged(CharSequence s, int start,
311+
int before, int count) {
312+
checkEmailValid(); // Change NEXT button color if needed.
313+
}
314+
};
267315
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static Intent createIntent(Context context, FlowParameters flowParams, St
5858
protected void onCreate(Bundle savedInstanceState) {
5959
super.onCreate(savedInstanceState);
6060
setContentView(R.layout.activity_register_email);
61-
61+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
6262
if (savedInstanceState != null) {
6363
return;
6464
}

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

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.firebase.ui.auth.ui.email;
22

3+
import android.content.Context;
34
import android.net.Uri;
45
import android.os.Bundle;
56
import android.support.annotation.ColorInt;
@@ -9,13 +10,18 @@
910
import android.support.customtabs.CustomTabsIntent;
1011
import android.support.design.widget.TextInputLayout;
1112
import android.support.v4.content.ContextCompat;
13+
import android.text.Editable;
1214
import android.text.SpannableStringBuilder;
1315
import android.text.TextUtils;
16+
import android.text.TextWatcher;
1417
import android.text.style.ForegroundColorSpan;
1518
import android.util.TypedValue;
19+
import android.view.KeyEvent;
1620
import android.view.LayoutInflater;
1721
import android.view.View;
1822
import android.view.ViewGroup;
23+
import android.view.inputmethod.EditorInfo;
24+
import android.view.inputmethod.InputMethodManager;
1925
import android.widget.EditText;
2026
import android.widget.TextView;
2127

@@ -112,12 +118,32 @@ public View onCreateView(LayoutInflater inflater,
112118
mEmailEditText.setOnFocusChangeListener(this);
113119
mNameEditText.setOnFocusChangeListener(this);
114120
mPasswordEditText.setOnFocusChangeListener(this);
115-
v.findViewById(R.id.button_create).setOnClickListener(this);
121+
// Handles finish button color change
122+
mNameEditText.addTextChangedListener(textListener);
123+
mEmailEditText.addTextChangedListener(textListener);
124+
mPasswordEditText.addTextChangedListener(textListener);
125+
126+
TextView buttonCreate = (TextView) v.findViewById(R.id.button_create);
127+
buttonCreate.setOnClickListener(this);
128+
buttonCreate.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.sign_up_disabled));
116129

117130
if (savedInstanceState != null) {
118131
return v;
119132
}
120133

134+
// If we press enter on soft-keyboard it simulates finish button click
135+
mPasswordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
136+
@Override
137+
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
138+
if (actionId == EditorInfo.IME_ACTION_DONE && getView() != null) {
139+
onClick(getView().findViewById(R.id.button_create));
140+
return true;
141+
} else {
142+
return false;
143+
}
144+
}
145+
});
146+
121147
// If email is passed in, fill in the field and move down to the name field.
122148
String email = mUser.getEmail();
123149
if (!TextUtils.isEmpty(email)) {
@@ -148,6 +174,11 @@ private void safeRequestFocus(final View v) {
148174
@Override
149175
public void run() {
150176
v.requestFocus();
177+
// Sometimes it doesn't receive focus.
178+
if (getActivity().getCurrentFocus() != null) {
179+
InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
180+
inputMethodManager.showSoftInput(getActivity().getCurrentFocus(), 0);
181+
}
151182
}
152183
});
153184
}
@@ -235,6 +266,17 @@ public void onClick(View view) {
235266
}
236267
}
237268

269+
private void checkAllFieldsValid() {
270+
if (getView() != null) {
271+
TextView buttonSignUp = (TextView) getView().findViewById(R.id.button_create);
272+
if (mEmailFieldValidator.isValid(mEmailEditText.getText().toString()) && mPasswordFieldValidator.isValid(mPasswordEditText.getText().toString()) && mNameValidator.isValid(mNameEditText.getText().toString())) {
273+
buttonSignUp.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.authui_colorAccent));
274+
} else if (buttonSignUp != null) {
275+
buttonSignUp.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.sign_up_disabled));
276+
}
277+
}
278+
}
279+
238280
private void registerUser(final String email, final String name, final String password) {
239281
mHelper.getFirebaseAuth()
240282
.createUserWithEmailAndPassword(email, password)
@@ -294,4 +336,21 @@ public void onFailure(@NonNull Exception e) {
294336
}
295337
});
296338
}
339+
340+
TextWatcher textListener = new TextWatcher() {
341+
@Override
342+
public void afterTextChanged(Editable s) {
343+
}
344+
345+
@Override
346+
public void beforeTextChanged(CharSequence s, int start,
347+
int count, int after) {
348+
}
349+
350+
@Override
351+
public void onTextChanged(CharSequence s, int start,
352+
int before, int count) {
353+
checkAllFieldsValid(); // Change SIGN UP button color if needed.
354+
}
355+
};
297356
}

auth/src/main/java/com/firebase/ui/auth/ui/email/fieldvalidators/EmailFieldValidator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import android.support.design.widget.TextInputLayout;
1818
import android.util.Patterns;
19+
import android.widget.TextView;
1920

2021
import com.firebase.ui.auth.R;
2122

@@ -28,7 +29,7 @@ public EmailFieldValidator(TextInputLayout errorContainer) {
2829
}
2930

3031
@Override
31-
protected boolean isValid(CharSequence charSequence) {
32+
public boolean isValid(CharSequence charSequence) {
3233
return Patterns.EMAIL_ADDRESS.matcher(charSequence).matches();
3334
}
3435
}

auth/src/main/java/com/firebase/ui/auth/ui/email/fieldvalidators/PasswordFieldValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public PasswordFieldValidator(TextInputLayout errorContainer, int minLength) {
2929
}
3030

3131
@Override
32-
protected boolean isValid(CharSequence charSequence) {
32+
public boolean isValid(CharSequence charSequence) {
3333
return charSequence.length() >= mMinLength;
3434
}
3535
}

auth/src/main/java/com/firebase/ui/auth/ui/email/fieldvalidators/RequiredFieldValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public RequiredFieldValidator(TextInputLayout errorContainer) {
2525
}
2626

2727
@Override
28-
protected boolean isValid(CharSequence charSequence) {
28+
public boolean isValid(CharSequence charSequence) {
2929
return charSequence != null && charSequence.length() > 0;
3030
}
3131
}

auth/src/main/java/com/firebase/ui/auth/ui/idp/AuthMethodPickerActivity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import android.util.Log;
2323
import android.view.View;
2424
import android.view.ViewGroup;
25+
import android.view.Window;
26+
import android.view.WindowManager;
2527
import android.widget.ImageView;
2628

2729
import com.firebase.ui.auth.AuthUI;
@@ -83,7 +85,7 @@ protected void onCreate(Bundle savedInstanceState) {
8385
if (logoId == AuthUI.NO_LOGO) {
8486
findViewById(R.id.logo_layout).setVisibility(View.GONE);
8587
} else {
86-
ImageView logo = (ImageView) findViewById(R.id.logo);
88+
ImageView logo = (ImageView) findViewById(R.id.logo_layout); // We can't wrap this view into linear layout so we have to change its id to avoid conflicts in tests.
8789
logo.setImageResource(logoId);
8890
}
8991
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:color="@color/gray_2"
5+
tools:targetApi="lollipop">
6+
<item android:drawable="@color/transparent" /> <!-- default -->
7+
<item android:id="@android:id/mask">
8+
<shape android:shape="rectangle">
9+
<solid android:color="@color/gray_2" />
10+
</shape>
11+
</item>
12+
</ripple>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<size android:width="2dip" />
5+
<solid android:color="@color/authui_colorAccent" />
6+
</shape>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_pressed="true">
4+
<shape>
5+
<solid android:color="@color/gray_2" />
6+
</shape>
7+
</item>
8+
9+
<item>
10+
<shape>
11+
<solid android:color="@color/transparent" />
12+
</shape>
13+
</item>
14+
</selector>

0 commit comments

Comments
 (0)