Skip to content

Commit

Permalink
Two item view wrappers: checkable and non
Browse files Browse the repository at this point in the history
So that setActivated() will be called on items that
are not checkable when some choice mode is enabled.
  • Loading branch information
bauerca committed Mar 12, 2013
1 parent 545a22a commit 1c8eae8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 27 deletions.
25 changes: 1 addition & 24 deletions library/src/com/mobeta/android/dslv/DragSortItemView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.Checkable;
import android.util.Log;

/**
Expand All @@ -24,7 +23,7 @@
* The purpose of this class is to optimize slide
* shuffle animations.
*/
public class DragSortItemView extends ViewGroup implements Checkable {
public class DragSortItemView extends ViewGroup {

private int mGravity = Gravity.TOP;

Expand Down Expand Up @@ -98,26 +97,4 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(width, height);
}

@Override
public boolean isChecked() {
View child = getChildAt(0);
if (child instanceof Checkable)
return ((Checkable) child).isChecked();
else
return false;
}

@Override
public void setChecked(boolean checked) {
View child = getChildAt(0);
if (child instanceof Checkable)
((Checkable) child).setChecked(checked);
}

@Override
public void toggle() {
View child = getChildAt(0);
if (child instanceof Checkable)
((Checkable) child).toggle();
}
}
55 changes: 55 additions & 0 deletions library/src/com/mobeta/android/dslv/DragSortItemViewCheckable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.mobeta.android.dslv;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.Checkable;
import android.util.Log;

/**
* Lightweight ViewGroup that wraps list items obtained from user's
* ListAdapter. ItemView expects a single child that has a definite
* height (i.e. the child's layout height is not MATCH_PARENT).
* The width of
* ItemView will always match the width of its child (that is,
* the width MeasureSpec given to ItemView is passed directly
* to the child, and the ItemView measured width is set to the
* child's measured width). The height of ItemView can be anything;
* the
*
*
* The purpose of this class is to optimize slide
* shuffle animations.
*/
public class DragSortItemViewCheckable extends DragSortItemView implements Checkable {

public DragSortItemViewCheckable(Context context) {
super(context);
}

@Override
public boolean isChecked() {
View child = getChildAt(0);
if (child instanceof Checkable)
return ((Checkable) child).isChecked();
else
return false;
}

@Override
public void setChecked(boolean checked) {
View child = getChildAt(0);
if (child instanceof Checkable)
((Checkable) child).setChecked(checked);
}

@Override
public void toggle() {
View child = getChildAt(0);
if (child instanceof Checkable)
((Checkable) child).toggle();
}
}
11 changes: 8 additions & 3 deletions library/src/com/mobeta/android/dslv/DragSortListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.Checkable;
import android.widget.ListAdapter;
import android.widget.ListView;

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

child = mAdapter.getView(position, oldChild, v);
child = mAdapter.getView(position, oldChild, DragSortListView.this);
if (child != oldChild) {
// shouldn't get here if user is reusing convertViews
// properly
v.removeViewAt(0);
v.addView(child);
}
} else {
v = new DragSortItemView(getContext());
child = mAdapter.getView(position, null, DragSortListView.this);
if (child instanceof Checkable) {
v = new DragSortItemViewCheckable(getContext());
} else {
v = new DragSortItemView(getContext());
}
v.setLayoutParams(new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
child = mAdapter.getView(position, null, v);
v.addView(child);
}

Expand Down

0 comments on commit 1c8eae8

Please sign in to comment.