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

Christian Lohmaier lohmaier+LibreOffice at googlemail.com
Mon May 11 07:01:17 PDT 2015


 android/experimental/LOAndroid3/AndroidManifest.xml.in                                 |    5 
 android/experimental/LOAndroid3/res/menu/main.xml                                      |   78 +++++-----
 android/experimental/LOAndroid3/res/menu/view_menu.xml                                 |    3 
 android/experimental/LOAndroid3/res/values/strings.xml                                 |    6 
 android/experimental/LOAndroid3/res/xml/libreoffice_preferences.xml                    |   49 +++---
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java               |    2 
 android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java  |   22 ++
 android/experimental/LOAndroid3/src/java/org/libreoffice/SettingsActivity.java         |   37 ++++
 android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java        |    6 
 android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java |    4 
 10 files changed, 156 insertions(+), 56 deletions(-)

New commits:
commit e7473c692cad4c19f1d9eadd2547df4a50875baf
Author: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
Date:   Tue May 5 22:20:47 2015 +0200

    editing/experimental mode as user-preference (Android Viewer)
    
    also exposes the other preferences (default document filter, default
    sorting) in a default settings dialog
    
    Change-Id: I7a4080f70f5727bfb2fabe8d8f57cb5b8337481f
    Reviewed-on: https://gerrit.libreoffice.org/15638
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>

diff --git a/android/experimental/LOAndroid3/AndroidManifest.xml.in b/android/experimental/LOAndroid3/AndroidManifest.xml.in
index 040246da..9364ea8 100644
--- a/android/experimental/LOAndroid3/AndroidManifest.xml.in
+++ b/android/experimental/LOAndroid3/AndroidManifest.xml.in
@@ -90,6 +90,11 @@
             </intent-filter>
         </activity>
 
+        <activity
+            android:name=".SettingsActivity"
+            android:label="@string/app_name_settings">
+        </activity>
+
         <!-- Document Browser Activity -->
         <activity android:name=".ui.LibreOfficeUIActivity"
                   android:label="@string/app_name"
diff --git a/android/experimental/LOAndroid3/res/menu/main.xml b/android/experimental/LOAndroid3/res/menu/main.xml
index 1ab1ef1..bf19105 100644
--- a/android/experimental/LOAndroid3/res/menu/main.xml
+++ b/android/experimental/LOAndroid3/res/menu/main.xml
@@ -3,46 +3,52 @@
     xmlns:tools="http://schemas.android.com/tools"
     tools:context="org.libreoffice.MainActivity">
 
-
-    <item android:id="@+id/action_bold"
-          android:title="@string/action_bold"
-          android:icon="@drawable/action_bold"
-          android:orderInCategory="100"
-          app:showAsAction="always"/>
-
-    <item android:id="@+id/action_italic"
-          android:title="@string/action_italic"
-          android:icon="@drawable/action_italic"
-          android:orderInCategory="100"
-          app:showAsAction="always"/>
-
-    <item android:id="@+id/action_underline"
-          android:title="@string/action_underline"
-          android:icon="@drawable/action_underline"
-          android:orderInCategory="100"
-          app:showAsAction="always"/>
-
-    <item android:id="@+id/action_strikeout"
-          android:title="@string/action_strikeout"
-          android:icon="@drawable/action_strikeout"
-          android:orderInCategory="100"
-          app:showAsAction="always"/>
-
-    <item android:id="@+id/action_keyboard"
-          android:title="@string/action_keyboard"
-          android:icon="@drawable/ic_format_keyboard_grey600_24dp"
-          android:orderInCategory="100"
-          app:showAsAction="always"/>
-
-    <item android:id="@+id/action_save"
-        android:title="@string/action_save"
-        android:orderInCategory="100" />
+    <group android:id="@+id/group_edit_actions"
+           android:visible="false">
+        <item android:id="@+id/action_bold"
+              android:title="@string/action_bold"
+              android:icon="@drawable/action_bold"
+              android:orderInCategory="100"
+              app:showAsAction="always"/>
+
+        <item android:id="@+id/action_italic"
+              android:title="@string/action_italic"
+              android:icon="@drawable/action_italic"
+              android:orderInCategory="100"
+              app:showAsAction="always"/>
+
+        <item android:id="@+id/action_underline"
+              android:title="@string/action_underline"
+              android:icon="@drawable/action_underline"
+              android:orderInCategory="100"
+              app:showAsAction="always"/>
+
+        <item android:id="@+id/action_strikeout"
+              android:title="@string/action_strikeout"
+              android:icon="@drawable/action_strikeout"
+              android:orderInCategory="100"
+              app:showAsAction="always"/>
+
+        <item android:id="@+id/action_keyboard"
+              android:title="@string/action_keyboard"
+              android:icon="@drawable/ic_format_keyboard_grey600_24dp"
+              android:orderInCategory="100"
+              app:showAsAction="always"/>
+
+        <item android:id="@+id/action_save"
+            android:title="@string/action_save"
+            android:orderInCategory="100" />
+    </group>
 
     <item android:id="@+id/action_parts"
           android:title="@string/action_parts"
           android:orderInCategory="100" />
 
     <item android:id="@+id/action_about"
