android: Use "compact_fonts" LibreOfficeKit option

For Android Viewer, set the "compact_fonts" LibreOfficeKit
option via environment variable `SAL_LOK_OPTIONS` introduced in

    Change-Id: I3dc9f5de876def6e4afc09a43105b1740f7c621f
    Author: Michael Meeks <michael.meeks@collabora.com>
    Date:   Fri May 17 21:25:29 2024 +0100

        lok: stop amazing waste of repeated font sizes in each font element.

and adjust the handling in `FontController` to process
the flat lists for font names and sizes that is reported
with that options set, rather than processing
font sizes for each individual font.

(See also discussion in original Gerrit change
for the distro/collabora/co-24.04 branch: [1].).

[1] https://gerrit.libreoffice.org/c/core/+/167799

Change-Id: I85734c1876d152f4f95f9182629affd6b250fdbc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167963
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
diff --git a/android/source/src/java/org/libreoffice/FontController.java b/android/source/src/java/org/libreoffice/FontController.java
index 72f35d8..211b9d6 100644
--- a/android/source/src/java/org/libreoffice/FontController.java
+++ b/android/source/src/java/org/libreoffice/FontController.java
@@ -19,8 +19,6 @@ import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

public class FontController implements AdapterView.OnItemSelectedListener {

@@ -32,7 +30,6 @@ public class FontController implements AdapterView.OnItemSelectedListener {
    private final LibreOfficeMainActivity mActivity;
    private final ArrayList<String> mFontList = new ArrayList<>();
    private final ArrayList<String> mFontSizes = new ArrayList<>();
    private final HashMap<String, ArrayList<String>> mAllFontSizes = new HashMap<>();

    private String mCurrentFontSelected = null;
    private String mCurrentFontSizeSelected = null;
@@ -210,21 +207,17 @@ public class FontController implements AdapterView.OnItemSelectedListener {

    public void parseJson(String json) {
        mFontList.clear();
        mAllFontSizes.clear();
        mFontSizes.clear();
        try {
            JSONObject jObject = new JSONObject(json);
            JSONObject jObject2 = jObject.getJSONObject("commandValues");
            Iterator<String> keys = jObject2.keys();
            ArrayList<String> fontSizes;
            while (keys.hasNext()) {
                String key = keys.next();
                mFontList.add(key);
                JSONArray array = jObject2.getJSONArray(key);
                fontSizes = new ArrayList<>();
                for (int i = 0; i < array.length(); i++) {
                    fontSizes.add(array.getString(i));
                }
                mAllFontSizes.put(key, fontSizes);
            final JSONArray fontNameArray = jObject.getJSONArray("FontNames");
            for (int i = 0; i < fontNameArray.length(); i++) {
                mFontList.add(fontNameArray.getString(i));
            }

            final JSONArray fontSizeArray = jObject.getJSONArray("FontSizes");
            for (int i = 0; i < fontSizeArray.length(); i++) {
                mFontSizes.add(fontSizeArray.getString(i));
            }
        } catch (JSONException e) {
            e.printStackTrace();
@@ -405,18 +398,6 @@ public class FontController implements AdapterView.OnItemSelectedListener {
            mCurrentFontSelected = fontName;
            spinner.setSelection(position,false);
        }

        resetFontSizes(fontName);
    }

    private void resetFontSizes(String fontName) {
        if (mAllFontSizes.get(fontName) != null) {
            mFontSizes.clear();
            mFontSizes.addAll(mAllFontSizes.get(fontName));
            Spinner spinner = mActivity.findViewById(R.id.font_size_spinner);
            ArrayAdapter<?> arrayAdapter = (ArrayAdapter<?>)spinner.getAdapter();
            arrayAdapter.notifyDataSetChanged();
        }
    }

    public void selectFontSize(final String fontSize) {
diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
index 5d1cf12..c8a0552 100644
--- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
@@ -64,6 +64,7 @@ class LOKitTileProvider implements TileProvider {
        mMessageCallback = messageCallback;

        LibreOfficeKit.putenv("SAL_LOG=+WARN+INFO");
        LibreOfficeKit.putenv("SAL_LOK_OPTIONS=compact_fonts");
        LibreOfficeKit.init(mContext);

        mOffice = new Office(LibreOfficeKit.getLibreOfficeKitHandle());