From e7473c692cad4c19f1d9eadd2547df4a50875baf Mon Sep 17 00:00:00 2001 From: Christian Lohmaier Date: Tue, 5 May 2015 22:20:47 +0200 Subject: 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 Reviewed-by: Christian Lohmaier --- .../experimental/LOAndroid3/AndroidManifest.xml.in | 5 ++ android/experimental/LOAndroid3/res/menu/main.xml | 78 ++++++++++++---------- .../experimental/LOAndroid3/res/menu/view_menu.xml | 3 + .../experimental/LOAndroid3/res/values/strings.xml | 6 ++ .../LOAndroid3/res/xml/libreoffice_preferences.xml | 49 ++++++++------ .../src/java/org/libreoffice/LOKitShell.java | 2 +- .../org/libreoffice/LibreOfficeMainActivity.java | 22 ++++++ .../src/java/org/libreoffice/SettingsActivity.java | 37 ++++++++++ .../java/org/libreoffice/ToolbarController.java | 6 ++ .../org/libreoffice/ui/LibreOfficeUIActivity.java | 4 ++ 10 files changed, 156 insertions(+), 56 deletions(-) create mode 100644 android/experimental/LOAndroid3/src/java/org/libreoffice/SettingsActivity.java (limited to 'android') diff --git a/android/experimental/LOAndroid3/AndroidManifest.xml.in b/android/experimental/LOAndroid3/AndroidManifest.xml.in index 040246da1bf8..9364ea837a68 100644 --- a/android/experimental/LOAndroid3/AndroidManifest.xml.in +++ b/android/experimental/LOAndroid3/AndroidManifest.xml.in @@ -90,6 +90,11 @@ + + + - - - - - - - - - - - - + + + + + + + + + + + + + + android:title="@string/action_about" + android:orderInCategory="100" /> + + diff --git a/android/experimental/LOAndroid3/res/menu/view_menu.xml b/android/experimental/LOAndroid3/res/menu/view_menu.xml index 37a39b140aad..32825b5287cc 100644 --- a/android/experimental/LOAndroid3/res/menu/view_menu.xml +++ b/android/experimental/LOAndroid3/res/menu/view_menu.xml @@ -13,4 +13,7 @@ + diff --git a/android/experimental/LOAndroid3/res/values/strings.xml b/android/experimental/LOAndroid3/res/values/strings.xml index b697c471eb72..e43c5a58b6ec 100644 --- a/android/experimental/LOAndroid3/res/values/strings.xml +++ b/android/experimental/LOAndroid3/res/values/strings.xml @@ -2,6 +2,7 @@ LibreOffice Viewer + LibreOffice Viewer Settings LibreOffice Viewer \'Beta\' Version: $VERSION\nBuild ID: $BUILDID @@ -31,9 +32,14 @@ EXPLORER_VIEW_TYPE CURRENT_DIRECTORY + Explorer View Defaults + General + Experimental Mode + Enable the experimental editing mode. Use at your own risk. About Parts + Settings Open Share Share via diff --git a/android/experimental/LOAndroid3/res/xml/libreoffice_preferences.xml b/android/experimental/LOAndroid3/res/xml/libreoffice_preferences.xml index f6da06f13aaf..17256b74b870 100644 --- a/android/experimental/LOAndroid3/res/xml/libreoffice_preferences.xml +++ b/android/experimental/LOAndroid3/res/xml/libreoffice_preferences.xml @@ -1,21 +1,32 @@ - - - - - - \ No newline at end of file + + + + + + + + + diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java index d76e6722cbac..5c8ce78018a5 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 2f47b1869b3f..822934f10f4d 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 000000000000..c453798a108a --- /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 dde1a614ccc8..abd1f3e8d6a7 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 938a2599e1cf..7ac40e4f8049 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); } -- cgit