LibreOffice Module android (master) 1
OnSlideSwipeListener.java
Go to the documentation of this file.
1/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10package org.mozilla.gecko;
11
12import android.content.Context;
13import android.view.GestureDetector;
14import android.view.GestureDetector.SimpleOnGestureListener;
15import android.view.MotionEvent;
16import android.view.View;
17import android.view.View.OnTouchListener;
18import android.util.Log;
19
23
24
25public class OnSlideSwipeListener implements OnTouchListener {
26 private static String LOGTAG = OnSlideSwipeListener.class.getName();
27
28 private final GestureDetector mGestureDetector;
30
31 public OnSlideSwipeListener(Context ctx, GeckoLayerClient client){
32 mGestureDetector = new GestureDetector(ctx, new GestureListener());
33 mLayerClient = client;
34 }
35
36 private final class GestureListener extends SimpleOnGestureListener {
37
38 private static final int SWIPE_THRESHOLD = 100;
39 private static final int SWIPE_VELOCITY_THRESHOLD = 100;
40
41 @Override
42 public boolean onDown(MotionEvent e) {
43 return false;
44 }
45
46 @Override
47 public boolean onFling(MotionEvent e1, MotionEvent e2, float velX, float velY) {
48 // Check if the page is already zoomed-in.
49 // Disable swiping gesture if that's the case.
51 if (viewportMetrics.viewportRectLeft > viewportMetrics.pageRectLeft ||
52 viewportMetrics.viewportRectRight < viewportMetrics.pageRectRight) {
53 return false;
54 }
55
56 // Otherwise, the page is smaller than viewport, perform swipe
57 // gesture.
58 try {
59 float diffY = e2.getY() - e1.getY();
60 float diffX = e2.getX() - e1.getX();
61 if (Math.abs(diffX) > Math.abs(diffY)) {
62 if (Math.abs(diffX) > SWIPE_THRESHOLD
63 && Math.abs(velX) > SWIPE_VELOCITY_THRESHOLD) {
64 if (diffX > 0) {
66 } else {
68 }
69 }
70 }
71 } catch (Exception exception) {
72 exception.printStackTrace();
73 }
74 return false;
75 }
76 }
77
78 public void onSwipeRight() {
79 Log.d(LOGTAG, "onSwipeRight");
81 }
82
83 public void onSwipeLeft() {
84 Log.d(LOGTAG, "onSwipeLeft");
86 }
87
88 @Override
89 public boolean onTouch(View v, MotionEvent me) {
90 return mGestureDetector.onTouchEvent(me);
91 }
92}
93
94/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Common static LOKit functions, functions to send events.
Definition: LOKitShell.java:26
static void sendSwipeLeftEvent()
static void sendSwipeRightEvent()
Definition: LOKitShell.java:98
boolean onFling(MotionEvent e1, MotionEvent e2, float velX, float velY)
OnSlideSwipeListener(Context ctx, GeckoLayerClient client)
boolean onTouch(View v, MotionEvent me)
ImmutableViewportMetrics getViewportMetrics()
Implementation of PanZoomTarget.
ImmutableViewportMetrics are used to store the viewport metrics in way that we can access a version o...
@ Exception
ctx