2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-22 01:51:47 +00:00

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.
This commit is contained in:
Forrest Hilton 2022-01-15 20:35:45 +00:00 committed by Albert Vaca Cintora
parent a6339312e4
commit 64ad798d70
7 changed files with 212 additions and 0 deletions

View File

@ -247,11 +247,20 @@
<activity
android:name="org.kde.kdeconnect.Plugins.MousePadPlugin.MousePadActivity"
android:label="@string/pref_plugin_mousepad"
android:launchMode="singleTop"
android:parentActivityName="org.kde.kdeconnect.UserInterface.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.kde.kdeconnect.UserInterface.MainActivity" />
</activity>
<activity
android:name="org.kde.kdeconnect.Plugins.MousePadPlugin.ComposeSendActivity"
android:label="Compose send"
android:parentActivityName="org.kde.kdeconnect.Plugins.MousePadPlugin.MousePadActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.kde.kdeconnect.Plugins.MousePadPlugin.MousePadActivity" />
</activity>
<activity
android:name="org.kde.kdeconnect.Plugins.MousePadPlugin.SendKeystrokesToHostActivity"
android:label="@string/pref_plugin_mousepad_send_keystrokes"

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
</com.google.android.material.appbar.AppBarLayout>
<EditText
android:id="@+id/compose"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:ems="10"
android:hint="@string/click_here_to_type"
android:imeActionLabel="@string/send_compose"
android:imeOptions="actionSend|actionDone"
android:importantForAutofill="no"
android:inputType="textLongMessage|textMultiLine"
android:isScrollContainer="true"
android:saveEnabled="true"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appBarLayout2"
app:layout_constraintVertical_bias="1.0"
tools:ignore="SpeakableTextPresentCheck,TextContrastCheck" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:kdeconnect="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_send_compose"
android:icon="@android:drawable/ic_menu_send"
android:title="@string/send_compose"
kdeconnect:showAsAction="ifRoom" />
<item
android:id="@+id/menu_clear_compose"
android:title="@string/clear_compose"
kdeconnect:showAsAction="always" />
</menu>

View File

@ -8,6 +8,10 @@
android:title="@string/show_keyboard"
kdeconnect:showAsAction="ifRoom" />
<item
android:id="@+id/menu_open_compose_send"
android:title="@string/open_compose_send"
kdeconnect:showAsAction="ifRoom" />
<item
android:id="@+id/menu_right_click"
android:title="@string/right_click"

View File

@ -488,6 +488,11 @@
<string name="rise_up">Rise Up</string>
<string name="rise_down">Rise Down</string>
<string name="click_here_to_type">Tap here to type</string>
<string name="clear_compose">Clear</string>
<string name="send_compose">Send</string>
<string name="open_compose_send">Compose text</string>
<string name="app_description">Multi-platform app that allows your devices to communicate (e.g., your phone and your computer)</string>
<string name="about_kde_about"><![CDATA[

View File

@ -0,0 +1,122 @@
/*
* SPDX-FileCopyrightText: 2021 Forrest Hilton <forrestmhilton@gmail.com>
*
* 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);
}
}
}

View File

@ -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);
}