blob: 1cafa09a7bf4b53b489423ef84a0a5e37bd68c6f [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;
Winson Chungb3347bb2010-08-19 14:51:28 -070020import android.graphics.Paint;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021import android.graphics.PixelFormat;
22import android.graphics.Bitmap;
23import android.graphics.Canvas;
24import android.graphics.ColorFilter;
25
26class FastBitmapDrawable extends Drawable {
27 private Bitmap mBitmap;
Romain Guya28fd3f2010-03-15 14:44:42 -070028 private int mWidth;
29 private int mHeight;
Winson Chungb3347bb2010-08-19 14:51:28 -070030 private final Paint mPaint = new Paint();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031
32 FastBitmapDrawable(Bitmap b) {
33 mBitmap = b;
Romain Guya28fd3f2010-03-15 14:44:42 -070034 if (b != null) {
35 mWidth = mBitmap.getWidth();
36 mHeight = mBitmap.getHeight();
37 } else {
38 mWidth = mHeight = 0;
39 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040 }
41
42 @Override
43 public void draw(Canvas canvas) {
Winson Chungb3347bb2010-08-19 14:51:28 -070044 canvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045 }
46
47 @Override
48 public int getOpacity() {
49 return PixelFormat.TRANSLUCENT;
50 }
51
52 @Override
53 public void setAlpha(int alpha) {
Winson Chungb3347bb2010-08-19 14:51:28 -070054 mPaint.setAlpha(alpha);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080055 }
56
57 @Override
58 public void setColorFilter(ColorFilter cf) {
59 }
60
61 @Override
62 public int getIntrinsicWidth() {
Romain Guya28fd3f2010-03-15 14:44:42 -070063 return mWidth;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064 }
65
66 @Override
67 public int getIntrinsicHeight() {
Romain Guya28fd3f2010-03-15 14:44:42 -070068 return mHeight;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069 }
70
71 @Override
72 public int getMinimumWidth() {
Romain Guya28fd3f2010-03-15 14:44:42 -070073 return mWidth;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074 }
75
76 @Override
77 public int getMinimumHeight() {
Romain Guya28fd3f2010-03-15 14:44:42 -070078 return mHeight;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080079 }
80
Joe Onorato0589f0f2010-02-08 13:44:00 -080081 public void setBitmap(Bitmap b) {
82 mBitmap = b;
Romain Guya28fd3f2010-03-15 14:44:42 -070083 if (b != null) {
84 mWidth = mBitmap.getWidth();
85 mHeight = mBitmap.getHeight();
86 } else {
87 mWidth = mHeight = 0;
88 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080089 }
90
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091 public Bitmap getBitmap() {
92 return mBitmap;
93 }
94}