FastBitmapDrawable.java revision a28fd3fa7c82947d847c05ed11905f556b8dcfa2
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 17package com.android.launcher2; 18 19import android.graphics.drawable.Drawable; 20import android.graphics.PixelFormat; 21import android.graphics.Bitmap; 22import android.graphics.Canvas; 23import android.graphics.ColorFilter; 24 25class FastBitmapDrawable extends Drawable { 26 private Bitmap mBitmap; 27 private int mWidth; 28 private int mHeight; 29 30 FastBitmapDrawable(Bitmap b) { 31 mBitmap = b; 32 if (b != null) { 33 mWidth = mBitmap.getWidth(); 34 mHeight = mBitmap.getHeight(); 35 } else { 36 mWidth = mHeight = 0; 37 } 38 } 39 40 @Override 41 public void draw(Canvas canvas) { 42 canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null); 43 } 44 45 @Override 46 public int getOpacity() { 47 return PixelFormat.TRANSLUCENT; 48 } 49 50 @Override 51 public void setAlpha(int alpha) { 52 } 53 54 @Override 55 public void setColorFilter(ColorFilter cf) { 56 } 57 58 @Override 59 public int getIntrinsicWidth() { 60 return mWidth; 61 } 62 63 @Override 64 public int getIntrinsicHeight() { 65 return mHeight; 66 } 67 68 @Override 69 public int getMinimumWidth() { 70 return mWidth; 71 } 72 73 @Override 74 public int getMinimumHeight() { 75 return mHeight; 76 } 77 78 public void setBitmap(Bitmap b) { 79 mBitmap = b; 80 if (b != null) { 81 mWidth = mBitmap.getWidth(); 82 mHeight = mBitmap.getHeight(); 83 } else { 84 mWidth = mHeight = 0; 85 } 86 } 87 88 public Bitmap getBitmap() { 89 return mBitmap; 90 } 91} 92