2009-03-03 19:32:27 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-07-30 13:37:37 -07:00
|
|
|
package com.android.launcher2;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
|
import android.graphics.ColorFilter;
|
2010-11-09 17:19:49 -08:00
|
|
|
import android.graphics.Paint;
|
|
|
|
|
import android.graphics.PixelFormat;
|
|
|
|
|
import android.graphics.Rect;
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
class FastBitmapDrawable extends Drawable {
|
|
|
|
|
private Bitmap mBitmap;
|
2010-12-01 15:47:31 -08:00
|
|
|
private int mAlpha;
|
2010-03-15 14:44:42 -07:00
|
|
|
private int mWidth;
|
|
|
|
|
private int mHeight;
|
2010-08-19 14:51:28 -07:00
|
|
|
private final Paint mPaint = new Paint();
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
FastBitmapDrawable(Bitmap b) {
|
2010-12-01 15:47:31 -08:00
|
|
|
mAlpha = 255;
|
2009-03-03 19:32:27 -08:00
|
|
|
mBitmap = b;
|
2010-03-15 14:44:42 -07:00
|
|
|
if (b != null) {
|
|
|
|
|
mWidth = mBitmap.getWidth();
|
|
|
|
|
mHeight = mBitmap.getHeight();
|
|
|
|
|
} else {
|
|
|
|
|
mWidth = mHeight = 0;
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void draw(Canvas canvas) {
|
2010-11-09 17:19:49 -08:00
|
|
|
final Rect r = getBounds();
|
|
|
|
|
canvas.drawBitmap(mBitmap, r.left, r.top, mPaint);
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getOpacity() {
|
|
|
|
|
return PixelFormat.TRANSLUCENT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setAlpha(int alpha) {
|
2010-12-01 15:47:31 -08:00
|
|
|
mAlpha = alpha;
|
2010-08-19 14:51:28 -07:00
|
|
|
mPaint.setAlpha(alpha);
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
2010-12-01 15:47:31 -08:00
|
|
|
public int getAlpha() {
|
|
|
|
|
return mAlpha;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
@Override
|
|
|
|
|
public void setColorFilter(ColorFilter cf) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getIntrinsicWidth() {
|
2010-03-15 14:44:42 -07:00
|
|
|
return mWidth;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getIntrinsicHeight() {
|
2010-03-15 14:44:42 -07:00
|
|
|
return mHeight;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getMinimumWidth() {
|
2010-03-15 14:44:42 -07:00
|
|
|
return mWidth;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getMinimumHeight() {
|
2010-03-15 14:44:42 -07:00
|
|
|
return mHeight;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 13:44:00 -08:00
|
|
|
public void setBitmap(Bitmap b) {
|
|
|
|
|
mBitmap = b;
|
2010-03-15 14:44:42 -07:00
|
|
|
if (b != null) {
|
|
|
|
|
mWidth = mBitmap.getWidth();
|
|
|
|
|
mHeight = mBitmap.getHeight();
|
|
|
|
|
} else {
|
|
|
|
|
mWidth = mHeight = 0;
|
|
|
|
|
}
|
2010-02-08 13:44:00 -08:00
|
|
|
}
|
|
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
public Bitmap getBitmap() {
|
|
|
|
|
return mBitmap;
|
|
|
|
|
}
|
|
|
|
|
}
|