Commit 70a60f36 authored by Adrien Maglo's avatar Adrien Maglo
Browse files

FlingViewGroup: add a new onTouchClick event to the listener interface

parent b75700ee
......@@ -116,6 +116,8 @@ public class AboutFragment extends SherlockFragment {
public void onTouchDown() {}
@Override
public void onTouchUp() {}
@Override
public void onTouchClick() {}
});
return v;
......
......@@ -153,6 +153,8 @@ public class AudioAlbumsSongsFragment extends SherlockFragment {
public void onTouchDown() {}
@Override
public void onTouchUp() {}
@Override
public void onTouchClick() {}
});
return v;
......
......@@ -328,6 +328,8 @@ public class AudioBrowserFragment extends SherlockFragment {
@Override
public void onTouchUp() {}
@Override
public void onTouchClick() {}
};
/**
......
......@@ -117,6 +117,10 @@ public abstract class AudioMediaSwitcher extends FlingViewGroup {
if (mAudioMediaSwitcherListener != null)
mAudioMediaSwitcherListener.onTouchUp();
}
@Override
public void onTouchClick() {
}
};
public void setAudioMediaSwitcherListener(AudioMediaSwitcherListener l) {
......
......@@ -51,6 +51,9 @@ public class AudioPlaylistItemViewGroup extends FlingViewGroup {
@Override
public void onTouchUp() { }
@Override
public void onTouchClick() { }
};
public void setOnItemSlidedListener(OnItemSlidedListener l) {
......
......@@ -45,6 +45,9 @@ public class FlingViewGroup extends ViewGroup {
private float mLastX;
private float mLastInterceptDownY;
private float mInitialMotionX;
private float mInitialMotionY;
private ViewSwitchListener mViewSwitchListener;
public FlingViewGroup(Context context, AttributeSet attrs) {
......@@ -165,9 +168,12 @@ public class FlingViewGroup extends ViewGroup {
final int action = event.getAction();
final float x = event.getX();
final float y = event.getY();
switch (action) {
case MotionEvent.ACTION_DOWN:
mInitialMotionX = x;
mInitialMotionY = y;
if (!mScroller.isFinished())
mScroller.abortAnimation();
mLastX = x;
......@@ -210,8 +216,15 @@ public class FlingViewGroup extends ViewGroup {
mVelocityTracker = null;
}
if (mViewSwitchListener != null)
if (mViewSwitchListener != null) {
mViewSwitchListener.onTouchUp();
final float dx = x - mInitialMotionX;
final float dy = y - mInitialMotionY;
ViewConfiguration config = ViewConfiguration.get(getContext());
final int slop = config.getScaledTouchSlop();
if (dx * dx + dy * dy < slop * slop)
mViewSwitchListener.onTouchClick();
}
break;
}
......@@ -270,6 +283,8 @@ public class FlingViewGroup extends ViewGroup {
void onTouchDown();
void onTouchUp();
void onTouchClick();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment