• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.launcher3;
18 
19 import android.graphics.Bitmap;
20 import android.graphics.Canvas;
21 import android.graphics.ColorFilter;
22 import android.graphics.Paint;
23 import android.graphics.PixelFormat;
24 import android.graphics.Rect;
25 import android.graphics.drawable.Drawable;
26 
27 class FastBitmapDrawable extends Drawable {
28     private Bitmap mBitmap;
29     private int mAlpha;
30     private final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
31 
FastBitmapDrawable(Bitmap b)32     FastBitmapDrawable(Bitmap b) {
33         mAlpha = 255;
34         mBitmap = b;
35         setBounds(0, 0, b.getWidth(), b.getHeight());
36     }
37 
38     @Override
draw(Canvas canvas)39     public void draw(Canvas canvas) {
40         final Rect r = getBounds();
41         // Draw the bitmap into the bounding rect
42         canvas.drawBitmap(mBitmap, null, r, mPaint);
43     }
44 
45     @Override
setColorFilter(ColorFilter cf)46     public void setColorFilter(ColorFilter cf) {
47         mPaint.setColorFilter(cf);
48     }
49 
50     @Override
getOpacity()51     public int getOpacity() {
52         return PixelFormat.TRANSLUCENT;
53     }
54 
55     @Override
setAlpha(int alpha)56     public void setAlpha(int alpha) {
57         mAlpha = alpha;
58         mPaint.setAlpha(alpha);
59     }
60 
setFilterBitmap(boolean filterBitmap)61     public void setFilterBitmap(boolean filterBitmap) {
62         mPaint.setFilterBitmap(filterBitmap);
63         mPaint.setAntiAlias(filterBitmap);
64     }
65 
getAlpha()66     public int getAlpha() {
67         return mAlpha;
68     }
69 
70     @Override
getIntrinsicWidth()71     public int getIntrinsicWidth() {
72         return getBounds().width();
73     }
74 
75     @Override
getIntrinsicHeight()76     public int getIntrinsicHeight() {
77         return getBounds().height();
78     }
79 
80     @Override
getMinimumWidth()81     public int getMinimumWidth() {
82         return getBounds().width();
83     }
84 
85     @Override
getMinimumHeight()86     public int getMinimumHeight() {
87         return getBounds().height();
88     }
89 
getBitmap()90     public Bitmap getBitmap() {
91         return mBitmap;
92     }
93 }
94