Advertisement
Guest User

Untitled

a guest
Oct 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 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 pc03 on 10/28/2017.
  20. */
  21.  
  22. public class adduseractivity extends Activity {
  23.  
  24. Button btnadduser;
  25. EditText tusername,tpassword,tfullname;
  26. TextView errmsg;
  27.  
  28. private ProgressDialog pdialog;
  29. String username,password,fullname;
  30. JSONParser jsonparser=new JSONParser();
  31. private String url_login="http://172.16.140.108/servercode/adduser.php";
  32.  
  33.  
  34. public void onCreate(Bundle b)
  35. {
  36. super.onCreate(b);
  37. setContentView(R.layout.adduserlayout);
  38.  
  39. btnadduser=(Button)findViewById(R.id.btnadduser);
  40. tusername=(EditText)findViewById(R.id.tusername);
  41. tpassword=(EditText)findViewById(R.id.tpassword);
  42. tfullname=(EditText)findViewById(R.id.tfullname);
  43. errmsg=(TextView)findViewById(R.id.errmsg);
  44. btnadduser.setOnClickListener(new View.OnClickListener() {
  45. @Override
  46. public void onClick(View v) {
  47. username=tusername.getText().toString();
  48. password=tpassword.getText().toString();
  49. fullname=tfullname.getText().toString();
  50. if(username.length()==0 || password.length()==0)
  51. {
  52. errmsg.setText("Invalid Details..");
  53. errmsg.setTextColor(Color.RED);
  54. }
  55. else
  56. {
  57.  
  58. new adduser().execute();
  59. }
  60. }
  61. });
  62. }
  63. class adduser extends AsyncTask<String,String,String>
  64. {
  65. protected void onPreExecute()
  66. {
  67. super.onPreExecute();
  68. pdialog=new ProgressDialog(adduseractivity.this);
  69. pdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  70. pdialog.setMessage("Logging in. Please wait...");
  71. pdialog.setIndeterminate(false);
  72. pdialog.setCancelable(true);
  73. pdialog.show();
  74. }
  75. @Override
  76. protected String doInBackground(String... params)
  77. {
  78. int success;
  79. try
  80. {
  81. Uri.Builder builder=new Uri.Builder()
  82. .appendQueryParameter("username",username)
  83. .appendQueryParameter("password",password)
  84. .appendQueryParameter("fullname",fullname);
  85. String query=builder.build().getEncodedQuery();
  86. JSONObject json=jsonparser.makeHttpRequest(url_login,query);
  87. if(json!=null)
  88. {
  89. success=json.getInt("result");
  90. if(success==1)
  91. {
  92. adduseractivity.this.runOnUiThread(new Runnable() {
  93. @Override
  94. public void run() {
  95. errmsg.setText("User Added!");
  96. errmsg.setTextColor(Color.BLUE);
  97. }
  98. });
  99. }
  100. else
  101. {
  102. adduseractivity.this.runOnUiThread(new Runnable() {
  103. @Override
  104. public void run() {
  105. errmsg.setText("User not found !");
  106. errmsg.setTextColor(Color.RED);
  107. }
  108. });
  109. }
  110. }
  111. else
  112. {
  113. adduseractivity.this.runOnUiThread(new Runnable() {
  114. @Override
  115. public void run() {
  116. errmsg.setText("Unable to contact server !");
  117. errmsg.setTextColor(Color.RED);
  118. }
  119. });
  120. }
  121. }
  122. catch(JSONException e)
  123. {
  124. e.printStackTrace();
  125. }
  126. return null;
  127. }
  128. protected void onPostExecute(String s)
  129. {
  130. pdialog.dismiss();
  131. }
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement