From d31aa7fc43dd9dcf343e3be9abbc60455ef413e3 Mon Sep 17 00:00:00 2001 From: Gyuhwan Park Date: Thu, 30 May 2019 21:22:28 +0900 Subject: [PATCH] feature(ComposeActivity): add shortcut for send new toot (CTRL + ENTER) [#505] --- .../keylesspalace/tusky/ComposeActivity.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 720b221ea..420f1fc0b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -47,6 +47,7 @@ import android.text.TextWatcher; import android.text.style.URLSpan; import android.util.DisplayMetrics; import android.util.Log; +import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -539,6 +540,8 @@ public final class ComposeActivity } }); + textEditor.setOnKeyListener((view, keyCode, event) -> this.onKeyShortcut(keyCode, event)); + textEditor.setAdapter( new ComposeAutoCompleteAdapter(this)); textEditor.setTokenizer(new ComposeTokenizer()); @@ -1624,6 +1627,7 @@ public final class ComposeActivity return super.onOptionsItemSelected(item); } + @Override public void onBackPressed() { // Acting like a teen: deliberately ignoring parent. @@ -1639,6 +1643,21 @@ public final class ComposeActivity handleCloseButton(); } + + @Override + public boolean onKeyShortcut(int keyCode, KeyEvent event) { + Log.d(TAG, event.toString()); + if (event.isCtrlPressed()) { + if (keyCode == KeyEvent.KEYCODE_ENTER) { + // send toot by pressing CTRL + ENTER + this.onSendClicked(); + return true; + } + } + + return super.onKeyDown(keyCode, event); + } + private void handleCloseButton() { CharSequence contentText = textEditor.getText();