diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-06-30 23:34:15 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-07-01 09:12:21 +0200 |
commit | b046b687f9caa71db29ce16e0d211d530648d141 (patch) | |
tree | f81fe55cc2c2f5380023e8a5f85dd78ace858c85 /android | |
parent | libreofficekit JNI for Android (diff) | |
download | core-b046b687f9caa71db29ce16e0d211d530648d141.tar.gz core-b046b687f9caa71db29ce16e0d211d530648d141.zip |
lok bootstrap: nicer function names, clean-up
+ prevent lokandroid JNI functions to be removed from the library
+ basic use of lok Office / Document in LibreOfficeMainActivity
Change-Id: I7bfe53738cf821b2270ab3e024cc506a7cff42f0
Diffstat (limited to 'android')
-rw-r--r-- | android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java (renamed from android/Bootstrap/src/org/libreoffice/android/LibreOfficeKit.java) | 77 | ||||
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java | 44 |
2 files changed, 40 insertions, 81 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/android/LibreOfficeKit.java b/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java index 58d6c500a17f..c76c0fd7cbaa 100644 --- a/android/Bootstrap/src/org/libreoffice/android/LibreOfficeKit.java +++ b/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java @@ -7,7 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.libreoffice.android; +package org.libreoffice.kit; import android.app.Activity; import android.content.pm.ApplicationInfo; @@ -21,6 +21,8 @@ import java.util.Arrays; // final because subclassing would be meaningless. public final class LibreOfficeKit { + private long handle; + // private constructor because instantiating would be meaningless private LibreOfficeKit() { @@ -33,88 +35,59 @@ public final class LibreOfficeKit // System.loadLibrary() and Android's JNI works only to such libraries, it // seems. - private static native boolean init(String dataDir, - String cacheDir, - String apkFile); + private static native boolean initializeNative(String dataDir, String cacheDir, String apkFile); -/* - // Wrapper for getpid() - public static native int getpid(); + public static native long getLibreOfficeKitHandle(); - // Wrapper for system() - public static native void system(String cmdline); -*/ // Wrapper for putenv() public static native void putenv(String string); -/* - // A wrapper for InitVCL() in libvcl (svmain.cxx), called indirectly - // through the lo-bootstrap library - public static native void initVCL(); - - // A wrapper for osl_setCommandArgs(). Before calling - // osl_setCommandArgs(), argv[0] is prefixed with the parent directory of - // where the lo-bootstrap library is. - public static native void setCommandArgs(String[] argv); -*/ + // A method that starts a thread to redirect stdout and stderr writes to // the Android logging mechanism, or stops the redirection. - public static native void redirect_stdio(boolean state); -/* - // The DIB returned by css.awt.XBitmap.getDIB is in BGR_888 form, at least - // for Writer documents. We need it in Android's Bitmap.Config.ARGB_888 - // format, which actually is RGBA_888, whee... At least in Android 4.0.3, - // at least on my device. No idea if it is always like that or not, the - // documentation sucks. - public static native void twiddle_BGR_to_RGBA(byte[] source, int offset, int width, int height, ByteBuffer destination); - - public static native void force_full_alpha_array(byte[] array, int offset, int length); - - public static native void force_full_alpha_bb(ByteBuffer buffer, int offset, int length); - - public static native long new_byte_buffer_wrapper(ByteBuffer bbuffer); + public static native void redirectStdio(boolean state); - public static native void delete_byte_buffer_wrapper(long bbw); -*/ - - static boolean init_done = false; + static boolean initializeDone = false; // This init() method should be called from the upper Java level of // LO-based apps. public static synchronized void init(Activity activity) { - if (init_done) + if (initializeDone) return; String dataDir = null; - ApplicationInfo ai = activity.getApplicationInfo(); - dataDir = ai.dataDir; + ApplicationInfo applicationInfo = activity.getApplicationInfo(); + dataDir = applicationInfo.dataDir; Log.i(TAG, String.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir)); - redirect_stdio(true); + redirectStdio(true); + + String cacheDir = activity.getApplication().getCacheDir().getAbsolutePath(); + String apkFile = activity.getApplication().getPackageResourcePath(); - if (!init(dataDir, - activity.getApplication().getCacheDir().getAbsolutePath(), - activity.getApplication().getPackageResourcePath())) + if (!initializeNative(dataDir, cacheDir, apkFile)) { return; + } // If we notice that a fonts.conf file was extracted, automatically // set the FONTCONFIG_FILE env var. - InputStream i; + InputStream inputStream = null; try { - i = activity.getAssets().open("unpack/etc/fonts/fonts.conf"); - } - catch (java.io.IOException e) { - i = null; + inputStream = activity.getAssets().open("unpack/etc/fonts/fonts.conf"); + } catch (java.io.IOException exception) { } + putenv("OOO_DISABLE_RECOVERY=1"); - if (i != null) + + if (inputStream != null) { putenv("FONTCONFIG_FILE=" + dataDir + "/etc/fonts/fonts.conf"); + } // TMPDIR is used by osl_getTempDirURL() putenv("TMPDIR=" + activity.getCacheDir().getAbsolutePath()); - init_done = true; + initializeDone = true; } // Now with static loading we always have all native code in one native diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java index a4ae79c5882b..2345aea1f58b 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -11,12 +11,16 @@ import android.view.MotionEvent; import android.view.View; import android.widget.LinearLayout; import android.widget.RelativeLayout; +import android.os.Environment; +import java.io.File; import org.mozilla.gecko.gfx.GeckoSoftwareLayerClient; import org.mozilla.gecko.gfx.LayerController; import org.mozilla.gecko.gfx.LayerView; -import org.libreoffice.android.LibreOfficeKit; +import org.libreoffice.kit.LibreOfficeKit; +import org.libreoffice.kit.Office; +import org.libreoffice.kit.Document; import com.sun.star.frame.XComponentLoader; import com.sun.star.lang.XMultiComponentFactory; @@ -76,48 +80,30 @@ public class LibreOfficeMainActivity extends Activity { try { // enable debugging messages as the first thing LibreOfficeKit.putenv("SAL_LOG=+WARN+INFO-INFO.legacy.osl"); - LibreOfficeKit.init(this); - setContentView(R.layout.activity_main); - - Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate"); - - /* - String input = "/assets/test1.odt"; - - String[] argv = { "lo-document-loader", input }; - - LibreOfficeKit.setCommandArgs(argv); - - Bootstrap.initVCL(); + Log.w(LOGTAG, "LOK Handle:" + handle); + Office office = new Office(LibreOfficeKit.getLibreOfficeKitHandle()); - context = com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext(); + File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); + String input = file.getPath() + "/test.odt"; + Document document = office.documentLoad(input); + if (document == null) { + Log.w(LOGTAG, "LOK Document error:" + office.getErrorNative()); + } - Log.i(LOGTAG, "context is" + (context!=null ? " not" : "") + " null"); - - mcf = context.getServiceManager(); - - Log.i(LOGTAG, "mcf is" + (mcf!=null ? " not" : "") + " null"); - - Object desktop = mcf.createInstanceWithContext("com.sun.star.frame.Desktop", context); - Log.i(LOGTAG, "desktop is" + (desktop!=null ? " not" : "") + " null"); - - componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop); - Log.i(LOGTAG, "componentLoader is" + (componentLoader!=null ? " not" : "") + " null"); - */ } catch (Exception e) { e.printStackTrace(System.err); - //finish(); + finish(); } setContentView(R.layout.activity_main); + Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate"); // setup gecko layout mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout); mMainLayout = (LinearLayout) findViewById(R.id.main_layout); - if (mLayerController == null) { mLayerController = new LayerController(this); |