Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
1,841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. package com.example.ajisetya.loginaquery;
  2.  
  3. import android.app.ProgressDialog;
  4. import android.content.Intent;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.widget.Button;
  8. import android.widget.TextView;
  9. import android.view.View;
  10.  
  11. import com.androidquery.callback.AjaxCallback;
  12. import com.androidquery.callback.AjaxStatus;
  13. import com.rengwuxian.materialedittext.MaterialEditText;
  14.  
  15. import org.json.JSONException;
  16. import org.json.JSONObject;
  17.  
  18. import java.util.HashMap;
  19. import java.util.Map;
  20.  
  21. public class ActivityRegister extends BaseApp {
  22.  
  23. private MaterialEditText regtxtEmail, regtxtPassword1, regtxtPassword2;
  24. private TextView reglblLogin;
  25. private Button regbtnRegister;
  26.  
  27. @Override
  28. protected void onCreate(Bundle savedInstanceState) {
  29. super.onCreate(savedInstanceState);
  30. setContentView(R.layout.activity_register);
  31. setupView();
  32. reglblLogin.setOnClickListener(new View.OnClickListener() {
  33. @Override
  34. public void onClick(View view) {
  35. view.startAnimation(BtnAnimasi);
  36. startActivity(new Intent(context, ActivityLogin.class));
  37. }
  38. });
  39. regbtnRegister.setOnClickListener(new View.OnClickListener() {
  40. @Override
  41. public void onClick(View view) {
  42. registerUser();
  43. }
  44. });
  45. }
  46.  
  47. private void registerUser() {
  48. regtxtEmail.setError(null);
  49. regtxtPassword1.setError(null);
  50. regtxtPassword2.setError(null);
  51. if (Helper.isEmpty(regtxtEmail)) {
  52. regtxtEmail.setError("Email masih kosong");
  53. regtxtEmail.requestFocus();
  54. } else if (!Helper.isEmailValid(regtxtEmail)) {
  55. regtxtEmail.setError("Format email salah");
  56. regtxtEmail.requestFocus();
  57. } else if (Helper.isEmpty(regtxtPassword1)) {
  58. regtxtPassword1.setError("Password masih kosong");
  59. regtxtPassword1.requestFocus();
  60. } else if (Helper.isEmpty(regtxtPassword2)) {
  61. regtxtPassword2.setError("Konfirmasi password masih kosong");
  62. regtxtPassword2.requestFocus();
  63. } else if (Helper.isCompare(regtxtPassword1, regtxtPassword2)) {
  64. regtxtPassword2.setError("Password tidak cocok");
  65. regtxtPassword2.requestFocus();
  66. } else {
  67.  
  68. String URL = Helper.BASE_URL + "register.php";
  69.  
  70. Map<String, String> param = new HashMap<>();
  71. param.put("email", regtxtEmail.getText().toString());
  72. param.put("password", regtxtPassword1.getText().toString());
  73.  
  74. ProgressDialog pd = new ProgressDialog(context);
  75. pd.setIndeterminate(true);
  76. pd.setCancelable(false);
  77. pd.setInverseBackgroundForced(false);
  78. pd.setCanceledOnTouchOutside(false);
  79. pd.setTitle("Info");
  80. pd.setMessage("Sedang menambah data");
  81. pd.show();
  82.  
  83. try {
  84. aQuery.progress(pd).ajax(URL, param, String.class, new AjaxCallback<String>() {
  85. @Override
  86. public void callback(String url, String object, AjaxStatus status) {
  87. if (object != null) {
  88. try {
  89. JSONObject jsonObject = new JSONObject(object);
  90. String result = jsonObject.getString("result");
  91. String msg = jsonObject.getString("msg");
  92.  
  93. if (result.equalsIgnoreCase("true")) {
  94. startActivity(new Intent(context, ActivityLogin.class));
  95. Helper.pesan(context, msg);
  96. finish();
  97. } else {
  98. Helper.pesan(context, msg);
  99. }
  100.  
  101. } catch (JSONException e) {
  102. Helper.pesan(context, "Error convert data json");
  103. }
  104. }
  105. }
  106. });
  107. } catch (Exception e) {
  108. Helper.pesan(context, "Gagal mengambil data");
  109. }
  110. }
  111. }
  112.  
  113. private void setupView() {
  114. regtxtEmail = (MaterialEditText) findViewById(R.id.regtxtEmail);
  115. regtxtPassword1 = (MaterialEditText) findViewById(R.id.regtxtPassword1);
  116. regtxtPassword2 = (MaterialEditText) findViewById(R.id.regtxtPassword2);
  117. regbtnRegister = (Button) findViewById(R.id.regbtnRegister);
  118. reglblLogin = (TextView) findViewById(R.id.reglblLogin);
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement