Index: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerWorkerTask.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerWorkerTask.java b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerWorkerTask.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bb5039bb8bf57eea4415bea46ba696ab425e3fd6 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerWorkerTask.java |
@@ -0,0 +1,59 @@ |
+// 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 BitmapScalerWorkerTask extends AsyncTask<Void, Void, Bitmap> { |
Michael van Ouwerkerk
2017/05/08 13:14:48
nit: BitmapScalerTask seems cleaner.
|
+ private final LruCache<String, Bitmap> mCache; |
+ private final Bitmap mBitmap; |
+ private final String mFilePath; |
+ private final int mSize; |
+ |
+ /** |
+ * A BitmapScalerWorkerTask constructor. |
+ */ |
+ public BitmapScalerWorkerTask( |
+ LruCache<String, Bitmap> cache, String filePath, Bitmap bitmap, int size) { |
+ mCache = cache; |
+ mBitmap = bitmap; |
Michael van Ouwerkerk
2017/05/08 13:14:48
nit: you could make this the execution input param
|
+ mFilePath = filePath; |
+ mSize = size; |
+ } |
+ |
+ /** |
+ * Enumerates (in the background) the image files on disk. Called on a non-UI thread |
+ * @param params Ignored, do not use. |
+ * @return A sorted list of images (by last-modified first). |
+ */ |
+ @Override |
+ protected Bitmap doInBackground(Void... params) { |
+ assert !ThreadUtils.runningOnUiThread(); |
+ |
+ if (isCancelled()) return null; |
+ |
+ return BitmapUtils.scale(mBitmap, 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); |
+ } |
+} |