Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
3,025
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 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.view.View;
  9. import android.widget.TextView;
  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 ActivityLogin extends BaseApp {
  22.  
  23. private MaterialEditText logtxtEmail, logtxtPassword;
  24. private TextView loglblRegister;
  25. private Button logbtnLogin;
  26.  
  27. SessionManager sessionManager;
  28.  
  29. @Override
  30. protected void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. setContentView(R.layout.activity_login);
  33. setupView();
  34. sessionManager = new SessionManager(getApplicationContext());
  35. loglblRegister.setOnClickListener(new View.OnClickListener() {
  36. @Override
  37. public void onClick(View view) {
  38. view.startAnimation(BtnAnimasi);
  39. startActivity(new Intent(getApplicationContext(), ActivityRegister.class));
  40. }
  41. });
  42.  
  43. logbtnLogin.setOnClickListener(new View.OnClickListener() {
  44. @Override
  45. public void onClick(View view) {
  46. loginUser();
  47. }
  48. });
  49. }
  50.  
  51. private void loginUser() {
  52. logtxtEmail.setError(null);
  53. logtxtPassword.setError(null);
  54. if (Helper.isEmpty(logtxtEmail)) {
  55. logtxtEmail.setError("Email masih kosong");
  56. logtxtEmail.requestFocus();
  57. } else if (Helper.isEmpty(logtxtPassword)) {
  58. logtxtPassword.setError("Password masih kosong");
  59. logtxtPassword.requestFocus();
  60. } else {
  61. String URL = Helper.BASE_URL + "login.php";
  62. Map<String, String> param = new HashMap<>();
  63. param.put("email", logtxtEmail.getText().toString());
  64. param.put("password", logtxtPassword.getText().toString());
  65.  
  66. ProgressDialog pd = new ProgressDialog(context);
  67. pd.setIndeterminate(true);
  68. pd.setCancelable(false);
  69. pd.setInverseBackgroundForced(false);
  70. pd.setCanceledOnTouchOutside(false);
  71. pd.setTitle("Info");
  72. pd.setMessage("Login");
  73. pd.show();
  74.  
  75. try {
  76. aQuery.progress(pd).ajax(URL, param, String.class, new AjaxCallback<String>() {
  77. @Override
  78. public void callback(String url, String object, AjaxStatus status) {
  79. if (object != null) {
  80. try {
  81. JSONObject jsonObject = new JSONObject(object);
  82. String result = jsonObject.getString("result");
  83. String msg = jsonObject.getString("msg");
  84. if (result.equalsIgnoreCase("true")) {
  85. sessionManager.createSession(logtxtEmail.getText().toString());
  86. startActivity(new Intent(context, MainActivity.class));
  87. Helper.pesan(context, msg);
  88. finish();
  89. } else {
  90. Helper.pesan(context, msg);
  91. }
  92. } catch (JSONException e) {
  93. Helper.pesan(context, "Error convert data json");
  94. }
  95. }
  96. }
  97. });
  98. } catch (Exception e) {
  99. Helper.pesan(context, "Gagal mengambil data");
  100. }
  101. }
  102. }
  103.  
  104. private void setupView() {
  105. logtxtEmail = (MaterialEditText) findViewById(R.id.logtxtEmail);
  106. logtxtPassword = (MaterialEditText) findViewById(R.id.logtxtPassword);
  107. logbtnLogin = (Button) findViewById(R.id.logbtnLogin);
  108. loglblRegister = (TextView) findViewById(R.id.loglblRegister);
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement