Browse Source

Added login activity, made it main and launcher

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
2bd0d13388
  1. 20
      app/src/main/AndroidManifest.xml
  2. 127
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java
  3. 5
      app/src/main/res/drawable/box_border.xml
  4. 69
      app/src/main/res/layout/activity_login.xml
  5. 6
      app/src/main/res/values/colors.xml
  6. 5
      app/src/main/res/values/strings.xml

20
app/src/main/AndroidManifest.xml

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gr.thmmy.mthmmy"> package="gr.thmmy.mthmmy">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application <application
android:allowBackup="true" android:allowBackup="true"
@ -12,15 +12,15 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.LoginActivity"
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTop" android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
@ -28,7 +28,7 @@
android:parentActivityName=".activities.MainActivity"> android:parentActivityName=".activities.MainActivity">
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity" /> android:value=".activities.MainActivity"/>
</activity> </activity>
<activity <activity
android:name=".activities.TopicActivity" android:name=".activities.TopicActivity"
@ -36,9 +36,11 @@
android:parentActivityName=".activities.MainActivity"> android:parentActivityName=".activities.MainActivity">
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity" /> android:value=".activities.MainActivity"/>
</activity>
<activity android:name=".activities.BaseActivity"/>
<activity android:name=".activities.MainActivity">
</activity> </activity>
<activity android:name=".activities.BaseActivity"></activity>
</application> </application>
</manifest> </manifest>

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

@ -0,0 +1,127 @@
package gr.thmmy.mthmmy.activities;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.concurrent.ExecutionException;
import gr.thmmy.mthmmy.R;
import static gr.thmmy.mthmmy.utils.Thmmy.CERTIFICATE_ERROR;
import static gr.thmmy.mthmmy.utils.Thmmy.FAILED;
import static gr.thmmy.mthmmy.utils.Thmmy.OK;
import static gr.thmmy.mthmmy.utils.Thmmy.OTHER_ERROR;
import static gr.thmmy.mthmmy.utils.Thmmy.WRONG_PASSWORD;
import static gr.thmmy.mthmmy.utils.Thmmy.WRONG_USER;
import static gr.thmmy.mthmmy.utils.Thmmy.authenticate;
public class LoginActivity extends BaseActivity {
private EditText inputUsername;
private EditText inputPassword;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
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);
// 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();
// Check for empty data in the form
if (!username.isEmpty() && !password.isEmpty()) {
// login user
try {
switch(new loginAsync().execute(username,password).get()){
case WRONG_USER:
Toast.makeText(getApplicationContext(),
"Wrong username!", Toast.LENGTH_LONG)
.show();
break;
case WRONG_PASSWORD:
Toast.makeText(getApplicationContext(),
"Wrong password!", Toast.LENGTH_LONG)
.show();
break;
case FAILED:
Toast.makeText(getApplicationContext(),
"Check your connection!", Toast.LENGTH_LONG)
.show();
break;
case CERTIFICATE_ERROR:
Toast.makeText(getApplicationContext(),
"Certificate error!", Toast.LENGTH_LONG)
.show();
break;
case OTHER_ERROR:
Toast.makeText(getApplicationContext(),
"Check your connection!", Toast.LENGTH_LONG)
.show();
break;
case OK:
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
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();
}
}
});
// Link to Register Screen
btnGuest.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//TO-DO
}
});
}
private class loginAsync extends AsyncTask<String, Void, Integer> {
@Override
protected Integer doInBackground(String... params) {
return authenticate(params[0], params[1]);
}
@Override
protected void onPostExecute(Integer result) {
}
@Override
protected void onPreExecute() {
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
}

5
app/src/main/res/drawable/box_border.xml

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@color/transparent" />
<stroke android:width="1dip" android:color="#4CFF00"/>
</shape>

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

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<EditText
android:id="@+id/username"
android:layout_width="fill_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"/>
<EditText
android:id="@+id/password"
android:layout_width="fill_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"/>
<!-- Login Button -->
<Button
android:id="@+id/btnLogin"
android:layout_width="fill_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 -->
<Button
android:id="@+id/btnContinueAsGuest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
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>

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

@ -5,6 +5,12 @@
<color name="colorPrimaryLight">#616161</color> <color name="colorPrimaryLight">#616161</color>
<color name="colorAccent">#2b2b2b</color> <color name="colorAccent">#2b2b2b</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>
<color name="transparent">#00000000</color> <color name="transparent">#00000000</color>
<color name="white">#ffffff</color> <color name="white">#ffffff</color>

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

@ -3,6 +3,11 @@
<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="hint_username">Username</string>
<string name="hint_password">Password</string>
<string name="btn_login">LOGIN</string>
<string name="btn_continue_as_guest">Don\'t have an account? Continue as guest!</string>
<string name="about">About</string> <string name="about">About</string>
<string name="version">v%1$s</string> <string name="version">v%1$s</string>
<string name="logo">logo</string> <string name="logo">logo</string>

Loading…
Cancel
Save