Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

login working

  • Loading branch information...
commit 0374a1e750f0541454fb23c43236bf0db78af836 1 parent 96d24a1
@mahmoud-abdelaziz authored
View
2  AndroidManifest.xml
@@ -7,6 +7,7 @@
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
+ <uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
@@ -22,6 +23,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity android:name="RegisterActivity"></activity>
</application>
</manifest>
View
61 gen/com/dkit/eventsmanger/R.java
@@ -14,36 +14,39 @@
public static final int ic_launcher=0x7f020000;
}
public static final class id {
- public static final int button1=0x7f070003;
- public static final int button2=0x7f070005;
- public static final int checkBox1=0x7f070004;
- public static final int editText1=0x7f070001;
- public static final int editText2=0x7f070002;
- public static final int editText3=0x7f070006;
- public static final int editText4=0x7f07000e;
- public static final int imageView1=0x7f070012;
- public static final int item_event_attending=0x7f070015;
- public static final int item_event_date=0x7f070014;
- public static final int item_event_edit=0x7f070016;
- public static final int item_event_mark_past=0x7f070017;
- public static final int item_event_name=0x7f070013;
- public static final int item_event_remove=0x7f070018;
- public static final int menu_settings=0x7f07001d;
- public static final int radio0=0x7f07001b;
- public static final int radio1=0x7f07001c;
- public static final int radio2=0x7f07001a;
- public static final int radioGroup1=0x7f070019;
- public static final int scrollView1=0x7f07000b;
- public static final int spinner1=0x7f070008;
- public static final int spinner2=0x7f07000a;
+ public static final int button1=0x7f07000d;
+ public static final int editText1=0x7f070006;
+ public static final int editText2=0x7f070007;
+ public static final int editText3=0x7f070008;
+ public static final int editText4=0x7f070011;
+ public static final int imageView1=0x7f070015;
+ public static final int item_event_attending=0x7f070018;
+ public static final int item_event_date=0x7f070017;
+ public static final int item_event_edit=0x7f070019;
+ public static final int item_event_mark_past=0x7f07001a;
+ public static final int item_event_name=0x7f070016;
+ public static final int item_event_remove=0x7f07001b;
+ public static final int login_btn=0x7f070005;
+ public static final int login_email=0x7f070001;
+ public static final int login_password=0x7f070002;
+ public static final int login_register_btn=0x7f070004;
+ public static final int login_remember_me=0x7f070003;
+ public static final int menu_settings=0x7f070020;
+ public static final int radio0=0x7f07001e;
+ public static final int radio1=0x7f07001f;
+ public static final int radio2=0x7f07001d;
+ public static final int radioGroup1=0x7f07001c;
+ public static final int scrollView1=0x7f07000e;
+ public static final int spinner1=0x7f07000a;
+ public static final int spinner2=0x7f07000c;
public static final int textView1=0x7f070000;
- public static final int textView2=0x7f070007;
- public static final int textView3=0x7f070009;
- public static final int textView4=0x7f07000c;
- public static final int textView5=0x7f07000d;
- public static final int textView6=0x7f07000f;
- public static final int textView7=0x7f070010;
- public static final int textView8=0x7f070011;
+ public static final int textView2=0x7f070009;
+ public static final int textView3=0x7f07000b;
+ public static final int textView4=0x7f07000f;
+ public static final int textView5=0x7f070010;
+ public static final int textView6=0x7f070012;
+ public static final int textView7=0x7f070013;
+ public static final int textView8=0x7f070014;
}
public static final class layout {
public static final int activity_login=0x7f030000;
View
47 res/layout/activity_login.xml
@@ -16,7 +16,7 @@
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
- android:id="@+id/editText1"
+ android:id="@+id/login_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
@@ -28,46 +28,41 @@
android:inputType="textEmailAddress" />
<EditText
- android:id="@+id/editText2"
+ android:id="@+id/login_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
- android:layout_below="@+id/editText1"
+ android:layout_below="@+id/login_email"
android:ems="10"
android:hint="Password"
- android:inputType="textPassword" >
-
- <requestFocus />
- </EditText>
-
- <Button
- android:id="@+id/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/checkBox1"
- android:layout_alignRight="@+id/checkBox1"
- android:layout_below="@+id/checkBox1"
- android:layout_marginTop="24dp"
- android:text="Login" />
+ android:inputType="textPassword" />
<CheckBox
- android:id="@+id/checkBox1"
+ android:id="@+id/login_remember_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/editText2"
- android:layout_marginLeft="73dp"
- android:layout_marginTop="32dp"
+ android:layout_alignLeft="@+id/textView1"
+ android:layout_below="@+id/login_password"
android:text="Remember me" />
<Button
- android:id="@+id/button2"
+ android:id="@+id/login_register_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/button1"
- android:layout_alignRight="@+id/button1"
- android:layout_below="@+id/button1"
+ android:layout_alignLeft="@+id/login_btn"
+ android:layout_alignRight="@+id/login_btn"
+ android:layout_below="@+id/login_remember_me"
+ android:layout_marginTop="67dp"
android:text="Register" />
+ <Button
+ android:id="@+id/login_btn"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignLeft="@+id/login_remember_me"
+ android:layout_alignRight="@+id/login_remember_me"
+ android:layout_below="@+id/login_remember_me"
+ android:text="Login" />
+
</RelativeLayout>
View
100 src/com/dkit/eventsmanger/JSONParser.java
@@ -0,0 +1,100 @@
+package com.dkit.eventsmanger;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.util.Log;
+
+public class JSONParser {
+
+ static InputStream is = null;
+ static JSONObject jObj = null;
+ static String json = "";
+
+ // constructor
+ public JSONParser() {
+
+ }
+
+ // function get json from url
+ // by making HTTP POST or GET mehtod
+ public JSONObject makeHttpRequest(String url, String method,
+ List<NameValuePair> params) {
+
+ // Making HTTP request
+ try {
+
+ // check for request method
+ if(method == "POST"){
+ // request method is POST
+ // defaultHttpClient
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ HttpPost httpPost = new HttpPost(url);
+ httpPost.setEntity(new UrlEncodedFormEntity(params));
+
+ HttpResponse httpResponse = httpClient.execute(httpPost);
+ HttpEntity httpEntity = httpResponse.getEntity();
+ is = httpEntity.getContent();
+
+ }else if(method == "GET"){
+ // request method is GET
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ String paramString = URLEncodedUtils.format(params, "utf-8");
+ url += "?" + paramString;
+ HttpGet httpGet = new HttpGet(url);
+
+ HttpResponse httpResponse = httpClient.execute(httpGet);
+ HttpEntity httpEntity = httpResponse.getEntity();
+ is = httpEntity.getContent();
+ }
+
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ is, "iso-8859-1"), 8);
+ StringBuilder sb = new StringBuilder();
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ sb.append(line + "\n");
+ }
+ is.close();
+ json = sb.toString();
+ } catch (Exception e) {
+ Log.e("Buffer Error", "Error converting result " + e.toString());
+ }
+
+ // try parse the string to a JSON object
+ try {
+ jObj = new JSONObject(json);
+ } catch (JSONException e) {
+ Log.e("JSON Parser", "Error parsing data " + e.toString());
+ }
+
+ // return JSON String
+ return jObj;
+
+ }
+}
View
97 src/com/dkit/eventsmanger/LoginActivity.java
@@ -1,16 +1,51 @@
package com.dkit.eventsmanger;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.http.NameValuePair;
+import org.apache.http.message.BasicNameValuePair;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.SharedPreferences;
+import android.util.Log;
import android.view.Menu;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.Toast;
public class LoginActivity extends Activity {
+ ProgressDialog pDialog;
+ JSONParser jsonParser = new JSONParser();
+ final String LOGIN_URL = "http://events-android.aws.af.cm/users.php";
+ TextView email, password;
+ Button loginBtn, registerBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.create_event);
- }
+ setContentView(R.layout.activity_login);
+ email = (TextView) findViewById(R.id.login_email);
+ password = (TextView) findViewById(R.id.login_password);
+ loginBtn = (Button) findViewById(R.id.login_btn);
+ SharedPreferences settings = getSharedPreferences("main", 0);
+ Log.d("login", settings.getString("token", "noLogged"));
+ loginBtn.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View arg0) {
+ // TODO Auto-generated method stub
+ new LoginTask().execute();
+ }
+ });
+ }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@@ -19,4 +54,62 @@ public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
+ class LoginTask extends AsyncTask<String, String, String> {
+ boolean login = false;
+
+ /**
+ * Before starting background thread Show Progress Dialog
+ * */
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+ pDialog = new ProgressDialog(LoginActivity.this);
+ pDialog.setMessage("Login in process....");
+ pDialog.setIndeterminate(false);
+ pDialog.setCancelable(true);
+ pDialog.show();
+ }
+
+ /**
+ * Creating product
+ * */
+ protected String doInBackground(String... args) {
+ String emailStr = email.getText().toString();
+ String passwordStr = password.getText().toString();
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("type", "login"));
+ params.add(new BasicNameValuePair("email", emailStr));
+ params.add(new BasicNameValuePair("password", passwordStr));
+
+ JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "GET",
+ params);
+ Log.d("here", "here");
+ try {
+ if (json.getString("status").compareTo("404") == 0) {
+ Log.d("Login", "Login 404");
+ } else {
+ SharedPreferences settings = getSharedPreferences("main", 0);
+ SharedPreferences.Editor editor = settings.edit();
+ editor.putString("token", json.getString("token"));
+ editor.commit();
+ Log.d("Login", "Login 200");
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ Log.d("Create Response", json.toString());
+ return null;
+ }
+
+ /**
+ * After completing background task Dismiss the progress dialog
+ * **/
+ protected void onPostExecute(String file_url) {
+ // dismiss the dialog once done
+ pDialog.dismiss();
+ }
+
+ }
}
View
18 src/com/dkit/eventsmanger/RegisterActivity.java
@@ -0,0 +1,18 @@
+package com.dkit.eventsmanger;
+
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class RegisterActivity extends Activity{
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_register);
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.