Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. package com.abc.helloworld;
  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.  
  14. import org.json.JSONException;
  15. import org.json.JSONObject;
  16.  
  17. /**
  18. * Created by selva on 7/23/2017.
  19. */
  20.  
  21. public class adduseractivity extends Activity
  22. {
  23. EditText tusername,tpassword,tconfirmpassword;
  24. Button btnadduser;
  25. private ProgressDialog pDialog;
  26. JSONParser jsonParser = new JSONParser();
  27. private static final String url_login = "http://192.168.43.105/xamarin/adduser.php";
  28. String username;
  29. String password;
  30. public void onCreate(Bundle b)
  31. {
  32. super.onCreate(b);
  33. setContentView(R.layout.adduserlayout);
  34. tusername=(EditText) findViewById(R.id.tusername);
  35. tpassword=(EditText) findViewById(R.id.tpassword);
  36.  
  37. btnadduser=(Button)findViewById(R.id.btnadduser);
  38. btnadduser.setOnClickListener(new View.OnClickListener(){
  39. public void onClick(View v)
  40. {
  41. tusername=(EditText)findViewById(R.id.tusername);
  42. tpassword=(EditText)findViewById(R.id.tpassword);
  43. tconfirmpassword=(EditText)findViewById(R.id.tconfirmpassword);
  44. if(tusername.getText().length()==0 || tpassword.getText().length()==0 || tconfirmpassword.getText().length()==0)
  45. {
  46. Toast.makeText(getApplicationContext(),"Incomplete Details",Toast.LENGTH_LONG).show();
  47. }
  48. else
  49. {
  50. if(tpassword.getText().toString().equals(tconfirmpassword.getText().toString()))
  51. {
  52. username=tusername.getText().toString();
  53. password=tpassword.getText().toString();
  54. new adduser().execute();
  55. }
  56. else
  57. {
  58. Toast.makeText(getApplicationContext(),"Password and Confirm Password doesn't match",Toast.LENGTH_LONG).show();
  59. }
  60.  
  61. }
  62. }
  63. });
  64. }
  65. class adduser extends AsyncTask<String, String, String>
  66. {
  67. protected void onPreExecute()
  68. {
  69. super.onPreExecute();
  70. pDialog = new ProgressDialog(adduseractivity.this);
  71. pDialog.setMessage("Adding user. Please wait...");
  72. pDialog.setIndeterminate(false);
  73. pDialog.setCancelable(true);
  74. pDialog.show();
  75. }
  76. protected String doInBackground(String... params)
  77. {
  78. int success;
  79. try
  80. {
  81.  
  82. JSONObject json = jsonParser.makeHttpRequest(url_login, username,password);
  83. success = json.getInt("result");
  84. if (success == 1)
  85. {
  86. adduseractivity.this.runOnUiThread(new Runnable()
  87. {
  88. public void run()
  89. {
  90. Toast.makeText(getApplicationContext(),"User added, returning to main menu",Toast.LENGTH_LONG).show();
  91. }
  92. });
  93. Intent menuintent=new Intent(getApplicationContext(),menuactivity.class);
  94. startActivity(menuintent);
  95. }
  96. else
  97. {
  98. adduseractivity.this.runOnUiThread(new Runnable()
  99. {
  100. public void run()
  101. {
  102. Toast.makeText(getApplicationContext(),"User not added",Toast.LENGTH_LONG).show();
  103. }
  104. });
  105. }
  106. }
  107. catch (JSONException e)
  108. {
  109. e.printStackTrace();
  110. }
  111. return null;
  112. }
  113. protected void onPostExecute(String file_url)
  114. {
  115. pDialog.dismiss();
  116. }
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement