@Override
  protected Bitmap doInBackground(Object... params) {
    long start = System.currentTimeMillis();
    Log.d(TAG, "Download " + vehiclesStr + " START for " + Thread.currentThread().getName());

    try {
      String bbox = vehicleSyncAdapter.getBBox();
      StringBuffer vs = new StringBuffer();
      Iterator<VehicleType> iterator = vehicleTypes.iterator();
      while (iterator.hasNext()) {
        VehicleType next = iterator.next();
        vs.append(next.getCode());
        if (iterator.hasNext()) {
          vs.append(",");
        }
      }
      vehiclesStr = vs.toString();
      Object[] paramss =
          new Object[] {
            vehiclesStr,
            bbox,
            vehicleSyncAdapter.getScaledWidth(),
            vehicleSyncAdapter.getScaledHeight()
          };
      String url = Constants.URL_TEMPLATE + String.format(Constants.URL_PARAMS, paramss);
      InputStream in = vehicleSyncAdapter.getPortalClient().doGet(url);
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inSampleSize = 1;
      Bitmap bitmap1 = BitmapFactory.decodeStream(in, null, options);
      Bitmap bitmap =
          Bitmap.createScaledBitmap(
              bitmap1,
              vehicleSyncAdapter.getScreenWidth(),
              vehicleSyncAdapter.getScreenHeight(),
              true);
      in.close();
      bitmap1.recycle();
      return bitmap;
    } catch (Exception e) {
      String message = e.getMessage();
      Log.e(TAG, message != null ? message : e.getClass().getName());
      Log.d(TAG, "Download " + vehiclesStr + " CANCELLED for " + Thread.currentThread().getName());
      return null;
    } finally {
      double duration = (System.currentTimeMillis() - start) / 1000d;
      Log.d(
          TAG,
          "Download "
              + vehiclesStr
              + " FINISHED takes "
              + duration
              + " sec for "
              + Thread.currentThread().getName());
    }
  }
  @Override
  protected void onPostExecute(Bitmap result) {
    if (isCancelled()) {
      Log.d(TAG, "onPostExecute skipped");
      return;
    }

    vehicleSyncAdapter.afterSync(result);

    if (result != null) {
      Log.d(
          TAG,
          "Overlay "
              + vehiclesStr
              + " FINISHED size "
              + result.getRowBytes()
              + " bytes for "
              + Thread.currentThread().getName());
    } else {
      Log.d(TAG, "Overlay " + vehiclesStr + " CANCELLED for " + Thread.currentThread().getName());
      cancel(true);
    }
  }
 @Override
 protected void onPreExecute() {
   vehicleSyncAdapter.beforeSync(false);
 }