1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 package org
.libreoffice
;
12 import android
.app
.ActivityManager
;
13 import android
.content
.Context
;
14 import android
.graphics
.PointF
;
15 import android
.graphics
.RectF
;
16 import android
.os
.Handler
;
17 import android
.util
.DisplayMetrics
;
18 import android
.view
.KeyEvent
;
20 import org
.libreoffice
.canvas
.SelectionHandle
;
21 import org
.mozilla
.gecko
.gfx
.ComposedTileLayer
;
24 * Common static LOKit functions, functions to send events.
26 public class LOKitShell
{
27 public static float getDpi(Context context
) {
28 LOKitTileProvider tileProvider
= ((LibreOfficeMainActivity
)context
).getTileProvider();
29 if (tileProvider
!= null && tileProvider
.isSpreadsheet())
31 DisplayMetrics metrics
= context
.getResources().getDisplayMetrics();
32 return metrics
.density
* 160;
35 // Get a Handler for the main java thread
36 public static Handler
getMainHandler() {
37 return LibreOfficeApplication
.getMainHandler();
40 public static void showProgressSpinner(final LibreOfficeMainActivity context
) {
41 getMainHandler().post(new Runnable() {
44 context
.showProgressSpinner();
49 public static void hideProgressSpinner(final LibreOfficeMainActivity context
) {
50 getMainHandler().post(new Runnable() {
53 context
.hideProgressSpinner();
58 public static int getMemoryClass(Context context
) {
59 ActivityManager activityManager
= (ActivityManager
) context
.getSystemService(Context
.ACTIVITY_SERVICE
);
60 return activityManager
.getMemoryClass() * 1024 * 1024;
63 public static boolean isEditingEnabled() {
64 return !LibreOfficeMainActivity
.isReadOnlyMode();
70 * Make sure LOKitThread is running and send event to it.
72 public static void sendEvent(LOEvent event
) {
73 LibreOfficeMainActivity
.loKitThread
.queueEvent(event
);
76 public static void sendThumbnailEvent(ThumbnailCreator
.ThumbnailCreationTask task
) {
77 LOKitShell
.sendEvent(new LOEvent(LOEvent
.THUMBNAIL
, task
));
81 * Send touch event to LOKitThread.
83 public static void sendTouchEvent(String touchType
, PointF documentTouchCoordinate
) {
84 LOKitShell
.sendEvent(new LOEvent(LOEvent
.TOUCH
, touchType
, documentTouchCoordinate
));
88 * Send key event to LOKitThread.
90 public static void sendKeyEvent(KeyEvent event
) {
91 LOKitShell
.sendEvent(new LOEvent(LOEvent
.KEY_EVENT
, event
));
94 public static void sendSizeChangedEvent(int width
, int height
) {
95 LOKitShell
.sendEvent(new LOEvent(LOEvent
.SIZE_CHANGED
));
98 public static void sendSwipeRightEvent() {
99 LOKitShell
.sendEvent(new LOEvent(LOEvent
.SWIPE_RIGHT
));
102 public static void sendSwipeLeftEvent() {
103 LOKitShell
.sendEvent(new LOEvent(LOEvent
.SWIPE_LEFT
));
106 public static void sendChangePartEvent(int part
) {
107 LOKitShell
.sendEvent(new LOEvent(LOEvent
.CHANGE_PART
, part
));
110 public static void sendLoadEvent(String inputFilePath
) {
111 LOKitShell
.sendEvent(new LOEvent(inputFilePath
, LOEvent
.LOAD
));
114 public static void sendNewDocumentLoadEvent(String newDocumentPath
, String newDocumentType
) {
115 LOKitShell
.sendEvent(new LOEvent(newDocumentPath
, newDocumentType
, LOEvent
.LOAD_NEW
));
118 public static void sendSaveAsEvent(String filePath
, String fileFormat
) {
119 LOKitShell
.sendEvent(new LOEvent(filePath
, fileFormat
, LOEvent
.SAVE_AS
));
122 public static void sendSaveCopyAsEvent(String filePath
, String fileFormat
) {
123 LOKitShell
.sendEvent(new LOEvent(filePath
, fileFormat
, LOEvent
.SAVE_COPY_AS
));
126 public static void sendCloseEvent() {
127 LOKitShell
.sendEvent(new LOEvent(LOEvent
.CLOSE
));
131 * Send tile reevaluation to LOKitThread.
133 public static void sendTileReevaluationRequest(ComposedTileLayer composedTileLayer
) {
134 LOKitShell
.sendEvent(new LOEvent(LOEvent
.TILE_REEVALUATION_REQUEST
, composedTileLayer
));
138 * Send tile invalidation to LOKitThread.
140 public static void sendTileInvalidationRequest(RectF rect
) {
141 LOKitShell
.sendEvent(new LOEvent(LOEvent
.TILE_INVALIDATION
, rect
));
145 * Send change handle position event to LOKitThread.
147 public static void sendChangeHandlePositionEvent(SelectionHandle
.HandleType handleType
, PointF documentCoordinate
) {
148 LOKitShell
.sendEvent(new LOEvent(LOEvent
.CHANGE_HANDLE_POSITION
, handleType
, documentCoordinate
));
151 public static void sendNavigationClickEvent() {
152 LOKitShell
.sendEvent(new LOEvent(LOEvent
.NAVIGATION_CLICK
));
156 * Move the viewport to the desired point (top-left), and change the zoom level.
157 * Ensure this runs on the UI thread.
159 public static void moveViewportTo(final LibreOfficeMainActivity context
, final PointF position
, final Float zoom
) {
160 context
.getLayerClient().post(new Runnable() {
163 context
.getLayerClient().moveTo(position
, zoom
);
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */