blob: 226d6d8d8e08449be4cf70949556def6b5517076 [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
19import android.graphics.drawable.Drawable;
20import android.graphics.PixelFormat;
21import android.graphics.Bitmap;
22import android.graphics.Canvas;
23import android.graphics.ColorFilter;
24
25class FastBitmapDrawable extends Drawable {
26 private Bitmap mBitmap;
Romain Guya28fd3f2010-03-15 14:44:42 -070027 private int mWidth;
28 private int mHeight;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029
30 FastBitmapDrawable(Bitmap b) {
31 mBitmap = b;
Romain Guya28fd3f2010-03-15 14:44:42 -070032 if (b != null) {
33 mWidth = mBitmap.getWidth();
34 mHeight = mBitmap.getHeight();
35 } else {
36 mWidth = mHeight = 0;
37 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080038 }
39
40 @Override
41 public void draw(Canvas canvas) {
42 canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null);
43 }
44
45 @Override
46 public int getOpacity() {
47 return PixelFormat.TRANSLUCENT;
48 }
49
50 @Override
51 public void setAlpha(int alpha) {
52 }
53
54 @Override
55 public void setColorFilter(ColorFilter cf) {
56 }
57
58 @Override
59 public int getIntrinsicWidth() {
Romain Guya28fd3f2010-03-15 14:44:42 -070060 return mWidth;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061 }
62
63 @Override
64 public int getIntrinsicHeight() {
Romain Guya28fd3f2010-03-15 14:44:42 -070065 return mHeight;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066 }
67
68 @Override
69 public int getMinimumWidth() {
Romain Guya28fd3f2010-03-15 14:44:42 -070070 return mWidth;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071 }
72
73 @Override
74 public int getMinimumHeight() {
Romain Guya28fd3f2010-03-15 14:44:42 -070075 return mHeight;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076 }
77
Joe Onorato0589f0f2010-02-08 13:44:00 -080078 public void setBitmap(Bitmap b) {
79 mBitmap = b;
Romain Guya28fd3f2010-03-15 14:44:42 -070080 if (b != null) {
81 mWidth = mBitmap.getWidth();
82 mHeight = mBitmap.getHeight();
83 } else {
84 mWidth = mHeight = 0;
85 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080086 }
87
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088 public Bitmap getBitmap() {
89 return mBitmap;
90 }
91}