am c1f7d39b: Introduce ignoreWhileTyping flags to Key.keyActionFlags

* commit 'c1f7d39b4aabe71ecf7934272a848d8c0fe5a7f0':
  Introduce ignoreWhileTyping flags to Key.keyActionFlags
main
Tadashi G. Takaoka 2011-11-22 18:31:46 -08:00 committed by Android Git Automerger
commit c92d08b71c
7 changed files with 32 additions and 24 deletions

View File

@ -201,6 +201,7 @@
<!-- This should be aligned with Key.ACTION_FLAGS_* --> <!-- This should be aligned with Key.ACTION_FLAGS_* -->
<flag name="isRepeatable" value="0x01" /> <flag name="isRepeatable" value="0x01" />
<flag name="noKeyPreview" value="0x02" /> <flag name="noKeyPreview" value="0x02" />
<flag name="ignoreWhileTyping" value="0x04" />
</attr> </attr>
<!-- The string of characters to output when this key is pressed. --> <!-- The string of characters to output when this key is pressed. -->
<attr name="keyOutputText" format="string" /> <attr name="keyOutputText" format="string" />

View File

@ -77,13 +77,13 @@
latin:styleName="shortcutKeyStyle" latin:styleName="shortcutKeyStyle"
latin:code="@integer/key_shortcut" latin:code="@integer/key_shortcut"
latin:keyIcon="iconShortcutKey" latin:keyIcon="iconShortcutKey"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview|ignoreWhileTyping"
latin:parentStyle="f2PopupStyle" /> latin:parentStyle="f2PopupStyle" />
<key-style <key-style
latin:styleName="settingsKeyStyle" latin:styleName="settingsKeyStyle"
latin:code="@integer/key_settings" latin:code="@integer/key_settings"
latin:keyIcon="iconSettingsKey" latin:keyIcon="iconSettingsKey"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview|ignoreWhileTyping"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="tabKeyStyle" latin:styleName="tabKeyStyle"

View File

@ -55,17 +55,17 @@
latin:keyLabelFlags="hasPopupHint" latin:keyLabelFlags="hasPopupHint"
latin:moreKeys="@string/more_keys_for_smiley" latin:moreKeys="@string/more_keys_for_smiley"
latin:maxMoreKeysColumn="5" /> latin:maxMoreKeysColumn="5" />
<key-style
latin:styleName="settingsKeyStyle"
latin:code="@integer/key_settings"
latin:keyIcon="iconSettingsKey"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="shortcutKeyStyle" latin:styleName="shortcutKeyStyle"
latin:code="@integer/key_shortcut" latin:code="@integer/key_shortcut"
latin:keyIcon="iconShortcutKey" latin:keyIcon="iconShortcutKey"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview|ignoreWhileTyping"
latin:backgroundType="functional" />
<key-style
latin:styleName="settingsKeyStyle"
latin:code="@integer/key_settings"
latin:keyIcon="iconSettingsKey"
latin:keyActionFlags="noKeyPreview|ignoreWhileTyping"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="tabKeyStyle" latin:styleName="tabKeyStyle"

View File

@ -163,13 +163,13 @@
latin:styleName="shortcutKeyStyle" latin:styleName="shortcutKeyStyle"
latin:code="@integer/key_shortcut" latin:code="@integer/key_shortcut"
latin:keyIcon="iconShortcutKey" latin:keyIcon="iconShortcutKey"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview|ignoreWhileTyping"
latin:parentStyle="f1PopupStyle" /> latin:parentStyle="f1PopupStyle" />
<key-style <key-style
latin:styleName="settingsKeyStyle" latin:styleName="settingsKeyStyle"
latin:code="@integer/key_settings" latin:code="@integer/key_settings"
latin:keyIcon="iconSettingsKey" latin:keyIcon="iconSettingsKey"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview|ignoreWhileTyping"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="tabKeyStyle" latin:styleName="tabKeyStyle"

View File

@ -108,6 +108,7 @@ public class Key {
private final int mActionFlags; private final int mActionFlags;
private static final int ACTION_FLAGS_IS_REPEATABLE = 0x01; private static final int ACTION_FLAGS_IS_REPEATABLE = 0x01;
private static final int ACTION_FLAGS_NO_KEY_PREVIEW = 0x02; private static final int ACTION_FLAGS_NO_KEY_PREVIEW = 0x02;
private static final int ACTION_FLAGS_IGNORE_WHILE_TYPING = 0x04;
/** The current pressed state of this key */ /** The current pressed state of this key */
private boolean mPressed; private boolean mPressed;
@ -325,6 +326,10 @@ public class Key {
return (mActionFlags & ACTION_FLAGS_NO_KEY_PREVIEW) != 0; return (mActionFlags & ACTION_FLAGS_NO_KEY_PREVIEW) != 0;
} }
public boolean ignoreWhileTyping() {
return (mActionFlags & ACTION_FLAGS_IGNORE_WHILE_TYPING) != 0;
}
public Typeface selectTypeface(Typeface defaultTypeface) { public Typeface selectTypeface(Typeface defaultTypeface) {
// TODO: Handle "bold" here too? // TODO: Handle "bold" here too?
if ((mLabelFlags & LABEL_FLAGS_FONT_NORMAL) != 0) { if ((mLabelFlags & LABEL_FLAGS_FONT_NORMAL) != 0) {

View File

@ -145,7 +145,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
} }
@Override @Override
public boolean isIgnoringSpecialKey() { public boolean isTyping() {
return hasMessages(MSG_KEY_TYPED); return hasMessages(MSG_KEY_TYPED);
} }

View File

@ -75,7 +75,7 @@ public class PointerTracker {
public interface TimerProxy { public interface TimerProxy {
public void startKeyTypedTimer(long delay); public void startKeyTypedTimer(long delay);
public boolean isIgnoringSpecialKey(); public boolean isTyping();
public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker); public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker);
public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker); public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker);
public void cancelLongPressTimer(); public void cancelLongPressTimer();
@ -85,7 +85,7 @@ public class PointerTracker {
@Override @Override
public void startKeyTypedTimer(long delay) {} public void startKeyTypedTimer(long delay) {}
@Override @Override
public boolean isIgnoringSpecialKey() { return false; } public boolean isTyping() { return false; }
@Override @Override
public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker) {} public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker) {}
@Override @Override
@ -720,10 +720,14 @@ public class PointerTracker {
return; return;
} }
if (key.mOutputText != null) { if (key.mOutputText != null) {
final boolean ignoreText = key.ignoreWhileTyping() && mTimerProxy.isTyping();
if (!ignoreText) {
callListenerOnTextInput(key); callListenerOnTextInput(key);
}
callListenerOnRelease(key, key.mCode, false); callListenerOnRelease(key, key.mCode, false);
// TODO: "text" input key could have a special action too if (!ignoreText) {
mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout); mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout);
}
} else { } else {
int code = key.mCode; int code = key.mCode;
final int[] codes = mKeyDetector.newCodeArray(); final int[] codes = mKeyDetector.newCodeArray();
@ -743,16 +747,14 @@ public class PointerTracker {
codes[1] = codes[0]; codes[1] = codes[0];
codes[0] = code; codes[0] = code;
} }
// TODO: Move this special action to Key.keyActionFlags final boolean ignoreCode = key.ignoreWhileTyping() && mTimerProxy.isTyping();
final boolean specialCode = ( if (!ignoreCode) {
code == Keyboard.CODE_SETTINGS || code == Keyboard.CODE_SHORTCUT); // TODO: It might be useful to register the nearest key code in codes[] instead of
final boolean ignoreSpecialCode = specialCode && mTimerProxy.isIgnoringSpecialKey(); // just ignoring.
final boolean shouldStartKeyTypedTyper = !(specialCode || isModifierCode(code));
if (!ignoreSpecialCode) {
callListenerOnCodeInput(key, code, codes, x, y); callListenerOnCodeInput(key, code, codes, x, y);
} }
callListenerOnRelease(key, code, false); callListenerOnRelease(key, code, false);
if (shouldStartKeyTypedTyper) { if (!key.ignoreWhileTyping() && !isModifierCode(code)) {
mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout); mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout);
} }
} }