-        android:title="@string/action_about"
-        android:orderInCategory="100" />
+          android:title="@string/action_about"
+          android:orderInCategory="100" />
+
+    <item android:id="@+id/action_settings"
+          android:title="@string/action_settings"
+          android:orderInCategory="100" />
 </menu>
diff --git a/android/experimental/LOAndroid3/res/menu/view_menu.xml b/android/experimental/LOAndroid3/res/menu/view_menu.xml
index 37a39b1..32825b5 100644
--- a/android/experimental/LOAndroid3/res/menu/view_menu.xml
+++ b/android/experimental/LOAndroid3/res/menu/view_menu.xml
@@ -13,4 +13,7 @@
     <item android:id="@+id/action_about"
           android:title="@string/action_about"
           android:orderInCategory="100"/>
+    <item android:id="@+id/action_settings"
+          android:title="@string/action_settings"
+          android:orderInCategory="100"/>
 </menu>
diff --git a/android/experimental/LOAndroid3/res/values/strings.xml b/android/experimental/LOAndroid3/res/values/strings.xml
index b697c47..e43c5a5 100644
--- a/android/experimental/LOAndroid3/res/values/strings.xml
+++ b/android/experimental/LOAndroid3/res/values/strings.xml
@@ -2,6 +2,7 @@
 <resources>
 
     <string name="app_name">LibreOffice Viewer</string>
+    <string name="app_name_settings">LibreOffice Viewer Settings</string>
 
     <string name="app_about_name"><b>LibreOffice Viewer \'Beta\'</b></string>
     <string name="app_version">Version: $VERSION\nBuild ID: $BUILDID</string>
@@ -31,9 +32,14 @@
     <!-- Pref keys as resources ; Not currently used -->
     <string name="EXPLORER_VIEW_TYPE_KEY">EXPLORER_VIEW_TYPE</string>
     <string name="CURRENT_DIRECTORY_KEY">CURRENT_DIRECTORY</string>
+    <string name="pref_category_explorer">Explorer View Defaults</string>
+    <string name="pref_category_general">General</string>
+    <string name="pref_experimental_editing">Experimental Mode</string>
+    <string name="pref_experimental_editing_summary">Enable the experimental editing mode. Use at your own risk.</string>
 
     <string name="action_about">About</string>
     <string name="action_parts">Parts</string>
+    <string name="action_settings">Settings</string>
     <string name="open">Open</string>
     <string name="share">Share</string>
     <string name="share_via">Share via</string>
