Advertisement
Guest User

Untitled

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