Permalink
Browse files

Implemented network login.

  • Loading branch information...
1 parent 3a4aa03 commit 2c24dd741491ff74f6141d5dc8b15aab435848fe @mfellner committed Jan 18, 2012
@@ -14,29 +14,25 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_relative_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
- android:id="@+id/lbl_email"
+ android:id="@+id/lbl_login_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
- android:text="@string/lbl_email" />
+ android:text="@string/lbl_login_email" />
<EditText
- android:id="@+id/txt_email"
+ android:id="@+id/txt_login_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:layout_below="@+id/lbl_email"
- android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
@@ -45,49 +41,41 @@
</EditText>
<TextView
- android:id="@+id/lbl_password"
+ android:id="@+id/lbl_login_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:layout_below="@+id/txt_email"
- android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
- android:text="@string/lbl_password" />
+ android:text="@string/lbl_login_password" />
<EditText
- android:id="@+id/txt_password"
+ android:id="@+id/txt_login_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:layout_below="@+id/lbl_password"
- android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:inputType="textPassword" />
<Button
- android:id="@+id/btn_login"
+ android:id="@+id/btn_login_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:layout_below="@+id/txt_password"
- android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/btn_login"
android:onClick="doLogin" />
<Button
- android:id="@+id/btn_register"
- android:layout_below="@id/btn_login"
+ android:id="@+id/btn_login_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/btn_register"
android:onClick="doRegister" />
-</RelativeLayout>
+</LinearLayout>
@@ -15,8 +15,8 @@
<resources>
<string name="app_name">Energy2Live</string>
- <string name="lbl_email">Enter your email address</string>
- <string name="lbl_password">Enter your password</string>
+ <string name="lbl_login_email">Enter your user name</string> <!-- TODO change back to email address -->
+ <string name="lbl_login_password">Enter your password</string>
<string name="lbl_latest_activities">Your latest activities</string>
<string name="lbl_add_new_name">Enter activity name</string>
<string name ="lbl_add_new_duration">Select duration of activity</string>
@@ -41,13 +41,14 @@
<string name="msg_delete_activity">Delete this activity?</string>
<string name="msg_stop_recording">Stop recording activity?</string>
<string name="msg_send_activity">Send activity to remote server?</string>
- <string name="msg_bad_time">Please enter a valid time!</string>
+ <string name="msg_bad_time">Please enter a valid time</string>
<string name="msg_creation_successful">Activity created</string>
- <string name="msg_empty_fields">Please fill out all fields!</string>
- <string name="msg_no_provider">No location provider available! (GPS, Wifi, network)</string>
+ <string name="msg_empty_fields">Please fill out all fields</string>
+ <string name="msg_no_provider">No location provider available (GPS, Wifi, network)</string>
<string name="msg_settings_bad_server">Invalid server address!</string>
<string name="msg_remote_no_server">No server address configured!</string>
<string name="msg_remote_post_data">Uploading…</string>
+ <string name="msg_login_failed">Login failed</string>
<string name="lbl_manage_activity_name_label">Name:</string>
<string name="lbl_manage_activity_time_label">Time:</string>
@@ -17,24 +17,68 @@
import android.app.Activity;
import android.os.Bundle;
+import android.util.Log;
import android.view.View;
+import android.widget.EditText;
+import android.widget.Toast;
+import at.tugraz.kmi.energy2live.model.E2LUser;
+import at.tugraz.kmi.energy2live.model.implementation.E2LUserImplementation;
+import at.tugraz.kmi.energy2live.remote.E2LNetworkConnection;
+import at.tugraz.kmi.energy2live.remote.E2LNetworkConnection.ACTION;
+
+public class E2LLoginActivity extends Activity implements E2LNetworkConnection.Callback {
+ private EditText txtEmail;
+ private EditText txtPassword;
-public class E2LLoginActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
+
+ txtEmail = (EditText) findViewById(R.id.txt_login_email);
+ txtPassword = (EditText) findViewById(R.id.txt_login_password);
}
// declared in xml
public void doLogin(View v) {
- // TODO: verify login
- startActivity(Utils.createIntent(this, E2LMainActivity.class));
- finish();
+ String email = txtEmail.getText().toString(); // TODO email is prompted as "username"
+ String password = txtPassword.getText().toString();
+
+ if (email.length() == 0 && password.length() == 0) { // TODO remove later
+ Log.w("E2L", "Start withouth login");
+ startActivity(Utils.createIntent(this, E2LMainActivity.class));
+ finish();
+ return;
+ }
+
+ E2LUser user = new E2LUserImplementation(email, password);
+ E2LNetworkConnection network = new E2LNetworkConnection(this);
+ network.addCallback(this);
+ network.loginUser(user);
}
// declared in xml
public void doRegister(View v) {
// TODO: perform registration
}
+
+ @Override
+ public void onNetworkConnectionResult(ACTION a, boolean b) {
+ switch (a) {
+ case LOGIN:
+ if (b) {
+ startActivity(Utils.createIntent(this, E2LMainActivity.class));
+ finish();
+ } else {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(E2LLoginActivity.this, getResources().getString(R.string.msg_login_failed),
+ Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+ break;
+ }
+ }
}
@@ -0,0 +1,51 @@
+/** Copyright 2011 Maximilian Fellner, Gernot Solic, Florian Sumann
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package at.tugraz.kmi.energy2live.model;
+
+import java.io.Serializable;
+import java.util.List;
+
+import at.tugraz.kmi.energy2live.model.implementation.E2LActivityImplementation;
+
+public interface E2LUser extends Serializable {
+ String getName();
+
+ void setName(String name);
+
+ String getPassword();
+
+ void setPassword(String password);
+
+ String getFullName();
+
+ void setFullName(String fullname);
+
+ String getEmail();
+
+ void setEmail(String email);
+
+ String getHomePage();
+
+ void setHomePage(String homepage);
+
+ int getPrivacy();
+
+ void setPrivacy(int privacy);
+
+ List<E2LActivityImplementation> getActivities();
+
+ void setActivities(List<E2LActivityImplementation> activities);
+}
@@ -0,0 +1,139 @@
+/** Copyright 2011 Maximilian Fellner, Gernot Solic, Florian Sumann
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package at.tugraz.kmi.energy2live.model.implementation;
+
+import java.util.List;
+
+import at.tugraz.kmi.energy2live.model.E2LUser;
+
+import com.j256.ormlite.field.DatabaseField;
+
+public class E2LUserImplementation implements E2LUser {
+ private static final long serialVersionUID = -1669538222952789588L;
+
+ @DatabaseField(generatedId = true)
+ private Integer mId;
+
+ @DatabaseField
+ private String mName;
+
+ @DatabaseField
+ private String mPassword;
+
+ @DatabaseField
+ private String mFullName;
+
+ @DatabaseField
+ private String mEmail;
+
+ @DatabaseField
+ private String mHomePage;
+
+ @DatabaseField
+ private int mPrivacy;
+
+ @DatabaseField
+ private List<E2LActivityImplementation> mActivities;
+
+ public E2LUserImplementation() {
+
+ }
+
+ // TODO add constructor with email address
+ public E2LUserImplementation(String name, String password) {
+ mName = name;
+ mPassword = password;
+ }
+
+ public Integer getId() {
+ return mId;
+ }
+
+ public void setId(Integer id) {
+ mId = id;
+ }
+
+ @Override
+ public String getName() {
+ return mName;
+ }
+
+ @Override
+ public void setName(String name) {
+ mName = name;
+ }
+
+ @Override
+ public String getPassword() {
+ return mPassword;
+ }
+
+ @Override
+ public void setPassword(String password) {
+ mPassword = password;
+ }
+
+ @Override
+ public String getFullName() {
+ return mFullName;
+ }
+
+ @Override
+ public void setFullName(String fullname) {
+ mFullName = fullname;
+ }
+
+ @Override
+ public String getEmail() {
+ return mEmail;
+ }
+
+ @Override
+ public void setEmail(String email) {
+ mEmail = email;
+ }
+
+ @Override
+ public String getHomePage() {
+ return mHomePage;
+ }
+
+ @Override
+ public void setHomePage(String homepage) {
+ mHomePage = homepage;
+ }
+
+ @Override
+ public int getPrivacy() {
+ return mPrivacy;
+ }
+
+ @Override
+ public void setPrivacy(int privacy) {
+ mPrivacy = privacy;
+ }
+
+ @Override
+ public List<E2LActivityImplementation> getActivities() {
+ return mActivities;
+ }
+
+ @Override
+ public void setActivities(List<E2LActivityImplementation> activities) {
+ mActivities = activities;
+ }
+
+}
Oops, something went wrong.

0 comments on commit 2c24dd7

Please sign in to comment.