The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 19 | import android.graphics.Bitmap; |
| 20 | import android.graphics.Canvas; |
| 21 | import android.graphics.ColorFilter; |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 22 | import android.graphics.Paint; |
| 23 | import android.graphics.PixelFormat; |
| 24 | import android.graphics.Rect; |
| 25 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 26 | |
| 27 | class FastBitmapDrawable extends Drawable { |
| 28 | private Bitmap mBitmap; |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 29 | private int mAlpha; |
Winson Chung | eecf02d | 2012-03-02 17:14:58 -0800 | [diff] [blame] | 30 | private final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | |
| 32 | FastBitmapDrawable(Bitmap b) { |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 33 | mAlpha = 255; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | mBitmap = b; |
Winson Chung | 268f1c5 | 2013-11-18 14:04:41 -0800 | [diff] [blame] | 35 | setBounds(0, 0, b.getWidth(), b.getHeight()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public void draw(Canvas canvas) { |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 40 | final Rect r = getBounds(); |
Winson Chung | 8a19635 | 2013-05-28 16:12:55 -0700 | [diff] [blame] | 41 | // Draw the bitmap into the bounding rect |
| 42 | canvas.drawBitmap(mBitmap, null, r, mPaint); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | @Override |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 46 | public void setColorFilter(ColorFilter cf) { |
| 47 | mPaint.setColorFilter(cf); |
| 48 | } |
| 49 | |
| 50 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 51 | public int getOpacity() { |
| 52 | return PixelFormat.TRANSLUCENT; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public void setAlpha(int alpha) { |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 57 | mAlpha = alpha; |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 58 | mPaint.setAlpha(alpha); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 61 | public void setFilterBitmap(boolean filterBitmap) { |
| 62 | mPaint.setFilterBitmap(filterBitmap); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 63 | mPaint.setAntiAlias(filterBitmap); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 66 | public int getAlpha() { |
| 67 | return mAlpha; |
| 68 | } |
| 69 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 70 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 71 | public int getIntrinsicWidth() { |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 72 | return getBounds().width(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public int getIntrinsicHeight() { |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 77 | return getBounds().height(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public int getMinimumWidth() { |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 82 | return getBounds().width(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public int getMinimumHeight() { |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 87 | return getBounds().height(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 88 | } |
| 89 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 90 | public Bitmap getBitmap() { |
| 91 | return mBitmap; |
| 92 | } |
| 93 | } |