diff options
Diffstat (limited to 'android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/DocumentOverlay.java')
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/DocumentOverlay.java | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/DocumentOverlay.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/DocumentOverlay.java new file mode 100644 index 000000000000..d28f33d306e7 --- /dev/null +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/DocumentOverlay.java @@ -0,0 +1,205 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.libreoffice.overlay; + +import android.app.Activity; +import android.graphics.RectF; +import android.util.Log; + +import org.libreoffice.LOKitShell; +import org.libreoffice.R; +import org.libreoffice.canvas.SelectionHandle; +import org.mozilla.gecko.gfx.Layer; +import org.mozilla.gecko.gfx.LayerView; +import org.mozilla.gecko.util.FloatUtils; + +import java.util.List; + +/** + * The DocumentOverlay is an overlay over the document. This class is responsible + * to setup the document overlay view, report visibility and position of its elements + * when they change and report any changes to the viewport. + */ +public class DocumentOverlay extends Layer { + private static final String LOGTAG = DocumentOverlay.class.getSimpleName(); + + private final DocumentOverlayView mCursorView; + private float mViewLeft; + private float mViewTop; + private float mViewZoom; + + public DocumentOverlay(Activity context, LayerView layerView) { + mCursorView = (DocumentOverlayView) context.findViewById(R.id.text_cursor_view); + if (mCursorView == null) { + Log.e(LOGTAG, "Failed to initialize TextCursorLayer - CursorView is null"); + } + layerView.addLayer(this); + mCursorView.initialize(layerView); + } + + /** + * @see Layer#draw(org.mozilla.gecko.gfx.Layer.RenderContext) + */ + @Override + public void draw(final RenderContext context) { + if (FloatUtils.fuzzyEquals(mViewLeft, context.viewport.left) + && FloatUtils.fuzzyEquals(mViewTop, context.viewport.top) + && FloatUtils.fuzzyEquals(mViewZoom, context.zoomFactor)) { + return; + } + + mViewLeft = context.viewport.left; + mViewTop = context.viewport.top; + mViewZoom = context.zoomFactor; + + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.repositionWithViewport(mViewLeft, mViewTop, mViewZoom); + } + }); + } + + /** + * Show the cursor at the defined cursor position on the overlay. + */ + public void showCursor() { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.showCursor(); + } + }); + } + + /** + * Hide the cursor at the defined cursor position on the overlay. + */ + public void hideCursor() { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.hideCursor(); + } + }); + } + + /** + * Position the cursor to the input position on the overlay. + */ + public void positionCursor(final RectF position) { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.changeCursorPosition(position); + } + }); + } + + /** + * Show selections on the overlay. + */ + public void showSelections() { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.showSelections(); + } + }); + } + + /** + * Hide selections on the overlay. + */ + public void hideSelections() { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.hideSelections(); + } + }); + } + + /** + * Change the list of selections. + */ + public void changeSelections(final List<RectF> selections) { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.changeSelections(selections); + } + }); + } + + /** + * Show the graphic selection on the overlay. + */ + public void showGraphicSelection() { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.showGraphicSelection(); + } + }); + } + + /** + * Hide the graphic selection. + */ + public void hideGraphicSelection() { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.hideGraphicSelection(); + } + }); + } + + /** + * Change the graphic selection rectangle to the input rectangle. + */ + public void changeGraphicSelection(final RectF rectangle) { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.changeGraphicSelection(rectangle); + } + }); + } + + /** + * Show the handle (of input type) on the overlay. + */ + public void showHandle(final SelectionHandle.HandleType type) { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.showHandle(type); + } + }); + } + + /** + * Hide the handle (of input type). + */ + public void hideHandle(final SelectionHandle.HandleType type) { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.hideHandle(type); + } + }); + } + + /** + * Position the handle (of input type) position to the input rectangle. + */ + public void positionHandle(final SelectionHandle.HandleType type, final RectF rectangle) { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.positionHandle(type, rectangle); + } + }); + } + + public RectF getCursorPosition() { + return mCursorView.getCursorPosition(); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |