Browse Source

Login modifications

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
680e2f90f9
  1. 3
      app/src/main/AndroidManifest.xml
  2. 82
      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. 79
      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"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
@ -29,8 +28,6 @@
android:launchMode="singleTop" android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar">
</activity> </activity>
<activity <activity
android:name=".activities.AboutActivity" android:name=".activities.AboutActivity"
android:parentActivityName=".activities.MainActivity"> android:parentActivityName=".activities.MainActivity">

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

@ -1,8 +1,10 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities;
import android.app.ProgressDialog;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; 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; import static gr.thmmy.mthmmy.utils.Thmmy.authenticate;
public class LoginActivity extends BaseActivity { public class LoginActivity extends BaseActivity {
private static final String TAG = "LoginActivity";
private EditText inputUsername; private EditText inputUsername;
private EditText inputPassword; private EditText inputPassword;
Button btnLogin;
Button btnGuest;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -32,18 +36,31 @@ public class LoginActivity extends BaseActivity {
inputUsername = (EditText) findViewById(R.id.username); inputUsername = (EditText) findViewById(R.id.username);
inputPassword = (EditText) findViewById(R.id.password); inputPassword = (EditText) findViewById(R.id.password);
Button btnLogin = (Button) findViewById(R.id.btnLogin); btnLogin = (Button) findViewById(R.id.btnLogin);
Button btnGuest = (Button) findViewById(R.id.btnContinueAsGuest); btnGuest = (Button) findViewById(R.id.btnContinueAsGuest);
// Login button Click Event // Login button Click Event
btnLogin.setOnClickListener(new View.OnClickListener() { btnLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) { public void onClick(View view) {
String username = inputUsername.getText().toString().trim(); Log.d(TAG, "Login");
String password = inputPassword.getText().toString().trim();
// Check for empty data in the form // 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 // login user
try { try {
switch (new loginAsync().execute(username, password).get()) { switch (new loginAsync().execute(username, password).get()) {
@ -73,25 +90,22 @@ public class LoginActivity extends BaseActivity {
.show(); .show();
break; break;
case OK: case OK:
progressDialog.dismiss();
Toast.makeText(getApplicationContext(),
"Login successful!", Toast.LENGTH_LONG)
.show();
Intent intent = new Intent(LoginActivity.this, MainActivity.class); Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent); startActivity(intent);
finish();
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
break; break;
} }
if(new loginAsync().execute(username,password).get() == OK){
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
}
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
e.printStackTrace(); e.printStackTrace();
} }
} else { progressDialog.dismiss();
// Prompt user to enter credentials btnLogin.setEnabled(true);
Toast.makeText(getApplicationContext(),
"Please enter the credentials!", Toast.LENGTH_LONG)
.show();
}
} }
}); });
// Link to Register Screen // Link to Register Screen
@ -101,7 +115,18 @@ public class LoginActivity extends BaseActivity {
//TO-DO //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> { private class loginAsync extends AsyncTask<String, Void, Integer> {
@ -123,5 +148,28 @@ public class LoginActivity extends BaseActivity {
protected void onProgressUpdate(Void... values) { 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

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

@ -1,69 +1,76 @@
<?xml version="1.0" encoding="utf-8"?> <?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_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="@color/bg_login" android:fitsSystemWindows="true">
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="20dp" android:paddingLeft="24dp"
android:paddingRight="20dp"> 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 <EditText
android:id="@+id/username" android:id="@+id/username"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="@drawable/box_border"
android:hint="@string/hint_username" android:hint="@string/hint_username"
android:inputType="textEmailAddress" android:inputType="textPersonName"/>
android:maxLines="1" </android.support.design.widget.TextInputLayout>
android:padding="10dp"
android:textColor="@color/input_login" <!-- Password Label -->
android:textColorHint="@color/input_login_hint"/> <android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp">
<EditText <EditText
android:id="@+id/password" android:id="@+id/password"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="@drawable/box_border"
android:hint="@string/hint_password" android:hint="@string/hint_password"
android:inputType="textPassword" android:inputType="textPassword"/>
android:maxLines="1" </android.support.design.widget.TextInputLayout>
android:padding="10dp"
android:textColor="@color/input_login"
android:textColorHint="@color/input_login_hint"/>
<!-- Login Button --> <!-- Login Button -->
<android.support.v7.widget.AppCompatButton
<Button
android:id="@+id/btnLogin" android:id="@+id/btnLogin"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dip" android:layout_marginBottom="24dp"
android:background="@drawable/box_border" android:layout_marginTop="24dp"
android:text="@string/btn_login" android:padding="12dp"
android:textColor="@color/btn_login"/> android:text="@string/btn_login"/>
<!-- Guest Button -->
<Button <Button
android:id="@+id/btnContinueAsGuest" android:id="@+id/btnContinueAsGuest"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginTop="40dip" android:layout_marginTop="40dip"
android:background="@null" android:background="@null"
android:text="@string/btn_continue_as_guest" android:text="@string/btn_continue_as_guest"
android:textAllCaps="false" android:textAllCaps="false"
android:textColor="@color/guest_color"
android:textSize="15sp"/> 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"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="colorPrimary">#313335</color> <!--Teal-Indigo-->
<color name="colorPrimaryDark">#2b2b2b</color> <!--<color name="primary">#009688</color>
<color name="colorPrimaryLight">#616161</color> <color name="primary_dark">#00796B</color>
<color name="colorAccent">#2b2b2b</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> <!--Indigo-Teal-->
<color name="input_login">#4CFF00</color> <color name="primary">#3F51B5</color>
<color name="input_login_hint">#4CFF00</color> <color name="primary_dark">#303F9F</color>
<color name="btn_login">#4CFF00</color> <color name="primary_light">#C5CAE9</color>
<color name="guest_color">#4CFF00</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="transparent">#00000000</color>
<color name="white">#ffffff</color> <color name="white">#ffffff</color>
<color name="iron">#CCCCCC</color>
<color name="background">#616161</color> <color name="background">#616161</color>
<color name="myColor1">#ffb74d</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="action_settings">Settings</string>
<string name="section_format">Hello World from section: %1$d</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_username">Username</string>
<string name="hint_password">Password</string> <string name="hint_password">Password</string>
<string name="btn_login">LOGIN</string> <string name="btn_login">LOGIN</string>

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

@ -3,9 +3,19 @@
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/colorAccent</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>
<style name="AppTheme.NoActionBar"> <style name="AppTheme.NoActionBar">
@ -24,4 +34,10 @@
<item name="android:colorBackground">@color/colorPrimary</item> <item name="android:colorBackground">@color/colorPrimary</item>
</style> </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> </resources>

Loading…
Cancel
Save