Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerTask.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerTask.java b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerTask.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ee6202a9ee62fbda4341718e77a1d1df624d83c2 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerTask.java |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.photo_picker; |
| + |
| +import android.graphics.Bitmap; |
| +import android.os.AsyncTask; |
| +import android.util.LruCache; |
| + |
| +import org.chromium.base.ThreadUtils; |
| + |
| +/** |
| + * A worker task to enumerate image files on disk. |
| + */ |
| +class BitmapScalerTask extends AsyncTask<Bitmap, Void, Bitmap> { |
| + private final LruCache<String, Bitmap> mCache; |
| + private final String mFilePath; |
| + private final int mSize; |
| + |
| + /** |
| + * A BitmapScalerTask constructor. |
| + */ |
| + public BitmapScalerTask(LruCache<String, Bitmap> cache, String filePath, int size) { |
| + mCache = cache; |
| + mFilePath = filePath; |
| + mSize = size; |
| + } |
| + |
| + /** |
| + * Enumerates (in the background) the image files on disk. Called on a non-UI thread |
|
Michael van Ouwerkerk
2017/05/08 14:44:22
nit: please update the description
Finnur
2017/05/08 14:59:17
Done.
|
| + * @param params Ignored, do not use. |
| + * @return A sorted list of images (by last-modified first). |
| + */ |
| + @Override |
| + protected Bitmap doInBackground(Bitmap... bitmaps) { |
| + assert !ThreadUtils.runningOnUiThread(); |
| + |
| + if (isCancelled()) return null; |
| + |
| + return BitmapUtils.scale(bitmaps[0], mSize, false); |
| + } |
| + |
| + /** |
| + * Communicates the results back to the client. Called on the UI thread. |
| + * @param result The resulting scaled bitmap |
| + */ |
| + @Override |
| + protected void onPostExecute(Bitmap result) { |
| + if (isCancelled()) { |
| + return; |
| + } |
| + |
| + mCache.put(mFilePath, result); |
| + } |
| +} |