blob: 85e90202b384ee676e2a95770f5db2e3c4aec2af [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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
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;
Winson Chung29d6fea2010-12-01 15:47:31 -080029 private int mAlpha;
Winson Chungeecf02d2012-03-02 17:14:58 -080030 private final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031
32 FastBitmapDrawable(Bitmap b) {
Winson Chungeeb5bbc2013-11-13 15:47:05 -080033 mAlpha = 255;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034 mBitmap = b;
Winson Chung268f1c52013-11-18 14:04:41 -080035 setBounds(0, 0, b.getWidth(), b.getHeight());
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036 }
37
38 @Override
39 public void draw(Canvas canvas) {
Winson Chung45e1d6e2010-11-09 17:19:49 -080040 final Rect r = getBounds();
Winson Chung8a196352013-05-28 16:12:55 -070041 // Draw the bitmap into the bounding rect
42 canvas.drawBitmap(mBitmap, null, r, mPaint);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043 }
44
45 @Override
Adam Cohenbadf71e2011-05-26 19:08:29 -070046 public void setColorFilter(ColorFilter cf) {
47 mPaint.setColorFilter(cf);
48 }
49
50 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051 public int getOpacity() {
52 return PixelFormat.TRANSLUCENT;
53 }
54
55 @Override
56 public void setAlpha(int alpha) {
Winson Chung29d6fea2010-12-01 15:47:31 -080057 mAlpha = alpha;
Winson Chungb3347bb2010-08-19 14:51:28 -070058 mPaint.setAlpha(alpha);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059 }
60
Adam Cohen76fc0852011-06-17 13:26:23 -070061 public void setFilterBitmap(boolean filterBitmap) {
62 mPaint.setFilterBitmap(filterBitmap);
Winson Chung6e1c0d32013-10-25 15:24:24 -070063 mPaint.setAntiAlias(filterBitmap);
Adam Cohen76fc0852011-06-17 13:26:23 -070064 }
65
Winson Chung29d6fea2010-12-01 15:47:31 -080066 public int getAlpha() {
67 return mAlpha;
68 }
69
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071 public int getIntrinsicWidth() {
Winson Chungeeb5bbc2013-11-13 15:47:05 -080072 return getBounds().width();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073 }
74
75 @Override
76 public int getIntrinsicHeight() {
Winson Chungeeb5bbc2013-11-13 15:47:05 -080077 return getBounds().height();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078 }
79
80 @Override
81 public int getMinimumWidth() {
Winson Chungeeb5bbc2013-11-13 15:47:05 -080082 return getBounds().width();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083 }
84
85 @Override
86 public int getMinimumHeight() {
Winson Chungeeb5bbc2013-11-13 15:47:05 -080087 return getBounds().height();
Joe Onorato0589f0f2010-02-08 13:44:00 -080088 }
89
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090 public Bitmap getBitmap() {
91 return mBitmap;
92 }
93}