LibreOffice Module android (master) 1
UNOCommandsController.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8package org.libreoffice;
9
10import android.content.DialogInterface;
11import androidx.appcompat.app.AlertDialog;
12import android.text.method.ScrollingMovementMethod;
13import android.view.View;
14import android.widget.EditText;
15import android.widget.Scroller;
16import android.widget.TextView;
17
18import org.json.JSONException;
19import org.json.JSONObject;
20
22
23class UNOCommandsController implements View.OnClickListener {
24 private final LibreOfficeMainActivity mActivity;
25 private JSONObject mRootJSON = new JSONObject();
26
27
28 UNOCommandsController(LibreOfficeMainActivity activity) {
29 mActivity = activity;
30
31 activity.findViewById(R.id.button_send_UNO_commands).setOnClickListener(this);
32 activity.findViewById(R.id.button_send_UNO_commands_clear).setOnClickListener(this);
33 activity.findViewById(R.id.button_send_UNO_commands_show).setOnClickListener(this);
34 activity.findViewById(R.id.button_add_property).setOnClickListener(this);
35 }
36
37 @Override
38 public void onClick(View view) {
39 if (view.getId() == R.id.button_send_UNO_commands) {
40 String cmdText = ((EditText) mActivity.findViewById(R.id.UNO_commands_string)).getText().toString();
41 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:" + cmdText, mRootJSON.toString()));
42 } else if (view.getId() == R.id.button_add_property) {
43 String parentValue = ((EditText) mActivity.findViewById(R.id.UNO_commands_string_parent_value)).getText().toString();
44 String type = ((EditText) mActivity.findViewById(R.id.UNO_commands_string_type)).getText().toString();
45 String value = ((EditText) mActivity.findViewById(R.id.UNO_commands_string_value)).getText().toString();
46 try {
47 addProperty(mRootJSON, parentValue, type, value);
48 } catch (JSONException e) {
49 e.printStackTrace();
50 }
51 showCommandDialog();
52 } else if (view.getId() == R.id.button_send_UNO_commands_clear) {
53 mRootJSON = new JSONObject();
54 ((EditText) mActivity.findViewById(R.id.UNO_commands_string_parent_value)).setText("");
55 ((EditText) mActivity.findViewById(R.id.UNO_commands_string_type)).setText("");
56 ((EditText) mActivity.findViewById(R.id.UNO_commands_string_value)).setText("");
57 showCommandDialog();
58 } else if (view.getId() == R.id.button_send_UNO_commands_show) {
59 showCommandDialog();
60 }
61 }
62
63 private void showCommandDialog() {
64 try {
65 AlertDialog dialog = new AlertDialog.Builder(mActivity)
66 .setTitle(R.string.current_uno_command)
67 .setMessage(mRootJSON.toString(2))
68 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
69 public void onClick(DialogInterface dialog, int which) {
70 dialog.dismiss();
71 }
72 })
73 .setIcon(android.R.drawable.ic_dialog_info)
74 .show();
75 TextView textView = dialog.findViewById(android.R.id.message);
76 if (textView != null) {
77 textView.setScroller(new Scroller(mActivity));
78 textView.setVerticalScrollBarEnabled(true);
79 textView.setMovementMethod(new ScrollingMovementMethod());
80 }
81 } catch (JSONException e) {
82 e.printStackTrace();
83 }
84 }
85}
static void addProperty(JSONObject json, String parentValue, String type, String value)
Any value
ResultType type
const sal_uInt8 R