Browse Source

Login modifications

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
680e2f90f9
  1. 3
      app/src/main/AndroidManifest.xml
  2. 84
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java
  3. 8
      app/src/main/res/anim/push_left_in.xml
  4. 7
      app/src/main/res/anim/push_left_out.xml
  5. BIN
      app/src/main/res/drawable/thmmy_3d_wshadow.png
  6. 81
      app/src/main/res/layout/activity_login.xml
  7. 25
      app/src/main/res/values/colors.xml
  8. 1
      app/src/main/res/values/strings.xml
  9. 22
      app/src/main/res/values/styles.xml

3
app/src/main/AndroidManifest.xml

@ -21,7 +21,6 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".activities.MainActivity"
android:label="@string/app_name"
@ -29,8 +28,6 @@
android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".activities.AboutActivity"
android:parentActivityName=".activities.MainActivity">

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

@ -1,8 +1,10 @@
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.widget.Button;
import android.widget.EditText;
@ -21,9 +23,11 @@ import static gr.thmmy.mthmmy.utils.Thmmy.WRONG_USER;
import static gr.thmmy.mthmmy.utils.Thmmy.authenticate;
public class LoginActivity extends BaseActivity {
private static final String TAG = "LoginActivity";
private EditText inputUsername;
private EditText inputPassword;
Button btnLogin;
Button btnGuest;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -32,21 +36,34 @@ public class LoginActivity extends BaseActivity {
inputUsername = (EditText) findViewById(R.id.username);
inputPassword = (EditText) findViewById(R.id.password);
Button btnLogin = (Button) findViewById(R.id.btnLogin);
Button btnGuest = (Button) findViewById(R.id.btnContinueAsGuest);
btnLogin = (Button) findViewById(R.id.btnLogin);
btnGuest = (Button) findViewById(R.id.btnContinueAsGuest);
// Login button Click Event
btnLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String username = inputUsername.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
Log.d(TAG, "Login");
// Check for empty data in the form
if (!username.isEmpty() && !password.isEmpty()) {
if (!validate()) {
onLoginFailed();
return;
}
btnLogin.setEnabled(false);
final ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this,
R.style.AppTheme_Dark_Dialog);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Authenticating...");
progressDialog.show();
String username = inputUsername.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
// login user
try {
switch(new loginAsync().execute(username,password).get()){
switch (new loginAsync().execute(username, password).get()) {
case WRONG_USER:
Toast.makeText(getApplicationContext(),
"Wrong username!", Toast.LENGTH_LONG)
@ -73,25 +90,22 @@ public class LoginActivity extends BaseActivity {
.show();
break;
case OK:
progressDialog.dismiss();
Toast.makeText(getApplicationContext(),
"Login successful!", Toast.LENGTH_LONG)
.show();
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
break;
}
if(new loginAsync().execute(username,password).get() == OK){
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
} else {
// Prompt user to enter credentials
Toast.makeText(getApplicationContext(),
"Please enter the credentials!", Toast.LENGTH_LONG)
.show();
}
progressDialog.dismiss();
btnLogin.setEnabled(true);
}
});
// Link to Register Screen
@ -101,7 +115,18 @@ public class LoginActivity extends BaseActivity {
//TO-DO
}
});
}
@Override
public void onBackPressed() {
// Disable going back to the MainActivity
moveTaskToBack(true);
}
public void onLoginFailed() {
Toast.makeText(getBaseContext(), "Login failed", Toast.LENGTH_LONG).show();
btnLogin.setEnabled(true);
}
private class loginAsync extends AsyncTask<String, Void, Integer> {
@ -123,5 +148,28 @@ public class LoginActivity extends BaseActivity {
protected void onProgressUpdate(Void... values) {
}
}
public boolean validate() {
boolean valid = true;
String email = inputUsername.getText().toString();
String password = inputPassword.getText().toString();
if (email.isEmpty()) {
inputUsername.setError("Enter a valid username");
valid = false;
} else {
inputUsername.setError(null);
}
if (password.isEmpty()) {
inputPassword.setError("Enter a valid password");
valid = false;
} else {
inputPassword.setError(null);
}
return valid;
}
}

8
app/src/main/res/anim/push_left_in.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromXDelta="100%p"
android:toXDelta="0" />
</set>

