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

Commit 4a6bc55c authored by Michael Jurka's avatar Michael Jurka
Browse files

Fix black bar drawn sometimes when swiping away items in Recents

- move drawing of faded black edges to RecentsPanelView
- invalidate RecentsPanelView when scroll value of Recents*ScrollView changes

Bug: 10022236

Change-Id: Idb102fb2454c2a077920b770e25c449ccd33486e
parent 6df7d4a5
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import android.widget.LinearLayout;

import com.android.systemui.R;

public class RecentsScrollViewPerformanceHelper {
public class FadedEdgeDrawHelper {
    public static final boolean OPTIMIZE_SW_RENDERED_RECENTS = true;
    public static final boolean USE_DARK_FADE_IN_HW_ACCELERATED_MODE = true;
    private View mScrollView;
@@ -43,18 +43,18 @@ public class RecentsScrollViewPerformanceHelper {
    private Matrix mFadeMatrix;
    private LinearGradient mFade;

    public static RecentsScrollViewPerformanceHelper create(Context context,
    public static FadedEdgeDrawHelper create(Context context,
            AttributeSet attrs, View scrollView, boolean isVertical) {
        boolean isTablet = context.getResources().
                getBoolean(R.bool.config_recents_interface_for_tablets);
        if (!isTablet && (OPTIMIZE_SW_RENDERED_RECENTS || USE_DARK_FADE_IN_HW_ACCELERATED_MODE)) {
            return new RecentsScrollViewPerformanceHelper(context, attrs, scrollView, isVertical);
            return new FadedEdgeDrawHelper(context, attrs, scrollView, isVertical);
        } else {
            return null;
        }
    }

    public RecentsScrollViewPerformanceHelper(Context context,
    public FadedEdgeDrawHelper(Context context,
            AttributeSet attrs, View scrollView, boolean isVertical) {
        mScrollView = scrollView;
        TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View);
@@ -64,7 +64,7 @@ public class RecentsScrollViewPerformanceHelper {
    }

    public void onAttachedToWindowCallback(
            RecentsCallback callback, LinearLayout layout, boolean hardwareAccelerated) {
            LinearLayout layout, boolean hardwareAccelerated) {
        mSoftwareRendered = !hardwareAccelerated;
        if ((mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS)
                || USE_DARK_FADE_IN_HW_ACCELERATED_MODE) {
@@ -178,11 +178,11 @@ public class RecentsScrollViewPerformanceHelper {
        }
    }

    public int getVerticalFadingEdgeLengthCallback() {
    public int getVerticalFadingEdgeLength() {
        return mFadingEdgeLength;
    }

    public int getHorizontalFadingEdgeLengthCallback() {
    public int getHorizontalFadingEdgeLength() {
        return mFadingEdgeLength;
    }

+26 −30
Original line number Diff line number Diff line
@@ -49,16 +49,17 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
    private RecentsCallback mCallback;
    protected int mLastScrollPosition;
    private SwipeHelper mSwipeHelper;
    private RecentsScrollViewPerformanceHelper mPerformanceHelper;
    private FadedEdgeDrawHelper mFadedEdgeDrawHelper;
    private HashSet<View> mRecycledViews;
    private int mNumItemsInOneScreenful;
    private Runnable mOnScrollListener;

    public RecentsHorizontalScrollView(Context context, AttributeSet attrs) {
        super(context, attrs, 0);
        float densityScale = getResources().getDisplayMetrics().density;
        float pagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
        mSwipeHelper = new SwipeHelper(SwipeHelper.Y, this, densityScale, pagingTouchSlop);
        mPerformanceHelper = RecentsScrollViewPerformanceHelper.create(context, attrs, this, false);
        mFadedEdgeDrawHelper = FadedEdgeDrawHelper.create(context, attrs, this, false);
        mRecycledViews = new HashSet<View>();
    }

@@ -108,8 +109,8 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView

            final View view = mAdapter.getView(i, old, mLinearLayout);

            if (mPerformanceHelper != null) {
                mPerformanceHelper.addViewCallback(view);
            if (mFadedEdgeDrawHelper != null) {
                mFadedEdgeDrawHelper.addViewCallback(view);
            }

            OnTouchListener noOpListener = new OnTouchListener() {
@@ -234,36 +235,32 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
    public void drawFadedEdges(Canvas canvas, int left, int right, int top, int bottom) {
        if (mFadedEdgeDrawHelper != null) {

        if (mPerformanceHelper != null) {
            int paddingLeft = mPaddingLeft;
            final boolean offsetRequired = isPaddingOffsetRequired();
            if (offsetRequired) {
                paddingLeft += getLeftPaddingOffset();
            }

            int left = mScrollX + paddingLeft;
            int right = left + mRight - mLeft - mPaddingRight - paddingLeft;
            int top = mScrollY + getFadeTop(offsetRequired);
            int bottom = top + getFadeHeight(offsetRequired);

            if (offsetRequired) {
                right += getRightPaddingOffset();
                bottom += getBottomPaddingOffset();
            }
            mPerformanceHelper.drawCallback(canvas,
            mFadedEdgeDrawHelper.drawCallback(canvas,
                    left, right, top, bottom, mScrollX, mScrollY,
                    0, 0,
                    getLeftFadingEdgeStrength(), getRightFadingEdgeStrength(), mPaddingTop);
        }
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
       super.onScrollChanged(l, t, oldl, oldt);
       if (mOnScrollListener != null) {
           mOnScrollListener.run();
       }
    }

    public void setOnScrollListener(Runnable listener) {
        mOnScrollListener = listener;
    }

    @Override
    public int getVerticalFadingEdgeLength() {
        if (mPerformanceHelper != null) {
            return mPerformanceHelper.getVerticalFadingEdgeLengthCallback();
        if (mFadedEdgeDrawHelper != null) {
            return mFadedEdgeDrawHelper.getVerticalFadingEdgeLength();
        } else {
            return super.getVerticalFadingEdgeLength();
        }
@@ -271,8 +268,8 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView

    @Override
    public int getHorizontalFadingEdgeLength() {
        if (mPerformanceHelper != null) {
            return mPerformanceHelper.getHorizontalFadingEdgeLengthCallback();
        if (mFadedEdgeDrawHelper != null) {
            return mFadedEdgeDrawHelper.getHorizontalFadingEdgeLength();
        } else {
            return super.getHorizontalFadingEdgeLength();
        }
@@ -290,9 +287,8 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView

    @Override
    public void onAttachedToWindow() {
        if (mPerformanceHelper != null) {
            mPerformanceHelper.onAttachedToWindowCallback(
                    mCallback, mLinearLayout, isHardwareAccelerated());
        if (mFadedEdgeDrawHelper != null) {
            mFadedEdgeDrawHelper.onAttachedToWindowCallback(mLinearLayout, isHardwareAccelerated());
        }
    }

+46 −35
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
@@ -74,7 +75,7 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
    private PopupMenu mPopup;
    private View mRecentsScrim;
    private View mRecentsNoApps;
    private ViewGroup mRecentsContainer;
    private RecentsScrollView mRecentsContainer;

    private boolean mShowing;
    private boolean mWaitingToShow;
@@ -98,6 +99,8 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        public void setCallback(RecentsCallback callback);
        public void setMinSwipeAlpha(float minAlpha);
        public View findViewForTask(int persistentTaskId);
        public void drawFadedEdges(Canvas c, int left, int right, int top, int bottom);
        public void setOnScrollListener(Runnable listener);
    }

    private final class OnLongClickDelegate implements View.OnLongClickListener {
@@ -270,13 +273,7 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
    }

    public int numItemsInOneScreenful() {
        if (mRecentsContainer instanceof RecentsScrollView){
            RecentsScrollView scrollView
                    = (RecentsScrollView) mRecentsContainer;
            return scrollView.numItemsInOneScreenful();
        }  else {
            throw new IllegalArgumentException("missing Recents[Horizontal]ScrollView");
        }
        return mRecentsContainer.numItemsInOneScreenful();
    }

    private boolean pointInside(int x, int y, View v) {
@@ -288,7 +285,7 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
    }

    public boolean isInContentArea(int x, int y) {
        return pointInside(x, y, mRecentsContainer);
        return pointInside(x, y, (View) mRecentsContainer);
    }

    public void show(boolean show) {
@@ -436,16 +433,16 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
    protected void onFinishInflate() {
        super.onFinishInflate();

        mRecentsContainer = (ViewGroup) findViewById(R.id.recents_container);
        mListAdapter = new TaskDescriptionAdapter(mContext);
        if (mRecentsContainer instanceof RecentsScrollView){
            RecentsScrollView scrollView
                    = (RecentsScrollView) mRecentsContainer;
            scrollView.setAdapter(mListAdapter);
            scrollView.setCallback(this);
        } else {
            throw new IllegalArgumentException("missing Recents[Horizontal]ScrollView");
        mRecentsContainer = (RecentsScrollView) findViewById(R.id.recents_container);
        mRecentsContainer.setOnScrollListener(new Runnable() {
            public void run() {
                // need to redraw the faded edges
                invalidate();
            }
        });
        mListAdapter = new TaskDescriptionAdapter(mContext);
        mRecentsContainer.setAdapter(mListAdapter);
        mRecentsContainer.setCallback(this);

        mRecentsScrim = findViewById(R.id.recents_bg_protect);
        mRecentsNoApps = findViewById(R.id.recents_no_apps);
@@ -462,11 +459,7 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
    }

    public void setMinSwipeAlpha(float minAlpha) {
        if (mRecentsContainer instanceof RecentsScrollView){
            RecentsScrollView scrollView
                = (RecentsScrollView) mRecentsContainer;
            scrollView.setMinSwipeAlpha(minAlpha);
        }
        mRecentsContainer.setMinSwipeAlpha(minAlpha);
    }

    private void createCustomAnimations(LayoutTransition transitioner) {
@@ -524,7 +517,7 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
    void onTaskThumbnailLoaded(TaskDescription td) {
        synchronized (td) {
            if (mRecentsContainer != null) {
                ViewGroup container = mRecentsContainer;
                ViewGroup container = (ViewGroup) mRecentsContainer;
                if (container instanceof RecentsScrollView) {
                    container = (ViewGroup) container.findViewById(
                            R.id.recents_linear_layout);
@@ -633,7 +626,7 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        final int items = mRecentTaskDescriptions != null
                ? mRecentTaskDescriptions.size() : 0;

        mRecentsContainer.setVisibility(items > 0 ? View.VISIBLE : View.GONE);
        ((View) mRecentsContainer).setVisibility(items > 0 ? View.VISIBLE : View.GONE);

        // Set description for accessibility
        int numRecentApps = mRecentTaskDescriptions != null
@@ -650,15 +643,11 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
    }

    public boolean simulateClick(int persistentTaskId) {
        if (mRecentsContainer instanceof RecentsScrollView){
            RecentsScrollView scrollView
                = (RecentsScrollView) mRecentsContainer;
            View v = scrollView.findViewForTask(persistentTaskId);
        View v = mRecentsContainer.findViewForTask(persistentTaskId);
        if (v != null) {
            handleOnClick(v);
            return true;
        }
        }
        return false;
    }

@@ -771,7 +760,7 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.recent_remove_item) {
                    mRecentsContainer.removeViewInLayout(selectedView);
                    ((ViewGroup) mRecentsContainer).removeViewInLayout(selectedView);
                } else if (item.getItemId() == R.id.recent_inspect_item) {
                    ViewHolder viewHolder = (ViewHolder) selectedView.getTag();
                    if (viewHolder != null) {
@@ -795,4 +784,26 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        });
        popup.show();
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);

        int paddingLeft = mPaddingLeft;
        final boolean offsetRequired = isPaddingOffsetRequired();
        if (offsetRequired) {
            paddingLeft += getLeftPaddingOffset();
        }

        int left = mScrollX + paddingLeft;
        int right = left + mRight - mLeft - mPaddingRight - paddingLeft;
        int top = mScrollY + getFadeTop(offsetRequired);
        int bottom = top + getFadeHeight(offsetRequired);

        if (offsetRequired) {
            right += getRightPaddingOffset();
            bottom += getBottomPaddingOffset();
        }
        mRecentsContainer.drawFadedEdges(canvas, left, right, top, bottom);
    }
}
+27 −31
Original line number Diff line number Diff line
@@ -49,9 +49,10 @@ public class RecentsVerticalScrollView extends ScrollView
    private RecentsCallback mCallback;
    protected int mLastScrollPosition;
    private SwipeHelper mSwipeHelper;
    private RecentsScrollViewPerformanceHelper mPerformanceHelper;
    private FadedEdgeDrawHelper mFadedEdgeDrawHelper;
    private HashSet<View> mRecycledViews;
    private int mNumItemsInOneScreenful;
    private Runnable mOnScrollListener;

    public RecentsVerticalScrollView(Context context, AttributeSet attrs) {
        super(context, attrs, 0);
@@ -59,7 +60,7 @@ public class RecentsVerticalScrollView extends ScrollView
        float pagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
        mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, densityScale, pagingTouchSlop);

        mPerformanceHelper = RecentsScrollViewPerformanceHelper.create(context, attrs, this, true);
        mFadedEdgeDrawHelper = FadedEdgeDrawHelper.create(context, attrs, this, true);
        mRecycledViews = new HashSet<View>();
    }

@@ -112,8 +113,8 @@ public class RecentsVerticalScrollView extends ScrollView
            }
            final View view = mAdapter.getView(i, old, mLinearLayout);

            if (mPerformanceHelper != null) {
                mPerformanceHelper.addViewCallback(view);
            if (mFadedEdgeDrawHelper != null) {
                mFadedEdgeDrawHelper.addViewCallback(view);
            }

            OnTouchListener noOpListener = new OnTouchListener() {
@@ -243,36 +244,32 @@ public class RecentsVerticalScrollView extends ScrollView
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);

        if (mPerformanceHelper != null) {
            int paddingLeft = mPaddingLeft;
    public void drawFadedEdges(Canvas canvas, int left, int right, int top, int bottom) {
        if (mFadedEdgeDrawHelper != null) {
            final boolean offsetRequired = isPaddingOffsetRequired();
            if (offsetRequired) {
                paddingLeft += getLeftPaddingOffset();
            mFadedEdgeDrawHelper.drawCallback(canvas,
                    left, right, top + getFadeTop(offsetRequired), bottom, mScrollX, mScrollY,
                    getTopFadingEdgeStrength(), getBottomFadingEdgeStrength(),
                    0, 0, mPaddingTop);
        }
    }

            int left = mScrollX + paddingLeft;
            int right = left + mRight - mLeft - mPaddingRight - paddingLeft;
            int top = mScrollY + getFadeTop(offsetRequired);
            int bottom = top + getFadeHeight(offsetRequired);

            if (offsetRequired) {
                right += getRightPaddingOffset();
                bottom += getBottomPaddingOffset();
    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
       super.onScrollChanged(l, t, oldl, oldt);
       if (mOnScrollListener != null) {
           mOnScrollListener.run();
       }
            mPerformanceHelper.drawCallback(canvas,
                    left, right, top, bottom, mScrollX, mScrollY,
                    getTopFadingEdgeStrength(), getBottomFadingEdgeStrength(),
                    0, 0, mPaddingTop);
    }

    public void setOnScrollListener(Runnable listener) {
        mOnScrollListener = listener;
    }

    @Override
    public int getVerticalFadingEdgeLength() {
        if (mPerformanceHelper != null) {
            return mPerformanceHelper.getVerticalFadingEdgeLengthCallback();
        if (mFadedEdgeDrawHelper != null) {
            return mFadedEdgeDrawHelper.getVerticalFadingEdgeLength();
        } else {
            return super.getVerticalFadingEdgeLength();
        }
@@ -280,8 +277,8 @@ public class RecentsVerticalScrollView extends ScrollView

    @Override
    public int getHorizontalFadingEdgeLength() {
        if (mPerformanceHelper != null) {
            return mPerformanceHelper.getHorizontalFadingEdgeLengthCallback();
        if (mFadedEdgeDrawHelper != null) {
            return mFadedEdgeDrawHelper.getHorizontalFadingEdgeLength();
        } else {
            return super.getHorizontalFadingEdgeLength();
        }
@@ -299,9 +296,8 @@ public class RecentsVerticalScrollView extends ScrollView

    @Override
    public void onAttachedToWindow() {
        if (mPerformanceHelper != null) {
            mPerformanceHelper.onAttachedToWindowCallback(
                    mCallback, mLinearLayout, isHardwareAccelerated());
        if (mFadedEdgeDrawHelper != null) {
            mFadedEdgeDrawHelper.onAttachedToWindowCallback(mLinearLayout, isHardwareAccelerated());
        }
    }