Skip to content

Commit

Permalink
fix #19
Browse files Browse the repository at this point in the history
  • Loading branch information
daimajia committed Sep 11, 2014
1 parent f2cec54 commit 34e2389
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions library/src/main/java/com/daimajia/swipe/SwipeLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.HeaderViewListAdapter;
import android.widget.ListAdapter;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -713,8 +717,12 @@ private boolean childNeedHandleTouchEvent(View v, MotionEvent event){
@Override
public boolean onTouchEvent(MotionEvent event) {

if(!isEnabledInAdapterView())
return true;

int action = event.getActionMasked();
ViewParent parent = getParent();

gestureDetector.onTouchEvent(event);
Status status = getOpenStatus();
ViewGroup touching = null;
Expand Down Expand Up @@ -818,6 +826,46 @@ public boolean onTouchEvent(MotionEvent event) {
return true;
}

/**
* if working in {@link android.widget.AdapterView}, we should response {@link android.widget.Adapter}
* isEnable(int position).
* @return true when item is enabled, else disabled.
*/
private boolean isEnabledInAdapterView(){
AdapterView adapterView = getAdapterView();
boolean enable = true;
if(adapterView != null){
Adapter adapter = adapterView.getAdapter();
if(adapter != null){
int p = adapterView.getPositionForView(SwipeLayout.this);
if(adapter instanceof BaseAdapter){
enable &= ((BaseAdapter) adapter).isEnabled(p);
}else if(adapter instanceof ListAdapter){
enable &= ((ListAdapter) adapter).isEnabled(p);
}else if(adapter instanceof HeaderViewListAdapter){
enable &= ((HeaderViewListAdapter) adapter).isEnabled(p);
}
}
}
return enable;
}

private boolean insideAdapterView(){
return getAdapterView() != null;
}

private AdapterView getAdapterView(){
ViewParent t = getParent();
while(t != null){
if(t instanceof AdapterView){
return (AdapterView)t;
}
t = t.getParent();
}
return null;
}



private GestureDetector gestureDetector = new GestureDetector(getContext(), new SwipeDetector());
class SwipeDetector extends GestureDetector.SimpleOnGestureListener{
Expand All @@ -838,9 +886,10 @@ public boolean onSingleTapUp(MotionEvent e) {
ViewParent t = getParent();
while(t != null) {
if(t instanceof AdapterView){
int p = ((AdapterView) t).getPositionForView(SwipeLayout.this);
AdapterView view = (AdapterView)t;
int p = view.getPositionForView(SwipeLayout.this);
if( p != AdapterView.INVALID_POSITION &&
((AdapterView) t).performItemClick(((AdapterView) t).getChildAt(p),p , ((AdapterView) t).getAdapter().getItemId(p)))
view.performItemClick(view.getChildAt(p), p, view.getAdapter().getItemId(p)))
return true;
}else{
if(t instanceof View && ((View) t).performClick())
Expand Down

0 comments on commit 34e2389

Please sign in to comment.