[Libreoffice-commits] online.git: android/lib loleaflet/src

Jan Holesovsky (via logerrit) logerrit at kemper.freedesktop.org
Sat Feb 29 10:04:00 UTC 2020


 android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java     |   78 ++++---
 android/lib/src/main/java/org/libreoffice/androidlib/ProgressDialog.java |  105 ++++++++++
 android/lib/src/main/res/layout/lolib_dialog_loading.xml                 |   31 ++
 loleaflet/src/map/Map.js                                                 |    6 
 4 files changed, 181 insertions(+), 39 deletions(-)

New commits:
commit 0acb00fc24bbdc15f63bc36d619cd7cb2cbb9b04
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Fri Feb 28 18:30:52 2020 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Sat Feb 29 11:03:42 2020 +0100

    android: Handle the loading progress directly in the app.
    
    This way we can easily extend the "preparing for the 1st start" to the
    follow-up "loading..."
    
    It should also look better while the webview is being initialized etc.
    
    Change-Id: I8de2dd96a726fa8302df558f691b1db82c9c8e71
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/89733
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
index 4a7c23151..ef8aa9bf3 100644
--- a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
+++ b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
@@ -43,7 +43,6 @@ import android.webkit.ValueCallback;
 import android.webkit.WebChromeClient;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
