summaryrefslogtreecommitdiff
path: root/android/source
diff options
context:
space:
mode:
authorXimeng Zu <uznomis@yahoo.com>2017-04-24 22:30:17 -0500
committerTomaž Vajngerl <quikee@gmail.com>2018-07-15 12:47:11 +0200
commit7c2d92ab63834f124c32ea49178974432159d980 (patch)
treeca68375de704b535c79db357d88735bea000941c /android/source
parent43d8bf8beefe31a41733c5c9b443df22ca3c22a9 (diff)
Developer Mode
Added an settings option to enable Developer Mode, in which you can send UNO commands from the Viewer. You can also add properties to the command. Change-Id: I76cbb55771cdd5cea89da65ddf67e48e12745b41 Reviewed-on: https://gerrit.libreoffice.org/37045 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'android/source')
-rw-r--r--android/source/res/layout/toolbar_bottom.xml92
-rw-r--r--android/source/res/menu/main.xml4
-rw-r--r--android/source/res/values/strings.xml9
-rw-r--r--android/source/res/xml/libreoffice_preferences.xml6
-rw-r--r--android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java73
-rw-r--r--android/source/src/java/org/libreoffice/ToolbarController.java12
-rw-r--r--android/source/src/java/org/libreoffice/UNOCommandsController.java85
7 files changed, 268 insertions, 13 deletions
diff --git a/android/source/res/layout/toolbar_bottom.xml b/android/source/res/layout/toolbar_bottom.xml
index d1820216d2ab..25f47b828a36 100644
--- a/android/source/res/layout/toolbar_bottom.xml
+++ b/android/source/res/layout/toolbar_bottom.xml
@@ -446,4 +446,96 @@
android:src="@drawable/ic_search_direction_up" />
</LinearLayout>
+ <LinearLayout
+ android:id="@+id/UNO_commands_toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <EditText
+ android:id="@+id/UNO_commands_string"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:maxLines="1"
+ android:scrollHorizontally="true"
+ android:inputType="textNoSuggestions"
+ android:hint="@string/UNO_commands_string_hint" />
+
+ <ImageButton
+ android:id="@+id/button_send_UNO_commands"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/image_button_background"
+ android:padding="10dp"
+ app:srcCompat="@drawable/ic_check" />
+
+ <ImageButton
+ android:id="@+id/button_send_UNO_commands_show"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/image_button_background"
+ android:padding="10dp"
+ app:srcCompat="@drawable/ic_filter_list_black_24dp" />
+
+ <ImageButton
+ android:id="@+id/button_send_UNO_commands_clear"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/image_button_background"
+ android:padding="10dp"
+ app:srcCompat="@drawable/ic_undo" />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <EditText
+ android:id="@+id/UNO_commands_string_parent_value"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:maxLines="1"
+ android:scrollHorizontally="true"
+ android:inputType="textNoSuggestions"
+ android:hint="@string/UNO_commands_string_parent_value_hint" />
+
+ <EditText
+ android:id="@+id/UNO_commands_string_type"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:maxLines="1"
+ android:scrollHorizontally="true"
+ android:inputType="textNoSuggestions"
+ android:hint="@string/UNO_commands_string_type_hint" />
+
+ <EditText
+ android:id="@+id/UNO_commands_string_value"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:maxLines="1"
+ android:scrollHorizontally="true"
+ android:inputType="textNoSuggestions"
+ android:hint="@string/UNO_commands_string_value_hint" />
+
+ <ImageButton
+ android:id="@+id/button_add_property"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/image_button_background"
+ android:padding="10dp"
+ app:srcCompat="@drawable/ic_add_black_24dp" />
+
+ </LinearLayout>
+
+ </LinearLayout>
+
</LinearLayout>
diff --git a/android/source/res/menu/main.xml b/android/source/res/menu/main.xml
index 7fba5f46e380..92b40c250aaa 100644
--- a/android/source/res/menu/main.xml
+++ b/android/source/res/menu/main.xml
@@ -36,6 +36,10 @@
android:title="@string/action_save"
android:orderInCategory="100" />
+ <item android:id="@+id/action_UNO_commands"
+ android:title="@string/action_UNO_commands"
+ android:orderInCategory="100" />
+
<item android:id="@+id/action_add_slide"
android:title="@string/action_add_slide"
android:orderInCategory="100"
diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml
index cbbce88d158c..b476ac38682e 100644
--- a/android/source/res/values/strings.xml
+++ b/android/source/res/values/strings.xml
@@ -51,6 +51,8 @@
<string name="pref_experimental_editing_summary">Enable the experimental editing mode. Use at your own risk.</string>
<string name="pref_show_hidden_files">Hidden Files/Folders</string>
<string name="pref_show_hidden_files_summary">Enable to show hidden files/folders</string>
+ <string name="pref_developer_mode">Developer Mode</string>
+ <string name="pref_developer_mode_summary">Enable developer mode where you can send UNO commands within app. Use at your own risk.</string>
<string name="action_about">About</string>
<string name="action_parts">Parts</string>
@@ -93,6 +95,7 @@
<string name="action_save">Save</string>
<string name="action_fromat">Enable Format</string>
<string name="action_search">Search</string>
+ <string name="action_UNO_commands">Send UNO Cmd</string>
<!-- Feedback messages -->
<string name="message_saved">Save complete</string>
@@ -196,4 +199,10 @@
<item>Delete Table</item>
</string-array>
+ <!-- UNO cmd controller Strings -->
+ <string name="UNO_commands_string_hint">UNO Command</string>
+ <string name="UNO_commands_string_type_hint">Type</string>
+ <string name="UNO_commands_string_value_hint">Value</string>
+ <string name="UNO_commands_string_parent_value_hint">Parent Value</string>
+
</resources>
diff --git a/android/source/res/xml/libreoffice_preferences.xml b/android/source/res/xml/libreoffice_preferences.xml
index 17236434daa2..2b3d9dde2f57 100644
--- a/android/source/res/xml/libreoffice_preferences.xml
+++ b/android/source/res/xml/libreoffice_preferences.xml
@@ -34,5 +34,11 @@
android:key="ENABLE_EXPERIMENTAL"
android:summary="@string/pref_experimental_editing_summary"
android:defaultValue="false" />
+ <CheckBoxPreference
+ android:title="@string/pref_developer_mode"
+ android:key="ENABLE_DEVELOPER"
+ android:dependency="ENABLE_EXPERIMENTAL"
+ android:summary="@string/pref_developer_mode_summary"
+ android:defaultValue="false" />
</PreferenceCategory>
</PreferenceScreen>
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index e65d6c31e51a..e6fbf26c20f3 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -62,6 +62,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
private static final String DEFAULT_DOC_PATH = "/assets/example.odt";
private static final String ENABLE_EXPERIMENTAL_PREFS_KEY = "ENABLE_EXPERIMENTAL";
private static final String ASSETS_EXTRACTED_PREFS_KEY = "ASSETS_EXTRACTED";
+ private static final String ENABLE_DEVELOPER_PREFS_KEY = "ENABLE_DEVELOPER";
//TODO "public static" is a temporary workaround
public static LOKitThread loKitThread;
@@ -69,6 +70,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
private GeckoLayerClient mLayerClient;
private static boolean mIsExperimentalMode;
+ private static boolean mIsDeveloperMode;
private int providerId;
private URI documentUri;
@@ -93,6 +95,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
private ToolbarController mToolbarController;
private FontController mFontController;
private SearchController mSearchController;
+ private UNOCommandsController mUNOCommandsController;
private CalcHeadersController mCalcHeadersController;
private boolean mIsSpreadsheet;
private LOKitTileProvider mTileProvider;
@@ -108,6 +111,10 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
return mIsExperimentalMode;
}
+ public static boolean isDeveloperMode() {
+ return mIsDeveloperMode;
+ }
+
public boolean usesTemporaryFile() {
return mTempFile != null;
}
@@ -116,6 +123,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
private boolean isFormattingToolbarOpen = false;
private boolean isSearchToolbarOpen = false;
private static boolean isDocumentChanged = false;
+ private boolean isUNOCommandsToolbarOpen = false;
public boolean isNewDocument = false;
private long lastModified = 0;
@@ -127,12 +135,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
SettingsListenerModel.getInstance().setListener(this);
SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
mIsExperimentalMode = sPrefs.getBoolean(ENABLE_EXPERIMENTAL_PREFS_KEY, false);
+ updatePreferences();
- if (sPrefs.getInt(ASSETS_EXTRACTED_PREFS_KEY, 0) != BuildConfig.VERSION_CODE) {
- if(copyFromAssets(getAssets(), "unpack", getApplicationInfo().dataDir)) {
- sPrefs.edit().putInt(ASSETS_EXTRACTED_PREFS_KEY, BuildConfig.VERSION_CODE).apply();
- }
- }
setContentView(R.layout.activity_main);
toolbarTop = findViewById(R.id.toolbar);
@@ -149,6 +153,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
mFontController = new FontController(this);
mSearchController = new SearchController(this);
+ mUNOCommandsController = new UNOCommandsController(this);
loKitThread = new LOKitThread(this);
loKitThread.start();
@@ -255,6 +260,17 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
toolbarBackColorPickerBottomSheetBehavior.setHideable(true);
}
+ private void updatePreferences() {
+ SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ mIsExperimentalMode = sPrefs.getBoolean(ENABLE_EXPERIMENTAL_PREFS_KEY, false);
+ mIsDeveloperMode = sPrefs.getBoolean(ENABLE_DEVELOPER_PREFS_KEY, false);
+ if (sPrefs.getInt(ASSETS_EXTRACTED_PREFS_KEY, 0) != BuildConfig.VERSION_CODE) {
+ if(copyFromAssets(getAssets(), "unpack", getApplicationInfo().dataDir)) {
+ sPrefs.edit().putInt(ASSETS_EXTRACTED_PREFS_KEY, BuildConfig.VERSION_CODE).apply();
+ }
+ }
+ }
+
// Loads a new Document
private void loadNewDocument(String newFilePath, String newDocumentType) {
mInputFile = new File(newFilePath);
@@ -375,9 +391,11 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
super.onResume();
Log.i(LOGTAG, "onResume..");
// check for config change
- boolean bEnableExperimental = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean(ENABLE_EXPERIMENTAL_PREFS_KEY, false);
- if (bEnableExperimental != mIsExperimentalMode) {
- mIsExperimentalMode = bEnableExperimental;
+ updatePreferences();
+ if (mToolbarController.getEditModeStatus() && isExperimentalMode()) {
+ mToolbarController.switchToEditMode();
+ } else {
+ mToolbarController.switchToViewMode();
}
}
@@ -510,6 +528,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
isKeyboardOpen=true;
isSearchToolbarOpen=false;
isFormattingToolbarOpen=false;
+ isUNOCommandsToolbarOpen=false;
hideBottomToolbar();
}
@@ -565,8 +584,10 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
toolbarColorPickerBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
toolbarBackColorPickerBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
findViewById(R.id.search_toolbar).setVisibility(View.GONE);
+ findViewById(R.id.UNO_commands_toolbar).setVisibility(View.GONE);
isFormattingToolbarOpen=false;
isSearchToolbarOpen=false;
+ isUNOCommandsToolbarOpen=false;
}
});
}
@@ -576,14 +597,17 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
@Override
public void run() {
if (isFormattingToolbarOpen) {
- hideBottomToolbar();
+ hideFormattingToolbar();
} else {
showBottomToolbar();
findViewById(R.id.search_toolbar).setVisibility(View.GONE);
findViewById(R.id.formatting_toolbar).setVisibility(View.VISIBLE);
+ findViewById(R.id.search_toolbar).setVisibility(View.GONE);
+ findViewById(R.id.UNO_commands_toolbar).setVisibility(View.GONE);
hideSoftKeyboardDirect();
isSearchToolbarOpen=false;
isFormattingToolbarOpen=true;
+ isUNOCommandsToolbarOpen=false;
}
}
@@ -611,9 +635,11 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
toolbarColorPickerBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
toolbarBackColorPickerBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
findViewById(R.id.search_toolbar).setVisibility(View.VISIBLE);
+ findViewById(R.id.UNO_commands_toolbar).setVisibility(View.GONE);
hideSoftKeyboardDirect();
isFormattingToolbarOpen=false;
isSearchToolbarOpen=true;
+ isUNOCommandsToolbarOpen=false;
}
}
});
@@ -628,6 +654,35 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
});
}
+ public void showUNOCommandsToolbar() {
+ LOKitShell.getMainHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ if(isUNOCommandsToolbarOpen){
+ hideUNOCommandsToolbar();
+ }else{
+ showBottomToolbar();
+ findViewById(R.id.formatting_toolbar).setVisibility(View.GONE);
+ findViewById(R.id.search_toolbar).setVisibility(View.GONE);
+ findViewById(R.id.UNO_commands_toolbar).setVisibility(View.VISIBLE);
+ hideSoftKeyboardDirect();
+ isFormattingToolbarOpen=false;
+ isSearchToolbarOpen=false;
+ isUNOCommandsToolbarOpen=true;
+ }
+ }
+ });
+ }
+
+ public void hideUNOCommandsToolbar() {
+ LOKitShell.getMainHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ hideBottomToolbar();
+ }
+ });
+ }
+
public void showProgressSpinner() {
findViewById(R.id.loadingPanel).setVisibility(View.VISIBLE);
}
diff --git a/android/source/src/java/org/libreoffice/ToolbarController.java b/android/source/src/java/org/libreoffice/ToolbarController.java
index 21e3e5ca7be2..146be9fdfd7c 100644
--- a/android/source/src/java/org/libreoffice/ToolbarController.java
+++ b/android/source/src/java/org/libreoffice/ToolbarController.java
@@ -72,12 +72,16 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
void switchToEditMode() {
if (!LOKitShell.isEditingEnabled())
return;
-
// Ensure the change is done on UI thread
LOKitShell.getMainHandler().post(new Runnable() {
@Override
public void run() {
mMainMenu.setGroupVisible(R.id.group_edit_actions, true);
+ if (!LibreOfficeMainActivity.isDeveloperMode() && mMainMenu.findItem(R.id.action_UNO_commands) != null) {
+ mMainMenu.findItem(R.id.action_UNO_commands).setVisible(false);
+ } else {
+ mMainMenu.findItem(R.id.action_UNO_commands).setVisible(true);
+ }
mToolbarTop.setNavigationIcon(R.drawable.ic_check);
mToolbarTop.setLogo(null);
setEditModeOn(true);
@@ -131,9 +135,6 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
* 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
@@ -211,6 +212,9 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
LOKitShell.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
mContext.setDocumentChanged(true);
return true;
+ case R.id.action_UNO_commands:
+ mContext.showUNOCommandsToolbar();
+ return true;
}
return false;
}
diff --git a/android/source/src/java/org/libreoffice/UNOCommandsController.java b/android/source/src/java/org/libreoffice/UNOCommandsController.java
new file mode 100644
index 000000000000..e61d3266ac1c
--- /dev/null
+++ b/android/source/src/java/org/libreoffice/UNOCommandsController.java
@@ -0,0 +1,85 @@
+/*
+ * 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.content.DialogInterface;
+import android.support.v7.app.AlertDialog;
+import android.text.method.ScrollingMovementMethod;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.Scroller;
+import android.widget.TextView;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import static org.libreoffice.SearchController.addProperty;
+
+class UNOCommandsController implements View.OnClickListener {
+ private LibreOfficeMainActivity mActivity;
+ private JSONObject mRootJSON = new JSONObject();
+
+
+ UNOCommandsController(LibreOfficeMainActivity activity) {
+ mActivity = activity;
+
+ activity.findViewById(R.id.button_send_UNO_commands).setOnClickListener(this);
+ activity.findViewById(R.id.button_send_UNO_commands_clear).setOnClickListener(this);
+ activity.findViewById(R.id.button_send_UNO_commands_show).setOnClickListener(this);
+ activity.findViewById(R.id.button_add_property).setOnClickListener(this);
+ }
+
+ @Override
+ public void onClick(View view) {
+ if (view.getId() == R.id.button_send_UNO_commands) {
+ String cmdText = ((EditText) mActivity.findViewById(R.id.UNO_commands_string)).getText().toString();
+ LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:" + cmdText, mRootJSON.toString()));
+ } else if (view.getId() == R.id.button_add_property) {
+ String parentValue = ((EditText) mActivity.findViewById(R.id.UNO_commands_string_parent_value)).getText().toString();
+ String type = ((EditText) mActivity.findViewById(R.id.UNO_commands_string_type)).getText().toString();
+ String value = ((EditText) mActivity.findViewById(R.id.UNO_commands_string_value)).getText().toString();
+ try {
+ addProperty(mRootJSON, parentValue, type, value);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ showCommandDialog();
+ } else if (view.getId() == R.id.button_send_UNO_commands_clear) {
+ mRootJSON = new JSONObject();
+ ((EditText) mActivity.findViewById(R.id.UNO_commands_string_parent_value)).setText("");
+ ((EditText) mActivity.findViewById(R.id.UNO_commands_string_type)).setText("");
+ ((EditText) mActivity.findViewById(R.id.UNO_commands_string_value)).setText("");
+ showCommandDialog();
+ } else if (view.getId() == R.id.button_send_UNO_commands_show) {
+ showCommandDialog();
+ }
+ }
+
+ private void showCommandDialog() {
+ try {
+ AlertDialog dialog = new AlertDialog.Builder(mActivity)
+ .setTitle("Current UNO command")
+ .setMessage(mRootJSON.toString(2))
+ .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ }
+ })
+ .setIcon(android.R.drawable.ic_dialog_info)
+ .show();
+ TextView textView = (TextView) dialog.findViewById(android.R.id.message);
+ if (textView != null) {
+ textView.setScroller(new Scroller(mActivity));
+ textView.setVerticalScrollBarEnabled(true);
+ textView.setMovementMethod(new ScrollingMovementMethod());
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+} \ No newline at end of file