1 /*
2  * Copyright (C) 2015 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 package com.android.messaging.datamodel.media;
17 
18 import android.content.res.Resources;
19 import android.graphics.Bitmap;
20 import android.graphics.drawable.Drawable;
21 
22 /**
23  * Base class for holding some form of image resource. The subclass gets to define the specific
24  * type of data format it's holding, whether it be Bitmap objects or compressed byte arrays.
25  */
26 public abstract class ImageResource extends RefCountedMediaResource {
27     protected final int mOrientation;
28 
ImageResource(final String key, int orientation)29     public ImageResource(final String key, int orientation) {
30         super(key);
31         mOrientation = orientation;
32     }
33 
34     /**
35      * Gets the contained image in drawable format.
36      */
getDrawable(Resources resources)37     public abstract Drawable getDrawable(Resources resources);
38 
39     /**
40      * Gets the contained image in bitmap format.
41      */
getBitmap()42     public abstract Bitmap getBitmap();
43 
44     /**
45      * Gets the contained image in byte array format.
46      */
getBytes()47     public abstract byte[] getBytes();
48 
49     /**
50      * Attempt to reuse the bitmap in the image resource and re-purpose it for something else.
51      * After this, the image resource will relinquish ownership on the bitmap resource so that
52      * it doesn't try to recycle it when getting closed.
53      */
reuseBitmap()54     public abstract Bitmap reuseBitmap();
supportsBitmapReuse()55     public abstract boolean supportsBitmapReuse();
56 
57     /**
58      * Gets the orientation of the image as one of the ExifInterface.ORIENTATION_* constants
59      */
getOrientation()60     public int getOrientation() {
61         return mOrientation;
62     }
63 }
64