Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public interface ResultListener {
  2. public void onResult(JSONObject result);
  3. }
  4.  
  5. private ResultListener listener;
  6.  
  7. public JSONObject logar(final String usuario , final String senha){
  8. Map<String, String> postParam= new HashMap<String, String>();
  9. postParam.put("username", usuario);
  10. postParam.put("password", senha);
  11.  
  12.  
  13.  
  14. JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
  15. "http://192.168.0.13:8088/onblox/login", new JSONObject(postParam),
  16. new Response.Listener<JSONObject>() {
  17.  
  18. @Override
  19. public void onResponse(JSONObject response) {
  20. Log.d("tag", response.toString());
  21. Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_LONG).show();
  22. listener.onResult(response);
  23. }
  24. }, new Response.ErrorListener() {
  25.  
  26. @Override
  27. public void onErrorResponse(VolleyError error) {
  28. VolleyLog.d("tag" , "Error: " + error.getMessage());
  29. Toast.makeText(getApplicationContext(),error.getMessage().toString(), Toast.LENGTH_LONG).show();
  30.  
  31. }
  32. }) {
  33.  
  34. };
  35.  
  36. jsonObjReq.setTag("TAG");
  37. // Adding request to request queue
  38. rq.add(jsonObjReq);
  39.  
  40. MainActivity objectLoader = new MainActivity();
  41.  
  42. return (JSONObject)listener;
  43. }
  44. public void setResultListener(ResultListener listener){
  45. this.listener = listener;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement