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

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

Fix alpha when swiping recents on tablets

When you swipe to dismiss a recent item on a
tablet, fade the item to 0 alpha

Also, create common interface for Recents-specific
methods for Recents[Horizontal/Vertical]ScrollView

Bug: 5953654

Change-Id: I0a72b49b3cfae0607b42dbf8f6d4da9898d7e491
parent 69db4df4
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ public class SwipeHelper {
                                                 // where fade starts
    static final float ALPHA_FADE_END = 0.5f; // fraction of thumbnail width
                                              // beyond which alpha->0
    private float mMinAlpha = 0f;

    private float mPagingTouchSlop;
    private Callback mCallback;
@@ -120,6 +121,10 @@ public class SwipeHelper {
                v.getMeasuredHeight();
    }

    public void setMinAlpha(float minAlpha) {
        mMinAlpha = minAlpha;
    }

    private float getAlphaForOffset(View view) {
        float viewSize = getSize(view);
        final float fadeSize = ALPHA_FADE_END * viewSize;
@@ -130,10 +135,7 @@ public class SwipeHelper {
        } else if (pos < viewSize * (1.0f - ALPHA_FADE_START)) {
            result = 1.0f + (viewSize * ALPHA_FADE_START + pos) / fadeSize;
        }
        // Make .03 alpha the minimum so you always see the item a bit-- slightly below
        // .03, the item disappears entirely (as if alpha = 0) and that discontinuity looks
        // a bit jarring
        return Math.max(0.03f, result);
        return Math.max(mMinAlpha, result);
    }

    // invalidate the view's own bounds all the way up the view hierarchy
+5 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ import com.android.systemui.recent.RecentsPanelView.TaskDescriptionAdapter;
import java.util.ArrayList;

public class RecentsHorizontalScrollView extends HorizontalScrollView
    implements SwipeHelper.Callback {
        implements SwipeHelper.Callback, RecentsPanelView.RecentsScrollView {
    private static final String TAG = RecentsPanelView.TAG;
    private static final boolean DEBUG = RecentsPanelView.DEBUG;
    private LinearLayout mLinearLayout;
@@ -65,6 +65,10 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
        mRecycledViews = new ArrayList<View>();
    }

    public void setMinSwipeAlpha(float minAlpha) {
        mSwipeHelper.setMinAlpha(minAlpha);
    }

    private int scrollPositionOfMostRecent() {
        return mLinearLayout.getWidth() - getWidth();
    }
+24 −21
Original line number Diff line number Diff line
@@ -92,6 +92,13 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        public void onRecentsPanelVisibilityChanged(boolean visible);
    }

    public static interface RecentsScrollView {
        public int numItemsInOneScreenful();
        public void setAdapter(TaskDescriptionAdapter adapter);
        public void setCallback(RecentsCallback callback);
        public void setMinSwipeAlpha(float minAlpha);
    }

    private final class OnLongClickDelegate implements View.OnLongClickListener {
        View mOtherView;
        OnLongClickDelegate(View other) {
@@ -196,16 +203,11 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
    }

    public int numItemsInOneScreenful() {
        if (mRecentsContainer instanceof RecentsHorizontalScrollView){
            RecentsHorizontalScrollView scrollView
                    = (RecentsHorizontalScrollView) mRecentsContainer;
            return scrollView.numItemsInOneScreenful();
        } else if (mRecentsContainer instanceof RecentsVerticalScrollView){
            RecentsVerticalScrollView scrollView
                    = (RecentsVerticalScrollView) mRecentsContainer;
        if (mRecentsContainer instanceof RecentsScrollView){
            RecentsScrollView scrollView
                    = (RecentsScrollView) mRecentsContainer;
            return scrollView.numItemsInOneScreenful();
        }
        else {
        }  else {
            throw new IllegalArgumentException("missing Recents[Horizontal]ScrollView");
        }
    }
@@ -427,18 +429,12 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        mRecentsContainer = (ViewGroup) findViewById(R.id.recents_container);
        mStatusBarTouchProxy = (StatusBarTouchProxy) findViewById(R.id.status_bar_touch_proxy);
        mListAdapter = new TaskDescriptionAdapter(mContext);
        if (mRecentsContainer instanceof RecentsHorizontalScrollView){
            RecentsHorizontalScrollView scrollView
                    = (RecentsHorizontalScrollView) mRecentsContainer;
            scrollView.setAdapter(mListAdapter);
            scrollView.setCallback(this);
        } else if (mRecentsContainer instanceof RecentsVerticalScrollView){
            RecentsVerticalScrollView scrollView
                    = (RecentsVerticalScrollView) mRecentsContainer;
        if (mRecentsContainer instanceof RecentsScrollView){
            RecentsScrollView scrollView
                    = (RecentsScrollView) mRecentsContainer;
            scrollView.setAdapter(mListAdapter);
            scrollView.setCallback(this);
        }
        else {
        } else {
            throw new IllegalArgumentException("missing Recents[Horizontal]ScrollView");
        }

@@ -467,6 +463,14 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        };
    }

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

    private void createCustomAnimations(LayoutTransition transitioner) {
        transitioner.setDuration(200);
        transitioner.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0);
@@ -523,8 +527,7 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        synchronized (td) {
            if (mRecentsContainer != null) {
                ViewGroup container = mRecentsContainer;
                if (container instanceof HorizontalScrollView
                        || container instanceof ScrollView) {
                if (container instanceof RecentsScrollView) {
                    container = (ViewGroup) container.findViewById(
                            R.id.recents_linear_layout);
                }
+6 −1
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ import com.android.systemui.recent.RecentsPanelView.TaskDescriptionAdapter;

import java.util.ArrayList;

public class RecentsVerticalScrollView extends ScrollView implements SwipeHelper.Callback {
public class RecentsVerticalScrollView extends ScrollView
        implements SwipeHelper.Callback, RecentsPanelView.RecentsScrollView {
    private static final String TAG = RecentsPanelView.TAG;
    private static final boolean DEBUG = RecentsPanelView.DEBUG;
    private LinearLayout mLinearLayout;
@@ -65,6 +66,10 @@ public class RecentsVerticalScrollView extends ScrollView implements SwipeHelper
        mRecycledViews = new ArrayList<View>();
    }

    public void setMinSwipeAlpha(float minAlpha) {
        mSwipeHelper.setMinAlpha(minAlpha);
    }

    private int scrollPositionOfMostRecent() {
        return mLinearLayout.getHeight() - getHeight();
    }
+5 −0
Original line number Diff line number Diff line
@@ -432,6 +432,11 @@ public class PhoneStatusBar extends StatusBar {
        mRecentsPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL,
                mRecentsPanel));
        mRecentsPanel.setVisibility(View.GONE);

        // Make .03 alpha the minimum so you always see the item a bit-- slightly below
        // .03, the item disappears entirely (as if alpha = 0) and that discontinuity looks
        // a bit jarring
        mRecentsPanel.setMinSwipeAlpha(0.03f);
        WindowManager.LayoutParams lp = getRecentsLayoutParams(mRecentsPanel.getLayoutParams());

        WindowManagerImpl.getDefault().addView(mRecentsPanel, lp);