Kaydet (Commit) c5581d19 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

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
üst 3b9e7f49
...@@ -2,13 +2,19 @@ package org.libreoffice; ...@@ -2,13 +2,19 @@ package org.libreoffice;
public class DocumentPartView { 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; this.partName = partName;
} }
public String getPartName() { public String getPartName() {
return partName; return partName;
} }
public int getPartIndex() {
return partIndex;
}
} }
...@@ -11,17 +11,16 @@ public class LOEvent { ...@@ -11,17 +11,16 @@ public class LOEvent {
public static final int TILE_SIZE = 2; public static final int TILE_SIZE = 2;
public static final int VIEWPORT = 3; public static final int VIEWPORT = 3;
public static final int DRAW = 4; public static final int DRAW = 4;
public static final int CHANGE_PART = 5;
private ViewportMetrics mViewportMetrics;
public int mType; public int mType;
private String mTypeString;
ViewportMetrics viewportMetrics; ViewportMetrics viewportMetrics;
private ViewportMetrics mViewportMetrics;
private String mTypeString;
private int mPartIndex;
public LOEvent(int type, int widthPixels, int heightPixels, int tileWidth, int tileHeight) { public LOEvent(int type, int widthPixels, int heightPixels, int tileWidth, int tileHeight) {
mType = type; mType = type;
mTypeString = "Size Changed: " + widthPixels + " "+ heightPixels; mTypeString = "Size Changed: " + widthPixels + " " + heightPixels;
} }
public LOEvent(int type, IntSize tileSize) { public LOEvent(int type, IntSize tileSize) {
...@@ -40,6 +39,12 @@ public class LOEvent { ...@@ -40,6 +39,12 @@ public class LOEvent {
mTypeString = "Draw"; mTypeString = "Draw";
} }
public LOEvent(int type, int partIndex) {
mType = type;
mPartIndex = partIndex;
mTypeString = "Change part";
}
public static LOEvent draw(Rect rect) { public static LOEvent draw(Rect rect) {
return new LOEvent(DRAW, rect); return new LOEvent(DRAW, rect);
} }
...@@ -56,6 +61,10 @@ public class LOEvent { ...@@ -56,6 +61,10 @@ public class LOEvent {
return new LOEvent(VIEWPORT, viewportMetrics); return new LOEvent(VIEWPORT, viewportMetrics);
} }
public static LOEvent changePart(int part) {
return new LOEvent(CHANGE_PART, part);
}
public String getTypeString() { public String getTypeString() {
return mTypeString; return mTypeString;
} }
...@@ -63,4 +72,8 @@ public class LOEvent { ...@@ -63,4 +72,8 @@ public class LOEvent {
public ViewportMetrics getViewport() { public ViewportMetrics getViewport() {
return mViewportMetrics; return mViewportMetrics;
} }
public int getPartIndex() {
return mPartIndex;
}
} }
...@@ -115,6 +115,13 @@ public class LOKitThread extends Thread { ...@@ -115,6 +115,13 @@ public class LOKitThread extends Thread {
return true; 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() { private boolean initialize() {
mApplication = LibreOfficeMainActivity.mAppContext; mApplication = LibreOfficeMainActivity.mAppContext;
mTileProvider = new LOKitTileProvider(mApplication.getLayerController(), mInputFile); mTileProvider = new LOKitTileProvider(mApplication.getLayerController(), mInputFile);
...@@ -144,6 +151,9 @@ public class LOKitThread extends Thread { ...@@ -144,6 +151,9 @@ public class LOKitThread extends Thread {
break; break;
case LOEvent.SIZE_CHANGED: case LOEvent.SIZE_CHANGED:
break; break;
case LOEvent.CHANGE_PART:
changePart(event.getPartIndex());
break;
} }
} }
......
...@@ -15,27 +15,14 @@ import java.nio.ByteBuffer; ...@@ -15,27 +15,14 @@ import java.nio.ByteBuffer;
public class LOKitTileProvider implements TileProvider { public class LOKitTileProvider implements TileProvider {
private static final String LOGTAG = LOKitTileProvider.class.getSimpleName(); private static final String LOGTAG = LOKitTileProvider.class.getSimpleName();
private final LayerController mLayerController;
public static int TILE_SIZE = 256; public static int TILE_SIZE = 256;
private final double mTileWidth;
private final double mTileHeight;
public final Office mOffice; public final Office mOffice;
public final Document mDocument; public final Document mDocument;
private final LayerController mLayerController;
private final double mTileWidth;
private final double mTileHeight;
private double mDPI; 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) { public LOKitTileProvider(LayerController layerController, String input) {
mLayerController = layerController; mLayerController = layerController;
mDPI = (double) LOKitShell.getDpi(); mDPI = (double) LOKitShell.getDpi();
...@@ -61,7 +48,7 @@ public class LOKitTileProvider implements TileProvider { ...@@ -61,7 +48,7 @@ public class LOKitTileProvider implements TileProvider {
partName = "Part " + (i + 1); partName = "Part " + (i + 1);
} }
Log.i(LOGTAG, "Document part " + i + " name:'" + partName + "'"); 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); LibreOfficeMainActivity.mAppContext.getDocumentPartView().add(partView);
} }
...@@ -74,8 +61,16 @@ public class LOKitTileProvider implements TileProvider { ...@@ -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() { private boolean checkDocument() {
if(mDocument == null || !mOffice.getError().isEmpty()) { if (mDocument == null || !mOffice.getError().isEmpty()) {
Log.e(LOGTAG, "Error at loading: " + mOffice.getError()); Log.e(LOGTAG, "Error at loading: " + mOffice.getError());
return false; return false;
} }
...@@ -108,7 +103,7 @@ public class LOKitTileProvider implements TileProvider { ...@@ -108,7 +103,7 @@ public class LOKitTileProvider implements TileProvider {
ByteBuffer buffer = ByteBuffer.allocateDirect(TILE_SIZE * TILE_SIZE * 4); ByteBuffer buffer = ByteBuffer.allocateDirect(TILE_SIZE * TILE_SIZE * 4);
Bitmap bitmap = Bitmap.createBitmap(TILE_SIZE, TILE_SIZE, Bitmap.Config.ARGB_8888); 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); bitmap.copyPixelsFromBuffer(buffer);
...@@ -117,4 +112,9 @@ public class LOKitTileProvider implements TileProvider { ...@@ -117,4 +112,9 @@ public class LOKitTileProvider implements TileProvider {
tile.beginTransaction(); tile.beginTransaction();
return tile; return tile;
} }
@Override
public void changePart(int partIndex) {
mDocument.setPart(partIndex);
}
} }
...@@ -8,6 +8,8 @@ import android.util.DisplayMetrics; ...@@ -8,6 +8,8 @@ import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
...@@ -104,6 +106,7 @@ public class LibreOfficeMainActivity extends Activity { ...@@ -104,6 +106,7 @@ public class LibreOfficeMainActivity extends Activity {
mDocumentPartViewListAdpater = new DocumentPartViewListAdpater(this, R.layout.document_part_list_layout, mDocumentPartView); mDocumentPartViewListAdpater = new DocumentPartViewListAdpater(this, R.layout.document_part_list_layout, mDocumentPartView);
mDrawerList.setAdapter(mDocumentPartViewListAdpater); mDrawerList.setAdapter(mDocumentPartViewListAdpater);
mDrawerList.setOnItemClickListener(new DocumentPartClickListener());
if (mLayerController == null) { if (mLayerController == null) {
mLayerController = new LayerController(this); mLayerController = new LayerController(this);
...@@ -122,6 +125,15 @@ public class LibreOfficeMainActivity extends Activity { ...@@ -122,6 +125,15 @@ public class LibreOfficeMainActivity extends Activity {
Log.w(LOGTAG, "UI almost up"); 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 @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
......
...@@ -18,7 +18,7 @@ public class MockTileProvider implements TileProvider { ...@@ -18,7 +18,7 @@ public class MockTileProvider implements TileProvider {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
String partName = "Part " + i; String partName = "Part " + i;
DocumentPartView partView = new DocumentPartView(partName); DocumentPartView partView = new DocumentPartView(i, partName);
LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdpater().add(partView); LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdpater().add(partView);
} }
LibreOfficeMainActivity.mAppContext.mMainHandler.post(new Runnable() { LibreOfficeMainActivity.mAppContext.mMainHandler.post(new Runnable() {
...@@ -60,4 +60,9 @@ public class MockTileProvider implements TileProvider { ...@@ -60,4 +60,9 @@ public class MockTileProvider implements TileProvider {
return tile; return tile;
} }
@Override
public void changePart(int partIndex) {
}
} }
...@@ -10,4 +10,6 @@ public interface TileProvider { ...@@ -10,4 +10,6 @@ public interface TileProvider {
boolean isReady(); boolean isReady();
SubTile createTile(int x, int y); SubTile createTile(int x, int y);
void changePart(int partIndex);
} }
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