• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         public float fontSize;
35 
36         public static final float SCALE_ONE = 1.0f;
37         public static final float SCALE_HALF = 0.5f;
38         public static final float SCALE_QUARTER = 0.25f;
39 
Dimensions()40         public Dimensions() {
41         }
42 
Dimensions(int w, int h, float s)43         public Dimensions(int w, int h, float s) {
44             this(w, h, s, -1f);
45         }
46 
Dimensions(int width, int height, float scale, float fontSize)47         public Dimensions(int width, int height, float scale, float fontSize) {
48             this.width = width;
49             this.height = height;
50             this.scale = scale;
51             this.fontSize = fontSize;
52         }
53 
54         @Override
toString()55         public String toString() {
56             return String.format("Dimens [%d x %d]", width, height);
57         }
58     }
59 
60     /**
61      * Draw/composite the given Bitmap corresponding with the key 'id'. It will be sized according
62      * to whatever {@link #getDesiredDimensions(Object, Dimensions)} reported when the
63      * decode request was made.
64      *
65      * @param decoded an exactly-sized, decoded bitmap to display
66      * @param key
67      */
drawImage(Bitmap decoded, Object key)68     void drawImage(Bitmap decoded, Object key);
69 
70     /**
71      * Reset all state associated with this view so that it can be reused.
72      */
reset()73     void reset();
74 
75     /**
76      * Outputs the desired dimensions that the object with key 'id' would like to be drawn to.
77      *
78      * @param key
79      * @param outDim caller-allocated {@link Dimensions} object to house the result
80      */
getDesiredDimensions(Object key, Dimensions outDim)81     void getDesiredDimensions(Object key, Dimensions outDim);
82 
83     /**
84      * Return an arbitrary integer to associate with any asynchronous requests for images that
85      * currently belong to this canvas. If, later on when results are available, the generation
86      * that is then reported does not match, the photo manager will assume the image is no longer
87      * desired and will not offer the image.
88      * <p>
89      * Implementors should basically treat this as a counter to increment upon reset() or
90      * data binding.
91      */
getGeneration()92     int getGeneration();
93 }
94