diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-08-13 09:21:21 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-08-13 09:27:48 +0200 |
commit | c5581d19c6c5d857c4117e72cb022dcfc9561409 (patch) | |
tree | 99fbc11703d94a40646bacc0c8051f525b4f59ac /android/experimental | |
parent | 3b9e7f49efc84d474151f6818a77de635efd3a47 (diff) |
android: Add logic to change document parts from sidebar
Add click listener for list elements (parts) in "drawer layout"
side bar, add new LOEvent - change parts, propagate the change event
up to TileProvider, call setPart on LOK facade, clean all tiles and
redraw.
Change-Id: I711e0fb5e7e867cef87f97b96f1292d7c6801083
Diffstat (limited to 'android/experimental')
7 files changed, 76 insertions, 28 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java index 436e37e8c460..e014e13d6399 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java @@ -2,13 +2,19 @@ package org.libreoffice; public class DocumentPartView { - private String partName; + private final int partIndex; + private final String partName; - public DocumentPartView(String partName) { + public DocumentPartView(int partIndex, String partName) { + this.partIndex = partIndex; this.partName = partName; } public String getPartName() { return partName; } + + public int getPartIndex() { + return partIndex; + } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java index 2814730db095..746ceb598a45 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java @@ -11,17 +11,16 @@ public class LOEvent { public static final int TILE_SIZE = 2; public static final int VIEWPORT = 3; public static final int DRAW = 4; - - private ViewportMetrics mViewportMetrics; - + public static final int CHANGE_PART = 5; public int mType; - private String mTypeString; - ViewportMetrics viewportMetrics; + private ViewportMetrics mViewportMetrics; + private String mTypeString; + private int mPartIndex; public LOEvent(int type, int widthPixels, int heightPixels, int tileWidth, int tileHeight) { mType = type; - mTypeString = "Size Changed: " + widthPixels + " "+ heightPixels; + mTypeString = "Size Changed: " + widthPixels + " " + heightPixels; } public LOEvent(int type, IntSize tileSize) { @@ -40,6 +39,12 @@ public class LOEvent { mTypeString = "Draw"; } + public LOEvent(int type, int partIndex) { + mType = type; + mPartIndex = partIndex; + mTypeString = "Change part"; + } + public static LOEvent draw(Rect rect) { return new LOEvent(DRAW, rect); } @@ -56,6 +61,10 @@ public class LOEvent { return new LOEvent(VIEWPORT, viewportMetrics); } + public static LOEvent changePart(int part) { + return new LOEvent(CHANGE_PART, part); + } + public String getTypeString() { return mTypeString; } @@ -63,4 +72,8 @@ public class LOEvent { public ViewportMetrics getViewport() { return mViewportMetrics; } + + public int getPartIndex() { + return mPartIndex; + } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java index d56f45156b70..a831a559073a 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java @@ -115,6 +115,13 @@ public class LOKitThread extends Thread { return true; } + private void changePart(int partIndex) throws InterruptedException { + mTileProvider.changePart(partIndex); + GeckoLayerClient layerClient = mApplication.getLayerClient(); + layerClient.getTiles().clear(); + LOKitShell.sendEvent(LOEvent.draw(new Rect())); + } + private boolean initialize() { mApplication = LibreOfficeMainActivity.mAppContext; mTileProvider = new LOKitTileProvider(mApplication.getLayerController(), mInputFile); @@ -144,6 +151,9 @@ public class LOKitThread extends Thread { break; case LOEvent.SIZE_CHANGED: break; + case LOEvent.CHANGE_PART: + changePart(event.getPartIndex()); + break; } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java index 4758b70838f0..8085d022429f 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java @@ -15,27 +15,14 @@ import java.nio.ByteBuffer; public class LOKitTileProvider implements TileProvider { private static final String LOGTAG = LOKitTileProvider.class.getSimpleName(); - - private final LayerController mLayerController; - public static int TILE_SIZE = 256; - private final double mTileWidth; - private final double mTileHeight; - - public final Office mOffice; public final Document mDocument; - + private final LayerController mLayerController; + private final double mTileWidth; + private final double mTileHeight; private double mDPI; - private double twipToPixel(double input, double dpi) { - return input / 1440.0 * dpi; - } - - private double pixelToTwip(double input, double dpi) { - return (input / dpi) * 1440.0; - } - public LOKitTileProvider(LayerController layerController, String input) { mLayerController = layerController; mDPI = (double) LOKitShell.getDpi(); @@ -61,7 +48,7 @@ public class LOKitTileProvider implements TileProvider { partName = "Part " + (i + 1); } Log.i(LOGTAG, "Document part " + i + " name:'" + partName + "'"); - final DocumentPartView partView = new DocumentPartView(partName); + final DocumentPartView partView = new DocumentPartView(i, partName); LibreOfficeMainActivity.mAppContext.getDocumentPartView().add(partView); } @@ -74,8 +61,16 @@ public class LOKitTileProvider implements TileProvider { } } + private double twipToPixel(double input, double dpi) { + return input / 1440.0 * dpi; + } + + private double pixelToTwip(double input, double dpi) { + return (input / dpi) * 1440.0; + } + private boolean checkDocument() { - if(mDocument == null || !mOffice.getError().isEmpty()) { + if (mDocument == null || !mOffice.getError().isEmpty()) { Log.e(LOGTAG, "Error at loading: " + mOffice.getError()); return false; } @@ -108,7 +103,7 @@ public class LOKitTileProvider implements TileProvider { ByteBuffer buffer = ByteBuffer.allocateDirect(TILE_SIZE * TILE_SIZE * 4); Bitmap bitmap = Bitmap.createBitmap(TILE_SIZE, TILE_SIZE, Bitmap.Config.ARGB_8888); - mDocument.paintTile(buffer, TILE_SIZE, TILE_SIZE, (int) pixelToTwip(x, mDPI), (int) pixelToTwip(y, mDPI), (int)mTileWidth, (int)mTileHeight); + mDocument.paintTile(buffer, TILE_SIZE, TILE_SIZE, (int) pixelToTwip(x, mDPI), (int) pixelToTwip(y, mDPI), (int) mTileWidth, (int) mTileHeight); bitmap.copyPixelsFromBuffer(buffer); @@ -117,4 +112,9 @@ public class LOKitTileProvider implements TileProvider { tile.beginTransaction(); return tile; } + + @Override + public void changePart(int partIndex) { + mDocument.setPart(partIndex); + } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java index c50fba4b6a9d..20c2cf3a3c85 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -8,6 +8,8 @@ import android.util.DisplayMetrics; import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; import android.widget.ListView; import android.widget.RelativeLayout; @@ -104,6 +106,7 @@ public class LibreOfficeMainActivity extends Activity { mDocumentPartViewListAdpater = new DocumentPartViewListAdpater(this, R.layout.document_part_list_layout, mDocumentPartView); mDrawerList.setAdapter(mDocumentPartViewListAdpater); + mDrawerList.setOnItemClickListener(new DocumentPartClickListener()); if (mLayerController == null) { mLayerController = new LayerController(this); @@ -122,6 +125,15 @@ public class LibreOfficeMainActivity extends Activity { Log.w(LOGTAG, "UI almost up"); } + private class DocumentPartClickListener implements android.widget.AdapterView.OnItemClickListener { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + DocumentPartView partView = mDocumentPartViewListAdpater.getItem(position); + LOKitShell.sendEvent(LOEvent.changePart(partView.getPartIndex())); + mDrawerLayout.closeDrawer(mDrawerList); + } + } + @Override protected void onResume() { super.onResume(); diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java index e7ced82c4fd6..8de60d6abd34 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java @@ -18,7 +18,7 @@ public class MockTileProvider implements TileProvider { for (int i = 0; i < 5; i++) { String partName = "Part " + i; - DocumentPartView partView = new DocumentPartView(partName); + DocumentPartView partView = new DocumentPartView(i, partName); LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdpater().add(partView); } LibreOfficeMainActivity.mAppContext.mMainHandler.post(new Runnable() { @@ -60,4 +60,9 @@ public class MockTileProvider implements TileProvider { return tile; } + + @Override + public void changePart(int partIndex) { + + } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java index 6743e0c4082e..63e358d7d984 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java @@ -10,4 +10,6 @@ public interface TileProvider { boolean isReady(); SubTile createTile(int x, int y); + + void changePart(int partIndex); } |