diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2017-01-08 13:13:47 -0800 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2017-01-08 13:14:51 -0800 |
commit | 260b07fa86865481ab3e1c6d4fec3ef52ba0a621 (patch) | |
tree | b56080225da638903b20de92dabb2129e0017195 /src | |
parent | 2c3194e87977c06a72e54e63745f790d619e77ed (diff) | |
download | android_packages_apps_Trebuchet-260b07fa86865481ab3e1c6d4fec3ef52ba0a621.tar.gz android_packages_apps_Trebuchet-260b07fa86865481ab3e1c6d4fec3ef52ba0a621.tar.bz2 android_packages_apps_Trebuchet-260b07fa86865481ab3e1c6d4fec3ef52ba0a621.zip |
Creating AllAppsBackgroundDrawable using DrawableFactory to allow
easier overriding using derivative projects
Change-Id: I7265d888876ea0928391f76ec1bcb7d928c0f27a
Diffstat (limited to 'src')
3 files changed, 70 insertions, 50 deletions
diff --git a/src/com/android/launcher3/allapps/AllAppsBackgroundDrawable.java b/src/com/android/launcher3/allapps/AllAppsBackgroundDrawable.java index bc602f37b..c71bc3166 100644 --- a/src/com/android/launcher3/allapps/AllAppsBackgroundDrawable.java +++ b/src/com/android/launcher3/allapps/AllAppsBackgroundDrawable.java @@ -23,71 +23,73 @@ 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. + * 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 + * single, large sparsely populated image. */ -class TransformedImageDrawable { - private Drawable mImage; - private float mXPercent; - private float mYPercent; - private int mGravity; - private int mAlpha; +public class AllAppsBackgroundDrawable extends Drawable { /** - * @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. + * A helper class to positon and orient a drawable to be drawn. */ - public TransformedImageDrawable(Resources res, int resourceId, float xPct, float yPct, - int gravity) { - mImage = res.getDrawable(resourceId); - mXPercent = xPct; - mYPercent = yPct; - mGravity = gravity; - } + 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 void setAlpha(int alpha) { + mImage.setAlpha(alpha); + mAlpha = alpha; + } - public int getAlpha() { - return mAlpha; - } + 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); + 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); } - if ((mGravity & Gravity.CENTER_VERTICAL) == Gravity.CENTER_VERTICAL) { - top -= (height / 2); + + public void draw(Canvas canvas) { + mImage.draw(canvas); } - 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); + public Rect getBounds() { + return mImage.getBounds(); + } } -} - -/** - * 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 - * single, large sparsely populated image. - */ -public class AllAppsBackgroundDrawable extends Drawable { - private final TransformedImageDrawable mHand; - private final TransformedImageDrawable[] mIcons; + protected final TransformedImageDrawable mHand; + protected final TransformedImageDrawable[] mIcons; private final int mWidth; private final int mHeight; diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java index 10d4c1506..a41d83244 100644 --- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java +++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java @@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.util.SparseIntArray; +import android.view.MotionEvent; import android.view.View; import com.android.launcher3.BaseRecyclerView; @@ -29,6 +30,7 @@ import com.android.launcher3.BubbleTextView; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.R; +import com.android.launcher3.graphics.DrawableFactory; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import java.util.List; @@ -207,7 +209,8 @@ public class AllAppsRecyclerView extends BaseRecyclerView { if (mApps.hasNoFilteredResults()) { if (mEmptySearchBackground == null) { - mEmptySearchBackground = new AllAppsBackgroundDrawable(getContext()); + mEmptySearchBackground = DrawableFactory.get(getContext()) + .getAllAppsBackground(getContext()); mEmptySearchBackground.setAlpha(0); mEmptySearchBackground.setCallback(this); updateEmptySearchBackgroundBounds(); @@ -220,6 +223,16 @@ public class AllAppsRecyclerView extends BaseRecyclerView { } } + @Override + public boolean onInterceptTouchEvent(MotionEvent e) { + boolean result = super.onInterceptTouchEvent(e); + if (!result && e.getAction() == MotionEvent.ACTION_DOWN + && mEmptySearchBackground != null && mEmptySearchBackground.getAlpha() > 0) { + mEmptySearchBackground.setHotspot(e.getX(), e.getY()); + } + return result; + } + /** * Maps the touch (from 0..1) to the adapter position that should be visible. */ diff --git a/src/com/android/launcher3/graphics/DrawableFactory.java b/src/com/android/launcher3/graphics/DrawableFactory.java index f6a4b844f..693df7ad8 100644 --- a/src/com/android/launcher3/graphics/DrawableFactory.java +++ b/src/com/android/launcher3/graphics/DrawableFactory.java @@ -23,6 +23,7 @@ import com.android.launcher3.FastBitmapDrawable; import com.android.launcher3.ItemInfo; import com.android.launcher3.R; import com.android.launcher3.Utilities; +import com.android.launcher3.allapps.AllAppsBackgroundDrawable; /** * Factory for creating new drawables. @@ -50,4 +51,8 @@ public class DrawableFactory { d.setFilterBitmap(true); return d; } + + public AllAppsBackgroundDrawable getAllAppsBackground(Context context) { + return new AllAppsBackgroundDrawable(context); + } } |