| Index: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/DecoderServiceHost.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/DecoderServiceHost.java b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/DecoderServiceHost.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1fa1640a51ed7e03058b7e6900a2c4aeb916877b
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/DecoderServiceHost.java
|
| @@ -0,0 +1,99 @@
|
| +// Copyright 2016 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.content.Context;
|
| +import android.graphics.Bitmap;
|
| +import android.graphics.Canvas;
|
| +import android.graphics.Color;
|
| +import android.graphics.Paint;
|
| +
|
| +/**
|
| + * A class to communicate with the decoder service.
|
| + */
|
| +public class DecoderServiceHost {
|
| + /**
|
| + * Interface for notifying clients of the service being ready.
|
| + */
|
| + public interface ServiceReadyCallback {
|
| + /**
|
| + * A function to define to receive a notification once the service is up and running.
|
| + */
|
| + void serviceReady();
|
| + }
|
| +
|
| + /**
|
| + * An interface notifying clients when an image has finished decoding.
|
| + */
|
| + public interface ImageDecodedCallback {
|
| + /**
|
| + * A function to define to receive a notification that an image has been decoded.
|
| + * @param filePath The file path for the newly decoded image.
|
| + * @param bitmap The results of the decoding (or placeholder image, if failed).
|
| + */
|
| + void imageDecodedCallback(String filePath, Bitmap bitmap);
|
| + }
|
| +
|
| + // The callback the client wants us to use to report back when the service is ready.
|
| + private ServiceReadyCallback mCallback;
|
| +
|
| + /**
|
| + * The DecoderServiceHost constructor.
|
| + * @param callback The callback to use when communicating back to the client.
|
| + */
|
| + public DecoderServiceHost(ServiceReadyCallback callback) {
|
| + mCallback = callback;
|
| + }
|
| +
|
| + /**
|
| + * Initiate binding with the decoder service.
|
| + * @param context The context to use.
|
| + */
|
| + public void bind(Context context) {
|
| + mCallback.serviceReady();
|
| + }
|
| +
|
| + /**
|
| + * Unbind from the decoder service.
|
| + * @param context The context to use.
|
| + */
|
| + public void unbind(Context context) {
|
| + // TODO(finnur): Implement.
|
| + }
|
| +
|
| + /**
|
| + * Accepts a request to decode a single image.
|
| + * @param filePath The path to the file to decode.
|
| + * @param width The requested width of the resulting bitmap.
|
| + * @param callback The callback to use to communicate the decoding results.
|
| + */
|
| + public void decodeImage(String filePath, int width, ImageDecodedCallback callback) {
|
| + // TODO(finnur): Queue up and actually decode the image requested.
|
| + callback.imageDecodedCallback(filePath, createPlaceholderBitmap(width, width));
|
| + }
|
| +
|
| + /**
|
| + * Cancels a request to decode an image (if it hasn't already been dispatched).
|
| + * @param filePath
|
| + */
|
| + public void cancelDecodeImage(String filePath) {
|
| + // TODO(finnur): Implement.
|
| + }
|
| +
|
| + /**
|
| + * Creates a placeholder bitmap, used when the server failed to decode the image.
|
| + * @param width The requested width of the resulting bitmap.
|
| + * @param height The requested height of the resulting bitmap.
|
| + * @return Placeholder bitmap.
|
| + */
|
| + private Bitmap createPlaceholderBitmap(int width, int height) {
|
| + Bitmap placeholder = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
| + Canvas canvas = new Canvas(placeholder);
|
| + Paint paint = new Paint();
|
| + paint.setColor(Color.GRAY);
|
| + canvas.drawRect(0, 0, (float) width, (float) height, paint);
|
| + return placeholder;
|
| + }
|
| +}
|
|
|