blob: 83be143695197680ac232b6b540612b0303b5643 [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;
35 }
36
37 @Override
38 public void draw(Canvas canvas) {
Winson Chung45e1d6e2010-11-09 17:19:49 -080039 final Rect r = getBounds();
Winson Chung8a196352013-05-28 16:12:55 -070040 // Draw the bitmap into the bounding rect
41 canvas.drawBitmap(mBitmap, null, r, mPaint);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042 }
43
44 @Override
Adam Cohenbadf71e2011-05-26 19:08:29 -070045 public void setColorFilter(ColorFilter cf) {
46 mPaint.setColorFilter(cf);
47 }
48
49 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050 public int getOpacity() {
51 return PixelFormat.TRANSLUCENT;
52 }
53
54 @Override
55 public void setAlpha(int alpha) {
Winson Chung29d6fea2010-12-01 15:47:31 -080056 mAlpha = alpha;
Winson Chungb3347bb2010-08-19 14:51:28 -070057 mPaint.setAlpha(alpha);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080058 }
59
Adam Cohen76fc0852011-06-17 13:26:23 -070060 public void setFilterBitmap(boolean filterBitmap) {
61 mPaint.setFilterBitmap(filterBitmap);
Winson Chung6e1c0d32013-10-25 15:24:24 -070062 mPaint.setAntiAlias(filterBitmap);
Adam Cohen76fc0852011-06-17 13:26:23 -070063 }
64
Winson Chung29d6fea2010-12-01 15:47:31 -080065 public int getAlpha() {
66 return mAlpha;
67 }
68
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070 public int getIntrinsicWidth() {
Winson Chungeeb5bbc2013-11-13 15:47:05 -080071 return getBounds().width();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072 }
73
74 @Override
75 public int getIntrinsicHeight() {
Winson Chungeeb5bbc2013-11-13 15:47:05 -080076 return getBounds().height();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077 }
78
79 @Override
80 public int getMinimumWidth() {
Winson Chungeeb5bbc2013-11-13 15:47:05 -080081 return getBounds().width();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082 }
83
84 @Override
85 public int getMinimumHeight() {
Winson Chungeeb5bbc2013-11-13 15:47:05 -080086 return getBounds().height();
Joe Onorato0589f0f2010-02-08 13:44:00 -080087 }
88
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089 public Bitmap getBitmap() {
90 return mBitmap;
91 }
92}