Advertisement
Guest User

Untitled

a guest
Oct 27th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. package com.kismec.kismecapp1;
  2.  
  3. import android.app.Activity;
  4. import android.app.ProgressDialog;
  5. import android.content.Intent;
  6. import android.graphics.Color;
  7. import android.net.Uri;
  8. import android.os.AsyncTask;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.TextView;
  14.  
  15. import org.json.JSONException;
  16. import org.json.JSONObject;
  17.  
  18. /**
  19. * Created by selva on 10/6/2017.
  20. */
  21.  
  22. public class loginactivity extends Activity
  23. {
  24. Button btnlogin;
  25. EditText tusername,tpassword;
  26. TextView errmsg;
  27.  
  28. private ProgressDialog pdialog;
  29. String username,password;
  30. JSONParser jsonparser=new JSONParser();
  31. private String url_login="http://172.16.140.138/servercode/loginprocess.php";
  32.  
  33. public void onCreate(Bundle b)
  34. {
  35. super.onCreate(b);
  36. setContentView(R.layout.loginlayout);
  37. btnlogin=(Button)findViewById(R.id.btnlogin);
  38. tusername=(EditText)findViewById(R.id.tusername);
  39. tpassword=(EditText)findViewById(R.id.tpassword);
  40. errmsg=(TextView)findViewById(R.id.errmsg);
  41. btnlogin.setOnClickListener(new View.OnClickListener() {
  42. @Override
  43. public void onClick(View v) {
  44. username=tusername.getText().toString();
  45. password=tpassword.getText().toString();
  46. if(username.length()==0 || password.length()==0)
  47. {
  48. errmsg.setText("Invalid Details..");
  49. errmsg.setTextColor(Color.RED);
  50. }
  51. else
  52. {
  53. new getlogindetails().execute();
  54. }
  55. }
  56. });
  57. }
  58. class getlogindetails extends AsyncTask<String,String,String>
  59. {
  60. protected void onPreExecute()
  61. {
  62. super.onPreExecute();
  63. pdialog=new ProgressDialog(loginactivity.this);
  64. pdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  65. pdialog.setMessage("Logging in. Please wait...");
  66. pdialog.setIndeterminate(false);
  67. pdialog.setCancelable(true);
  68. pdialog.show();
  69. }
  70. @Override
  71. protected String doInBackground(String... params)
  72. {
  73. int success;
  74. try
  75. {
  76. Uri.Builder builder=new Uri.Builder()
  77. .appendQueryParameter("username",username)
  78. .appendQueryParameter("password",password);
  79. String query=builder.build().getEncodedQuery();
  80. JSONObject json=jsonparser.makeHttpRequest(url_login,query);
  81. if(json!=null)
  82. {
  83. success=json.getInt("result");
  84. if(success==1)
  85. {
  86. Intent menuintent=new Intent(getApplicationContext(),menuactivity.class);
  87. startActivity(menuintent);
  88. }
  89. else
  90. {
  91. loginactivity.this.runOnUiThread(new Runnable() {
  92. @Override
  93. public void run() {
  94. errmsg.setText("User not found !");
  95. errmsg.setTextColor(Color.RED);
  96. }
  97. });
  98. }
  99. }
  100. else
  101. {
  102. loginactivity.this.runOnUiThread(new Runnable() {
  103. @Override
  104. public void run() {
  105. errmsg.setText("Unable to contact server !");
  106. errmsg.setTextColor(Color.RED);
  107. }
  108. });
  109. }
  110. }
  111. catch(JSONException e)
  112. {
  113. e.printStackTrace();
  114. }
  115. return null;
  116. }
  117. protected void onPostExecute(String s)
  118. {
  119. pdialog.dismiss();
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement