From 64ad798d70bd075479a2a8e8fa9b34e5a5cda8bd Mon Sep 17 00:00:00 2001 From: Forrest Hilton Date: Sat, 15 Jan 2022 20:35:45 +0000 Subject: [PATCH] Added a screen to allow users to compose the key strokes to send. Added a screen to allow users to compose the key strokes to send. This is necessary because the keyboard that appears on the mouse pad screen does not have the voice to text microphone button on my phone. Even if it could be made to appear as it does on my tablet, some kind of text buffering is necessary because the voice text will change its mind. --- AndroidManifest.xml | 9 ++ res/layout/activity_compose_send.xml | 50 +++++++ res/menu/menu_compose_send.xml | 15 +++ res/menu/menu_mousepad.xml | 4 + res/values/strings.xml | 5 + .../MousePadPlugin/ComposeSendActivity.java | 122 ++++++++++++++++++ .../MousePadPlugin/MousePadActivity.java | 7 + 7 files changed, 212 insertions(+) create mode 100644 res/layout/activity_compose_send.xml create mode 100644 res/menu/menu_compose_send.xml create mode 100644 src/org/kde/kdeconnect/Plugins/MousePadPlugin/ComposeSendActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 02ac75cb..6364da48 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -247,11 +247,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/menu/menu_compose_send.xml b/res/menu/menu_compose_send.xml new file mode 100644 index 00000000..69aa5ff7 --- /dev/null +++ b/res/menu/menu_compose_send.xml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/res/menu/menu_mousepad.xml b/res/menu/menu_mousepad.xml index cd484135..2c772640 100644 --- a/res/menu/menu_mousepad.xml +++ b/res/menu/menu_mousepad.xml @@ -8,6 +8,10 @@ android:title="@string/show_keyboard" kdeconnect:showAsAction="ifRoom" /> + Rise Up Rise Down + Tap here to type + Clear + Send + Compose text + Multi-platform app that allows your devices to communicate (e.g., your phone and your computer) + * + * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + */ + + +package org.kde.kdeconnect.Plugins.MousePadPlugin; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; + +import android.os.Bundle; +import android.util.Log; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; + +import org.kde.kdeconnect.BackgroundService; +import org.kde.kdeconnect.NetworkPacket; +import org.kde.kdeconnect.UserInterface.ThemeUtil; +import org.kde.kdeconnect_tp.R; + +import android.view.inputmethod.EditorInfo; +import android.widget.EditText; +import android.widget.TextView; + +import java.util.Objects; + + +public class ComposeSendActivity extends AppCompatActivity { + + private String deviceId; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + ThemeUtil.setUserPreferredTheme(this); + + setContentView(R.layout.activity_compose_send); + + setSupportActionBar(findViewById(R.id.toolbar)); + Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + Intent intent = getIntent(); + + deviceId = intent.getStringExtra("org.kde.kdeconnect.Plugins.MousePadPlugin.deviceId"); + + EditText editText = findViewById(R.id.compose); + + editText.requestFocus(); + editText.setOnEditorActionListener(new EditText.OnEditorActionListener() { + @Override + + // this is almost never used + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == EditorInfo.IME_ACTION_SEND) { + sendComposed(); + return true; + } + if (actionId == EditorInfo.IME_ACTION_DONE) { + clear(); + return true; + } + return false; + } + }); + } + + public void sendChars(CharSequence chars) { + final NetworkPacket np = new NetworkPacket(MousePadPlugin.PACKET_TYPE_MOUSEPAD_REQUEST); + np.set("key", chars.toString()); + sendKeyPressPacket(np); + } + + private void sendKeyPressPacket(final NetworkPacket np) { + try { + Log.d("packed", np.serialize()); + } catch (Exception e) { + Log.e("KDE/ComposeSend", "Exception", e); + } + + BackgroundService.RunWithPlugin(this, deviceId, MousePadPlugin.class, plugin -> plugin.sendKeyboardPacket(np)); + } + + public void sendComposed() { + EditText editText = findViewById(R.id.compose); + + String editTextStr = editText.getText().toString(); + sendChars(editTextStr); + } + + public void clear() { + EditText editText = findViewById(R.id.compose); + editText.setText(""); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.menu_compose_send, menu); + + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_clear_compose: + clear(); + return true; + case R.id.menu_send_compose: + sendComposed(); + default: + return super.onOptionsItemSelected(item); + } + } +} diff --git a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java index 504389a6..7f56afe8 100644 --- a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java +++ b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java @@ -6,6 +6,7 @@ package org.kde.kdeconnect.Plugins.MousePadPlugin; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; @@ -192,6 +193,12 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect case R.id.menu_show_keyboard: showKeyboard(); return true; + case R.id.menu_open_compose_send: + + Intent intent = new Intent(this, ComposeSendActivity.class); + intent.putExtra("org.kde.kdeconnect.Plugins.MousePadPlugin.deviceId",deviceId); + startActivity(intent); + return true; default: return super.onOptionsItemSelected(item); }