OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.photo_picker; | |
6 | |
7 import android.graphics.Bitmap; | |
8 import android.os.AsyncTask; | |
9 import android.util.LruCache; | |
10 | |
11 import org.chromium.base.ThreadUtils; | |
12 | |
13 /** | |
14 * A worker task to enumerate image files on disk. | |
15 */ | |
16 class BitmapScalerTask extends AsyncTask<Bitmap, Void, Bitmap> { | |
17 private final LruCache<String, Bitmap> mCache; | |
18 private final String mFilePath; | |
19 private final int mSize; | |
20 | |
21 /** | |
22 * A BitmapScalerTask constructor. | |
23 */ | |
24 public BitmapScalerTask(LruCache<String, Bitmap> cache, String filePath, int size) { | |
25 mCache = cache; | |
26 mFilePath = filePath; | |
27 mSize = size; | |
28 } | |
29 | |
30 /** | |
31 * Enumerates (in the background) the image files on disk. Called on a non-U I thread | |
Michael van Ouwerkerk
2017/05/08 14:44:22
nit: please update the description
Finnur
2017/05/08 14:59:17
Done.
| |
32 * @param params Ignored, do not use. | |
33 * @return A sorted list of images (by last-modified first). | |
34 */ | |
35 @Override | |
36 protected Bitmap doInBackground(Bitmap... bitmaps) { | |
37 assert !ThreadUtils.runningOnUiThread(); | |
38 | |
39 if (isCancelled()) return null; | |
40 | |
41 return BitmapUtils.scale(bitmaps[0], mSize, false); | |
42 } | |
43 | |
44 /** | |
45 * Communicates the results back to the client. Called on the UI thread. | |
46 * @param result The resulting scaled bitmap | |
47 */ | |
48 @Override | |
49 protected void onPostExecute(Bitmap result) { | |
50 if (isCancelled()) { | |
51 return; | |
52 } | |
53 | |
54 mCache.put(mFilePath, result); | |
55 } | |
56 } | |
OLD | NEW |