mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-02 00:36:49 +00:00
Creating AllAppsBackgroundDrawable using DrawableFactory to allow
easier overriding using derivative projects Change-Id: I7265d888876ea0928391f76ec1bcb7d928c0f27a
This commit is contained in:
@@ -23,62 +23,10 @@ import android.graphics.ColorFilter;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
|
||||
/**
|
||||
* A helper class to positon and orient a drawable to be drawn.
|
||||
*/
|
||||
class TransformedImageDrawable {
|
||||
private Drawable mImage;
|
||||
private float mXPercent;
|
||||
private float mYPercent;
|
||||
private int mGravity;
|
||||
private int mAlpha;
|
||||
|
||||
/**
|
||||
* @param gravity If one of the Gravity center values, the x and y offset will take the width
|
||||
* and height of the image into account to center the image to the offset.
|
||||
*/
|
||||
public TransformedImageDrawable(Resources res, int resourceId, float xPct, float yPct,
|
||||
int gravity) {
|
||||
mImage = res.getDrawable(resourceId);
|
||||
mXPercent = xPct;
|
||||
mYPercent = yPct;
|
||||
mGravity = gravity;
|
||||
}
|
||||
|
||||
public void setAlpha(int alpha) {
|
||||
mImage.setAlpha(alpha);
|
||||
mAlpha = alpha;
|
||||
}
|
||||
|
||||
public int getAlpha() {
|
||||
return mAlpha;
|
||||
}
|
||||
|
||||
public void updateBounds(Rect bounds) {
|
||||
int width = mImage.getIntrinsicWidth();
|
||||
int height = mImage.getIntrinsicHeight();
|
||||
int left = bounds.left + (int) (mXPercent * bounds.width());
|
||||
int top = bounds.top + (int) (mYPercent * bounds.height());
|
||||
if ((mGravity & Gravity.CENTER_HORIZONTAL) == Gravity.CENTER_HORIZONTAL) {
|
||||
left -= (width / 2);
|
||||
}
|
||||
if ((mGravity & Gravity.CENTER_VERTICAL) == Gravity.CENTER_VERTICAL) {
|
||||
top -= (height / 2);
|
||||
}
|
||||
mImage.setBounds(left, top, left + width, top + height);
|
||||
}
|
||||
|
||||
public void draw(Canvas canvas) {
|
||||
int c = canvas.save(Canvas.MATRIX_SAVE_FLAG);
|
||||
mImage.draw(canvas);
|
||||
canvas.restoreToCount(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a custom composite drawable that has a fixed virtual size and dynamically lays out its
|
||||
* children images relatively within its bounds. This way, we can reduce the memory usage of a
|
||||
@@ -86,8 +34,62 @@ class TransformedImageDrawable {
|
||||
*/
|
||||
public class AllAppsBackgroundDrawable extends Drawable {
|
||||
|
||||
private final TransformedImageDrawable mHand;
|
||||
private final TransformedImageDrawable[] mIcons;
|
||||
/**
|
||||
* A helper class to positon and orient a drawable to be drawn.
|
||||
*/
|
||||
protected static class TransformedImageDrawable {
|
||||
private Drawable mImage;
|
||||
private float mXPercent;
|
||||
private float mYPercent;
|
||||
private int mGravity;
|
||||
private int mAlpha;
|
||||
|
||||
/**
|
||||
* @param gravity If one of the Gravity center values, the x and y offset will take the width
|
||||
* and height of the image into account to center the image to the offset.
|
||||
*/
|
||||
public TransformedImageDrawable(Resources res, int resourceId, float xPct, float yPct,
|
||||
int gravity) {
|
||||
mImage = res.getDrawable(resourceId);
|
||||
mXPercent = xPct;
|
||||
mYPercent = yPct;
|
||||
mGravity = gravity;
|
||||
}
|
||||
|
||||
public void setAlpha(int alpha) {
|
||||
mImage.setAlpha(alpha);
|
||||
mAlpha = alpha;
|
||||
}
|
||||
|
||||
public int getAlpha() {
|
||||
return mAlpha;
|
||||
}
|
||||
|
||||
public void updateBounds(Rect bounds) {
|
||||
int width = mImage.getIntrinsicWidth();
|
||||
int height = mImage.getIntrinsicHeight();
|
||||
int left = bounds.left + (int) (mXPercent * bounds.width());
|
||||
int top = bounds.top + (int) (mYPercent * bounds.height());
|
||||
if ((mGravity & Gravity.CENTER_HORIZONTAL) == Gravity.CENTER_HORIZONTAL) {
|
||||
left -= (width / 2);
|
||||
}
|
||||
if ((mGravity & Gravity.CENTER_VERTICAL) == Gravity.CENTER_VERTICAL) {
|
||||
top -= (height / 2);
|
||||
}
|
||||
mImage.setBounds(left, top, left + width, top + height);
|
||||
}
|
||||
|
||||
public void draw(Canvas canvas) {
|
||||
mImage.draw(canvas);
|
||||
}
|
||||
|
||||
public Rect getBounds() {
|
||||
return mImage.getBounds();
|
||||
}
|
||||
}
|
||||
|
||||
protected final TransformedImageDrawable mHand;
|
||||
protected final TransformedImageDrawable[] mIcons;
|
||||
private final int mWidth;
|
||||
private final int mHeight;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user