1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.mail.ui; 18 19 import android.graphics.Bitmap; 20 21 /** 22 * A canvas to draw loaded photos. 23 */ 24 public interface ImageCanvas { 25 26 /** 27 * Dimensions holds the desired width, height, and scale for a bitmap being 28 * placed in the ImageCanvas. 29 */ 30 public static class Dimensions { 31 public int width; 32 public int height; 33 public float scale; 34 35 public static final float SCALE_ONE = 1.0f; 36 public static final float SCALE_HALF = 0.5f; 37 public static final float SCALE_QUARTER = 0.25f; 38 39 public Dimensions() { 40 } 41 42 public Dimensions(int w, int h, float s) { 43 width = w; 44 height = h; 45 scale = s; 46 } 47 48 @Override 49 public String toString() { 50 return String.format("Dimens [%d x %d]", width, height); 51 } 52 } 53 54 /** 55 * Draw/composite the given Bitmap corresponding with the key 'id'. It will be sized according 56 * to whatever {@link #getDesiredDimensions(Object, Dimensions)} reported when the 57 * decode request was made. 58 * 59 * @param decoded an exactly-sized, decoded bitmap to display 60 * @param key 61 */ 62 void drawImage(Bitmap decoded, Object key); 63 64 /** 65 * Reset all state associated with this view so that it can be reused. 66 */ 67 void reset(); 68 69 /** 70 * Outputs the desired dimensions that the object with key 'id' would like to be drawn to. 71 * 72 * @param key 73 * @param outDim caller-allocated {@link Dimensions} object to house the result 74 */ 75 void getDesiredDimensions(Object key, Dimensions outDim); 76 77 /** 78 * Return an arbitrary integer to associate with any asynchronous requests for images that 79 * currently belong to this canvas. If, later on when results are available, the generation 80 * that is then reported does not match, the photo manager will assume the image is no longer 81 * desired and will not offer the image. 82 * <p> 83 * Implementors should basically treat this as a counter to increment upon reset() or 84 * data binding. 85 */ 86 int getGeneration(); 87 } 88