Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 KB | None | 0 0
  1. package com.ocbc.app1;
  2.  
  3. import android.app.Activity;
  4. import android.app.ProgressDialog;
  5. import android.content.Context;
  6. import android.graphics.Color;
  7. import android.graphics.Point;
  8. import android.graphics.drawable.BitmapDrawable;
  9. import android.net.Uri;
  10. import android.os.AsyncTask;
  11. import android.os.Bundle;
  12. import android.view.Gravity;
  13. import android.view.LayoutInflater;
  14. import android.view.View;
  15. import android.widget.Button;
  16. import android.widget.EditText;
  17. import android.widget.LinearLayout;
  18. import android.widget.PopupWindow;
  19. import android.widget.TextView;
  20.  
  21. import org.json.JSONException;
  22. import org.json.JSONObject;
  23.  
  24. /**
  25. * Created by selva on 3/21/2018.
  26. */
  27.  
  28. public class registeractivity extends Activity
  29. {
  30. Button btnregister;
  31. EditText tusername,tpassword,tconfirmpassword,tfullname;
  32. TextView tmsg;
  33. private ProgressDialog pdialog;
  34. String username,password,fullname;
  35. JSONParser jsonParser=new JSONParser();
  36. private String url_login="http://10.2.4.36/iverson/adduser.php";
  37. private PopupWindow mPopupWindow;
  38. private LinearLayout linearLayout;
  39.  
  40. public void onCreate(Bundle b)
  41. {
  42. super.onCreate(b);
  43. setContentView(R.layout.registerlayout);
  44. tusername=findViewById(R.id.tusername);
  45. tpassword=findViewById(R.id.tpassword);
  46. tconfirmpassword=findViewById(R.id.tconfirmpassword);
  47. tfullname=findViewById(R.id.tfullname);
  48. btnregister=findViewById(R.id.btnregister);
  49. tmsg=findViewById(R.id.tmsg);
  50. linearLayout=findViewById(R.id.toast_layout_root);
  51. btnregister.setOnClickListener(new View.OnClickListener() {
  52. @Override
  53. public void onClick(View v) {
  54. showPopup(registeractivity.this);
  55. if(tusername.getText().toString().length()==0 || tpassword.getText().toString().length()==0 || tconfirmpassword.getText().toString().length()==0 || tfullname.getText().toString().length()==0)
  56. {
  57. tmsg.setText("username or password is mising !");
  58. tmsg.setTextColor(Color.RED);
  59. }
  60. else
  61. {
  62. if(tpassword.getText().toString().equals(tconfirmpassword.getText().toString()))
  63. {
  64. username=tusername.getText().toString();
  65. password=tpassword.getText().toString();
  66. fullname=tfullname.getText().toString();
  67. //new adduser().execute();
  68.  
  69. }
  70. else
  71. {
  72. tmsg.setText("password and confirm password is not matched !");
  73. tmsg.setTextColor(Color.RED);
  74. }
  75. }
  76. }
  77. });
  78. }
  79. private void showPopup(final Activity context)
  80. {
  81. int popupWidth = 1000;
  82. int popupHeight = 1000;
  83. LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.toast_layout_root);
  84. LayoutInflater layoutInflater = (LayoutInflater) context
  85. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  86. View layout = layoutInflater.inflate(R.layout.popuplayout, viewGroup);
  87. final PopupWindow popup = new PopupWindow(context);
  88. popup.setContentView(layout);
  89. popup.setWidth(popupWidth);
  90. popup.setHeight(popupHeight);
  91. popup.setFocusable(true);
  92. popup.showAtLocation(layout,Gravity.CENTER,0,0);
  93. Button btnverify = (Button) layout.findViewById(R.id.btnverify);
  94. btnverify.setOnClickListener(new View.OnClickListener() {
  95. public void onClick(View v) {
  96. popup.dismiss();
  97. }
  98. });
  99. }
  100. class adduser extends AsyncTask<String,String,String>
  101. {
  102. protected void onPreExecute()
  103. {
  104. super.onPreExecute();
  105. pdialog=new ProgressDialog(registeractivity.this);
  106. pdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  107. pdialog.setMessage("Adding user in. Please wait...");
  108. pdialog.setIndeterminate(false);
  109. pdialog.setCancelable(true);
  110. pdialog.show();
  111. }
  112. protected String doInBackground(String... params)
  113. {
  114. int success;
  115. try
  116. {
  117. Uri.Builder builder=new Uri.Builder()
  118. .appendQueryParameter("username",username)
  119. .appendQueryParameter("password",password)
  120. .appendQueryParameter("fullname",fullname);
  121. String query=builder.build().getEncodedQuery();
  122. JSONObject json=jsonParser.makeHttpRequest(url_login,query);
  123. if(json!=null)
  124. {
  125. success=json.getInt("result");
  126. if(success==1)
  127. {
  128. registeractivity.this.runOnUiThread(new Runnable() {
  129. @Override
  130. public void run() {
  131. showPopup(registeractivity.this);
  132. }
  133. });
  134.  
  135. }
  136. else
  137. {
  138. registeractivity.this.runOnUiThread(new Runnable() {
  139. @Override
  140. public void run() {
  141. tmsg.setText("Registration failed !");
  142. tmsg.setTextColor(Color.RED);
  143. }
  144. });
  145. }
  146. }
  147. else
  148. {
  149. registeractivity.this.runOnUiThread(new Runnable() {
  150. @Override
  151. public void run() {
  152. tmsg.setText("Unable to contact server !");
  153. tmsg.setTextColor(Color.RED);
  154. }
  155. });
  156. }
  157. }
  158. catch(JSONException e)
  159. {
  160. e.printStackTrace();
  161. }
  162. return null;
  163. }
  164. protected void onPostExecute(String s)
  165. {
  166. pdialog.dismiss();
  167. }
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement