Ejemplo n.º 1
0
    private void processVideoTask(MediaVideoTask task) throws Exception {
      Bitmap res = fetchChatPreview();
      Optimizer.BitmapInfo info = tryToLoadFromCache(task.getStorageKey(), res);
      if (info != null) {
        Bitmap pRes = fetchChatPreview();
        int[] sizes = drawPreview(res, info.getWidth(), info.getHeight(), pRes, task.isOut());
        imageCache.putFree(res, SIZE_CHAT_PREVIEW);
        onImageLoaded(pRes, sizes[0], sizes[1], task, SIZE_CHAT_PREVIEW);
        return;
      }

      VideoOptimizer.VideoMetadata metadata = VideoOptimizer.getVideoSize(task.getFileName());
      int[] tempSize =
          Optimizer.scaleToRatio(
              metadata.getImg(), metadata.getImg().getWidth(), metadata.getImg().getHeight(), res);
      putToDiskCache(task.getStorageKey(), res, tempSize[0], tempSize[1]);

      int[] sizes =
          drawPreview(
              metadata.getImg(),
              metadata.getImg().getWidth(),
              metadata.getImg().getHeight(),
              res,
              task.isOut());
      onImageLoaded(res, sizes[0], sizes[1], task, SIZE_CHAT_PREVIEW);
    }
Ejemplo n.º 2
0
    private void processTask(MediaRawUriTask rawTask) throws Exception {
      Bitmap res = fetchChatPreview();
      Optimizer.BitmapInfo info = tryToLoadFromCache(rawTask.getKey(), res);
      if (info != null) {
        Bitmap pRes = fetchChatPreview();
        int[] size = drawPreview(res, info.getWidth(), info.getHeight(), pRes, rawTask.isOut());
        imageCache.putFree(res, SIZE_CHAT_PREVIEW);
        onImageLoaded(pRes, size[0], size[1], rawTask, SIZE_CHAT_PREVIEW);
        return;
      }
      Bitmap tmp = Optimizer.optimize(rawTask.getUri(), application);
      int[] tmpSizes = Optimizer.scaleToRatio(tmp, tmp.getWidth(), tmp.getHeight(), res);
      putToDiskCache(rawTask.getKey(), res, tmpSizes[0], tmpSizes[1]);

      int[] sizes = drawPreview(tmp, tmp.getWidth(), tmp.getHeight(), res, rawTask.isOut());
      onImageLoaded(res, sizes[0], sizes[1], rawTask, SIZE_CHAT_PREVIEW);
    }
Ejemplo n.º 3
0
    private void processFileTask(MediaFileTask fileTask) throws Exception {
      synchronized (fullImageCachedLock) {
        if (fullImageCached == null) {
          fullImageCached =
              Bitmap.createBitmap(
                  ApiUtils.MAX_SIZE / 2, ApiUtils.MAX_SIZE / 2, Bitmap.Config.ARGB_8888);
        }
        Optimizer.clearBitmap(fullImageCached);

        boolean useScaled = false;

        try {
          Optimizer.BitmapInfo info = Optimizer.getInfo(fileTask.getFileName());
          useScaled =
              info.getWidth() > fullImageCached.getWidth()
                  || info.getHeight() > fullImageCached.getHeight();
        } catch (IOException e) {
          e.printStackTrace();
        }

        int scaledW =
            useScaled
                ? fileTask.getLocalPhoto().getFullW() / 2
                : fileTask.getLocalPhoto().getFullW();
        int scaledH =
            useScaled
                ? fileTask.getLocalPhoto().getFullH() / 2
                : fileTask.getLocalPhoto().getFullH();

        if (useScaled) {
          BitmapDecoderEx.decodeReuseBitmapScaled(fileTask.getFileName(), fullImageCached);
        } else {
          BitmapDecoderEx.decodeReuseBitmap(fileTask.getFileName(), fullImageCached);
        }

        Bitmap res = fetchChatPreview();
        int[] sizes = drawPreview(fullImageCached, scaledW, scaledH, res, fileTask.isOut());

        onImageLoaded(res, sizes[0], sizes[1], fileTask, SIZE_CHAT_PREVIEW);
      }
    }
Ejemplo n.º 4
0
    private PrepareResult createBitmap(MediaGeoTask geoTask) throws IOException {
      Bitmap res = fetchMapPreview();
      Optimizer.BitmapInfo info = tryToLoadFromCache(geoTask.getStorageKey(), res);
      if (info != null) {
        return new PrepareResult(info.getWidth(), info.getHeight(), res);
      }

      int scale = 1;
      float density = application.getResources().getDisplayMetrics().density;
      if (density >= 1.5f) {
        scale = 2;
      }

      String url =
          "https://maps.googleapis.com/maps/api/staticmap?"
              + "center="
              + geoTask.getLatitude()
              + ","
              + geoTask.getLongitude()
              + "&zoom=15"
              + "&size="
              + (MAP_W / scale)
              + "x"
              + (MAP_H / scale)
              + "&scale="
              + scale
              + "&sensor=false"
              + "&format=jpg";

      HttpGet get = new HttpGet(url.replace(" ", "%20"));
      HttpResponse response = client.execute(get);
      if (response.getEntity().getContentLength() == 0) {
        throw new IOException();
      }

      if (response.getStatusLine().getStatusCode() == 404) {
        throw new IOException();
      }

      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      response.getEntity().writeTo(outputStream);
      byte[] data = outputStream.toByteArray();

      Optimizer.BitmapInfo info1 = Optimizer.loadTo(data, res);

      putToDiskCache(geoTask.getStorageKey(), res, MAP_W, MAP_H);

      return new PrepareResult(info1.getWidth(), info1.getHeight(), res);
    }
