2 * This file is part of the LibreOffice project.
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/.
8 package org
.libreoffice
;
10 import android
.content
.DialogInterface
;
11 import androidx
.appcompat
.app
.AlertDialog
;
12 import android
.text
.method
.ScrollingMovementMethod
;
13 import android
.view
.View
;
14 import android
.widget
.EditText
;
15 import android
.widget
.Scroller
;
16 import android
.widget
.TextView
;
18 import org
.json
.JSONException
;
19 import org
.json
.JSONObject
;
21 import static org
.libreoffice
.SearchController
.addProperty
;
23 class 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
) {