FastBitmapDrawable.java revision b3347bb9f4ccf41fb7043bca66c3a565bde1083b
1/*
2 * Copyright (C) 2008 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
17package com.android.launcher2;
18
19import android.graphics.drawable.Drawable;
20import android.graphics.Paint;
21import android.graphics.PixelFormat;
22import android.graphics.Bitmap;
23import android.graphics.Canvas;
24import android.graphics.ColorFilter;
25
26class FastBitmapDrawable extends Drawable {
27    private Bitmap mBitmap;
28    private int mWidth;
29    private int mHeight;
30    private final Paint mPaint = new Paint();
31
32    FastBitmapDrawable(Bitmap b) {
33        mBitmap = b;
34        if (b != null) {
35            mWidth = mBitmap.getWidth();
36            mHeight = mBitmap.getHeight();
37        } else {
38            mWidth = mHeight = 0;
39        }
40    }
41
42    @Override
43    public void draw(Canvas canvas) {
44        canvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint);
45    }
46
47    @Override
48    public int getOpacity() {
49        return PixelFormat.TRANSLUCENT;
50    }
51
52    @Override
53    public void setAlpha(int alpha) {
54        mPaint.setAlpha(alpha);
55    }
56
57    @Override
58    public void setColorFilter(ColorFilter cf) {
59    }
60
61    @Override
62    public int getIntrinsicWidth() {
63        return mWidth;
64    }
65
66    @Override
67    public int getIntrinsicHeight() {
68        return mHeight;
69    }
70
71    @Override
72    public int getMinimumWidth() {
73        return mWidth;
74    }
75
76    @Override
77    public int getMinimumHeight() {
78        return mHeight;
79    }
80
81    public void setBitmap(Bitmap b) {
82        mBitmap = b;
83        if (b != null) {
84            mWidth = mBitmap.getWidth();
85            mHeight = mBitmap.getHeight();
86        } else {
87            mWidth = mHeight = 0;
88        }
89    }
90
91    public Bitmap getBitmap() {
92        return mBitmap;
93    }
94}
95