mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Fix issues with long-pressing the spacebar
bug: 5114433 Change-Id: I18f2147724a08965147bafe93e11fc86c7c59d33
This commit is contained in:
parent
60a004f78e
commit
cadb2128f5
@ -27,5 +27,5 @@
|
|||||||
<integer name="key_switch_alpha_symbol">-2</integer>
|
<integer name="key_switch_alpha_symbol">-2</integer>
|
||||||
<integer name="key_delete">-5</integer>
|
<integer name="key_delete">-5</integer>
|
||||||
<integer name="key_settings">-6</integer>
|
<integer name="key_settings">-6</integer>
|
||||||
<integer name="key_shortcut">-8</integer>
|
<integer name="key_shortcut">-7</integer>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -79,8 +79,7 @@ public class Keyboard {
|
|||||||
public static final int CODE_CANCEL = -4;
|
public static final int CODE_CANCEL = -4;
|
||||||
public static final int CODE_DELETE = -5;
|
public static final int CODE_DELETE = -5;
|
||||||
public static final int CODE_SETTINGS = -6;
|
public static final int CODE_SETTINGS = -6;
|
||||||
public static final int CODE_SETTINGS_LONGPRESS = -7;
|
public static final int CODE_SHORTCUT = -7;
|
||||||
public static final int CODE_SHORTCUT = -8;
|
|
||||||
// Code value representing the code is not specified.
|
// Code value representing the code is not specified.
|
||||||
public static final int CODE_UNSPECIFIED = -99;
|
public static final int CODE_UNSPECIFIED = -99;
|
||||||
|
|
||||||
|
@ -70,4 +70,10 @@ public interface KeyboardActionListener {
|
|||||||
* Called when user released a finger outside any key.
|
* Called when user released a finger outside any key.
|
||||||
*/
|
*/
|
||||||
public void onCancelInput();
|
public void onCancelInput();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a non-"code input" custom request to the listener.
|
||||||
|
* @return true if the request has been consumed, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean onCustomRequest(int requestCode);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import android.util.Log;
|
|||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
import com.android.inputmethod.deprecated.VoiceProxy;
|
import com.android.inputmethod.deprecated.VoiceProxy;
|
||||||
|
import com.android.inputmethod.latin.LatinIME;
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.Utils;
|
import com.android.inputmethod.latin.Utils;
|
||||||
|
|
||||||
@ -99,9 +100,14 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) {
|
if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) {
|
||||||
tracker.onLongPressed();
|
|
||||||
// Both long pressing settings key and space key invoke IME switcher dialog.
|
// Both long pressing settings key and space key invoke IME switcher dialog.
|
||||||
return invokeOnKey(Keyboard.CODE_SETTINGS_LONGPRESS);
|
if (getKeyboardActionListener().onCustomRequest(
|
||||||
|
LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) {
|
||||||
|
tracker.onLongPressed();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return super.onLongPress(key, tracker);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return super.onLongPress(key, tracker);
|
return super.onLongPress(key, tracker);
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,8 @@ public class PointerTracker {
|
|||||||
public void onTextInput(CharSequence text) {}
|
public void onTextInput(CharSequence text) {}
|
||||||
@Override
|
@Override
|
||||||
public void onCancelInput() {}
|
public void onCancelInput() {}
|
||||||
|
@Override
|
||||||
|
public boolean onCustomRequest(int requestCode) { return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
public static void init(boolean hasDistinctMultitouch, Context context) {
|
public static void init(boolean hasDistinctMultitouch, Context context) {
|
||||||
|
@ -79,6 +79,8 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
|
|||||||
public void onRelease(int primaryCode, boolean withSliding) {
|
public void onRelease(int primaryCode, boolean withSliding) {
|
||||||
mParentKeyboardView.getKeyboardActionListener().onRelease(primaryCode, withSliding);
|
mParentKeyboardView.getKeyboardActionListener().onRelease(primaryCode, withSliding);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public boolean onCustomRequest(int requestCode) { return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
public PopupMiniKeyboardView(Context context, AttributeSet attrs) {
|
public PopupMiniKeyboardView(Context context, AttributeSet attrs) {
|
||||||
|
@ -430,8 +430,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||||||
public boolean postStartInputView(EditorInfo attribute) {
|
public boolean postStartInputView(EditorInfo attribute) {
|
||||||
if (hasMessages(MSG_CONFIRM_ORIENTATION_CHANGE) || hasMessages(MSG_START_INPUT_VIEW)) {
|
if (hasMessages(MSG_CONFIRM_ORIENTATION_CHANGE) || hasMessages(MSG_START_INPUT_VIEW)) {
|
||||||
removeMessages(MSG_START_INPUT_VIEW);
|
removeMessages(MSG_START_INPUT_VIEW);
|
||||||
// Postpone onStartInputView 20ms afterward and see if orientation change has
|
// Postpone onStartInputView by ACCUMULATE_START_INPUT_VIEW_DELAY and see if
|
||||||
// finished.
|
// orientation change has finished.
|
||||||
sendMessageDelayed(obtainMessage(MSG_START_INPUT_VIEW, attribute),
|
sendMessageDelayed(obtainMessage(MSG_START_INPUT_VIEW, attribute),
|
||||||
ACCUMULATE_START_INPUT_VIEW_DELAY);
|
ACCUMULATE_START_INPUT_VIEW_DELAY);
|
||||||
return true;
|
return true;
|
||||||
@ -1152,25 +1152,33 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onSettingsKeyPressed() {
|
private void onSettingsKeyPressed() {
|
||||||
if (isShowingOptionDialog())
|
if (isShowingOptionDialog()) return;
|
||||||
return;
|
|
||||||
if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
|
if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
|
||||||
showSubtypeSelectorAndSettings();
|
showSubtypeSelectorAndSettings();
|
||||||
} else if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm)) {
|
} else if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm,
|
||||||
|
false /* should exclude auxiliary subtypes */)) {
|
||||||
showOptionsMenu();
|
showOptionsMenu();
|
||||||
} else {
|
} else {
|
||||||
launchSettings();
|
launchSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSettingsKeyLongPressed() {
|
// Virtual codes representing custom requests. These are used in onCustomRequest() below.
|
||||||
if (!isShowingOptionDialog()) {
|
public static final int CODE_SHOW_INPUT_METHOD_PICKER = 1;
|
||||||
if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm)) {
|
|
||||||
|
@Override
|
||||||
|
public boolean onCustomRequest(int requestCode) {
|
||||||
|
if (isShowingOptionDialog()) return false;
|
||||||
|
switch (requestCode) {
|
||||||
|
case CODE_SHOW_INPUT_METHOD_PICKER:
|
||||||
|
if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm,
|
||||||
|
true /* should include auxiliary subtypes */)) {
|
||||||
mImm.showInputMethodPicker();
|
mImm.showInputMethodPicker();
|
||||||
} else {
|
return true;
|
||||||
launchSettings();
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isShowingOptionDialog() {
|
private boolean isShowingOptionDialog() {
|
||||||
@ -1214,9 +1222,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||||||
case Keyboard.CODE_SETTINGS:
|
case Keyboard.CODE_SETTINGS:
|
||||||
onSettingsKeyPressed();
|
onSettingsKeyPressed();
|
||||||
break;
|
break;
|
||||||
case Keyboard.CODE_SETTINGS_LONGPRESS:
|
|
||||||
onSettingsKeyLongPressed();
|
|
||||||
break;
|
|
||||||
case Keyboard.CODE_CAPSLOCK:
|
case Keyboard.CODE_CAPSLOCK:
|
||||||
switcher.toggleCapsLock();
|
switcher.toggleCapsLock();
|
||||||
break;
|
break;
|
||||||
@ -2135,14 +2140,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void launchSettings() {
|
protected void launchSettings() {
|
||||||
launchSettings(Settings.class);
|
launchSettingsClass(Settings.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void launchDebugSettings() {
|
public void launchDebugSettings() {
|
||||||
launchSettings(DebugSettings.class);
|
launchSettingsClass(DebugSettings.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void launchSettings(Class<? extends PreferenceActivity> settingsClass) {
|
protected void launchSettingsClass(Class<? extends PreferenceActivity> settingsClass) {
|
||||||
handleClose();
|
handleClose();
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setClass(LatinIME.this, settingsClass);
|
intent.setClass(LatinIME.this, settingsClass);
|
||||||
|
@ -111,35 +111,42 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManagerCompatWrapper imm) {
|
public static boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManagerCompatWrapper imm,
|
||||||
|
boolean shouldIncludeAuxiliarySubtypes) {
|
||||||
final List<InputMethodInfoCompatWrapper> enabledImis = imm.getEnabledInputMethodList();
|
final List<InputMethodInfoCompatWrapper> enabledImis = imm.getEnabledInputMethodList();
|
||||||
|
|
||||||
// Filters out IMEs that have auxiliary subtypes only (including either implicitly or
|
// Number of the filtered IMEs
|
||||||
// explicitly enabled ones).
|
int filteredImisCount = 0;
|
||||||
final ArrayList<InputMethodInfoCompatWrapper> filteredImis =
|
|
||||||
new ArrayList<InputMethodInfoCompatWrapper>();
|
|
||||||
|
|
||||||
outerloop:
|
|
||||||
for (InputMethodInfoCompatWrapper imi : enabledImis) {
|
for (InputMethodInfoCompatWrapper imi : enabledImis) {
|
||||||
// We can return true immediately after we find two or more filtered IMEs.
|
// We can return true immediately after we find two or more filtered IMEs.
|
||||||
if (filteredImis.size() > 1) return true;
|
if (filteredImisCount > 1) return true;
|
||||||
final List<InputMethodSubtypeCompatWrapper> subtypes =
|
final List<InputMethodSubtypeCompatWrapper> subtypes =
|
||||||
imm.getEnabledInputMethodSubtypeList(imi, true);
|
imm.getEnabledInputMethodSubtypeList(imi, true);
|
||||||
// IMEs that have no subtypes should be included.
|
// IMEs that have no subtypes should be counted.
|
||||||
if (subtypes.isEmpty()) {
|
if (subtypes.isEmpty()) {
|
||||||
filteredImis.add(imi);
|
++filteredImisCount;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// IMEs that have one or more non-auxiliary subtypes should be included.
|
|
||||||
|
int auxCount = 0;
|
||||||
for (InputMethodSubtypeCompatWrapper subtype : subtypes) {
|
for (InputMethodSubtypeCompatWrapper subtype : subtypes) {
|
||||||
if (!subtype.isAuxiliary()) {
|
if (subtype.isAuxiliary()) {
|
||||||
filteredImis.add(imi);
|
++auxCount;
|
||||||
continue outerloop;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
final int nonAuxCount = subtypes.size() - auxCount;
|
||||||
|
|
||||||
|
// IMEs that have one or more non-auxiliary subtypes should be counted.
|
||||||
|
// If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary
|
||||||
|
// subtypes should be counted as well.
|
||||||
|
if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) {
|
||||||
|
++filteredImisCount;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return filteredImis.size() > 1
|
return filteredImisCount > 1
|
||||||
// imm.getEnabledInputMethodSubtypeList(null, false) will return the current IME's enabled
|
// imm.getEnabledInputMethodSubtypeList(null, false) will return the current IME's enabled
|
||||||
// input method subtype (The current IME should be LatinIME.)
|
// input method subtype (The current IME should be LatinIME.)
|
||||||
|| imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
|
|| imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user