I am asking this rather complex question hoping that i would get an idea from you.
Here is the thing: I have created a custom list view class, the one above:
public class FolderListView extends ListView {
private float xDistance, yDistance, lastX, lastY;
private int folder_index;
private FolderViewInterface openFolder;
// private boolean swiping = false;
// If built programmatically
public FolderListView(Context context) {
super(context);
}
// This example uses this method since being built from XML
public FolderListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
// Build from XML layout
public FolderListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_UP:
// if (swiping == false) {
//if (xDistance > yDistance)
// return false;
// else {
folder_index = pointToPosition((int) lastX, (int) lastY);
// Toast.makeText(getContext(),
// "You pressed a folder with index: " + folder_index,
// Toast.LENGTH_SHORT).show();
// }
HomeScreenFragment f = new HomeScreenFragment();
openFolder = (FolderViewInterface) f;
openFolder.onFolderOpened(folder_index);
// }
// swiping = false;
break;
case MotionEvent.ACTION_DOWN:
// swiping = false;
xDistance = yDistance = 0f;
lastX = ev.getX();
lastY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
// swiping = true;
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - lastX);
yDistance += Math.abs(curY - lastY);
lastX = curX;
lastY = curY;
if (xDistance > yDistance)
return false;
}
return super.onInterceptTouchEvent(ev);
}
}
thing is here i am looking to properly detect the touch event. I want on touch to open the other fragment, but right now the fragment is opened both on touch and on swipe.
I have used the onInterceptTouchEvent because the elements of my list are viewpagers and they were not behaving properly when scrolling.
I need some kind of logic here to detect the swiping and not perform this part:
HomeScreenFragment f = new HomeScreenFragment();
openFolder = (FolderViewInterface) f;
openFolder.onFolderOpened(folder_index);
Only if the event is a touch event, not a swipe one.
Any kind of suggestion/help is highly appreciated, please let me know if you need any more details.
Thanks!