From 8cbf8b59bda075ae4d4dd723063a05b5afce006e Mon Sep 17 00:00:00 2001 From: Gyuhwan Park Date: Thu, 30 May 2019 20:32:18 +0900 Subject: [PATCH 1/3] feature(MainActivity): add shortcut for compose new toot (SHIFT + N or CTRL + N) [#505] --- .../com/keylesspalace/tusky/MainActivity.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index 99311307..9e3a58f6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -280,9 +280,26 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut return true; } } + return super.onKeyDown(keyCode, event); } + @Override + public boolean onKeyShortcut(int keyCode, KeyEvent event) { + if (event.isCtrlPressed() || event.isShiftPressed()) { + // FIXME: blackberry keyONE raises SHIFT key event even CTRL IS PRESSED + switch (keyCode) { + case KeyEvent.KEYCODE_N: { + // open compose activity by pressing SHIFT + N (or CTRL + N) + Intent composeIntent = new Intent(getApplicationContext(), ComposeActivity.class); + startActivity(composeIntent); + return true; + } + } + } + return super.onKeyShortcut(keyCode, event); + } + @Override public void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); From d31aa7fc43dd9dcf343e3be9abbc60455ef413e3 Mon Sep 17 00:00:00 2001 From: Gyuhwan Park Date: Thu, 30 May 2019 21:22:28 +0900 Subject: [PATCH 2/3] 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 720b221e..420f1fc0 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(); From 50b50a182e0a984e4c72ab90a14a54b5058321eb Mon Sep 17 00:00:00 2001 From: Gyuhwan Park Date: Fri, 31 May 2019 17:34:53 +0900 Subject: [PATCH 3/3] fix(MainActivity,ComposeActivity): use onKeyDown() instead --- .../java/com/keylesspalace/tusky/ComposeActivity.java | 4 ++-- .../main/java/com/keylesspalace/tusky/MainActivity.java | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 420f1fc0..ea736bbe 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -540,7 +540,7 @@ public final class ComposeActivity } }); - textEditor.setOnKeyListener((view, keyCode, event) -> this.onKeyShortcut(keyCode, event)); + textEditor.setOnKeyListener((view, keyCode, event) -> this.onKeyDown(keyCode, event)); textEditor.setAdapter( new ComposeAutoCompleteAdapter(this)); @@ -1645,7 +1645,7 @@ public final class ComposeActivity @Override - public boolean onKeyShortcut(int keyCode, KeyEvent event) { + public boolean onKeyDown(int keyCode, KeyEvent event) { Log.d(TAG, event.toString()); if (event.isCtrlPressed()) { if (keyCode == KeyEvent.KEYCODE_ENTER) { diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index 9e3a58f6..90b35d5f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -281,11 +281,6 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut } } - return super.onKeyDown(keyCode, event); - } - - @Override - public boolean onKeyShortcut(int keyCode, KeyEvent event) { if (event.isCtrlPressed() || event.isShiftPressed()) { // FIXME: blackberry keyONE raises SHIFT key event even CTRL IS PRESSED switch (keyCode) { @@ -297,7 +292,8 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut } } } - return super.onKeyShortcut(keyCode, event); + + return super.onKeyDown(keyCode, event); } @Override