[Android] FlingViewGroup : add a onBackSwitched touch event
Alexandre Perraud
git at videolan.org
Mon May 12 14:20:16 CEST 2014
vlc-ports/android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Fri May 9 12:27:35 2014 +0200| [99e066a688b7bbd83df83f81e356739d1107c34d] | committer: Adrien Maglo
FlingViewGroup : add a onBackSwitched touch event
Signed-off-by: Adrien Maglo <magsoft at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=99e066a688b7bbd83df83f81e356739d1107c34d
---
.../src/org/videolan/vlc/gui/AboutFragment.java | 5 +++++
.../vlc/gui/audio/AudioAlbumsSongsFragment.java | 6 ++++++
.../vlc/gui/audio/AudioBrowserFragment.java | 3 +++
.../videolan/vlc/widget/AudioMediaSwitcher.java | 3 +++
.../vlc/widget/AudioPlaylistItemViewGroup.java | 4 ++++
.../org/videolan/vlc/widget/FlingViewGroup.java | 21 ++++++++++++--------
6 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
index cc0cedb..26865b4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
@@ -119,6 +119,11 @@ public class AboutFragment extends SherlockFragment {
public void onTouchUp() {}
@Override
public void onTouchClick() {}
+ @Override
+ public void onBackSwitched() {
+ MainActivity activity = (MainActivity)getActivity();
+ activity.popSecondaryFragment();
+ }
});
return v;
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index c24c40d..4c19645 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -32,6 +32,7 @@ import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.VlcRunnable;
import org.videolan.vlc.gui.CommonDialogs;
+import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.widget.FlingViewGroup;
import android.annotation.TargetApi;
@@ -158,6 +159,11 @@ public class AudioAlbumsSongsFragment extends SherlockFragment {
public void onTouchUp() {}
@Override
public void onTouchClick() {}
+ @Override
+ public void onBackSwitched() {
+ MainActivity activity = (MainActivity)getActivity();
+ activity.popSecondaryFragment();
+ }
});
return v;
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index de4b667..7b502a2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -346,6 +346,9 @@ public class AudioBrowserFragment extends SherlockFragment {
@Override
public void onTouchClick() {}
+
+ @Override
+ public void onBackSwitched() {}
};
/**
diff --git a/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java b/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java
index 8fec80e..1eec001 100644
--- a/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java
+++ b/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java
@@ -123,6 +123,9 @@ public abstract class AudioMediaSwitcher extends FlingViewGroup {
if (mAudioMediaSwitcherListener != null)
mAudioMediaSwitcherListener.onTouchClick();
}
+
+ @Override
+ public void onBackSwitched() {}
};
public void setAudioMediaSwitcherListener(AudioMediaSwitcherListener l) {
diff --git a/vlc-android/src/org/videolan/vlc/widget/AudioPlaylistItemViewGroup.java b/vlc-android/src/org/videolan/vlc/widget/AudioPlaylistItemViewGroup.java
index 49988eb..5e5c0a0 100644
--- a/vlc-android/src/org/videolan/vlc/widget/AudioPlaylistItemViewGroup.java
+++ b/vlc-android/src/org/videolan/vlc/widget/AudioPlaylistItemViewGroup.java
@@ -54,6 +54,10 @@ public class AudioPlaylistItemViewGroup extends FlingViewGroup {
@Override
public void onTouchClick() { }
+
+ @Override
+ public void onBackSwitched() {}
+
};
public void setOnItemSlidedListener(OnItemSlidedListener l) {
diff --git a/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java b/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java
index 470144f..46147a1 100644
--- a/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java
+++ b/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java
@@ -136,6 +136,8 @@ public class FlingViewGroup extends ViewGroup {
case MotionEvent.ACTION_DOWN:
mLastX = x;
mLastInterceptDownY = ev.getY();
+ mInitialMotionX = x;
+ mInitialMotionY = y;
mTouchState = mScroller.isFinished() ?
TOUCH_STATE_REST : TOUCH_STATE_MOVE;
mInterceptTouchState = TOUCH_STATE_REST;
@@ -172,8 +174,6 @@ public class FlingViewGroup extends ViewGroup {
switch (action) {
case MotionEvent.ACTION_DOWN:
- mInitialMotionX = x;
- mInitialMotionY = y;
if (!mScroller.isFinished())
mScroller.abortAnimation();
mLastX = x;
@@ -201,8 +201,15 @@ public class FlingViewGroup extends ViewGroup {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
int velocityX = (int) velocityTracker.getXVelocity();
-
- if (velocityX > 1000 && mCurrentView > 0) {
+ ViewConfiguration config = ViewConfiguration.get(getContext());
+ final int slop = config.getScaledTouchSlop();
+ final float dx = x - mInitialMotionX;
+ final float dy = y - mInitialMotionY;
+
+ if (dx > 0 && mCurrentView == 0 && dx > slop) {
+ if (mViewSwitchListener != null)
+ mViewSwitchListener.onBackSwitched();
+ } else if (velocityX > 1000 && mCurrentView > 0) {
snapToScreen(mCurrentView - 1);
} else if (velocityX < -1000
&& mCurrentView < getChildCount() - 1) {
@@ -218,10 +225,6 @@ public class FlingViewGroup extends ViewGroup {
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();
}
@@ -285,6 +288,8 @@ public class FlingViewGroup extends ViewGroup {
void onTouchUp();
void onTouchClick();
+
+ void onBackSwitched();
}
}
More information about the Android
mailing list