Chromium Code Reviews| 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 17dde3f751d184e8bdd61754dbf8f3b81d296824..265092bc6f83911e2b03d3d445a60abb73759630 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 |
| @@ -28,7 +28,9 @@ import java.util.List; |
| * A class for keeping track of common data associated with showing photos in |
| * the photo picker, for example the RecyclerView and the bitmap caches. |
| */ |
| -public class PickerCategoryView extends RelativeLayout implements OnMenuItemClickListener { |
| +public class PickerCategoryView extends RelativeLayout |
| + implements RecyclerView.RecyclerListener, DecoderServiceHost.ServiceReadyCallback, |
| + OnMenuItemClickListener { |
| // The dialog that owns us. |
| private PhotoPickerDialog mDialog; |
| @@ -47,6 +49,9 @@ public class PickerCategoryView extends RelativeLayout implements OnMenuItemClic |
| // 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; |
| @@ -92,6 +97,9 @@ public class PickerCategoryView extends RelativeLayout implements OnMenuItemClic |
| private void postConstruction(Context context) { |
| mContext = context; |
| + mDecoderServiceHost = new DecoderServiceHost(this); |
| + mDecoderServiceHost.bind(mContext); |
| + |
| mSelectionDelegate = new SelectionDelegate<PickerBitmap>(); |
| View root = LayoutInflater.from(context).inflate(R.layout.photo_picker_dialog, this); |
| @@ -115,8 +123,16 @@ public class PickerCategoryView extends RelativeLayout implements OnMenuItemClic |
| mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(mColumns, mPadding)); |
| // TODO(finnur): Implement caching. |
| - // TODO(finnur): Remove this once the decoder service is in place. |
| - prepareBitmaps(); |
| + } |
| + |
| + /** |
| + * Severs the connection to the decoding utility process. |
| + */ |
| + public void onDialogDismissed() { |
| + if (mDecoderServiceHost != null) { |
| + mDecoderServiceHost.unbind(mContext); |
| + mDecoderServiceHost = null; |
| + } |
| } |
| /** |
| @@ -134,6 +150,24 @@ public class PickerCategoryView extends RelativeLayout implements OnMenuItemClic |
| mListener = listener; |
| } |
| + // DecoderServiceHost.ServiceReadyCallback: |
| + |
| + @Override |
| + public void serviceReady() { |
| + prepareBitmaps(); |
| + } |
| + |
| + // RecyclerView.RecyclerListener: |
| + |
| + @Override |
| + public void onViewRecycled(RecyclerView.ViewHolder holder) { |
| + PickerBitmapViewHolder bitmapHolder = (PickerBitmapViewHolder) holder; |
| + String filePath = bitmapHolder.getFilePath(); |
| + if (filePath != null) { |
| + getDecoderServiceHost().cancelDecodeImage(filePath); |
| + } |
| + } |
| + |
| // OnMenuItemClickListener: |
| @Override |
| @@ -164,6 +198,10 @@ public class PickerCategoryView extends RelativeLayout implements OnMenuItemClic |
| return mPickerBitmaps; |
| } |
| + public DecoderServiceHost getDecoderServiceHost() { |
| + return mDecoderServiceHost; |
| + } |
| + |
| public boolean isMultiSelectAllowed() { |
| return mMultiSelectionAllowed; |
| } |
| @@ -207,10 +245,18 @@ public class PickerCategoryView extends RelativeLayout implements OnMenuItemClic |
| mPickerBitmaps = new ArrayList<>(); |
| mPickerBitmaps.add(0, new PickerBitmap("", 0, PickerBitmap.GALLERY)); |
| mPickerBitmaps.add(0, new PickerBitmap("", 0, PickerBitmap.CAMERA)); |
| - mPickerBitmaps.add(new PickerBitmap("foo/bar1.jpg", 1, PickerBitmap.PICTURE)); |
| - mPickerBitmaps.add(new PickerBitmap("foo/bar2.jpg", 2, PickerBitmap.PICTURE)); |
| - mPickerBitmaps.add(new PickerBitmap("foo/bar3.jpg", 3, PickerBitmap.PICTURE)); |
| - mPickerBitmaps.add(new PickerBitmap("foo/bar4.jpg", 4, PickerBitmap.PICTURE)); |
| + mPickerBitmaps.add( |
| + new PickerBitmap("/storage/emulated/0/DCIM/Camera/IMG_20170201_154701.jpg", 1, |
| + PickerBitmap.PICTURE)); |
| + mPickerBitmaps.add( |
| + new PickerBitmap("/storage/emulated/0/DCIM/Camera/IMG_20170201_154704.jpg", 2, |
| + PickerBitmap.PICTURE)); |
| + mPickerBitmaps.add( |
| + new PickerBitmap("/storage/emulated/0/DCIM/Camera/IMG_20170201_154707.jpg", 3, |
| + PickerBitmap.PICTURE)); |
| + mPickerBitmaps.add( |
| + new PickerBitmap("/storage/emulated/0/DCIM/Camera/IMG_20170201_154709.jpg", 4, |
| + PickerBitmap.PICTURE)); |
|
Finnur
2017/04/12 14:57:42
This code is for testing only and is going away an
Theresa
2017/04/13 02:25:27
Acknowledged.
|
| mPickerAdapter.notifyDataSetChanged(); |
| } |