7
app/src/main/res/anim/push_left_out.xml

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromXDelta="0"
android:toXDelta="-100%p" />
</set>

BIN
app/src/main/res/drawable/thmmy_3d_wshadow.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 820 KiB

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

@ -1,69 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/bg_login"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp">
android:paddingLeft="24dp"
android:paddingRight="24dp">
<ImageView
android:id="@+id/thmmy3dImg"
android:layout_width="wrap_content"
android:layout_height="90dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="40dp"
android:contentDescription="@string/thmmy_img_description"
android:src="@drawable/thmmy_3d_wshadow"/>
<!-- 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">
<EditText
android:id="@+id/username"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="@drawable/box_border"
android:hint="@string/hint_username"
android:inputType="textEmailAddress"
android:maxLines="1"
android:padding="10dp"
android:textColor="@color/input_login"
android:textColorHint="@color/input_login_hint"/>
android:inputType="textPersonName"/>
</android.support.design.widget.TextInputLayout>
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">
<EditText
android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="@drawable/box_border"
android:hint="@string/hint_password"
android:inputType="textPassword"
android:maxLines="1"
android:padding="10dp"
android:textColor="@color/input_login"
android:textColorHint="@color/input_login_hint"/>
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
<!-- Login Button -->
<Button
<android.support.v7.widget.AppCompatButton
android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:background="@drawable/box_border"
android:text="@string/btn_login"
android:textColor="@color/btn_login"/>
<!-- Guest Button -->
android:layout_marginBottom="24dp"
android:layout_marginTop="24dp"
android:padding="12dp"
android:text="@string/btn_login"/>
<Button
android:id="@+id/btnContinueAsGuest"
android:layout_width="fill_parent"
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:textColor="@color/guest_color"
android:textSize="15sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>

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

@ -1,19 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#313335</color>
<color name="colorPrimaryDark">#2b2b2b</color>
<color name="colorPrimaryLight">#616161</color>
<color name="colorAccent">#2b2b2b</color>
<!--Teal-Indigo-->
<!--<color name="primary">#009688</color>
<color name="primary_dark">#00796B</color>
<color name="primary_light">#B2DFDB</color>
<color name="accent">#536DFE</color>
<color name="primary_text">#E7E7E7</color>
<color name="secondary_text">#757575</color>-->
<color name="bg_login">#000000</color>
<color name="input_login">#4CFF00</color>
<color name="input_login_hint">#4CFF00</color>
<color name="btn_login">#4CFF00</color>
<color name="guest_color">#4CFF00</color>
<!--Indigo-Teal-->
<color name="primary">#3F51B5</color>
<color name="primary_dark">#303F9F</color>
<color name="primary_light">#C5CAE9</color>
<color name="accent">#009688</color>
<color name="primary_text">#E7E7E7</color>
<color name="secondary_text">#757575</color>
<color name="transparent">#00000000</color>
<color name="white">#ffffff</color>
<color name="iron">#CCCCCC</color>
<color name="background">#616161</color>
<color name="myColor1">#ffb74d</color>

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

@ -3,6 +3,7 @@
<string name="action_settings">Settings</string>
<string name="section_format">Hello World from section: %1$d</string>
<string name="thmmy_img_description">thmmy.gr</string>
<string name="hint_username">Username</string>
<string name="hint_password">Password</string>
<string name="btn_login">LOGIN</string>

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

@ -3,9 +3,19 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/primary_text</item>
<item name="android:textColorSecondary">@color/secondary_text</item>
<item name="android:windowBackground">@color/primary</item>
<item name="colorControlNormal">@color/iron</item>
<item name="colorControlActivated">@color/white</item>
<item name="colorControlHighlight">@color/white</item>
<item name="android:textColorHint">@color/iron</item>
<item name="colorButtonNormal">@color/primary_dark</item>
</style>
<style name="AppTheme.NoActionBar">
@ -24,4 +34,10 @@
<item name="android:colorBackground">@color/colorPrimary</item>
</style>
<style name="AppTheme.Dark.Dialog" parent="Theme.AppCompat.Dialog">
<item name="colorAccent">@color/white</item>
<item name="android:textColorPrimary">@color/iron</item>
<item name="android:background">@color/primary</item>
</style>
</resources>

Loading…
Cancel
Save