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

Commit 3616a412 authored by Romain Guy's avatar Romain Guy
Browse files

Preserve ListView's pressed state when the adapter changes its content while...

Preserve ListView's pressed state when the adapter changes its content while the user is pressing an item.

Change-Id: Id5ac804a4053951430d16cf0d87fc7b64c816717
parent 5adeba4b
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -1148,6 +1148,9 @@ public class GridView extends AbsListView {
            if (sel != null) {
               positionSelector(sel);
               mSelectedTop = sel.getTop();
            } else if (mTouchMode > TOUCH_MODE_DOWN && mTouchMode < TOUCH_MODE_SCROLL) {
                View child = getChildAt(mMotionPosition - mFirstPosition);
                positionSelector(child);
            } else {
                mSelectedTop = 0;
                mSelectorRect.setEmpty();
@@ -1231,8 +1234,12 @@ public class GridView extends AbsListView {
    private void setupChild(View child, int position, int y, boolean flow, int childrenLeft,
            boolean selected, boolean recycled, int where) {
        boolean isSelected = selected && shouldShowSelector();

        final boolean updateChildSelected = isSelected != child.isSelected();
        final int mode = mTouchMode;
        final boolean isPressed = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLL &&
                mMotionPosition == position;
        final boolean updateChildPressed = isPressed != child.isPressed();
        
        boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

        // Respect layout params that are already in the view. Otherwise make
@@ -1257,6 +1264,10 @@ public class GridView extends AbsListView {
            }
        }

        if (updateChildPressed) {
            child.setPressed(isPressed);
        }

        if (needToMeasure) {
            int childHeightSpec = ViewGroup.getChildMeasureSpec(
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.height);
+42 −29
Original line number Diff line number Diff line
@@ -1564,9 +1564,14 @@ public class ListView extends AbsListView {
                    positionSelector(sel);
                }
                mSelectedTop = sel.getTop();
            } else {
                if (mTouchMode > TOUCH_MODE_DOWN && mTouchMode < TOUCH_MODE_SCROLL) {
                    View child = getChildAt(mMotionPosition - mFirstPosition);
                    positionSelector(child);
                } else {
                    mSelectedTop = 0;
                    mSelectorRect.setEmpty();
                }

                // even if there is not selected position, we may need to restore
                // focus (i.e. something focusable in touch mode)
@@ -1686,6 +1691,10 @@ public class ListView extends AbsListView {
            boolean selected, boolean recycled) {
        final boolean isSelected = selected && shouldShowSelector();
        final boolean updateChildSelected = isSelected != child.isSelected();
        final int mode = mTouchMode;
        final boolean isPressed = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLL &&
                mMotionPosition == position;
        final boolean updateChildPressed = isPressed != child.isPressed();
        final boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

        // Respect layout params that are already in the view. Otherwise make some up...
@@ -1711,6 +1720,10 @@ public class ListView extends AbsListView {
            child.setSelected(isSelected);
        }

        if (updateChildPressed) {
            child.setPressed(isPressed);
        }

        if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
            if (child instanceof Checkable) {
                ((Checkable) child).setChecked(mCheckStates.get(position));