8package org.libreoffice;
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;
18import org.json.JSONException;
19import org.json.JSONObject;
23class UNOCommandsController
implements View.OnClickListener {
24 private final LibreOfficeMainActivity mActivity;
25 private JSONObject mRootJSON =
new JSONObject();
28 UNOCommandsController(LibreOfficeMainActivity activity) {
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);
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();
47 addProperty(mRootJSON, parentValue, type, value);
48 }
catch (JSONException e) {
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(
"");
58 }
else if (view.getId() ==
R.id.button_send_UNO_commands_show) {
63 private void showCommandDialog() {
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) {
73 .setIcon(android.R.drawable.ic_dialog_info)
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());
81 }
catch (JSONException e) {
static void addProperty(JSONObject json, String parentValue, String type, String value)