diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-10-02 15:56:00 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-10-04 17:52:44 +0200 |
commit | e910aa45d3d4fb92d2ac1e975f411785d5fc70ae (patch) | |
tree | 55e8921954e006e9de40be2735d86f600f43035c /android | |
parent | android: use tile size and change the type to IntSize (diff) | |
download | core-e910aa45d3d4fb92d2ac1e975f411785d5fc70ae.tar.gz core-e910aa45d3d4fb92d2ac1e975f411785d5fc70ae.zip |
android: construct LayerView in xml GUI definition (activity_main)
Change-Id: I6cd3c8dff2ca36f3d64559b218d005d5a6da9066
Diffstat (limited to 'android')
5 files changed, 64 insertions, 20 deletions
diff --git a/android/experimental/LOAndroid3/res/layout/activity_main.xml b/android/experimental/LOAndroid3/res/layout/activity_main.xml index fd7d63bfa1da..1b1bb0779b7e 100644 --- a/android/experimental/LOAndroid3/res/layout/activity_main.xml +++ b/android/experimental/LOAndroid3/res/layout/activity_main.xml @@ -16,19 +16,25 @@ android:id="@+id/gecko_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" - android:layout_weight="1"/> + android:layout_weight="1"> + + <org.mozilla.gecko.gfx.LayerView + android:id="@+id/layer_view" + android:layout_width="fill_parent" + android:layout_height="fill_parent"/> + </RelativeLayout> <RelativeLayout android:id="@+id/loadingPanel" android:layout_width="match_parent" android:layout_height="match_parent" - android:gravity="center" - android:background="#9333"> + android:background="#9333" + android:gravity="center"> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" - android:indeterminate="true" /> + android:indeterminate="true"/> </RelativeLayout> <View diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java index 8607ebfa1d5a..aa4f70c1eea9 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -9,6 +9,7 @@ import android.os.Handler; import android.support.v4.widget.DrawerLayout; import android.util.DisplayMetrics; import android.util.Log; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -21,6 +22,7 @@ import android.widget.TextView; import org.mozilla.gecko.ZoomConstraints; import org.mozilla.gecko.gfx.GeckoLayerClient; import org.mozilla.gecko.gfx.LayerController; +import org.mozilla.gecko.gfx.LayerView; import java.util.ArrayList; import java.util.List; @@ -96,6 +98,8 @@ public class LibreOfficeMainActivity extends Activity { mMainHandler = new Handler(); + LayoutInflater.from(this).setFactory(ViewFactory.getInstance()); + if (getIntent().getData() != null) { mInputFile = getIntent().getData().getEncodedPath(); } else { @@ -128,8 +132,9 @@ public class LibreOfficeMainActivity extends Activity { mLayerController = new LayerController(this); mLayerController.setZoomConstraints(new ZoomConstraints(true)); mLayerClient = new GeckoLayerClient(this); + LayerView layerView = (LayerView)findViewById(R.id.layer_view); + mLayerController.setView(layerView); mLayerController.setLayerClient(mLayerClient); - mGeckoLayout.addView(mLayerController.getView(), 0); LOKitShell.sendEvent(LOEventFactory.load(mInputFile)); } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ViewFactory.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ViewFactory.java new file mode 100644 index 000000000000..c26ad222e0d9 --- /dev/null +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ViewFactory.java @@ -0,0 +1,32 @@ +package org.libreoffice; + +import android.content.Context; +import android.util.AttributeSet; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; + +import org.mozilla.gecko.gfx.LayerView; + +public class ViewFactory implements LayoutInflater.Factory { + private static final String LOGTAG = ViewFactory.class.getSimpleName(); + private static final String LAYER_VIEW_ID = "org.mozilla.gecko.gfx.LayerView"; + private static final ViewFactory INSTANCE = new ViewFactory(); + + private ViewFactory() { + } + + public static LayoutInflater.Factory getInstance() { + return INSTANCE; + } + + @Override + public View onCreateView(String name, Context context, AttributeSet attrs) { + if (name.equals(LAYER_VIEW_ID)) { + Log.i(LOGTAG, "Creating custom Gecko view: " + name); + return new LayerView(context, attrs); + } + + return null; + } +}
\ No newline at end of file diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java index 2e6a4a0f20df..f35ee9df2599 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java @@ -69,11 +69,15 @@ public class LayerController implements PanZoomTarget { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); mViewportMetrics = new ImmutableViewportMetrics(displayMetrics); mPanZoomController = new PanZoomController(this); - mView = new LayerView(context, this); mCheckerboardShouldShowChecks = true; mZoomConstraints = new ZoomConstraints(false); } + public void setView(LayerView v) { + mView = v; + mView.connect(this); + } + public void setRoot(Layer layer) { mRootLayer = layer; } public void setLayerClient(GeckoLayerClient layerClient) { diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java index 38a09d818f61..874d10ae8be4 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java @@ -9,6 +9,7 @@ package org.mozilla.gecko.gfx; import android.content.Context; import android.graphics.Bitmap; import android.graphics.PixelFormat; +import android.util.AttributeSet; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; @@ -32,7 +33,6 @@ import java.nio.IntBuffer; public class LayerView extends SurfaceView implements SurfaceHolder.Callback { private static String LOGTAG = "GeckoLayerView"; - private Context mContext; private LayerController mController; private TouchEventHandler mTouchEventHandler; private GLController mGLController; @@ -51,18 +51,19 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback { public static final int PAINT_BEFORE_FIRST = 1; public static final int PAINT_AFTER_FIRST = 2; - - public LayerView(Context context, LayerController controller) { - super(context); + public LayerView(Context context, AttributeSet attrs) { + super(context, attrs); SurfaceHolder holder = getHolder(); holder.addCallback(this); holder.setFormat(PixelFormat.RGB_565); mGLController = new GLController(this); - mContext = context; + } + + void connect(LayerController controller) { mController = controller; - mTouchEventHandler = new TouchEventHandler(context, this, mController); + mTouchEventHandler = new TouchEventHandler(getContext(), this, mController); mRenderer = new LayerRenderer(this); mInputConnectionHandler = null; @@ -208,6 +209,10 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback { mListener = listener; } + Listener getListener() { + return mListener; + } + public GLController getGLController() { return mGLController; } @@ -267,10 +272,6 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback { private GLThread mGLThread; // Protected by this class's monitor. - /** - * Creates a Java GL thread. After this is called, the FlexibleGLSurfaceView may be used just - * like a GLSurfaceView. It is illegal to access the controller after this has been called. - */ public synchronized void createGLThread() { if (mGLThread != null) { throw new LayerViewException ("createGLThread() called with a GL thread already in place!"); @@ -282,10 +283,6 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback { notifyAll(); } - /** - * Destroys the Java GL thread. Returns a Thread that completes when the Java GL thread is - * fully shut down. - */ public synchronized Thread destroyGLThread() { // Wait for the GL thread to be started. Log.e(LOGTAG, "### Waiting for GL thread to be created..."); |