Kaydet (Commit) dc43b61e authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Miklos Vajna

android: create InvalidationHandler outside of LOKitTileProvider

Change-Id: I79bb20ca5a16a2ebdc6ed3f1c97a483173b0762b
üst 5b4fc00b
...@@ -13,14 +13,19 @@ import org.mozilla.gecko.TextSelectionHandle; ...@@ -13,14 +13,19 @@ import org.mozilla.gecko.TextSelectionHandle;
public class InvalidationHandler { public class InvalidationHandler {
private static String LOGTAG = InvalidationHandler.class.getSimpleName(); private static String LOGTAG = InvalidationHandler.class.getSimpleName();
public InvalidationHandler() { private TextCursorLayer mTextCursorLayer;
private TextSelection mTextSelection;
public InvalidationHandler(LibreOfficeMainActivity mainActivity) {
mTextCursorLayer = mainActivity.getTextCursorLayer();
mTextSelection = mainActivity.getTextSelection();
} }
/** /**
* Processes invalidation message * Processes invalidation message
* *
* @param messageID - ID of the message * @param messageID - ID of the message
* @param payload - additional invalidation message payload * @param payload - additional invalidation message payload
*/ */
public void processMessage(int messageID, String payload) { public void processMessage(int messageID, String payload) {
switch (messageID) { switch (messageID) {
...@@ -28,6 +33,7 @@ public class InvalidationHandler { ...@@ -28,6 +33,7 @@ public class InvalidationHandler {
invalidateTiles(payload); invalidateTiles(payload);
break; break;
case Document.CALLBACK_INVALIDATE_VISIBLE_CURSOR: case Document.CALLBACK_INVALIDATE_VISIBLE_CURSOR:
Log.i(LOGTAG, "Cursor: " + payload);
invalidateCursor(payload); invalidateCursor(payload);
break; break;
case Document.CALLBACK_INVALIDATE_TEXT_SELECTION: case Document.CALLBACK_INVALIDATE_TEXT_SELECTION:
...@@ -80,24 +86,23 @@ public class InvalidationHandler { ...@@ -80,24 +86,23 @@ public class InvalidationHandler {
/** /**
* Handles the cursor invalidation message * Handles the cursor invalidation message
*
* @param payload * @param payload
*/ */
private void invalidateCursor(String payload) { private void invalidateCursor(String payload) {
RectF rect = convertCallbackMessageStringToRectF(payload); RectF rect = convertCallbackMessageStringToRectF(payload);
if (rect != null) { if (rect != null) {
RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom); RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection(); mTextSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, underSelection);
textSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, underSelection); mTextSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
textSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE); mTextCursorLayer.positionCursor(rect);
mTextCursorLayer.showCursor();
TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
textCursorLayer.positionCursor(rect);
textCursorLayer.showCursor();
} }
} }
/** /**
* Handles the tile invalidation message * Handles the tile invalidation message
*
* @param payload * @param payload
*/ */
private void invalidateTiles(String payload) { private void invalidateTiles(String payload) {
...@@ -109,51 +114,45 @@ public class InvalidationHandler { ...@@ -109,51 +114,45 @@ public class InvalidationHandler {
/** /**
* Handles the selection start invalidation message * Handles the selection start invalidation message
*
* @param payload * @param payload
*/ */
private void invalidateSelectionStart(String payload) { private void invalidateSelectionStart(String payload) {
RectF rect = convertCallbackMessageStringToRectF(payload); RectF rect = convertCallbackMessageStringToRectF(payload);
if (rect != null) { if (rect != null) {
RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom); RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection(); mTextSelection.positionHandle(TextSelectionHandle.HandleType.START, underSelection);
textSelection.positionHandle(TextSelectionHandle.HandleType.START, underSelection); mTextSelection.showHandle(TextSelectionHandle.HandleType.START);
textSelection.showHandle(TextSelectionHandle.HandleType.START); mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
mTextCursorLayer.hideCursor();
textSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
textCursorLayer.hideCursor();
} }
} }
/** /**
* Handles the selection end invalidation message * Handles the selection end invalidation message
*
* @param payload * @param payload
*/ */
private void invalidateSelectionEnd(String payload) { private void invalidateSelectionEnd(String payload) {
RectF rect = convertCallbackMessageStringToRectF(payload); RectF rect = convertCallbackMessageStringToRectF(payload);
if (rect != null) { if (rect != null) {
RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom); RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection(); mTextSelection.positionHandle(TextSelectionHandle.HandleType.END, underSelection);
textSelection.positionHandle(TextSelectionHandle.HandleType.END, underSelection); mTextSelection.showHandle(TextSelectionHandle.HandleType.END);
textSelection.showHandle(TextSelectionHandle.HandleType.END); mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
mTextCursorLayer.hideCursor();
textSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
textCursorLayer.hideCursor();
} }
} }
/** /**
* Handles the selection invalidation message * Handles the selection invalidation message
*
* @param payload * @param payload
*/ */
private void invalidateSelection(String payload) { private void invalidateSelection(String payload) {
if (payload.isEmpty()) { if (payload.isEmpty()) {
TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection(); mTextSelection.hideHandle(TextSelectionHandle.HandleType.START);
textSelection.hideHandle(TextSelectionHandle.HandleType.START); mTextSelection.hideHandle(TextSelectionHandle.HandleType.END);
textSelection.hideHandle(TextSelectionHandle.HandleType.END);
} }
} }
......
...@@ -24,10 +24,12 @@ public class LOKitThread extends Thread { ...@@ -24,10 +24,12 @@ public class LOKitThread extends Thread {
private LibreOfficeMainActivity mApplication; private LibreOfficeMainActivity mApplication;
private TileProvider mTileProvider; private TileProvider mTileProvider;
private InvalidationHandler mInvalidationHandler;
private ImmutableViewportMetrics mViewportMetrics; private ImmutableViewportMetrics mViewportMetrics;
private GeckoLayerClient mLayerClient; private GeckoLayerClient mLayerClient;
public LOKitThread() { public LOKitThread() {
mInvalidationHandler = null;
TileProviderFactory.initialize(); TileProviderFactory.initialize();
} }
...@@ -154,7 +156,8 @@ public class LOKitThread extends Thread { ...@@ -154,7 +156,8 @@ public class LOKitThread extends Thread {
mLayerClient = mApplication.getLayerClient(); mLayerClient = mApplication.getLayerClient();
mTileProvider = TileProviderFactory.create(mLayerClient, filename); mInvalidationHandler = new InvalidationHandler(LibreOfficeMainActivity.mAppContext);
mTileProvider = TileProviderFactory.create(mLayerClient, mInvalidationHandler, filename);
if (mTileProvider.isReady()) { if (mTileProvider.isReady()) {
LOKitShell.showProgressSpinner(); LOKitShell.showProgressSpinner();
......
...@@ -37,12 +37,13 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback ...@@ -37,12 +37,13 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
private float mWidthTwip; private float mWidthTwip;
private float mHeightTwip; private float mHeightTwip;
private InvalidationHandler mInvalidationHandler = new InvalidationHandler(); private InvalidationHandler mInvalidationHandler;
private long objectCreationTime = System.currentTimeMillis(); private long objectCreationTime = System.currentTimeMillis();
public LOKitTileProvider(GeckoLayerClient layerClient, String input) { public LOKitTileProvider(GeckoLayerClient layerClient, InvalidationHandler invalidationHandler, String input) {
mLayerClient = layerClient; mLayerClient = layerClient;
mInvalidationHandler = invalidationHandler;
mDPI = (float) LOKitShell.getDpi(); mDPI = (float) LOKitShell.getDpi();
mTileWidth = pixelToTwip(TILE_SIZE, mDPI); mTileWidth = pixelToTwip(TILE_SIZE, mDPI);
mTileHeight = pixelToTwip(TILE_SIZE, mDPI); mTileHeight = pixelToTwip(TILE_SIZE, mDPI);
......
...@@ -8,7 +8,6 @@ public class TileProviderFactory { ...@@ -8,7 +8,6 @@ public class TileProviderFactory {
private static TileProviderID currentTileProvider = TileProviderID.LOKIT; private static TileProviderID currentTileProvider = TileProviderID.LOKIT;
private TileProviderFactory() { private TileProviderFactory() {
} }
public static void initialize() { public static void initialize() {
...@@ -17,9 +16,9 @@ public class TileProviderFactory { ...@@ -17,9 +16,9 @@ public class TileProviderFactory {
} }
} }
public static TileProvider create(GeckoLayerClient layerClient, String filename) { public static TileProvider create(GeckoLayerClient layerClient, InvalidationHandler invalidationHandler, String filename) {
if (currentTileProvider == TileProviderID.LOKIT) { if (currentTileProvider == TileProviderID.LOKIT) {
return new LOKitTileProvider(layerClient, filename); return new LOKitTileProvider(layerClient, invalidationHandler, filename);
} else { } else {
return new MockTileProvider(layerClient, filename); return new MockTileProvider(layerClient, filename);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment