Fix issues with long-pressing the spacebar

bug: 5114433
Change-Id: I18f2147724a08965147bafe93e11fc86c7c59d33
main
Ken Wakasa 2011-08-06 10:45:19 +09:00
parent 60a004f78e
commit cadb2128f5
8 changed files with 62 additions and 35 deletions

View File

@ -27,5 +27,5 @@
<integer name="key_switch_alpha_symbol">-2</integer>
<integer name="key_delete">-5</integer>
<integer name="key_settings">-6</integer>
<integer name="key_shortcut">-8</integer>
<integer name="key_shortcut">-7</integer>
</resources>

View File

@ -79,8 +79,7 @@ public class Keyboard {
public static final int CODE_CANCEL = -4;
public static final int CODE_DELETE = -5;
public static final int CODE_SETTINGS = -6;
public static final int CODE_SETTINGS_LONGPRESS = -7;
public static final int CODE_SHORTCUT = -8;
public static final int CODE_SHORTCUT = -7;
// Code value representing the code is not specified.
public static final int CODE_UNSPECIFIED = -99;

View File

@ -70,4 +70,10 @@ public interface KeyboardActionListener {
* Called when user released a finger outside any key.
*/
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);
}

View File

@ -23,6 +23,7 @@ import android.util.Log;
import android.view.MotionEvent;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.Utils;
@ -99,9 +100,14 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
}
}
if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) {
tracker.onLongPressed();
// 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 {
return super.onLongPress(key, tracker);
}

View File

@ -151,6 +151,8 @@ public class PointerTracker {
public void onTextInput(CharSequence text) {}
@Override
public void onCancelInput() {}
@Override
public boolean onCustomRequest(int requestCode) { return false; }
};
public static void init(boolean hasDistinctMultitouch, Context context) {

View File

@ -79,6 +79,8 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
public void onRelease(int primaryCode, boolean withSliding) {
mParentKeyboardView.getKeyboardActionListener().onRelease(primaryCode, withSliding);
}
@Override
public boolean onCustomRequest(int requestCode) { return false; }
};
public PopupMiniKeyboardView(Context context, AttributeSet attrs) {

View File

@ -430,8 +430,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
public boolean postStartInputView(EditorInfo attribute) {
if (hasMessages(MSG_CONFIRM_ORIENTATION_CHANGE) || hasMessages(MSG_START_INPUT_VIEW)) {
removeMessages(MSG_START_INPUT_VIEW);
// Postpone onStartInputView 20ms afterward and see if orientation change has
// finished.
// Postpone onStartInputView by ACCUMULATE_START_INPUT_VIEW_DELAY and see if
// orientation change has finished.
sendMessageDelayed(obtainMessage(MSG_START_INPUT_VIEW, attribute),
ACCUMULATE_START_INPUT_VIEW_DELAY);
return true;
@ -1152,25 +1152,33 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
private void onSettingsKeyPressed() {
if (isShowingOptionDialog())
return;
if (isShowingOptionDialog()) return;
if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
showSubtypeSelectorAndSettings();
} else if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm)) {
} else if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm,
false /* should exclude auxiliary subtypes */)) {
showOptionsMenu();
} else {
launchSettings();
}
}
private void onSettingsKeyLongPressed() {
if (!isShowingOptionDialog()) {
if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm)) {
// Virtual codes representing custom requests. These are used in onCustomRequest() below.
public static final int CODE_SHOW_INPUT_METHOD_PICKER = 1;
@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();
} else {
launchSettings();
return true;
}
return false;
}
return false;
}
private boolean isShowingOptionDialog() {
@ -1214,9 +1222,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
case Keyboard.CODE_SETTINGS:
onSettingsKeyPressed();
break;
case Keyboard.CODE_SETTINGS_LONGPRESS:
onSettingsKeyLongPressed();
break;
case Keyboard.CODE_CAPSLOCK:
switcher.toggleCapsLock();
break;
@ -2135,14 +2140,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
protected void launchSettings() {
launchSettings(Settings.class);
launchSettingsClass(Settings.class);
}
public void launchDebugSettings() {
launchSettings(DebugSettings.class);
launchSettingsClass(DebugSettings.class);
}
protected void launchSettings(Class<? extends PreferenceActivity> settingsClass) {
protected void launchSettingsClass(Class<? extends PreferenceActivity> settingsClass) {
handleClose();
Intent intent = new Intent();
intent.setClass(LatinIME.this, settingsClass);

View File

@ -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();
// Filters out IMEs that have auxiliary subtypes only (including either implicitly or
// explicitly enabled ones).
final ArrayList<InputMethodInfoCompatWrapper> filteredImis =
new ArrayList<InputMethodInfoCompatWrapper>();
// Number of the filtered IMEs
int filteredImisCount = 0;
outerloop:
for (InputMethodInfoCompatWrapper imi : enabledImis) {
// 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 =
imm.getEnabledInputMethodSubtypeList(imi, true);
// IMEs that have no subtypes should be included.
// IMEs that have no subtypes should be counted.
if (subtypes.isEmpty()) {
filteredImis.add(imi);
++filteredImisCount;
continue;
}
// IMEs that have one or more non-auxiliary subtypes should be included.
int auxCount = 0;
for (InputMethodSubtypeCompatWrapper subtype : subtypes) {
if (!subtype.isAuxiliary()) {
filteredImis.add(imi);
continue outerloop;
if (subtype.isAuxiliary()) {
++auxCount;
}
}
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
// input method subtype (The current IME should be LatinIME.)
|| imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;