diff --git a/android/experimental/LOAndroid3/res/xml/libreoffice_preferences.xml b/android/experimental/LOAndroid3/res/xml/libreoffice_preferences.xml
index f6da06f..17256b7 100644
--- a/android/experimental/LOAndroid3/res/xml/libreoffice_preferences.xml
+++ b/android/experimental/LOAndroid3/res/xml/libreoffice_preferences.xml
@@ -1,21 +1,32 @@
 <?xml version="1.0" encoding="utf-8"?>
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
-    <ListPreference
-        android:title="Default File Filter"
-        android:summary="Set which files to show by default"
-        android:entries="@array/FilterTypeNames"
-        android:entryValues="@array/FilterTypeStringValues"
-        android:key="FILTER_MODE"/>
-    <ListPreference
-        android:summary="Select how to order files; A-Z, by size, etc."
-        android:key="SORT_MODE"
-        android:title="File Order" android:entries="@array/SortModeNames" android:entryValues="@array/SortModeStringValues"/>
-    <ListPreference
-        android:entries="@array/ViewModeNames"
-        android:entryValues="@array/ViewModeStringValues"
-        android:title="Default File Explorer View"
-        android:key="EXPLORER_VIEW_TYPE"
-        android:summary="View files as a grid or in a list. #not functional, yet."/>
-
-
-</PreferenceScreen>
\ No newline at end of file
+    <PreferenceCategory
+        android:title="@string/pref_category_explorer"
+        android:key="PREF_CATEGORY_EXPLORER">
+        <ListPreference
+            android:title="Default File Filter"
+            android:summary="Set which files to show by default"
+            android:entries="@array/FilterTypeNames"
+            android:entryValues="@array/FilterTypeStringValues"
+            android:key="FILTER_MODE"/>
+        <ListPreference
+            android:summary="Select how to order files; A-Z, by size, etc."
+            android:key="SORT_MODE"
+            android:title="File Order" android:entries="@array/SortModeNames" android:entryValues="@array/SortModeStringValues"/>
+        <ListPreference
+            android:entries="@array/ViewModeNames"
+            android:entryValues="@array/ViewModeStringValues"
+            android:title="Default File Explorer View"
+            android:key="EXPLORER_VIEW_TYPE"
+            android:summary="View files as a grid or in a list. #not functional, yet."/>
+    </PreferenceCategory>
+    <PreferenceCategory
+        android:title="@string/pref_category_general"
+        android:key="PREF_CATEGORY_GENERAL">
+        <CheckBoxPreference
+            android:title="@string/pref_experimental_editing"
+            android:key="ENABLE_EXPERIMENTAL"
+            android:summary="@string/pref_experimental_editing_summary"
+            android:defaultValue="false" />
+    </PreferenceCategory>
+</PreferenceScreen>
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
index d76e672..5c8ce78 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
@@ -74,7 +74,7 @@ public class LOKitShell {
     }
 
     public static boolean isEditingEnabled() {
-        return true;
+        return LibreOfficeMainActivity.isExperimentalMode();
     }
 
     public static LayerView getLayerView() {
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 2f47b18..822934f 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -4,8 +4,10 @@ import android.app.AlertDialog;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.content.Intent;
 import android.os.Bundle;
 import android.os.Handler;
+import android.preference.PreferenceManager;
 import android.support.v4.widget.DrawerLayout;
 import android.support.v7.app.ActionBarActivity;
 import android.support.v7.widget.Toolbar;
@@ -39,12 +41,15 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
 
     private static final String LOGTAG = "LibreOfficeMainActivity";
     private static final String DEFAULT_DOC_PATH = "/assets/example.odt";
+    private static final String ENABLE_EXPERIMENTAL_PREFS_KEY = "ENABLE_EXPERIMENTAL";
 
     public static LibreOfficeMainActivity mAppContext;
 
     private static GeckoLayerClient mLayerClient;
     private static LOKitThread sLOKitThread;
 
+    private static boolean mEnableEditing;
+
     public Handler mMainHandler;
 
     private DrawerLayout mDrawerLayout;
@@ -65,6 +70,10 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
         return mLayerClient;
     }
 