Ejemplo n.º 5
0
    private void processSmallTask(SmallRawTask task) throws Exception {
      synchronized (fullImageCachedLock) {
        if (fullImageCached == null) {
          fullImageCached =
              Bitmap.createBitmap(
                  ApiUtils.MAX_SIZE / 2, ApiUtils.MAX_SIZE / 2, Bitmap.Config.ARGB_8888);
        }
        Optimizer.clearBitmap(fullImageCached);

        boolean useScaled = false;

        Optimizer.BitmapInfo info;
        try {
          info = Optimizer.getInfo(task.getFileName());
        } catch (IOException e) {
          e.printStackTrace();
          return;
        }

        useScaled =
            info.getWidth() > fullImageCached.getWidth()
                || info.getHeight() > fullImageCached.getHeight();

        int scaledW = useScaled ? info.getWidth() / 2 : info.getWidth();
        int scaledH = useScaled ? info.getHeight() / 2 : info.getHeight();

        if (useScaled) {
          BitmapDecoderEx.decodeReuseBitmapScaled(task.getFileName(), fullImageCached);
        } else {
          BitmapDecoderEx.decodeReuseBitmap(task.getFileName(), fullImageCached);
        }

        Bitmap res = fetchMediaPreview();
        Optimizer.scaleToFill(fullImageCached, scaledW, scaledH, res);
        onImageLoaded(res, res.getWidth(), res.getHeight(), task, SIZE_SMALL_PREVIEW);
      }
    }
Ejemplo n.º 6
0
    private void processTask(MediaRawTask rawTask) throws Exception {
      synchronized (fullImageCachedLock) {
        if (fullImageCached == null) {
          fullImageCached =
              Bitmap.createBitmap(
                  ApiUtils.MAX_SIZE / 2, ApiUtils.MAX_SIZE / 2, Bitmap.Config.ARGB_8888);
        }
      }

      Bitmap res = fetchChatPreview();

      Optimizer.BitmapInfo info = tryToLoadFromCache(rawTask.getKey(), res);
      if (info != null) {
        Bitmap pRes = fetchChatPreview();
        int[] size = drawPreview(res, info.getWidth(), info.getHeight(), pRes, rawTask.isOut());
        imageCache.putFree(res, SIZE_CHAT_PREVIEW);
        onImageLoaded(pRes, size[0], size[1], rawTask, SIZE_CHAT_PREVIEW);
        return;
      }

      info = Optimizer.getInfo(rawTask.getFileName());

      if (info.getMimeType() != null && info.getMimeType().equals("image/jpeg")) {
        if (info.getHeight() <= fullImageCached.getHeight()
            && info.getWidth() <= fullImageCached.getWidth()) {
          synchronized (fullImageCachedLock) {
            BitmapDecoderEx.decodeReuseBitmap(rawTask.getFileName(), fullImageCached);
            int[] sizes =
                drawPreview(
                    fullImageCached, info.getWidth(), info.getHeight(), res, rawTask.isOut());
            onImageLoaded(res, sizes[0], sizes[1], rawTask, SIZE_CHAT_PREVIEW);
            return;
          }
        } else if (info.getWidth() / 2 <= fullImageCached.getWidth()
            && info.getHeight() / 2 <= fullImageCached.getHeight()) {
          synchronized (fullImageCachedLock) {
            BitmapDecoderEx.decodeReuseBitmap(rawTask.getFileName(), fullImageCached);
            int[] sizes =
                drawPreview(
                    fullImageCached,
                    info.getWidth() / 2,
                    info.getHeight() / 2,
                    res,
                    rawTask.isOut());
            onImageLoaded(res, sizes[0], sizes[1], rawTask, SIZE_CHAT_PREVIEW);
            return;
          }
        }
      }

      Bitmap tmp = Optimizer.optimize(rawTask.getFileName());
      int[] tmpSizes = Optimizer.scaleToRatio(tmp, tmp.getWidth(), tmp.getHeight(), res);
      putToDiskCache(rawTask.getKey(), res, tmpSizes[0], tmpSizes[1]);

      int[] sizes = drawPreview(tmp, tmp.getWidth(), tmp.getHeight(), res, rawTask.isOut());
      onImageLoaded(res, sizes[0], sizes[1], rawTask, SIZE_CHAT_PREVIEW);
    }