1 package org
.libreoffice
;
3 import android
.content
.Intent
;
4 import android
.os
.Bundle
;
5 import androidx
.annotation
.Nullable
;
6 import androidx
.core
.view
.GestureDetectorCompat
;
7 import androidx
.appcompat
.app
.AppCompatActivity
;
8 import android
.view
.GestureDetector
;
9 import android
.view
.KeyEvent
;
10 import android
.view
.MotionEvent
;
11 import android
.view
.View
;
12 import android
.webkit
.WebView
;
13 import android
.widget
.Button
;
14 import android
.widget
.ImageButton
;
16 public class PresentationActivity
extends AppCompatActivity
{
18 private static final String LOGTAG
= PresentationActivity
.class.getSimpleName();
23 protected void onCreate(@Nullable Bundle savedInstanceState
) {
24 super.onCreate(savedInstanceState
);
26 View decorView
= getWindow().getDecorView();
27 // Hide the status bar.
28 int uiOptions
= View
.SYSTEM_UI_FLAG_FULLSCREEN
;
29 decorView
.setSystemUiVisibility(uiOptions
);
31 setContentView(R
.layout
.presentation_mode
);
34 Intent intent
= getIntent();
35 String filePath
= intent
.getDataString();
38 mWebView
= findViewById(R
.id
.presentation_view
);
39 mWebView
.getSettings().setJavaScriptEnabled(true);
40 mWebView
.setOnTouchListener(new View
.OnTouchListener() {
42 public boolean onTouch(View v
, MotionEvent event
) {
47 // set up buttons within presentation_gesture_view
48 ImageButton prevButton
= findViewById(R
.id
.slide_show_nav_prev
);
49 ImageButton nextButton
= findViewById(R
.id
.slide_show_nav_next
);
50 Button backButton
= findViewById(R
.id
.slide_show_nav_back
);
52 prevButton
.setOnClickListener(new View
.OnClickListener() {
54 public void onClick(View v
) {
58 nextButton
.setOnClickListener(new View
.OnClickListener() {
60 public void onClick(View v
) {
64 backButton
.setOnClickListener(new View
.OnClickListener() {
66 public void onClick(View v
) {
71 // set up presentation_gesture_view
72 mGestureView
= findViewById(R
.id
.presentation_gesture_view
);
73 final GestureDetectorCompat gestureDetector
=
74 new GestureDetectorCompat(this, new PresentationGestureViewListener());
75 mGestureView
.setOnTouchListener(new View
.OnTouchListener() {
77 public boolean onTouch(View v
, MotionEvent event
) {
78 return gestureDetector
.onTouchEvent(event
);
83 mWebView
.loadUrl(filePath
);
86 private class PresentationGestureViewListener
extends GestureDetector
.SimpleOnGestureListener
{
87 private static final int SWIPE_VELOCITY_THRESHOLD
= 100;
88 private static final int SCROLL_THRESHOLD
= 10; // if scrollCounter is larger than this, a page switch is triggered
89 private int scrollCounter
= 0; // a counter for measuring scrolling distance
92 public boolean onDown(MotionEvent e
) {
97 public boolean onFling(MotionEvent e1
, MotionEvent e2
, float velocityX
, float velocityY
) {
98 boolean result
= false;
100 float diffY
= e2
.getY() - e1
.getY();
101 float diffX
= e2
.getX() - e1
.getX();
102 if (Math
.abs(diffX
) > Math
.abs(diffY
)) {
103 if (Math
.abs(velocityX
) > SWIPE_VELOCITY_THRESHOLD
) {
112 } catch (Exception exception
) {
113 exception
.printStackTrace();
119 public boolean onScroll(MotionEvent e1
, MotionEvent e2
, float distanceX
, float distanceY
) {
120 boolean result
= false;
122 float diffY
= e2
.getY() - e1
.getY();
123 float diffX
= e2
.getX() - e1
.getX();
124 if (Math
.abs(diffX
) < Math
.abs(diffY
)) {
127 if (scrollCounter
>= SCROLL_THRESHOLD
) {
133 if (scrollCounter
<= -SCROLL_THRESHOLD
) {
140 } catch (Exception exception
) {
141 exception
.printStackTrace();
147 public boolean onSingleTapUp(MotionEvent e
) {
148 if (e
.getX() < mGestureView
.getWidth()/3) {
150 } else if (e
.getX() < mGestureView
.getWidth()*2/3) {
151 hideControlButtons();
159 private void hideControlButtons() {
160 View
[] views
= {findViewById(R
.id
.slide_show_nav_prev
),findViewById(R
.id
.slide_show_nav_next
),findViewById(R
.id
.slide_show_nav_back
)} ;
161 for (View view
: views
) {
162 if (view
.getVisibility() == View
.GONE
) {
163 view
.setVisibility(View
.VISIBLE
);
164 } else if (view
.getVisibility() == View
.VISIBLE
) {
165 view
.setVisibility(View
.GONE
);
170 private void pageLeft() {
171 mWebView
.dispatchKeyEvent(new KeyEvent(KeyEvent
.ACTION_DOWN
, KeyEvent
.KEYCODE_DPAD_LEFT
));
174 private void pageRight() {
175 mWebView
.dispatchKeyEvent(new KeyEvent(KeyEvent
.ACTION_DOWN
, KeyEvent
.KEYCODE_DPAD_RIGHT
));