+    public static boolean isExperimentalMode() {
+        return mEnableEditing;
+    }
+
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         // Inflate the menu; this adds items to the action bar if it is present.
@@ -107,6 +116,9 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
             case R.id.action_parts:
                 mDrawerLayout.openDrawer(mDrawerList);
                 return true;
+            case R.id.action_settings:
+                startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
+                return true;
         }
         return super.onOptionsItemSelected(item);
     }
@@ -118,6 +130,7 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
         // Do the same in case the drawer is locked.
         boolean isDrawerLocked = mDrawerLayout.getDrawerLockMode(mDrawerList) != DrawerLayout.LOCK_MODE_UNLOCKED;
         menu.findItem(R.id.action_parts).setVisible(!isDrawerOpen && !isDrawerLocked);
+        menu.setGroupVisible(R.id.group_edit_actions, mEnableEditing);
         return super.onPrepareOptionsMenu(menu);
     }
 
@@ -127,6 +140,9 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
         mAppContext = this;
         super.onCreate(savedInstanceState);
 
+        mEnableEditing = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
+                                          .getBoolean(ENABLE_EXPERIMENTAL_PREFS_KEY, false);
+
         mMainHandler = new Handler();
 
         setContentView(R.layout.activity_main);
@@ -226,6 +242,12 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
     protected void onResume() {
         super.onResume();
         Log.i(LOGTAG, "onResume..");
+        // check for config change
+        boolean bEnableExperimental = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean(ENABLE_EXPERIMENTAL_PREFS_KEY, false);
+        if (bEnableExperimental != mEnableEditing) {
+            mEnableEditing = bEnableExperimental;
+            invalidateOptionsMenu();
+        }
     }
 
     @Override
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/SettingsActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/SettingsActivity.java
new file mode 100644
index 0000000..c453798
--- /dev/null
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/SettingsActivity.java
@@ -0,0 +1,37 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+
+import org.libreoffice.R;
+
+public class SettingsActivity extends Activity {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        // Display the fragment as the main content.
+        getFragmentManager().beginTransaction()
+            .replace(android.R.id.content, new SettingsFragment())
+            .commit();
+    }
+
+    public static class SettingsFragment extends PreferenceFragment {
+        @Override
+        public void onCreate(Bundle savedInstanceState) {
+            super.onCreate(savedInstanceState);
+
+            addPreferencesFromResource(R.xml.libreoffice_preferences);
+        }
+    }
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java
index dde1a61..abd1f3e 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java
@@ -102,6 +102,9 @@ public class ToolbarController {
      * Change the toolbar to edit mode.
      */
     void switchToEditMode() {
+        if (!LOKitShell.isEditingEnabled())
+            return;
+
         // Ensure the change is done on UI thread
         LOKitShell.getMainHandler().post(new Runnable() {
             @Override
@@ -118,6 +121,9 @@ public class ToolbarController {
      * Change the toolbar to view mode.
      */
     void switchToViewMode() {
+        if (!LOKitShell.isEditingEnabled())
+            return;
+
         // Ensure the change is done on UI thread
         LOKitShell.getMainHandler().post(new Runnable() {
             @Override
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 938a259..7ac40e4 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -51,6 +51,7 @@ import android.widget.Toast;
 import org.libreoffice.LOAbout;
 import org.libreoffice.LibreOfficeMainActivity;
 import org.libreoffice.R;
+import org.libreoffice.SettingsActivity;
 import org.libreoffice.storage.DocumentProviderFactory;
 import org.libreoffice.storage.IDocumentProvider;
 import org.libreoffice.storage.IFile;
@@ -454,6 +455,9 @@ public class LibreOfficeUIActivity extends ActionBarActivity implements ActionBa
             case R.id.action_about:
                 mAbout.showAbout();
                 return true;
+            case R.id.action_settings:
+                startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
+                return true;
             default:
                 return super.onOptionsItemSelected(item);
         }


More information about the Libreoffice-commits mailing list