-import android.widget.ProgressBar;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -114,6 +113,8 @@ public class LOActivity extends AppCompatActivity {
     private Looper nativeLooper;
     private Bundle savedInstanceState;
 
+    private ProgressDialog mProgressDialog = null;
+
     /** In case the mobile-wizard is visible, we have to intercept the Android's Back button. */
     private boolean mMobileWizardVisible = false;
 
@@ -251,7 +252,10 @@ public class LOActivity extends AppCompatActivity {
         this.savedInstanceState = savedInstanceState;
         getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
         sPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+
         setContentView(R.layout.lolib_activity_main);
+        mProgressDialog = new ProgressDialog(this);
+
         init();
     }
 
@@ -263,8 +267,7 @@ public class LOActivity extends AppCompatActivity {
             return;
         }
 
-        final AlertDialog assetsProgress = createProgressDialog(R.string.preparing_for_the_first_start_after_an_update);
-        assetsProgress.show();
+        mProgressDialog.indeterminate(R.string.preparing_for_the_first_start_after_an_update);
 
         new AsyncTask<Void, Void, Void>() {
             @Override
@@ -278,7 +281,6 @@ public class LOActivity extends AppCompatActivity {
 
             @Override
             protected void onPostExecute(Void aVoid) {
-                assetsProgress.dismiss();
                 initUI();
             }
         }.execute();
@@ -507,18 +509,16 @@ public class LOActivity extends AppCompatActivity {
 
     @Override
     protected void onPause() {
-        super.onPause();
-        Log.d(TAG, "onPause() - hinting to save, we might need to return to the doc");
-
         // A Save similar to an autosave
         if (documentLoaded)
             postMobileMessageNative("save dontTerminateEdit=true dontSaveIfUnmodified=true");
+
+        super.onPause();
+        Log.d(TAG, "onPause() - hinting to save, we might need to return to the doc");
     }
 
     @Override
     protected void onDestroy() {
-        super.onDestroy();
-        Log.i(TAG, "onDestroy() - we know we are leaving the document");
         nativeLooper.quit();
 
         // Remove the webview from the hierarchy & destroy
@@ -532,6 +532,11 @@ public class LOActivity extends AppCompatActivity {
         // than never, so let's call it from here too anyway
         documentLoaded = false;
         postMobileMessageNative("BYE");
+
+        mProgressDialog.dismiss();
+
+        super.onDestroy();
+        Log.i(TAG, "onDestroy() - we know we are leaving the document");
     }
 
     @Override
@@ -601,24 +606,9 @@ public class LOActivity extends AppCompatActivity {
         return null;
     }
 
-    /** Create the progress dialog. */
-    private AlertDialog createProgressDialog(int id) {
-        LayoutInflater inflater = this.getLayoutInflater();
-
-        View loadingView = inflater.inflate(R.layout.lolib_dialog_loading, null);
-        TextView loadingText = loadingView.findViewById(R.id.lolib_loading_dialog_text);
-        loadingText.setText(getText(id));
-
-        return new AlertDialog.Builder(LOActivity.this)
-            .setView(loadingView)
-            .setCancelable(true)
-            .create();
-    }
-
     /** Show the Saving progress and finish the app. */
     private void finishWithProgress() {
-        final AlertDialog savingProgress = createProgressDialog(R.string.saving);
-        savingProgress.show();
+        mProgressDialog.indeterminate(R.string.saving);
 
         // The 'BYE' takes a considerable amount of time, we need to post it
         // so that it starts after the saving progress is actually shown
@@ -629,12 +619,12 @@ public class LOActivity extends AppCompatActivity {
                 postMobileMessageNative("BYE");
                 copyTempBackToIntent();
 
-                runOnUiThread(new Runnable() {
+                /*runOnUiThread(new Runnable() {
                     @Override
                     public void run() {
-                        savingProgress.dismiss();
+                        mProgressDialog.dismiss();
                     }
-                });
+                });*/
 
                 finish();
             }
@@ -654,6 +644,8 @@ public class LOActivity extends AppCompatActivity {
     }
 
     private void loadDocument() {
+        mProgressDialog.determinate(R.string.loading);
+
         // setup the LOOLWSD
         ApplicationInfo applicationInfo = getApplicationInfo();
         String dataDir = applicationInfo.dataDir;
@@ -752,6 +744,31 @@ public class LOActivity extends AppCompatActivity {
                 mWebView.loadUrl("javascript:window.TheFakeWebSocket.onmessage({'data':" + message + "});");
             }
         });
+
+        // update progress bar when loading
+        if (message.startsWith("'statusindicator")) {
+            runOnUiThread(new Runnable() {
+                public void run() {
+                    // update progress bar if it exists
+                    final String statusIndicatorSetValue = "'statusindicatorsetvalue: ";
+                    if (message.startsWith(statusIndicatorSetValue)) {
+                        int start = statusIndicatorSetValue.length();
+                        int end = message.indexOf("'", start);
+
+                        int progress = 0;
+                        try {
+                            progress = Integer.parseInt(message.substring(start, end));
+                        } catch (Exception e) {
+                        }
+
+                        mProgressDialog.determinateProgress(progress);
+                    }
+                    else if (message.startsWith("'statusindicatorfinish:")) {
+                        mProgressDialog.dismiss();
+                    }
+                }
+            });
+        }
     }
 
     /**
@@ -912,8 +929,7 @@ public class LOActivity extends AppCompatActivity {
     }
 
     private void initiateSlideShow() {
-        final AlertDialog slideShowProgress = createProgressDialog(R.string.loading);
-        slideShowProgress.show();
+        mProgressDialog.indeterminate(R.string.loading);
 
         nativeHandler.post(new Runnable() {
             @Override
@@ -924,7 +940,7 @@ public class LOActivity extends AppCompatActivity {
                 LOActivity.this.runOnUiThread(new Runnable() {
                     @Override
                     public void run() {
-                        slideShowProgress.dismiss();
+                        mProgressDialog.dismiss();
                         Intent slideShowActIntent = new Intent(LOActivity.this, SlideShowActivity.class);
                         slideShowActIntent.putExtra(SlideShowActivity.SVG_URI_KEY, slideShowFileUri);
                         LOActivity.this.startActivity(slideShowActIntent);
diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/ProgressDialog.java b/android/lib/src/main/java/org/libreoffice/androidlib/ProgressDialog.java
new file mode 100644
index 000000000..39115fc29
--- /dev/null
+++ b/android/lib/src/main/java/org/libreoffice/androidlib/ProgressDialog.java
@@ -0,0 +1,105 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+package org.libreoffice.androidlib;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+/** Class to handle progress when loading, saving, or handling other time intensive operations. */
+public class ProgressDialog {
+    /** For the inflater. */
+    Activity mActivity;
+
+    /** The underlying dialog. */
+    AlertDialog mProgressDialog = null;
+
+    /** Various elements of the dialog. */
+    TextView mTextView;
+    ProgressBar mIndeterminateProgress;
+    ProgressBar mDeterminateProgress;
+
+    /** Current progress of the determinate progress bar. */
+    int mProgress = 0;
+
+    public ProgressDialog(Activity activity) {
+        mActivity = activity;
+    }
+
+    /** Set up the dialog if it does not exist; but don't show it yet. */
+    private void create() {
+        if (mProgressDialog != null)
+            return;
+
+        LayoutInflater inflater = mActivity.getLayoutInflater();
+
+        View loadingView = inflater.inflate(R.layout.lolib_dialog_loading, null);
+
+        mTextView = loadingView.findViewById(R.id.progress_dialog_text);
+        mIndeterminateProgress = loadingView.findViewById(R.id.progress_indeterminate);
+        mDeterminateProgress = loadingView.findViewById(R.id.progress_determinate);
+
+        mProgressDialog = new AlertDialog.Builder(mActivity)
+            .setView(loadingView)
+            .setCancelable(false)
+            .create();
+    }
+
+    /** Set the progress to indereterminate state. */
+    public void indeterminate(int messageId) {
+        create();
+
+        mIndeterminateProgress.setVisibility(View.VISIBLE);
+        mDeterminateProgress.setVisibility(View.INVISIBLE);
+        mTextView.setText(mActivity.getText(messageId));
+
+        mProgressDialog.show();
+    }
+
+    /** Set the progress to indereterminate state. */
+    public void determinate(int messageId) {
+        create();
+
+        mIndeterminateProgress.setVisibility(View.INVISIBLE);
+        mDeterminateProgress.setVisibility(View.VISIBLE);
+        mTextView.setText(mActivity.getText(messageId));
+
+        mProgress = 0;
+        mDeterminateProgress.setProgress(mProgress);
+
+        mProgressDialog.show();
+    }
+
+    /** Update the progress value. */
+    public void determinateProgress(int progress) {
+        if (mProgressDialog == null)
+            return;
+
+        if (mProgress > progress)
+            return;
+
+        mProgress = progress;
+        mDeterminateProgress.setProgress(mProgress);
+    }
+
+    /** Kill the dialog. */
+    public void dismiss() {
+        if (mProgressDialog == null)
+            return;
+
+        mProgressDialog.dismiss();
+        mProgressDialog = null;
+    }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/android/lib/src/main/res/layout/lolib_dialog_loading.xml b/android/lib/src/main/res/layout/lolib_dialog_loading.xml
index db4825bb7..b0fef6554 100644
--- a/android/lib/src/main/res/layout/lolib_dialog_loading.xml
+++ b/android/lib/src/main/res/layout/lolib_dialog_loading.xml
@@ -4,16 +4,31 @@
     android:layout_height="wrap_content"
     android:orientation="horizontal"
     android:padding="20dp">
-    <ProgressBar
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:layout_weight="1" />
+
+    <FrameLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content">
+
+        <ProgressBar
+            android:id="@+id/progress_indeterminate"
+            android:layout_width="50dp"
+            android:layout_height="50dp" />
+
+        <ProgressBar
+            android:id="@+id/progress_determinate"
+            style="?android:attr/progressBarStyleHorizontal"
+            android:layout_width="50dp"
+            android:layout_height="50dp"
+            android:indeterminate="false"
+            android:min="0"
+            android:max="100"
+            android:visibility="invisible" />
+    </FrameLayout>
 
     <TextView
-        android:id="@+id/lolib_loading_dialog_text"
+        android:id="@+id/progress_dialog_text"
         android:layout_width="0dp"
         android:layout_height="match_parent"
-        android:layout_weight="4"
-        android:gravity="center"
-        android:text="@string/loading" />
+        android:layout_weight="1"
+        android:gravity="center"/>
 </LinearLayout>
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 4aa7fd7c7..a4804775d 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -441,6 +441,9 @@ L.Map = L.Evented.extend({
 	},
 
 	showBusy: function(label, bar) {
+		if (window.ThisIsTheAndroidApp)
+			return;
+
 		// If document is already loaded, ask the toolbar widget to show busy
 		// status on the bottom statusbar
 		if (this._docLayer) {
@@ -451,6 +454,9 @@ L.Map = L.Evented.extend({
 	},
 
 	hideBusy: function () {
+		if (window.ThisIsTheAndroidApp)
+			return;
+
 		this.fire('hidebusy');
 		this._progressBar.end(this);
 	},


More information about the Libreoffice-commits mailing list