Updated theming for the new login screen

This commit is contained in:
Paul Hawke 2017-10-06 07:29:35 -05:00
parent 529f5415c3
commit f55c27a625
8 changed files with 193 additions and 114 deletions

View file

@ -19,7 +19,7 @@
android:name=".CommonsApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat"
android:theme="@style/LightAppTheme"
android:supportsRtl="true" >
<activity android:name="org.acra.CrashReportDialog"
android:theme="@android:style/Theme.Dialog"

View file

@ -5,11 +5,15 @@ import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatDelegate;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@ -17,10 +21,10 @@ import android.widget.Toast;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.WelcomeActivity;
import fr.free.nrw.commons.PageTitle;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.WelcomeActivity;
import fr.free.nrw.commons.contributions.ContributionsActivity;
import timber.log.Timber;
@ -32,6 +36,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
public static final String PARAM_USERNAME = "fr.free.nrw.commons.login.username";
private AppCompatDelegate delegate;
private SharedPreferences prefs = null;
private Button loginButton;
@ -40,22 +45,24 @@ public class LoginActivity extends AccountAuthenticatorActivity {
private EditText twoFactorEdit;
ProgressDialog progressDialog;
private LoginTextWatcher textWatcher = new LoginTextWatcher();
private CommonsApplication app;
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(Utils.isDarkTheme(this) ? R.style.DarkAppTheme : R.style.LightAppTheme);
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
app = CommonsApplication.getInstance();
setContentView(R.layout.activity_login);
loginButton = (Button) findViewById(R.id.loginButton);
Button signupButton = (Button) findViewById(R.id.signupButton);
usernameEdit = (EditText) findViewById(R.id.loginUsername);
passwordEdit = (EditText) findViewById(R.id.loginPassword);
twoFactorEdit = (EditText) findViewById(R.id.loginTwoFactor);
loginButton = findViewById(R.id.loginButton);
Button signupButton = findViewById(R.id.signupButton);
usernameEdit = findViewById(R.id.loginUsername);
passwordEdit = findViewById(R.id.loginPassword);
twoFactorEdit = findViewById(R.id.loginTwoFactor);
prefs = getSharedPreferences("fr.free.nrw.commons", MODE_PRIVATE);
@ -64,8 +71,77 @@ public class LoginActivity extends AccountAuthenticatorActivity {
twoFactorEdit.addTextChangedListener(textWatcher);
passwordEdit.setOnEditorActionListener(newLoginInputActionListener());
loginButton.setOnClickListener(this::performLogin);
signupButton.setOnClickListener(this::signUp);
loginButton.setOnClickListener(view -> performLogin());
signupButton.setOnClickListener(view -> signUp());
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
}
@Override
protected void onResume() {
super.onResume();
if (prefs.getBoolean("firstrun", true)) {
WelcomeActivity.startYourself(this);
prefs.edit().putBoolean("firstrun", false).apply();
}
if (app.getCurrentAccount() != null) {
startMainActivity();
}
}
@Override
protected void onDestroy() {
try {
// To prevent leaked window when finish() is called, see http://stackoverflow.com/questions/32065854/activity-has-leaked-window-at-alertdialog-show-method
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
} catch (Exception e) {
e.printStackTrace();
}
usernameEdit.removeTextChangedListener(textWatcher);
passwordEdit.removeTextChangedListener(textWatcher);
twoFactorEdit.removeTextChangedListener(textWatcher);
delegate.onDestroy();
super.onDestroy();
}
@Override
protected void onStart() {
super.onStart();
delegate.onStart();
}
@Override
protected void onStop() {
super.onStop();
delegate.onStop();
}
@Override
protected void onPostResume() {
super.onPostResume();
getDelegate().onPostResume();
}
@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().setContentView(view, params);
}
private void performLogin() {
Timber.d("Login to start!");
LoginTask task = getLoginTask();
task.execute();
}
private void signUp() {
Intent intent = new Intent(this, SignupActivity.class);
startActivity(intent);
}
private class LoginTextWatcher implements TextWatcher {
@ -92,10 +168,10 @@ public class LoginActivity extends AccountAuthenticatorActivity {
return (textView, actionId, keyEvent) -> {
if (loginButton.isEnabled()) {
if (actionId == IME_ACTION_DONE) {
performLogin(textView);
performLogin();
return true;
} else if ((keyEvent != null) && keyEvent.getKeyCode() == KEYCODE_ENTER) {
performLogin(textView);
performLogin();
return true;
}
}
@ -103,39 +179,6 @@ public class LoginActivity extends AccountAuthenticatorActivity {
};
}
protected void onResume() {
super.onResume();
if (prefs.getBoolean("firstrun", true)) {
WelcomeActivity.startYourself(this);
prefs.edit().putBoolean("firstrun", false).apply();
}
if (app.getCurrentAccount() != null) {
startMainActivity();
}
}
@Override
protected void onDestroy() {
try {
// To prevent leaked window when finish() is called, see http://stackoverflow.com/questions/32065854/activity-has-leaked-window-at-alertdialog-show-method
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
} catch (Exception e) {
e.printStackTrace();
}
usernameEdit.removeTextChangedListener(textWatcher);
passwordEdit.removeTextChangedListener(textWatcher);
twoFactorEdit.removeTextChangedListener(textWatcher);
super.onDestroy();
}
private void performLogin(View view) {
Timber.d("Login to start!");
LoginTask task = getLoginTask();
task.execute();
}
private LoginTask getLoginTask() {
return new LoginTask(
this,
@ -164,13 +207,10 @@ public class LoginActivity extends AccountAuthenticatorActivity {
return super.onOptionsItemSelected(item);
}
/**
* Called when Sign Up button is clicked.
* @param view View
*/
public void signUp(View view) {
Intent intent = new Intent(this, SignupActivity.class);
startActivity(intent);
@Override
@NonNull
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();
}
public void askUserForTwoFactorAuth() {
@ -207,4 +247,10 @@ public class LoginActivity extends AccountAuthenticatorActivity {
finish();
}
private AppCompatDelegate getDelegate() {
if (delegate == null) {
delegate = AppCompatDelegate.create(this, null);
}
return delegate;
}
}

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/primarySuperLightColor" />
</shape>

View file

@ -5,20 +5,20 @@
android:layout_height="match_parent">
<FrameLayout
android:layout_width="320sp"
android:layout_width="400sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp">
android:layout_gravity="center"
android:layout_marginTop="8dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
app:cardCornerRadius="4dp"
app:cardElevation="4dp">
@ -32,7 +32,7 @@
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/action_bar_blue"
android:background="@color/primaryColor"
android:gravity="center"
android:paddingBottom="32dp"
android:paddingTop="32dp"
@ -127,6 +127,7 @@
<Button
android:id="@+id/signupButton"
android:layout_width="0dp"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginEnd="8dp"
@ -137,6 +138,7 @@
<Button
android:id="@+id/loginButton"
android:layout_width="0dp"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
@ -149,20 +151,20 @@
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
<android.support.v7.widget.AppCompatImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:elevation="8dp"
android:layout_gravity="center_horizontal"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="32dp"
app:cardElevation="6dp">
app:srcCompat="@drawable/blue_rinse_circle" />
<android.support.v7.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
app:srcCompat="@drawable/commons_logo_large" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.AppCompatImageView
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:elevation="8dp"
app:srcCompat="@drawable/commons_logo_large" />
</FrameLayout>

View file

@ -5,20 +5,20 @@
android:layout_height="match_parent">
<FrameLayout
android:layout_width="320sp"
android:layout_width="400sp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp">
android:layout_marginTop="8dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
app:cardCornerRadius="4dp"
app:cardElevation="4dp">
@ -32,7 +32,7 @@
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/action_bar_blue"
android:background="@color/primaryColor"
android:gravity="center"
android:paddingBottom="32dp"
android:paddingTop="32dp"
@ -127,6 +127,7 @@
<Button
android:id="@+id/signupButton"
android:layout_width="0dp"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginEnd="8dp"
@ -137,6 +138,7 @@
<Button
android:id="@+id/loginButton"
android:layout_width="0dp"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
@ -149,20 +151,20 @@
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
<android.support.v7.widget.AppCompatImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:elevation="8dp"
android:layout_gravity="center_horizontal"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="32dp"
app:cardElevation="6dp">
app:srcCompat="@drawable/blue_rinse_circle" />
<android.support.v7.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
app:srcCompat="@drawable/commons_logo_large" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.AppCompatImageView
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:elevation="8dp"
app:srcCompat="@drawable/commons_logo_large" />
</FrameLayout>

View file

@ -5,19 +5,19 @@
android:layout_height="match_parent">
<FrameLayout
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp">
android:layout_gravity="center"
android:layout_marginTop="8dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
app:cardCornerRadius="4dp"
app:cardElevation="4dp">
@ -32,7 +32,7 @@
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/action_bar_blue"
android:background="@color/primaryColor"
android:gravity="center"
android:paddingBottom="32dp"
android:paddingTop="32dp"
@ -127,6 +127,7 @@
<Button
android:id="@+id/signupButton"
android:layout_width="0dp"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginEnd="8dp"
@ -137,6 +138,7 @@
<Button
android:id="@+id/loginButton"
android:layout_width="0dp"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
@ -149,20 +151,20 @@
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
<android.support.v7.widget.AppCompatImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:elevation="8dp"
android:layout_gravity="center_horizontal"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="32dp"
app:cardElevation="6dp">
app:srcCompat="@drawable/blue_rinse_circle" />
<android.support.v7.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
app:srcCompat="@drawable/commons_logo_large" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.AppCompatImageView
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:elevation="8dp"
app:srcCompat="@drawable/commons_logo_large" />
</FrameLayout>

View file

@ -1,11 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Main application background color -->
<color name="main_background_dark">#303030</color>
<color name="main_background_light">#fafafa</color>
<!-- Colors used by newer Android + Support library for material design theme -->
<color name="primaryColor">#0c609c</color>
<color name="primaryDarkColor">#00376d</color>
<color name="primaryLightColor">#528dcd</color>
<color name="primarySuperLightColor">#d7e8fb</color>
<color name="secondaryColor">#f38b04</color>
<color name="secondaryDarkColor">#ba5d00</color>
<color name="secondaryLightColor">#ffbc46</color>
<color name="primaryTextColor">#ffffff</color>
<color name="secondaryTextColor">#000000</color>
<!-- Some colours are same for dark/light themes. They are written two times in case
we want to change light ones later.
-->
<color name="item_white_background">#ffffffff</color>
<color name="main_background_dark">#000000</color>
<color name="main_background_light">#ffffff</color>
<color name="commons_app_blue_dark">#33FFFFFF</color>
<color name="commons_app_blue_light">#33FFFFFF</color>
<color name="activity_welcome_background_dark">#0c609c</color>
@ -20,4 +33,5 @@
<color name="button_background_light">#B0000000</color>
<color name="upload_overlay_background_dark">#77000000</color>
<color name="upload_overlay_background_light">#44000000</color>
</resources>

View file

@ -2,6 +2,11 @@
<style name="DarkAppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="mainBackground">@color/main_background_dark</item>
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryDarkColor</item>
<item name="colorAccent">@color/primaryColor</item>
<item name="colorButtonNormal">@color/primaryColor</item>
<item name="semitransparentText">@color/commons_app_blue_dark</item>
<item name="commonsAppBlue">@color/activity_welcome_background_dark</item>
<item name="subBackground">@color/sub_background_dark</item>
@ -18,6 +23,11 @@
<style name="LightAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="mainBackground">@color/main_background_light</item>
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryDarkColor</item>
<item name="colorAccent">@color/primaryColor</item>
<item name="colorButtonNormal">@color/primaryColor</item>
<item name="semitransparentText">@color/commons_app_blue_light</item>
<item name="commonsAppBlue">@color/activity_welcome_background_light</item>
<item name="subBackground">@color/sub_background_light</item>
@ -30,8 +40,6 @@
<item name="iconPhoto">@drawable/ic_photo_white_24dp</item>
<item name="iconUndo">@drawable/ic_undo_white_24dp</item>
<item name="colorPrimary">@color/action_bar_blue</item>
<item name="colorPrimaryDark">@color/status_bar_blue</item>
<item name="spinnerTheme">@style/LightSpinnerTheme</item>
</style>