Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. package com.xyz.dbapp;
  2.  
  3. import android.app.Activity;
  4. import android.app.ProgressDialog;
  5. import android.content.Intent;
  6. import android.os.AsyncTask;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.Toast;
  13. import org.json.JSONException;
  14. import org.json.JSONObject;
  15.  
  16.  
  17. /**
  18. * Created by selvakumar on 6/23/2015.
  19. */
  20. public class loginactivity extends Activity
  21. {
  22. private ProgressDialog pDialog;
  23. JSONParser jsonParser = new JSONParser();
  24. private static final String url_login = "http://192.168.43.105/xamarin/loginprocess.php";
  25. String username;
  26. String password;
  27. EditText e1;
  28. EditText e2;
  29. public void onCreate(Bundle b)
  30. {
  31. super.onCreate(b);
  32. setContentView(R.layout.loginlayout);
  33. e1=(EditText)findViewById(R.id.tusername);
  34. e2=(EditText)findViewById(R.id.tpassword);
  35. Button btnlogin = (Button) findViewById(R.id.btnlogin);
  36. btnlogin.setOnClickListener(new View.OnClickListener()
  37. {
  38. public void onClick(View view)
  39. {
  40. username=e1.getText().toString();
  41. password=e2.getText().toString();
  42. new getlogindetails().execute(username,password);
  43. }
  44. });
  45.  
  46. }
  47. class getlogindetails extends AsyncTask<String, String, String>
  48. {
  49. protected void onPreExecute()
  50. {
  51. super.onPreExecute();
  52. pDialog = new ProgressDialog(loginactivity.this);
  53. pDialog.setMessage("Logging in. Please wait...");
  54. pDialog.setIndeterminate(false);
  55. pDialog.setCancelable(true);
  56. pDialog.show();
  57. }
  58. protected String doInBackground(String... params)
  59. {
  60. int success;
  61. try
  62. {
  63.  
  64. JSONObject json = jsonParser.makeHttpRequest(url_login, username,password);
  65. Log.d("Login", json.toString());
  66. success = json.getInt("result");
  67. if (success == 1)
  68. {
  69. Intent myintent=new Intent(getApplicationContext(),menuactivity.class);
  70. startActivity(myintent);
  71. }
  72. else
  73. {
  74. loginactivity.this.runOnUiThread(new Runnable()
  75. {
  76. public void run()
  77. {
  78. Toast.makeText(getApplicationContext(),"Not Found",Toast.LENGTH_LONG).show();
  79. }
  80. });
  81. }
  82. }
  83. catch (JSONException e)
  84. {
  85. e.printStackTrace();
  86. }
  87. return null;
  88. }
  89. protected void onPostExecute(String file_url)
  90. {
  91. pDialog.dismiss();
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement