Advertisement
Guest User

Untitled

a guest
Jan 15th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. package com.flaviotps.provedor.Webservice;
  2.  
  3. import android.app.Activity;
  4. import android.util.Log;
  5.  
  6. import com.android.volley.Request;
  7. import com.android.volley.RequestQueue;
  8. import com.android.volley.Response;
  9. import com.android.volley.VolleyError;
  10. import com.android.volley.toolbox.StringRequest;
  11. import com.android.volley.toolbox.Volley;
  12.  
  13. /**
  14.  * Created by flaviotps on 15/01/18.
  15.  */
  16.  
  17. public class Auth {
  18.  
  19.     private String URL_AUTH = "https://cervejaetal.000webhostapp.com/Auth.php";
  20.     private RequestQueue queue;
  21.  
  22.     private static final int SUCCESS = 1;
  23.     private static final int FAIL = 0;
  24.     private Activity mActivity;
  25.  
  26.     public Auth(Activity mActivity) {
  27.         this.mActivity = mActivity;
  28.         queue = Volley.newRequestQueue(mActivity);
  29.     }
  30.  
  31.     private void OnLoginSucceed(){
  32.         Log.i("Auth","OnLoginSucceed");
  33.     }
  34.  
  35.     private void OnLoginFail(){
  36.         Log.e("Auth","OnLoginFail");
  37.     }
  38.     private void OnLoginError(VolleyError error){
  39.         Log.e("Auth","OnLoginError");
  40.     }
  41.  
  42.     public void Login(String username,String password){
  43.  
  44.         String URL_AUTH_GET = URL_AUTH+"?username="+username+"&password="+password;
  45.         StringRequest stringRequest = new StringRequest(Request.Method.GET, URL_AUTH_GET,
  46.                 new Response.Listener<String>() {
  47.                     @Override
  48.                     public void onResponse(String response) {
  49.  
  50.                         switch (Integer.valueOf(response)){
  51.                             case FAIL:
  52.                                 OnLoginFail();
  53.                                 break;
  54.  
  55.                             case SUCCESS:
  56.                                 OnLoginSucceed();
  57.                                 break;
  58.  
  59.                         }
  60.  
  61.                     }
  62.                 }, new Response.ErrorListener() {
  63.             @Override
  64.             public void onErrorResponse(VolleyError error) {
  65.                OnLoginError(error);            }
  66.         });
  67.  
  68.         queue.add(stringRequest);
  69.  
  70.  
  71.     }
  72.  
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement