Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable popup duration, plus some minor changes relating to popups #691

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,25 @@ public class InputLanguageSelection extends PreferenceActivity {
private static final String[] KBD_LOCALIZATIONS = {
"ar", "bg", "bg_ST", "ca", "cs", "cs_QY", "da", "de", "de_NE",
"el", "en", "en_CX", "en_DV", "en_GB", "es", "es_LA", "es_US",
"fa", "fi", "fr", "fr_CA", "he", "hr", "hu", "hu_QY", "hy", "in",
"it", "iw", "ja", "ka", "ko", "lo", "lt", "lv", "nb", "nl", "pl",
"pt", "pt_PT", "rm", "ro", "ru", "ru_PH", "si", "sk", "sk_QY", "sl",
"sr", "sv", "ta", "th", "tl", "tr", "uk", "vi", "zh_CN", "zh_TW"
"fa", "fi", "fr", "fr_CA", "fr_CH", "he", "hr", "hu", "hu_QY", "hy",
"in", "it", "iw", "ja", "ka", "ko", "lb", "lo", "lt", "lv", "nb", "nl",
"pl", "pt", "pt_PT", "rm", "ro", "ru", "ru_PH", "si", "sk", "sk_QY",
"sl", "sr", "sv", "ta", "th", "tl", "tr", "uk", "vi", "zh_CN", "zh_TW"
};

private static final String[] KBD_5_ROW = {
"ar", "bg", "bg_ST", "cs", "cs_QY", "da", "de", "de_NE", "el",
"en", "en_CX", "en_DV", "en_GB", "es", "es_LA", "fa", "fi", "fr",
"fr_CA", "he", "hr", "hu", "hu_QY", "hy", "it", "iw", "lo", "lt",
"nb", "pt_PT", "ro", "ru", "ru_PH", "si", "sk", "sk_QY", "sl",
"sr", "sv", "ta", "th", "tr", "uk"
"fr_CA", "fr_CH", "he", "hr", "hu", "hu_QY", "hy", "it", "iw", "lb",
"lo", "lt", "nb", "pt_PT", "ro", "ru", "ru_PH", "si", "sk", "sk_QY",
"sl", "sr", "sv", "ta", "th", "tr", "uk"
};

private static final String[] KBD_4_ROW = {
"ar", "bg", "bg_ST", "cs", "cs_QY", "da", "de", "de_NE", "el",
"en", "en_CX", "en_DV", "es", "es_LA", "es_US", "fa", "fr", "fr_CA",
"he", "hr", "hu", "hu_QY", "iw", "nb", "ru", "ru_PH", "sk", "sk_QY",
"sl", "sr", "sv", "tr", "uk"
"fr_CH", "he", "hr", "hu", "hu_QY", "iw", "lb", "nb", "ru", "ru_PH",
"sk", "sk_QY", "sl", "sr", "sv", "tr", "uk"
};

private static String getLocaleName(Locale l) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ public String getHintLabel(boolean wantAscii, boolean wantAll) {
hint = "";
if (shiftLabel != null && !isSimpleUppercase) {
char c = shiftLabel.charAt(0);
if (wantAll || wantAscii && is7BitAscii(c)) {
if (wantAll || wantAscii && isNotAlpha(c)) {
hint = Character.toString(c);
}
}
Expand All @@ -664,6 +664,11 @@ private static boolean is7BitAscii(char c) {
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) return false;
return c >= 32 && c < 127;
}

private static boolean isNotAlpha(char c) {
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) return false;
return true;
}

/**
* Informs the key that it has been pressed, in case it needs to change its appearance or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class LatinIME extends InputMethodService implements
static final String PREF_VIBRATE_LEN = "vibrate_len";
private static final String PREF_SOUND_ON = "sound_on";
private static final String PREF_POPUP_ON = "popup_on";
private static final String PREF_POPUP_DURATION = "pref_popup_duration";
private static final String PREF_AUTO_CAP = "auto_cap";
private static final String PREF_QUICK_FIXES = "quick_fixes";
private static final String PREF_SHOW_SUGGESTIONS = "show_suggestions";
Expand Down Expand Up @@ -209,6 +210,7 @@ public class LatinIME extends InputMethodService implements
private boolean mPasswordText;
private boolean mVibrateOn;
private int mVibrateLen;
private int mPopupDuration;
private boolean mSoundOn;
private boolean mPopupOn;
private boolean mAutoCapPref;
Expand Down Expand Up @@ -933,6 +935,7 @@ public void onStartInputView(EditorInfo attribute, boolean restarting) {
updateCorrectionMode();

inputView.setPreviewEnabled(mPopupOn);
inputView.setPreviewDuration(mPopupDuration);
inputView.setProximityCorrectionEnabled(true);
// If we just entered a text field, maybe it has some old text that
// requires correction
Expand Down Expand Up @@ -2241,6 +2244,7 @@ && sameAsTextBeforeCursor(ic, mEnteredText)) {
}
mJustRevertedSeparator = null;
ic.endBatchEdit();
updateShiftKeyState(getCurrentInputEditorInfo());
}

private void setModCtrl(boolean val) {
Expand Down Expand Up @@ -3108,6 +3112,8 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
mVolDownAction = sharedPreferences.getString(PREF_VOL_DOWN, res.getString(R.string.default_vol_down));
} else if (PREF_VIBRATE_LEN.equals(key)) {
mVibrateLen = getPrefInt(sharedPreferences, PREF_VIBRATE_LEN, getResources().getString(R.string.vibrate_duration_ms));
} else if (PREF_POPUP_DURATION.equals(key)) {
mPopupDuration = getPrefInt(sharedPreferences, PREF_POPUP_DURATION, getResources().getString(R.string.popup_duration_ms));
}

updateKeyboardOptions();
Expand Down Expand Up @@ -3494,6 +3500,7 @@ private void loadSettings() {
mSoundOn = sp.getBoolean(PREF_SOUND_ON, false);
mPopupOn = sp.getBoolean(PREF_POPUP_ON, mResources
.getBoolean(R.bool.default_popup_preview));
mPopupDuration = getPrefInt(sp, PREF_POPUP_DURATION, getResources().getString(R.string.popup_duration_ms));
mAutoCapPref = sp.getBoolean(PREF_AUTO_CAP, getResources().getBoolean(
R.bool.default_auto_cap));
mQuickFixes = sp.getBoolean(PREF_QUICK_FIXES, true);
Expand Down Expand Up @@ -3620,6 +3627,7 @@ protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
p.println(" mSoundOn=" + mSoundOn);
p.println(" mVibrateOn=" + mVibrateOn);
p.println(" mPopupOn=" + mPopupOn);
p.println(" mPopupDuration=" + mPopupDuration);
}

// Characters per second measurement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public interface OnKeyboardActionListener {
protected int mPreviewTextSizeLarge;
protected int[] mOffsetInWindow;
protected int mOldPreviewKeyIndex = NOT_A_KEY;
protected int mPopupDuration;
protected boolean mShowPreview = true;
protected boolean mShowTouchPoints = true;
protected int mPopupPreviewOffsetX;
Expand All @@ -215,7 +216,6 @@ public interface OnKeyboardActionListener {
protected int mPopupPreviewDisplayedY;
protected final int mDelayBeforePreview;
protected final int mDelayBeforeSpacePreview;
protected final int mDelayAfterPreview;

// Popup mini keyboard
protected PopupWindow mMiniKeyboardPopup;
Expand Down Expand Up @@ -274,6 +274,7 @@ public interface OnKeyboardActionListener {
private final HashMap<Integer, Integer> mTextHeightCache = new HashMap<Integer, Integer>();
// Distance from horizontal center of the key, proportional to key label text height.
private final float KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR = 0.55f;
private final float KEY_LABEL_ALTHINT_HORIZONTAL_ADJUSTMENT_FACTOR = 0.70f;
private final String KEY_LABEL_HEIGHT_REFERENCE_CHAR = "H";
/* package */ static Method sSetRenderMode;
private static int sPrevRenderMode = -1;
Expand Down Expand Up @@ -553,7 +554,6 @@ public LatinKeyboardBaseView(Context context, AttributeSet attrs, int defStyle)
mShowPreview = false;
mDelayBeforePreview = res.getInteger(R.integer.config_delay_before_preview);
mDelayBeforeSpacePreview = res.getInteger(R.integer.config_delay_before_space_preview);
mDelayAfterPreview = res.getInteger(R.integer.config_delay_after_preview);

mPopupLayout = 0;

Expand Down Expand Up @@ -773,6 +773,13 @@ public void setPreviewEnabled(boolean previewEnabled) {
mShowPreview = previewEnabled;
}

/**
* Sets for how long the key feedback popup is shown.
* By default the preview lasts 10ms.
* @param popupDuration the duration in ms to show the key feedback popup
*/
public void setPreviewDuration(int popupDuration) { mPopupDuration = popupDuration; }

/**
* Returns the enabled state of the key feedback popup.
* @return whether or not the key feedback popup is enabled
Expand Down Expand Up @@ -1038,7 +1045,7 @@ private void onBufferDraw(Canvas canvas) {

// Draw alternate hint label (if present) behind the main key
String altHint = key.getAltHintLabel(showHints7Bit(), showHintsAll());
if (!altHint.equals("")) {
if (!altHint.equals("") && !key.isShifted()) {
int hintTextSize = (int)(mKeyTextSize * 0.6 * mLabelScale);
paintHint.setTextSize(hintTextSize);

Expand All @@ -1053,7 +1060,10 @@ private void onBufferDraw(Canvas canvas) {
}

// Draw main key label
final int centerX = (key.width + padding.left - padding.right) / 2;
final int centerX = Math.round(
(key.width + padding.left - padding.right) / 2
* (!altHint.equals("") && !key.isShifted()
? KEY_LABEL_ALTHINT_HORIZONTAL_ADJUSTMENT_FACTOR : 1f));
final int centerY = (key.height + padding.top - padding.bottom) / 2;
final float baseline = centerY
+ labelHeight * KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR;
Expand Down Expand Up @@ -1169,7 +1179,7 @@ public void showPreview(int keyIndex, PointerTracker tracker) {
|| (hidePreviewOrShowSpaceKeyPreview && isLanguageSwitchEnabled))) {
if (keyIndex == NOT_A_KEY) {
mHandler.cancelPopupPreview();
mHandler.dismissPreview(mDelayAfterPreview);
mHandler.dismissPreview(mPopupDuration);
} else if (tracker != null) {
int delay = mShowPreview ? mDelayBeforePreview : mDelayBeforeSpacePreview;
mHandler.popupPreview(delay, keyIndex, tracker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,17 @@ private boolean isModifierInternal(int keyIndex) {
return false;
int primaryCode = key.codes[0];
return primaryCode == Keyboard.KEYCODE_SHIFT
|| primaryCode == Keyboard.KEYCODE_DELETE
|| primaryCode == Keyboard.KEYCODE_MODE_CHANGE
|| primaryCode == LatinKeyboardView.KEYCODE_FORWARD_DEL
|| primaryCode == LatinKeyboardView.KEYCODE_CTRL_LEFT
|| primaryCode == LatinKeyboardView.KEYCODE_ALT_LEFT
|| primaryCode == LatinKeyboardView.KEYCODE_META_LEFT
|| primaryCode == LatinKeyboardView.KEYCODE_FN;
|| primaryCode == LatinKeyboardView.KEYCODE_FN
|| primaryCode == LatinKeyboardView.KEYCODE_DPAD_DOWN
|| primaryCode == LatinKeyboardView.KEYCODE_DPAD_LEFT
|| primaryCode == LatinKeyboardView.KEYCODE_DPAD_RIGHT
|| primaryCode == LatinKeyboardView.KEYCODE_DPAD_UP;
}

public boolean isModifier() {
Expand Down Expand Up @@ -513,15 +519,15 @@ private static int getSquareDistanceToKeyEdge(int x, int y, Key key) {
}

private void showKeyPreviewAndUpdateKey(int keyIndex) {
updateKey(keyIndex);
// The modifier key, such as shift key, should not be shown as preview when multi-touch is
// supported. On the other hand, if multi-touch is not supported, the modifier key should
// be shown as preview.
if (mHasDistinctMultitouch && isModifier()) {
mProxy.showPreview(NOT_A_KEY, this);
} else {
mProxy.showPreview(keyIndex, this);
}
updateKey(keyIndex);
// The modifier key, such as shift key, should not be shown as preview when multi-touch is
// supported. On the other hand, if multi-touch is not supported, the modifier key should
// be shown as preview.
}

private void startLongPressTimer(int keyIndex) {
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/res/values-fr-rCH/donottranslate-altchars.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2010, The Android Open Source Project
** Copyright 2011, Darren Salt
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="alternates_for_e">3éèêë€</string>
<string name="alternates_for_v">√</string>
<string name="alternates_for_w">2ŵ</string>
<string name="alternates_for_y">6ýÿŷ¥</string>
</resources>
Loading