Advertisement
Guest User

Untitled

a guest
Oct 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 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.ArrayAdapter;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.widget.Spinner;
  15. import android.widget.TextView;
  16.  
  17. import org.json.JSONException;
  18. import org.json.JSONObject;
  19.  
  20. /**
  21. * Created by user on 10/28/2017.
  22. */
  23.  
  24. public class registernewuseractivity extends Activity
  25. {
  26. Button btnregister;
  27. EditText runame,rupass,rfullname;
  28. TextView msg;
  29. String rusername,ruserpass,ruserfullname;
  30. private ProgressDialog pdialog;
  31. JSONParser jsonParser=new JSONParser();
  32. private String url_registeruser="http://172.16.140.107/servercode/adduser.php";
  33.  
  34. public void onCreate(Bundle b)
  35. {
  36. super.onCreate(b);
  37. setContentView(R.layout.registernewuserlayout);
  38. btnregister=(Button)findViewById(R.id.btnregister);
  39. runame =(EditText)findViewById(R.id.runame);
  40. rupass =(EditText)findViewById(R.id.rupass);
  41. rfullname=(EditText)findViewById(R.id.rfullname);
  42. msg =(TextView)findViewById(R.id.msg);
  43.  
  44. btnregister.setOnClickListener(new View.OnClickListener()
  45. {
  46. @Override
  47. public void onClick(View v)
  48. {
  49. rusername=runame.getText().toString();
  50. ruserpass=rupass.getText().toString();
  51. ruserfullname=rfullname.getText().toString();
  52.  
  53. if(runame.length()==0||ruserpass.length()==0||rfullname.length()==0)
  54. {
  55. msg.setText("Cannot be Empty");
  56. msg.setTextColor(Color.RED);
  57. }
  58. else
  59. {
  60. new getnewuserdetails().execute();
  61. }
  62. }
  63.  
  64. });
  65. }
  66.  
  67. //create track //async task : bt kerja dtg blik bru bt something
  68. class getnewuserdetails extends AsyncTask<String,String,String>
  69. {
  70. //add method
  71. @Override
  72. protected void onPreExecute() {
  73. super.onPreExecute();
  74. pdialog=new ProgressDialog(registernewuseractivity.this);
  75. pdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  76. pdialog.setMessage("Registering New User..Please wait");
  77. pdialog.setIndeterminate(false);
  78. pdialog.setCancelable(true);
  79. pdialog.show();
  80. }
  81.  
  82. @Override
  83. protected String doInBackground(String... params)
  84. {
  85. int success;
  86. try
  87. {
  88. Uri.Builder builder=new Uri.Builder()
  89. .appendQueryParameter("username",rusername)
  90. .appendQueryParameter("password",ruserpass)
  91. .appendQueryParameter("fullname",ruserfullname);
  92.  
  93.  
  94. String query=builder.build().getEncodedQuery();
  95. JSONObject json=jsonParser.makeHttpRequest(url_registeruser,query);
  96. if (json!=null)
  97. {
  98. success=json.getInt("result");
  99. if (success==1)
  100. {
  101. Intent registeruserintent=new Intent(getApplicationContext(),registernewuseractivity.class);
  102. startActivity(registeruserintent);
  103. }
  104. else
  105. {
  106. registernewuseractivity.this.runOnUiThread(new Runnable() {
  107. @Override
  108. public void run() {
  109. msg.setText("Cannot have empty field !");
  110. msg.setTextColor(Color.RED);
  111. }
  112. });
  113. }
  114. }
  115. else
  116. {
  117. registernewuseractivity.this.runOnUiThread(new Runnable() {
  118. @Override
  119. public void run() {
  120. msg.setText("Added Sucessfully !");
  121. msg.setTextColor(Color.GREEN);
  122. }
  123. });
  124. }
  125.  
  126. }
  127. catch (JSONException e)
  128. {
  129. e.printStackTrace();
  130. }
  131. return null;
  132. }
  133. protected void onPostExecute(String s)
  134. {
  135. pdialog.dismiss();
  136. }
  137. }
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement