Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. package com.joshua.connectu;
  2.  
  3. import android.content.Intent;
  4. import android.support.v7.app.AlertDialog;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10.  
  11. import com.android.volley.RequestQueue;
  12. import com.android.volley.Response;
  13. import com.android.volley.toolbox.Volley;
  14.  
  15. import org.json.JSONException;
  16. import org.json.JSONObject;
  17.  
  18. public class RegisterActivity extends AppCompatActivity {
  19.  
  20. @Override
  21. protected void onCreate(Bundle savedInstanceState) {
  22. super.onCreate(savedInstanceState);
  23. setContentView(R.layout.activity_register);
  24.  
  25. final EditText etAge = (EditText) findViewById(R.id.etAge);
  26. final EditText etName = (EditText) findViewById(R.id.etName);
  27. final EditText etUsername = (EditText) findViewById(R.id.etUsername);
  28. final EditText etPassword = (EditText) findViewById(R.id.etPassword);
  29. final Button bRegister = (Button) findViewById(R.id.bRegister);
  30.  
  31. bRegister.setOnClickListener(new View.OnClickListener() {
  32. @Override
  33. public void onClick(View v) {
  34. final String name = etName.getText().toString();
  35. final String username = etUsername.getText().toString();
  36. final int age = Integer.parseInt(etAge.getText().toString());
  37. final String password = etPassword.getText().toString();
  38.  
  39. Response.Listener<String> responseListener = new Response.Listener<String>() {
  40. @Override
  41. public void onResponse(String response) {
  42. try {
  43. JSONObject jsonResponse = new JSONObject(response);
  44. boolean success = jsonResponse.getBoolean("success");
  45. if (success) {
  46. Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
  47. RegisterActivity.this.startActivity(intent);
  48. } else {
  49. AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
  50. builder.setMessage("Register Failed")
  51. .setNegativeButton("Retry", null)
  52. .create()
  53. .show();
  54. }
  55. } catch (JSONException e) {
  56. e.printStackTrace();
  57. }
  58. }
  59. };
  60.  
  61. RegisterRequest registerRequest = new RegisterRequest(name, username, age, password, responseListener);
  62. RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
  63. queue.add(registerRequest);
  64. }
  65. });
  66. }
  67. }
  68.  
  69. package com.joshua.connectu;
  70.  
  71. import com.android.volley.Response;
  72. import com.android.volley.toolbox.StringRequest;
  73.  
  74. import java.util.HashMap;
  75. import java.util.Map;
  76.  
  77. /**
  78. * Created by Joshua on 8/1/16.
  79. */
  80. public class RegisterRequest extends StringRequest {
  81. private static final String REGISTER_REQUEST_URL = "http://aragon.comli.com/Register.php";
  82. private Map<String, String> params;
  83.  
  84. public RegisterRequest(String name, String username, int age, String password, Response.Listener<String> listener) {
  85. super(Method.POST, REGISTER_REQUEST_URL, listener, null);
  86. params = new HashMap<>();
  87. params.put("name", name);
  88. params.put("age", age + "");
  89. params.put("username", username);
  90. params.put("password", password);
  91. }
  92. @Override
  93. public Map<String, String> getParams() {
  94. return params;
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement