am 7bd66001: Merge change 25117 into eclair
Merge commit '7bd660012ca5d946f4f4efb9d357a785e6a4d4eb' into eclair-plus-aosp * commit '7bd660012ca5d946f4f4efb9d357a785e6a4d4eb': Preserve ListView's pressed state when the adapter changes its content while the user is pressing an item.
This commit is contained in:
@@ -1148,9 +1148,12 @@ public class GridView extends AbsListView {
|
|||||||
if (sel != null) {
|
if (sel != null) {
|
||||||
positionSelector(sel);
|
positionSelector(sel);
|
||||||
mSelectedTop = sel.getTop();
|
mSelectedTop = sel.getTop();
|
||||||
|
} else if (mTouchMode > TOUCH_MODE_DOWN && mTouchMode < TOUCH_MODE_SCROLL) {
|
||||||
|
View child = getChildAt(mMotionPosition - mFirstPosition);
|
||||||
|
positionSelector(child);
|
||||||
} else {
|
} else {
|
||||||
mSelectedTop = 0;
|
mSelectedTop = 0;
|
||||||
mSelectorRect.setEmpty();
|
mSelectorRect.setEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
mLayoutMode = LAYOUT_NORMAL;
|
mLayoutMode = LAYOUT_NORMAL;
|
||||||
@@ -1231,8 +1234,12 @@ public class GridView extends AbsListView {
|
|||||||
private void setupChild(View child, int position, int y, boolean flow, int childrenLeft,
|
private void setupChild(View child, int position, int y, boolean flow, int childrenLeft,
|
||||||
boolean selected, boolean recycled, int where) {
|
boolean selected, boolean recycled, int where) {
|
||||||
boolean isSelected = selected && shouldShowSelector();
|
boolean isSelected = selected && shouldShowSelector();
|
||||||
|
|
||||||
final boolean updateChildSelected = isSelected != child.isSelected();
|
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();
|
boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();
|
||||||
|
|
||||||
// Respect layout params that are already in the view. Otherwise make
|
// 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) {
|
if (needToMeasure) {
|
||||||
int childHeightSpec = ViewGroup.getChildMeasureSpec(
|
int childHeightSpec = ViewGroup.getChildMeasureSpec(
|
||||||
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.height);
|
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.height);
|
||||||
|
|||||||
@@ -1542,37 +1542,42 @@ public class ListView extends AbsListView {
|
|||||||
recycleBin.scrapActiveViews();
|
recycleBin.scrapActiveViews();
|
||||||
|
|
||||||
if (sel != null) {
|
if (sel != null) {
|
||||||
// the current selected item should get focus if items
|
// the current selected item should get focus if items
|
||||||
// are focusable
|
// are focusable
|
||||||
if (mItemsCanFocus && hasFocus() && !sel.hasFocus()) {
|
if (mItemsCanFocus && hasFocus() && !sel.hasFocus()) {
|
||||||
final boolean focusWasTaken = (sel == focusLayoutRestoreDirectChild &&
|
final boolean focusWasTaken = (sel == focusLayoutRestoreDirectChild &&
|
||||||
focusLayoutRestoreView.requestFocus()) || sel.requestFocus();
|
focusLayoutRestoreView.requestFocus()) || sel.requestFocus();
|
||||||
if (!focusWasTaken) {
|
if (!focusWasTaken) {
|
||||||
// selected item didn't take focus, fine, but still want
|
// selected item didn't take focus, fine, but still want
|
||||||
// to make sure something else outside of the selected view
|
// to make sure something else outside of the selected view
|
||||||
// has focus
|
// has focus
|
||||||
final View focused = getFocusedChild();
|
final View focused = getFocusedChild();
|
||||||
if (focused != null) {
|
if (focused != null) {
|
||||||
focused.clearFocus();
|
focused.clearFocus();
|
||||||
}
|
}
|
||||||
positionSelector(sel);
|
positionSelector(sel);
|
||||||
} else {
|
} else {
|
||||||
sel.setSelected(false);
|
sel.setSelected(false);
|
||||||
mSelectorRect.setEmpty();
|
mSelectorRect.setEmpty();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
positionSelector(sel);
|
positionSelector(sel);
|
||||||
}
|
}
|
||||||
mSelectedTop = sel.getTop();
|
mSelectedTop = sel.getTop();
|
||||||
} else {
|
} else {
|
||||||
mSelectedTop = 0;
|
if (mTouchMode > TOUCH_MODE_DOWN && mTouchMode < TOUCH_MODE_SCROLL) {
|
||||||
mSelectorRect.setEmpty();
|
View child = getChildAt(mMotionPosition - mFirstPosition);
|
||||||
|
positionSelector(child);
|
||||||
|
} else {
|
||||||
|
mSelectedTop = 0;
|
||||||
|
mSelectorRect.setEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
// even if there is not selected position, we may need to restore
|
// even if there is not selected position, we may need to restore
|
||||||
// focus (i.e. something focusable in touch mode)
|
// focus (i.e. something focusable in touch mode)
|
||||||
if (hasFocus() && focusLayoutRestoreView != null) {
|
if (hasFocus() && focusLayoutRestoreView != null) {
|
||||||
focusLayoutRestoreView.requestFocus();
|
focusLayoutRestoreView.requestFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tell focus view we are done mucking with it, if it is still in
|
// tell focus view we are done mucking with it, if it is still in
|
||||||
@@ -1686,6 +1691,10 @@ public class ListView extends AbsListView {
|
|||||||
boolean selected, boolean recycled) {
|
boolean selected, boolean recycled) {
|
||||||
final boolean isSelected = selected && shouldShowSelector();
|
final boolean isSelected = selected && shouldShowSelector();
|
||||||
final boolean updateChildSelected = isSelected != child.isSelected();
|
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();
|
final boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();
|
||||||
|
|
||||||
// Respect layout params that are already in the view. Otherwise make some up...
|
// 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);
|
child.setSelected(isSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (updateChildPressed) {
|
||||||
|
child.setPressed(isPressed);
|
||||||
|
}
|
||||||
|
|
||||||
if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
|
if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
|
||||||
if (child instanceof Checkable) {
|
if (child instanceof Checkable) {
|
||||||
((Checkable) child).setChecked(mCheckStates.get(position));
|
((Checkable) child).setChecked(mCheckStates.get(position));
|
||||||
|
|||||||
Reference in New Issue
Block a user