| Index: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java
|
| index 6c73972eadb3c87da1d3b42c7a18259e2ac6809e..9ed19c9448c644d4709ae6189320f179331f6070 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java
|
| @@ -20,6 +20,7 @@ import org.chromium.chrome.browser.widget.selection.SelectableListLayout;
|
| import org.chromium.chrome.browser.widget.selection.SelectionDelegate;
|
| import org.chromium.ui.PhotoPickerListener;
|
|
|
| +import java.util.Arrays;
|
| import java.util.List;
|
|
|
| /**
|
| @@ -27,7 +28,8 @@ import java.util.List;
|
| * the photo picker, for example the RecyclerView and the bitmap caches.
|
| */
|
| public class PickerCategoryView extends RelativeLayout
|
| - implements FileEnumWorkerTask.FilesEnumeratedCallback, OnMenuItemClickListener {
|
| + implements FileEnumWorkerTask.FilesEnumeratedCallback, RecyclerView.RecyclerListener,
|
| + DecoderServiceHost.ServiceReadyCallback, OnMenuItemClickListener {
|
| // The dialog that owns us.
|
| private PhotoPickerDialog mDialog;
|
|
|
| @@ -46,6 +48,9 @@ public class PickerCategoryView extends RelativeLayout
|
| // The callback to notify the listener of decisions reached in the picker.
|
| private PhotoPickerListener mListener;
|
|
|
| + // The host class for the decoding service.
|
| + private DecoderServiceHost mDecoderServiceHost;
|
| +
|
| // The RecyclerView showing the images.
|
| private RecyclerView mRecyclerView;
|
|
|
| @@ -71,6 +76,9 @@ public class PickerCategoryView extends RelativeLayout
|
| // A worker task for asynchronously enumerating files off the main thread.
|
| private FileEnumWorkerTask mWorkerTask;
|
|
|
| + // Whether the connection to the service has been established.
|
| + private boolean mServiceReady;
|
| +
|
| public PickerCategoryView(Context context) {
|
| super(context);
|
| postConstruction(context);
|
| @@ -84,6 +92,11 @@ public class PickerCategoryView extends RelativeLayout
|
| private void postConstruction(Context context) {
|
| mContext = context;
|
|
|
| + mDecoderServiceHost = new DecoderServiceHost(this);
|
| + mDecoderServiceHost.bind(mContext);
|
| +
|
| + enumerateBitmaps();
|
| +
|
| mSelectionDelegate = new SelectionDelegate<PickerBitmap>();
|
|
|
| View root = LayoutInflater.from(context).inflate(R.layout.photo_picker_dialog, this);
|
| @@ -107,18 +120,21 @@ public class PickerCategoryView extends RelativeLayout
|
| mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(mColumns, mPadding));
|
|
|
| // TODO(finnur): Implement caching.
|
| - // TODO(finnur): Remove this once the decoder service is in place.
|
| - prepareBitmaps();
|
| }
|
|
|
| /**
|
| - * Cancels any outstanding requests.
|
| + * Severs the connection to the decoding utility process and cancels any outstanding requests.
|
| */
|
| public void onDialogDismissed() {
|
| if (mWorkerTask != null) {
|
| mWorkerTask.cancel(true);
|
| mWorkerTask = null;
|
| }
|
| +
|
| + if (mDecoderServiceHost != null) {
|
| + mDecoderServiceHost.unbind(mContext);
|
| + mDecoderServiceHost = null;
|
| + }
|
| }
|
|
|
| /**
|
| @@ -141,8 +157,25 @@ public class PickerCategoryView extends RelativeLayout
|
| @Override
|
| public void filesEnumeratedCallback(List<PickerBitmap> files) {
|
| mPickerBitmaps = files;
|
| - if (files != null && files.size() > 0) {
|
| - mPickerAdapter.notifyDataSetChanged();
|
| + processBitmaps();
|
| + }
|
| +
|
| + // DecoderServiceHost.ServiceReadyCallback:
|
| +
|
| + @Override
|
| + public void serviceReady() {
|
| + mServiceReady = true;
|
| + processBitmaps();
|
| + }
|
| +
|
| + // RecyclerView.RecyclerListener:
|
| +
|
| + @Override
|
| + public void onViewRecycled(RecyclerView.ViewHolder holder) {
|
| + PickerBitmapViewHolder bitmapHolder = (PickerBitmapViewHolder) holder;
|
| + String filePath = bitmapHolder.getFilePath();
|
| + if (filePath != null) {
|
| + getDecoderServiceHost().cancelDecodeImage(filePath);
|
| }
|
| }
|
|
|
| @@ -162,6 +195,16 @@ public class PickerCategoryView extends RelativeLayout
|
| return false;
|
| }
|
|
|
| + /**
|
| + * Start loading of bitmaps, once files have been enumerated and service is
|
| + * ready to decode.
|
| + */
|
| + private void processBitmaps() {
|
| + if (mServiceReady && mPickerBitmaps != null) {
|
| + mPickerAdapter.notifyDataSetChanged();
|
| + }
|
| + }
|
| +
|
| // Simple accessors:
|
|
|
| public int getImageSize() {
|
| @@ -176,6 +219,10 @@ public class PickerCategoryView extends RelativeLayout
|
| return mPickerBitmaps;
|
| }
|
|
|
| + public DecoderServiceHost getDecoderServiceHost() {
|
| + return mDecoderServiceHost;
|
| + }
|
| +
|
| public boolean isMultiSelectAllowed() {
|
| return mMultiSelectionAllowed;
|
| }
|
| @@ -212,14 +259,15 @@ public class PickerCategoryView extends RelativeLayout
|
| }
|
|
|
| /**
|
| - * Prepares bitmaps for loading.
|
| + * Asynchronously enumerates bitmaps on disk.
|
| */
|
| - private void prepareBitmaps() {
|
| + private void enumerateBitmaps() {
|
| if (mWorkerTask != null) {
|
| mWorkerTask.cancel(true);
|
| }
|
|
|
| - mWorkerTask = new FileEnumWorkerTask(this, new MimeTypeFileFilter("image/*"));
|
| + mWorkerTask =
|
| + new FileEnumWorkerTask(this, new MimeTypeFileFilter(Arrays.asList("image/*")));
|
| mWorkerTask.execute();
|
| }
|
|
|
|
|