Skip to content

Commit 1c8eae8

Browse files
committed
Two item view wrappers: checkable and non
So that setActivated() will be called on items that are not checkable when some choice mode is enabled.
1 parent 545a22a commit 1c8eae8

File tree

3 files changed

+64
-27
lines changed

3 files changed

+64
-27
lines changed

library/src/com/mobeta/android/dslv/DragSortItemView.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import android.view.View.MeasureSpec;
77
import android.view.ViewGroup;
88
import android.widget.AbsListView;
9-
import android.widget.Checkable;
109
import android.util.Log;
1110

1211
/**
@@ -24,7 +23,7 @@
2423
* The purpose of this class is to optimize slide
2524
* shuffle animations.
2625
*/
27-
public class DragSortItemView extends ViewGroup implements Checkable {
26+
public class DragSortItemView extends ViewGroup {
2827

2928
private int mGravity = Gravity.TOP;
3029

@@ -98,26 +97,4 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
9897
setMeasuredDimension(width, height);
9998
}
10099

101-
@Override
102-
public boolean isChecked() {
103-
View child = getChildAt(0);
104-
if (child instanceof Checkable)
105-
return ((Checkable) child).isChecked();
106-
else
107-
return false;
108-
}
109-
110-
@Override
111-
public void setChecked(boolean checked) {
112-
View child = getChildAt(0);
113-
if (child instanceof Checkable)
114-
((Checkable) child).setChecked(checked);
115-
}
116-
117-
@Override
118-
public void toggle() {
119-
View child = getChildAt(0);
120-
if (child instanceof Checkable)
121-
((Checkable) child).toggle();
122-
}
123100
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.mobeta.android.dslv;
2+
3+
import android.content.Context;
4+
import android.view.Gravity;
5+
import android.view.View;
6+
import android.view.View.MeasureSpec;
7+
import android.view.ViewGroup;
8+
import android.widget.AbsListView;
9+
import android.widget.Checkable;
10+
import android.util.Log;
11+
12+
/**
13+
* Lightweight ViewGroup that wraps list items obtained from user's
14+
* ListAdapter. ItemView expects a single child that has a definite
15+
* height (i.e. the child's layout height is not MATCH_PARENT).
16+
* The width of
17+
* ItemView will always match the width of its child (that is,
18+
* the width MeasureSpec given to ItemView is passed directly
19+
* to the child, and the ItemView measured width is set to the
20+
* child's measured width). The height of ItemView can be anything;
21+
* the
22+
*
23+
*
24+
* The purpose of this class is to optimize slide
25+
* shuffle animations.
26+
*/
27+
public class DragSortItemViewCheckable extends DragSortItemView implements Checkable {
28+
29+
public DragSortItemViewCheckable(Context context) {
30+
super(context);
31+
}
32+
33+
@Override
34+
public boolean isChecked() {
35+
View child = getChildAt(0);
36+
if (child instanceof Checkable)
37+
return ((Checkable) child).isChecked();
38+
else
39+
return false;
40+
}
41+
42+
@Override
43+
public void setChecked(boolean checked) {
44+
View child = getChildAt(0);
45+
if (child instanceof Checkable)
46+
((Checkable) child).setChecked(checked);
47+
}
48+
49+
@Override
50+
public void toggle() {
51+
View child = getChildAt(0);
52+
if (child instanceof Checkable)
53+
((Checkable) child).toggle();
54+
}
55+
}

library/src/com/mobeta/android/dslv/DragSortListView.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import android.view.ViewGroup;
4141
import android.widget.AbsListView;
4242
import android.widget.BaseAdapter;
43+
import android.widget.Checkable;
4344
import android.widget.ListAdapter;
4445
import android.widget.ListView;
4546

@@ -716,19 +717,23 @@ public View getView(int position, View convertView, ViewGroup parent) {
716717
v = (DragSortItemView) convertView;
717718
View oldChild = v.getChildAt(0);
718719

719-
child = mAdapter.getView(position, oldChild, v);
720+
child = mAdapter.getView(position, oldChild, DragSortListView.this);
720721
if (child != oldChild) {
721722
// shouldn't get here if user is reusing convertViews
722723
// properly
723724
v.removeViewAt(0);
724725
v.addView(child);
725726
}
726727
} else {
727-
v = new DragSortItemView(getContext());
728+
child = mAdapter.getView(position, null, DragSortListView.this);
729+
if (child instanceof Checkable) {
730+
v = new DragSortItemViewCheckable(getContext());
731+
} else {
732+
v = new DragSortItemView(getContext());
733+
}
728734
v.setLayoutParams(new AbsListView.LayoutParams(
729735
ViewGroup.LayoutParams.FILL_PARENT,
730736
ViewGroup.LayoutParams.WRAP_CONTENT));
731-
child = mAdapter.getView(position, null, v);
732737
v.addView(child);
733738
}
734739

0 commit comments

Comments
 (0)