ppamorim

Untitled

Aug 28th, 2014
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.98 KB | None | 0 0
  1. public class NearbyService extends AbstractService {
  2.  
  3.     private LatLng bla;
  4.     private int bla;
  5.     private int bla;
  6.  
  7.     public NearbyService(LatLng bla, int bla, int bla, OnRestResponse response, Context context) {
  8.         super(response, context);
  9.         bla = bla;
  10.         bla = bla;
  11.         bla = bla;
  12.     }
  13.  
  14.     public void getNearby() {
  15.         NearbyAsyncTaskParams params = new NearbyAsyncTaskParams(bla, bla, bla);
  16.         NearbyAsyncTask nearbyAsyncTask = new NearbyAsyncTask();
  17.         if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) {
  18.             nearbyAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
  19.         }
  20.         else {
  21.             nearbyAsyncTask.execute(params);
  22.         }
  23.     }
  24.  
  25.     private static class NearbyAsyncTaskParams {
  26.  
  27.         LatLng bla;
  28.         int bla;
  29.         int bla;
  30.  
  31.         NearbyAsyncTaskParams(LatLng bla, int bla, int bla) {
  32.             this.bla = bla;
  33.             this.bla = bla;
  34.             this.bla = bla;
  35.         }
  36.     }
  37.  
  38.     private class NearbyAsyncTask extends AsyncTask<NearbyAsyncTaskParams, Void, String> {
  39.  
  40.         @Override
  41.         protected String doInBackground(NearbyAsyncTaskParams... params) {
  42.  
  43.             try {
  44.  
  45.                 JSONObject array = new JSONObject();
  46.  
  47.                 array.put("bla", params[0].bla.bla);
  48.                 array.put("bla", params[0].bla.bla);
  49.                 array.put("bla", params[0].bla);
  50.                 array.put("bla", params[0].bla);
  51.  
  52.                 JSONObject data = new JSONObject();
  53.  
  54.                 data.put("bla", "bla");
  55.                 data.put("bla", bla);
  56.  
  57.                 RequestBody formBody = new FormEncodingBuilder()
  58.                         .add("token", ConvertUtils.MD5(new SimpleDateFormat(bla.FORMAT_DATE).format(new Date()).replace("-", "")))
  59.                         .add("data", ConvertUtils.encode(data.toString()))
  60.                         .build();
  61.  
  62.                 Request request = new Request.Builder()
  63.                         .url(TagApplication.URL_SERVER)
  64.                         .post(formBody)
  65.                         .build();
  66.  
  67.                 Response response = new OkHttpClient().newCall(request).execute();
  68.  
  69.                 if(response != null) {
  70.                     if (response.isSuccessful()) {
  71.                         return response.body().string();
  72.                     } else {
  73.                         return null;
  74.                     }
  75.                 } else {
  76.                     return null;
  77.                 }
  78.  
  79.             } catch (Exception e) {
  80.                 e.printStackTrace();
  81.                 return null;
  82.             }
  83.         }
  84.  
  85.         @Override
  86.         protected void onPostExecute(String response) {
  87.             super.onPostExecute(response);
  88.             if(response != null) {
  89.                 mRestResponse.onSuccess(AbstractService.SUCCESS, response);
  90.             } else {
  91.                 mRestResponse.onFail(AbstractService.ERROR);
  92.             }
  93.         }
  94.     }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment