protected void onPreExecute() { // NOTE: You can call UI Element here. // Start Progress Dialog (Message) mProgressHUD = ProgressHUD.show(LoginActivity.this, "Connecting", true, true, this); ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); String names = username.getText().toString(); String appide = pass.getText().toString(); /* nameValuePairs.add(new BasicNameValuePair("user", names)); nameValuePairs.add(new BasicNameValuePair("pass", appide)); */ nameValuePairs.add(new BasicNameValuePair("email", names)); nameValuePairs.add(new BasicNameValuePair("password", appide)); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.thumpi.com/jazeit_api/api_user/login"); // "http://thumpi.com/webservices/code/User/authenticate"); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Toast.makeText(getBaseContext(), "Invalid Ip", Toast.LENGTH_LONG).show(); e.printStackTrace(); } }
@Override public void onCancel(DialogInterface dialog) { this.cancel(true); mProgressHUD.dismiss(); }
protected void onPostExecute(Void unused) { // NOTE: You can call UI Element here. // Close progress dialog mProgressHUD.dismiss(); try { JSONObject json_data = new JSONObject(result); String status = json_data.getString("status"); if (status.equals("false")) { new AlertDialog.Builder(LoginActivity.this) .setTitle(R.string.app_name) .setMessage(R.string.Password_is_Match) .setNeutralButton(R.string.OK_btn, null) .setInverseBackgroundForced(true) .show(); } else { JSONObject json_obj1 = json_data.getJSONObject("userinfo"); String status1 = json_obj1.getString("status").toString(); String Email = json_obj1.getString("email").toString(); String user_id = json_obj1.getString("userid").toString(); String firstname = json_obj1.getString("fname").toString(); prefs = getSharedPreferences(prefName, MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); // ---save the values in the EditText view to preferences--- editor.putString("firstname", firstname); editor.putString("status", status1); editor.putString("Email", Email); editor.putString("user_id", user_id); // ---saves the values--- editor.commit(); progressDialog.dismiss(); Log.d("Original data : ", "" + status1 + "" + Email); Intent intent = new Intent(LoginActivity.this, Search_catagory.class); // Intent intent = new Intent(LoginActivity.this,Home_activity.class); startActivity(intent); } /* if(json_data==null) { new AlertDialog.Builder(LoginActivity.this).setTitle(R.string.app_name).setMessage(R.string.Password_is_Match).setNeutralButton(R.string.OK_btn,null).setInverseBackgroundForced(true).show(); }else { Log.d("json_data : ", "" + json_data); String flag = json_data.getString("code").toString(); if (flag.equals("5")) { new AlertDialog.Builder(LoginActivity.this).setTitle(R.string.app_name).setMessage(R.string.Password_is_Match).setNeutralButton(R.string.OK_btn,null).setInverseBackgroundForced(true).show(); }else if (flag.equals("4")) { new AlertDialog.Builder(LoginActivity.this).setTitle(R.string.app_name).setMessage(R.string.User_not_Creted).setNeutralButton(R.string.OK_btn,null).setInverseBackgroundForced(true).show(); }else { } }*/ } catch (Exception e) { Log.e("Fail 3", e.toString()); } }