Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Add support for Bluetooth keyboards. Fixes #775 #1878

Merged
merged 1 commit into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,15 @@ public void onBackPressed() {

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (mKeyboard.dispatchKeyEvent(event)) {
return true;
}
final int keyCode = event.getKeyCode();
if (DeviceType.isOculusBuild()) {
int action = event.getAction();
if (action != KeyEvent.ACTION_DOWN) {
return super.dispatchKeyEvent(event);
}
int keyCode = event.getKeyCode();
boolean result;
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
Expand All @@ -621,14 +624,17 @@ public boolean dispatchKeyEvent(KeyEvent event) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
result = callOnAudioManager((AudioManager aManager) -> aManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI));
break;
case KeyEvent.KEYCODE_VOLUME_MUTE:
result = callOnAudioManager((AudioManager aManager) -> aManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, AudioManager.FLAG_SHOW_UI));
break;
default:
return super.dispatchKeyEvent(event);
}
return result || super.dispatchKeyEvent(event);

} else if (DeviceType.isGoogleVR()) {
boolean result;
switch( event.getKeyCode() ) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN:
result = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -308,6 +311,10 @@ private void resetKeyboardLayout() {
updateCandidates();
}

private boolean isAttachToWindowWidget() {
return mFocusedView instanceof WindowWidget;
}

public void updateFocusedView(View aFocusedView) {
if (mFocusedView != null && mFocusedView instanceof TextView) {
((TextView)mFocusedView).removeTextChangedListener(this);
Expand Down Expand Up @@ -905,6 +912,59 @@ private void displayComposingText(String aText, ComposingAction aAction) {
}
}

private void moveCursor(final int direction) {
EditText textView;
if (mFocusedView != null && mFocusedView instanceof EditText) {
textView = (EditText)mFocusedView;
final int cursor = textView.getSelectionStart() + direction;
if ((cursor <= textView.length()) && (cursor >= 0)) {
textView.setSelection(cursor);
}
}
}

@Override
public boolean dispatchKeyEvent(final KeyEvent event) {
final int keyCode = event.getKeyCode();
final InputConnection connection = mInputConnection;
if (connection != null) {
if (isAttachToWindowWidget()) {
connection.sendKeyEvent(event);
hide(UIWidget.KEEP_WIDGET);
return true;
}
// Android Components do not support InputConnection.sendKeyEvent()
if (event.getAction() == KeyEvent.ACTION_DOWN) {
Log.e("reb", "key = " + KeyEvent.keyCodeToString(keyCode));

switch (keyCode) {
case KeyEvent.KEYCODE_DEL:
handleBackspace(event.isLongPress());
return true;
case KeyEvent.KEYCODE_ENTER:
case KeyEvent.KEYCODE_NUMPAD_ENTER:
handleDone();
return true;
case KeyEvent.KEYCODE_DPAD_LEFT:
moveCursor(-1);
return true;
case KeyEvent.KEYCODE_DPAD_RIGHT:
moveCursor(1);
return true;
default:
break;
}
if (event.getUnicodeChar() != 0) {
KeyCharacterMap map = event.getKeyCharacterMap();
String value = String.valueOf((char) map.get(keyCode, event.getMetaState()));
connection.commitText(value, 1);
return true;
}
}
}
return false;
}

// GeckoSession.TextInputDelegate

@Override
Expand Down