Skip to content

Commit

Permalink
Fix bauerca#77: OnClickListener crashes controller
Browse files Browse the repository at this point in the history
Testing: add OnClickListener to TextView in CursorAdapter
demo.
  • Loading branch information
bauerca committed Feb 14, 2013
1 parent 739f317 commit c5f07d4
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

0.6.1
-----

* Fix #77: OnClickListener in list item crashes
DragSortController.

0.6.0
-----

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ dependency to your pom.xml:
<dependency>
<groupId>com.mobeta.android.dslv</groupId>
<artifactId>drag-sort-listview</artifactId>
<version>0.6.0-SNAPSHOT</version>
<version>0.6.1-SNAPSHOT</version>
<type>apklib</type>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ Copyright 2012 Andreas Schildbach
<parent>
<groupId>com.mobeta.android.dslv</groupId>
<artifactId>parent</artifactId>
<version>0.6.0-SNAPSHOT</version>
<version>0.6.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>com.mobeta.android.demodslv</groupId>
<artifactId>drag-sort-listview-demo</artifactId>
<packaging>apk</packaging>
<version>0.6.0-SNAPSHOT</version>
<version>0.6.1-SNAPSHOT</version>

<dependencies>
<dependency>
Expand Down
30 changes: 28 additions & 2 deletions demo/src/com/mobeta/android/demodslv/CursorDSLV.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import android.database.MatrixCursor;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.database.Cursor;
import android.widget.Toast;

public class CursorDSLV extends FragmentActivity {

Expand All @@ -20,7 +24,7 @@ public void onCreate(Bundle savedInstanceState) {

String[] cols = {"name"};
int[] ids = {R.id.text};
adapter = new SimpleDragSortCursorAdapter(this,
adapter = new MAdapter(this,
R.layout.list_item_click_remove, null, cols, ids, 0);

DragSortListView dslv = (DragSortListView) findViewById(android.R.id.list);
Expand All @@ -36,4 +40,26 @@ public void onCreate(Bundle savedInstanceState) {
}
adapter.changeCursor(cursor);
}

private class MAdapter extends SimpleDragSortCursorAdapter {
private Context mContext;

public MAdapter(Context ctxt, int rmid, Cursor c, String[] cols, int[] ids, int something) {
super(ctxt, rmid, c, cols, ids, something);
mContext = ctxt;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
View tv = v.findViewById(R.id.text);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext, "text clicked", Toast.LENGTH_SHORT).show();
}
});
return v;
}
}
}
4 changes: 2 additions & 2 deletions library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Copyright 2012 Andreas Schildbach
<groupId>com.mobeta.android.dslv</groupId>
<artifactId>drag-sort-listview</artifactId>
<packaging>apklib</packaging>
<version>0.6.0-SNAPSHOT</version>
<version>0.6.1-SNAPSHOT</version>

<parent>
<groupId>com.mobeta.android.dslv</groupId>
<artifactId>parent</artifactId>
<version>0.6.0-SNAPSHOT</version>
<version>0.6.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
3 changes: 1 addition & 2 deletions library/src/com/mobeta/android/dslv/DragSortController.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public boolean startDrag(int position, int deltaX, int deltaY) {

@Override
public boolean onTouch(View v, MotionEvent ev) {
if (!mDslv.isDragEnabled()) {
if (!mDslv.isDragEnabled() || mDslv.listViewIntercepted()) {
return false;
}

Expand All @@ -246,7 +246,6 @@ public boolean onTouch(View v, MotionEvent ev) {
}

int action = ev.getAction() & MotionEvent.ACTION_MASK;

switch (action) {
case MotionEvent.ACTION_DOWN:
mCurrX = (int) ev.getX();
Expand Down
8 changes: 8 additions & 0 deletions library/src/com/mobeta/android/dslv/DragSortListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,7 @@ private void doActionUpOrCancel() {
mDragState = IDLE;
}
mCurrFloatAlpha = mFloatAlpha;
mListViewIntercepted = false;
mChildHeightCache.clear();
}

Expand All @@ -1623,6 +1624,12 @@ private void saveTouchCoords(MotionEvent ev) {
mOffsetY = (int) ev.getRawY() - mY;
}

public boolean listViewIntercepted() {
return mListViewIntercepted;
}

private boolean mListViewIntercepted = false;

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (!mDragEnabled) {
Expand Down Expand Up @@ -1651,6 +1658,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
intercept = true;
} else {
if (super.onInterceptTouchEvent(ev)) {
mListViewIntercepted = true;
intercept = true;
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Copyright 2012 Andreas Schildbach

<groupId>com.mobeta.android.dslv</groupId>
<artifactId>parent</artifactId>
<version>0.6.0-SNAPSHOT</version>
<version>0.6.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down

0 comments on commit c5f07d4

Please sign in to comment.