Browse Source

ProgressDialog replaced by ProgressBar. Login screen focuses fixes.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
994d4d5057
  1. 35
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java
  2. 24
      app/src/main/res/drawable/login_progress_bar_bg.xml
  3. 188
      app/src/main/res/layout/activity_login.xml
  4. 7
      app/src/main/res/values/strings.xml

35
app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java

@ -1,13 +1,15 @@
package gr.thmmy.mthmmy.activities;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;
import gr.thmmy.mthmmy.R;
@ -100,6 +102,7 @@ public class LoginActivity extends BaseActivity {
if (username.isEmpty()) {
inputUsername.setError("Enter a valid username");
inputUsername.requestFocus();
valid = false;
} else {
inputUsername.setError(null);
@ -107,6 +110,8 @@ public class LoginActivity extends BaseActivity {
if (password.isEmpty()) {
inputPassword.setError("Enter a valid password", null);
if (valid)
inputPassword.requestFocus();
valid = false;
} else {
inputPassword.setError(null);
@ -118,7 +123,8 @@ public class LoginActivity extends BaseActivity {
//--------------------------------------------LOGIN-------------------------------------------------
private class LoginTask extends AsyncTask<String, Void, Integer> {
//Class variables
ProgressDialog progressDialog;
private LinearLayout spinner;
private ScrollView loginContent;
@Override
protected Integer doInBackground(String... params) {
@ -129,11 +135,17 @@ public class LoginActivity extends BaseActivity {
protected void onPreExecute() { //Show a progress dialog until done
btnLogin.setEnabled(false); //Login button shouldn't be pressed during this
progressDialog = new ProgressDialog(LoginActivity.this,R.style.AppTheme_Dark_Dialog);
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Authenticating...");
progressDialog.show();
spinner = (LinearLayout) findViewById(R.id.login_progress_bar);
loginContent = (ScrollView) findViewById(R.id.inner_scroll_view);
View view = getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
loginContent.setVisibility(View.INVISIBLE);
spinner.setVisibility(View.VISIBLE);
}
@ -153,10 +165,12 @@ public class LoginActivity extends BaseActivity {
case WRONG_USER:
Toast.makeText(getApplicationContext(),
"Wrong username!", Toast.LENGTH_LONG).show();
inputUsername.requestFocus();
break;
case WRONG_PASSWORD:
Toast.makeText(getApplicationContext(),
"Wrong password!", Toast.LENGTH_LONG).show();
inputPassword.requestFocus();
break;
case FAILURE:
Toast.makeText(getApplicationContext(),
@ -174,9 +188,10 @@ public class LoginActivity extends BaseActivity {
}
//Login failed
btnLogin.setEnabled(true); //Re-enable login button
progressDialog.dismiss(); //Hide progress dialog
loginContent.setVisibility(View.VISIBLE);
spinner.setVisibility(View.INVISIBLE);
}
}
//---------------------------------------LOGIN ENDS-------------------------------------------------
}
}

24
app/src/main/res/drawable/login_progress_bar_bg.xml

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360">
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false">
<size
android:width="76dip"
android:height="76dip"/>
<gradient
android:angle="0"
android:endColor="@color/accent"
android:startColor="@color/accent"
android:type="sweep"
android:useLevel="false"
/>
</shape>
</rotate>

188
app/src/main/res/layout/activity_login.xml

@ -1,97 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true">
<LinearLayout
<ScrollView
android:id="@+id/inner_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp">
android:layout_height="match_parent">
<Space
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"/>
android:layout_height="wrap_content"
android:layout_gravity="top"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp">
<ImageView
android:id="@+id/thmmyLogo"
android:layout_width="match_parent"
android:layout_height="144dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="0dp"
android:contentDescription="@string/thmmy_img_description"
android:src="@drawable/logo_try_no_letter"/>
<ImageView
android:id="@+id/thmmy3dImg"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="0dp"
android:contentDescription="@string/thmmy_img_description"
android:src="@drawable/thmmy_material_somehow"/>
<Space
android:layout_width="match_parent"
android:layout_height="25dp"/>
<Space
android:layout_width="match_parent"
android:layout_height="10dp"/>
<ImageView
android:id="@+id/thmmyLogo"
android:layout_width="match_parent"
android:layout_height="144dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="0dp"
android:contentDescription="@string/thmmy_img_description"
android:src="@drawable/logo_try_no_letter"/>
<!-- Username Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">
<ImageView
android:id="@+id/thmmy3dImg"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="0dp"
android:contentDescription="@string/thmmy_img_description"
android:src="@drawable/thmmy_material_somehow"/>
<Space
android:layout_width="match_parent"
android:layout_height="10dp"/>
<EditText
android:id="@+id/username"
<!-- Username Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_username"
android:inputType="textPersonName"/>
</android.support.design.widget.TextInputLayout>
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_username"
android:inputType="textPersonName"/>
</android.support.design.widget.TextInputLayout>
<EditText
android:id="@+id/password"
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_password"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:passwordToggleEnabled="true">
<!-- Login Button -->
<android.support.v7.widget.AppCompatButton
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginTop="24dp"
android:padding="12dp"
android:text="@string/btn_login"
android:textSize="18sp"/>
<Button
android:id="@+id/btnContinueAsGuest"
android:layout_width="match_parent"
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_password"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
<!-- Login Button -->
<android.support.v7.widget.AppCompatButton
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginTop="24dp"
android:padding="12dp"
android:text="@string/btn_login"
android:textSize="18sp"/>
<Button
android:id="@+id/btnContinueAsGuest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginTop="40dip"
android:background="@null"
android:text="@string/btn_continue_as_guest"
android:textAllCaps="false"
android:textSize="15sp"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/login_progress_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="invisible">
<ProgressBar
style="?android:attr/progressBarStyleInverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginTop="40dip"
android:background="@null"
android:text="@string/btn_continue_as_guest"
android:textAllCaps="false"
android:textSize="15sp"/>
android:layout_gravity="center"
android:background="@drawable/login_progress_bar_bg"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="@string/login_spinner"
android:textColor="@color/accent"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>

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

@ -11,11 +11,12 @@
<string name="version">v%1$s</string>
<string name="logo">logo</string>
<string name="login">Login</string>
<string name="login_spinner">Authenticating&#8230;</string>
<string name="logout">Logout</string>
<string name="username">Username should be here...</string>
<string name="subject">Subject should be here...</string>
<string name="post">Post should be here...</string>
<string name="username">Username should be here&#8230;</string>
<string name="subject">Subject should be here&#8230;</string>
<string name="post">Post should be here&#8230;</string>
<string name="text_first">first</string>
<string name="text_previous">previous</string>
<string name="text_page">Page</string>

Loading…
Cancel
Save