[Libreoffice-commits] core.git: 3 commits - android/experimental

Jan Holesovsky kendy at collabora.com
Thu Oct 9 11:58:46 PDT 2014


 android/experimental/LOAndroid3/res/layout/about.xml                                  |   22 ------
 android/experimental/LOAndroid3/res/values/strings.xml                                |    5 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java                 |    6 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java          |    4 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java             |   19 +++--
 android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java |   34 ++++------
 6 files changed, 42 insertions(+), 48 deletions(-)

New commits:
commit 83386129f5be002f2649db81bba4c468c7f6e4de
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Oct 9 20:50:35 2014 +0200

    android: Fix the application lifecycle.
    
    Now onStart() loads the file, and onStop() closes it again.  Fixes the case
    when the user leaves the app by pressing Home, and starts it again;
    previously, this caused a race.
    
    Change-Id: I493a76eaf5e8ca8a68b53f70c7acd09b638f7e11

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
index 3f39257..d9f3219 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
@@ -13,7 +13,8 @@ public class LOEvent {
     public static final int DRAW = 4;
     public static final int CHANGE_PART = 5;
     public static final int LOAD = 6;
-    public static final int REDRAW = 7;
+    public static final int CLOSE = 7;
+    public static final int REDRAW = 8;
 
     public int mType;
     private ImmutableViewportMetrics mViewportMetrics;
@@ -58,6 +59,9 @@ public class LOEvent {
     }
 
     public String getTypeString() {
+        if (mTypeString == null) {
+            return "Event type: " + mType;
+        }
         return mTypeString;
     }
 
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java
index 90a3582..a63b5db 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java
@@ -31,6 +31,10 @@ public class LOEventFactory {
         return new LOEvent(LOEvent.LOAD, inputFile);
     }
 
+    public static LOEvent close() {
+        return new LOEvent(LOEvent.CLOSE);
+    }
+
     public static LOEvent redraw() {
         return new LOEvent(LOEvent.REDRAW);
     }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index 528f419..e5765e6 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -61,7 +61,7 @@ public class LOKitThread extends Thread {
         LOKitShell.hideProgressSpinner();
     }
 
-    private boolean load(String filename) {
+    private boolean loadDocument(String filename) {
         if (mApplication == null) {
             mApplication = LibreOfficeMainActivity.mAppContext;
         }
@@ -69,10 +69,6 @@ public class LOKitThread extends Thread {
         mController = mApplication.getLayerController();
         mLayerClient = mApplication.getLayerClient();
 
-        if (mTileProvider != null) {
-            mTileProvider.close();
-        }
-
         mTileProvider = TileProviderFactory.create(mController, filename);
         boolean isReady = mTileProvider.isReady();
         if (isReady) {
@@ -82,9 +78,16 @@ public class LOKitThread extends Thread {
             refresh();
             LOKitShell.hideProgressSpinner();
         }
+
         return isReady;
     }
 
+    public void closeDocument() {
+        if (mTileProvider != null) {
+            mTileProvider.close();
+        }
+    }
+
     public void run() {
         try {
             while (true) {
@@ -95,9 +98,13 @@ public class LOKitThread extends Thread {
     }
 
     private void processEvent(LOEvent event) {
+        Log.i(LOGTAG, "processEvent: " + event.getTypeString());
         switch (event.mType) {
             case LOEvent.LOAD:
-                load(event.getFilename());
+                loadDocument(event.getFilename());
+                break;
+            case LOEvent.CLOSE:
+                closeDocument();
                 break;
             case LOEvent.VIEWPORT:
                 mViewportMetrics = event.getViewport();
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 1778e35..6ca7b4d 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -136,8 +136,6 @@ public class LibreOfficeMainActivity extends Activity {
         LayerView layerView = (LayerView) findViewById(R.id.layer_view);
         mLayerController.setView(layerView);
         mLayerController.setLayerClient(mLayerClient);
-
-        LOKitShell.sendEvent(LOEventFactory.load(mInputFile));
     }
 
     @Override
@@ -156,11 +154,13 @@ public class LibreOfficeMainActivity extends Activity {
     protected void onStart() {
         Log.i(LOGTAG, "onStart..");
         super.onStart();
+        LOKitShell.sendEvent(LOEventFactory.load(mInputFile));
     }
 
     @Override
     protected void onStop() {
         Log.i(LOGTAG, "onStop..");
+        LOKitShell.sendEvent(LOEventFactory.close());
         super.onStop();
     }
 
@@ -199,21 +199,19 @@ public class LibreOfficeMainActivity extends Activity {
 
         builder.setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
             @Override
-            public void onClick(View view) {
-                Intent intent = new Intent(view.getContext(), LibreOfficeMainActivity.class);
-                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-                intent.setData(Uri.parse("file:///assets/license.txt"));
-                startActivity(intent);
+            public void onClick(DialogInterface dialog, int id) {
+                LOKitShell.sendEvent(LOEventFactory.close());
+                LOKitShell.sendEvent(LOEventFactory.load("/assets/license.txt"));
+                dialog.dismiss();
             }
         });
 
         builder.setPositiveButton(R.string.about_notice, new DialogInterface.OnClickListener() {
             @Override
-            public void onClick(View view) {
-                Intent intent = new Intent(view.getContext(), LibreOfficeMainActivity.class);
-                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-                intent.setData(Uri.parse("file:///assets/notice.txt"));
-                startActivity(intent);
+            public void onClick(DialogInterface dialog, int id) {
+                LOKitShell.sendEvent(LOEventFactory.close());
+                LOKitShell.sendEvent(LOEventFactory.load("/assets/notice.txt"));
+                dialog.dismiss();
             }
         });
 
commit 2b85db8b6b7cbdef8e8a8645c33d122ef987a27d
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Oct 9 20:49:36 2014 +0200

    android: Simplify the About dialog creation.
    
    Change-Id: I40fb007e8f672e1c5ff4e6e23c043b7305e726a9

diff --git a/android/experimental/LOAndroid3/res/layout/about.xml b/android/experimental/LOAndroid3/res/layout/about.xml
index ec014a0..06c5bfe 100644
--- a/android/experimental/LOAndroid3/res/layout/about.xml
+++ b/android/experimental/LOAndroid3/res/layout/about.xml
@@ -25,24 +25,4 @@
         android:textColor="@android:color/secondary_text_light"
         android:textSize="18dip"/>
 
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                  android:layout_width="match_parent"
-                  android:layout_height="wrap_content"
-                  android:orientation="horizontal">
-
-        <Button
-            android:id="@+id/about_license_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginRight="12dp"
-            android:text="License"/>
-
-        <Button
-            android:id="@+id/about_notice_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginRight="12dp"
-            android:text="Notice"/>
-    </LinearLayout>
-
-</LinearLayout>
\ No newline at end of file
+</LinearLayout>
diff --git a/android/experimental/LOAndroid3/res/values/strings.xml b/android/experimental/LOAndroid3/res/values/strings.xml
index f913e5e..c98c0cd 100644
--- a/android/experimental/LOAndroid3/res/values/strings.xml
+++ b/android/experimental/LOAndroid3/res/values/strings.xml
@@ -4,9 +4,12 @@
     <string name="app_name">LibreOffice Viewer</string>
 
     <string name="app_about_name"><b>LibreOffice Viewer \'Beta\'</b></string>
-    <string name="app_description">LibreOffice Viewer is a document viewer based on LibreOffice</string>
+    <string name="app_description">LibreOffice Viewer is a document viewer based on LibreOffice.</string>
     <string name="app_credits">http://www.libreoffice.org</string>
 
+    <string name="about_license">License</string>
+    <string name="about_notice">Notice</string>
+
     <string name="browser_app_name">LibreOffice Browser</string>
     <string name="menu_search">Search</string>
     <string name="list_view">List</string>
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 1df149a..1778e35 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -196,11 +196,8 @@ public class LibreOfficeMainActivity extends Activity {
         builder.setIcon(R.drawable.lo_icon);
         builder.setTitle(R.string.app_name);
         builder.setView(messageView);
-        builder.create();
-        builder.show();
 
-        Button licenseButton = (Button) messageView.findViewById(R.id.about_license_button);
-        licenseButton.setOnClickListener(new View.OnClickListener() {
+        builder.setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
             @Override
             public void onClick(View view) {
                 Intent intent = new Intent(view.getContext(), LibreOfficeMainActivity.class);
@@ -210,8 +207,7 @@ public class LibreOfficeMainActivity extends Activity {
             }
         });
 
-        Button noticeButton = (Button) messageView.findViewById(R.id.about_notice_button);
-        noticeButton.setOnClickListener(new View.OnClickListener() {
+        builder.setPositiveButton(R.string.about_notice, new DialogInterface.OnClickListener() {
             @Override
             public void onClick(View view) {
                 Intent intent = new Intent(view.getContext(), LibreOfficeMainActivity.class);
@@ -221,6 +217,8 @@ public class LibreOfficeMainActivity extends Activity {
             }
         });
 
+        AlertDialog dialog = builder.create();
+        dialog.show();
     }
 
     public void showProgressSpinner() {
commit 05e5da6ad085091f8c392502cd230273e6688aea
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Oct 9 20:46:43 2014 +0200

    android: Fix typo.
    
    Change-Id: Ie2a321f1d8461d9fa665be11a8e5085c24ad032b

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index c5ecccb..1df149a 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -155,7 +155,7 @@ public class LibreOfficeMainActivity extends Activity {
     @Override
     protected void onStart() {
         Log.i(LOGTAG, "onStart..");
-        super.onStop();
+        super.onStart();
     }
 
     @Override


More information about the Libreoffice-commits mailing list