Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19ea5cc0 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Creating AllAppsBackgroundDrawable using DrawableFactory to allow...

Merge "Creating AllAppsBackgroundDrawable using DrawableFactory to allow easier overriding using derivative projects" into ub-launcher3-master
parents 006d0994 260b07fa
Loading
Loading
Loading
Loading
+51 −49
Original line number Diff line number Diff line
@@ -23,14 +23,21 @@ 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;

/**
 * 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 {

    /**
     * A helper class to positon and orient a drawable to be drawn.
     */
class TransformedImageDrawable {
    protected static class TransformedImageDrawable {
        private Drawable mImage;
        private float mXPercent;
        private float mYPercent;
@@ -73,21 +80,16 @@ class TransformedImageDrawable {
        }

        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
 * single, large sparsely populated image.
 */
public class AllAppsBackgroundDrawable extends Drawable {
        public Rect getBounds() {
            return mImage.getBounds();
        }
    }

    private final TransformedImageDrawable mHand;
    private final TransformedImageDrawable[] mIcons;
    protected final TransformedImageDrawable mHand;
    protected final TransformedImageDrawable[] mIcons;
    private final int mWidth;
    private final int mHeight;

+14 −1
Original line number Diff line number Diff line
@@ -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.
     */
+5 −0
Original line number Diff line number Diff line
@@ -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);
    }
}