blob: 1aa8b35221956f7dc113b5729b9a078a263fabe4 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019import android.graphics.Bitmap;
20import android.graphics.Canvas;
21import android.graphics.ColorFilter;
Winson Chung45e1d6e2010-11-09 17:19:49 -080022import android.graphics.Paint;
23import android.graphics.PixelFormat;
24import android.graphics.Rect;
25import android.graphics.drawable.Drawable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080026
27class FastBitmapDrawable extends Drawable {
28 private Bitmap mBitmap;
Romain Guya28fd3f2010-03-15 14:44:42 -070029 private int mWidth;
30 private int mHeight;
Winson Chungb3347bb2010-08-19 14:51:28 -070031 private final Paint mPaint = new Paint();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032
33 FastBitmapDrawable(Bitmap b) {
34 mBitmap = b;
Romain Guya28fd3f2010-03-15 14:44:42 -070035 if (b != null) {
36 mWidth = mBitmap.getWidth();
37 mHeight = mBitmap.getHeight();
38 } else {
39 mWidth = mHeight = 0;
40 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041 }
42
43 @Override
44 public void draw(Canvas canvas) {
Winson Chung45e1d6e2010-11-09 17:19:49 -080045 final Rect r = getBounds();
46 canvas.drawBitmap(mBitmap, r.left, r.top, mPaint);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047 }
48
49 @Override
50 public int getOpacity() {
51 return PixelFormat.TRANSLUCENT;
52 }
53
54 @Override
55 public void setAlpha(int alpha) {
Winson Chungb3347bb2010-08-19 14:51:28 -070056 mPaint.setAlpha(alpha);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057 }
58
59 @Override
60 public void setColorFilter(ColorFilter cf) {
61 }
62
63 @Override
64 public int getIntrinsicWidth() {
Romain Guya28fd3f2010-03-15 14:44:42 -070065 return mWidth;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066 }
67
68 @Override
69 public int getIntrinsicHeight() {
Romain Guya28fd3f2010-03-15 14:44:42 -070070 return mHeight;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071 }
72
73 @Override
74 public int getMinimumWidth() {
Romain Guya28fd3f2010-03-15 14:44:42 -070075 return mWidth;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076 }
77
78 @Override
79 public int getMinimumHeight() {
Romain Guya28fd3f2010-03-15 14:44:42 -070080 return mHeight;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081 }
82
Joe Onorato0589f0f2010-02-08 13:44:00 -080083 public void setBitmap(Bitmap b) {
84 mBitmap = b;
Romain Guya28fd3f2010-03-15 14:44:42 -070085 if (b != null) {
86 mWidth = mBitmap.getWidth();
87 mHeight = mBitmap.getHeight();
88 } else {
89 mWidth = mHeight = 0;
90 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080091 }
92
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093 public Bitmap getBitmap() {
94 return mBitmap;
95 }
96}