summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2013-12-17 01:18:07 +0100
committerAndrzej Hunt <andrzej.hunt@collabora.com>2014-01-16 15:47:32 +0000
commit7e08428ceb523896dbeb4afa4502e7197437231e (patch)
tree4d195735c64021e1a36d7167bb4f2e5b54e37717 /android
parent4d6244cc80f1a384d571af2efd539bd3fa3f9291 (diff)
add support for double-tap to go back a transition
by replacing the onClickListener with an onTouchListener with the simple variant of the GestureDetector. Also drop the check that prevents going to the "end-of-presentation, click to exit" slide and exiting the presentation that way. Change-Id: I54b49bf11929ad9415b8c85581fe16998ab3a7a7 Reviewed-on: https://gerrit.libreoffice.org/7107 Reviewed-by: Andrzej Hunt <andrzej.hunt@collabora.com> Tested-by: Andrzej Hunt <andrzej.hunt@collabora.com>
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java11
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java51
2 files changed, 37 insertions, 25 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java b/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java
index 94304fbfe784..da7826414262 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java
@@ -25,15 +25,15 @@ public class SlidesPagerAdapter extends PagerAdapter {
private final SlideShow mSlideShow;
- private final View.OnClickListener mSlideClickListener;
+ private final View.OnTouchListener mSlideTouchListener;
- public SlidesPagerAdapter(Context aContext, SlideShow aSlideShow, View.OnClickListener aSlideClickListener) {
+ public SlidesPagerAdapter(Context aContext, SlideShow aSlideShow, View.OnTouchListener aSlideTouchListener) {
mLayoutInflater = LayoutInflater.from(aContext);
mImageLoader = new ImageLoader(aContext.getResources(), R.drawable.bg_slide_unknown);
mSlideShow = aSlideShow;
- mSlideClickListener = aSlideClickListener;
+ mSlideTouchListener = aSlideTouchListener;
}
@Override
@@ -52,9 +52,8 @@ public class SlidesPagerAdapter extends PagerAdapter {
setUpUnknownSlidePreview(aSlideView);
}
- // ViewPager itself cannot handle click events,
- // so we need to use hacks. Android is good.
- aSlideView.setOnClickListener(mSlideClickListener);
+ // touch listener that handles tap and double-tap
+ aSlideView.setOnTouchListener(mSlideTouchListener);
aViewGroup.addView(aSlideView);
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
index 3d13a116357b..002484a6ee79 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
@@ -18,11 +18,14 @@ import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.app.Fragment;
import android.support.v4.content.LocalBroadcastManager;
+import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.text.TextUtils;
+import android.view.GestureDetector;
import android.view.LayoutInflater;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
@@ -34,9 +37,10 @@ import org.libreoffice.impressremote.R;
import org.libreoffice.impressremote.adapter.SlidesPagerAdapter;
import org.libreoffice.impressremote.communication.CommunicationService;
-public class SlidesPagerFragment extends Fragment implements ServiceConnection, ViewPager.OnPageChangeListener, View.OnClickListener {
+public class SlidesPagerFragment extends Fragment implements ServiceConnection, ViewPager.OnPageChangeListener, View.OnTouchListener {
private CommunicationService mCommunicationService;
private BroadcastReceiver mIntentsReceiver;
+ private GestureDetectorCompat mDetector;
public static SlidesPagerFragment newInstance() {
return new SlidesPagerFragment();
@@ -44,6 +48,7 @@ public class SlidesPagerFragment extends Fragment implements ServiceConnection,
@Override
public View onCreateView(LayoutInflater aInflater, ViewGroup aContainer, Bundle aSavedInstanceState) {
+ mDetector = new GestureDetectorCompat(aContainer.getContext(), new MyGestureListener());
return aInflater.inflate(R.layout.fragment_slides_pager, aContainer, false);
}
@@ -96,24 +101,6 @@ public class SlidesPagerFragment extends Fragment implements ServiceConnection,
return new SlidesPagerAdapter(getActivity(), aSlideShow, this);
}
- @Override
- public void onClick(View aView) {
- if (!isLastSlideDisplayed()) {
- showNextTransition();
- }
- }
-
- private boolean isLastSlideDisplayed() {
- int aCurrentSlideIndex = mCommunicationService.getSlideShow().getHumanCurrentSlideIndex();
- int aSlidesCount = mCommunicationService.getSlideShow().getSlidesCount();
-
- return aCurrentSlideIndex == aSlidesCount;
- }
-
- private void showNextTransition() {
- mCommunicationService.getCommandsTransmitter().performNextTransition();
- }
-
private int getSlidesMargin() {
return getResources().getDimensionPixelSize(R.dimen.margin_slide);
}
@@ -346,6 +333,32 @@ public class SlidesPagerFragment extends Fragment implements ServiceConnection,
private boolean isServiceBound() {
return mCommunicationService != null;
}
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ return mDetector.onTouchEvent(event);
+ }
+
+ class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
+ @Override
+ public boolean onDown(MotionEvent event) {
+ // down is the start for everything, we want that..
+ return true;
+ }
+
+ @Override
+ public boolean onSingleTapConfirmed(MotionEvent event) {
+ mCommunicationService.getCommandsTransmitter().performNextTransition();
+ return true;
+ }
+
+ @Override
+ public boolean onDoubleTap(MotionEvent event) {
+ mCommunicationService.getCommandsTransmitter().performPreviousTransition();
+ return true;
+ }
+ }
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */