aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/BaseKeyboard.java3
-rw-r--r--java/src/com/android/inputmethod/latin/BaseKeyboardView.java51
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java21
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIMESettings.java39
-rw-r--r--java/src/com/android/inputmethod/voice/VoiceIMEConnector.java104
5 files changed, 154 insertions, 64 deletions
diff --git a/java/src/com/android/inputmethod/latin/BaseKeyboard.java b/java/src/com/android/inputmethod/latin/BaseKeyboard.java
index 00ed453c4..e2331f334 100644
--- a/java/src/com/android/inputmethod/latin/BaseKeyboard.java
+++ b/java/src/com/android/inputmethod/latin/BaseKeyboard.java
@@ -537,7 +537,8 @@ public class BaseKeyboard {
column = 0;
}
final Key key = new Key(row);
- key.x = x;
+ // Horizontal gap is divided equally to both sides of the key.
+ key.x = x + key.gap / 2;
key.y = y;
key.label = String.valueOf(c);
key.codes = new int[] { c };
diff --git a/java/src/com/android/inputmethod/latin/BaseKeyboardView.java b/java/src/com/android/inputmethod/latin/BaseKeyboardView.java
index 954f264bd..3193cd46e 100644
--- a/java/src/com/android/inputmethod/latin/BaseKeyboardView.java
+++ b/java/src/com/android/inputmethod/latin/BaseKeyboardView.java
@@ -170,9 +170,10 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
private static final int HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL = -1;
// XML attribute
- private int mKeyTextSize;
+ private int mKeyLetterSize;
private int mKeyTextColor;
- private Typeface mKeyTextStyle = Typeface.DEFAULT;
+ private int mKeyTextColorDisabled;
+ private Typeface mKeyLetterStyle = Typeface.DEFAULT;
private int mLabelTextSize;
private int mColorScheme = COLOR_SCHEME_WHITE;
private int mShadowColor;
@@ -455,12 +456,15 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
case R.styleable.BaseKeyboardView_keyPreviewHeight:
mPreviewHeight = a.getDimensionPixelSize(attr, 80);
break;
- case R.styleable.BaseKeyboardView_keyTextSize:
- mKeyTextSize = a.getDimensionPixelSize(attr, 18);
+ case R.styleable.BaseKeyboardView_keyLetterSize:
+ mKeyLetterSize = a.getDimensionPixelSize(attr, 18);
break;
case R.styleable.BaseKeyboardView_keyTextColor:
mKeyTextColor = a.getColor(attr, 0xFF000000);
break;
+ case R.styleable.BaseKeyboardView_keyTextColorDisabled:
+ mKeyTextColorDisabled = a.getColor(attr, 0xFF000000);
+ break;
case R.styleable.BaseKeyboardView_labelTextSize:
mLabelTextSize = a.getDimensionPixelSize(attr, 14);
break;
@@ -477,20 +481,8 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
case R.styleable.BaseKeyboardView_backgroundDimAmount:
mBackgroundDimAmount = a.getFloat(attr, 0.5f);
break;
- //case android.R.styleable.
- case R.styleable.BaseKeyboardView_keyTextStyle:
- int textStyle = a.getInt(attr, 0);
- switch (textStyle) {
- case 0:
- mKeyTextStyle = Typeface.DEFAULT;
- break;
- case 1:
- mKeyTextStyle = Typeface.DEFAULT_BOLD;
- break;
- default:
- mKeyTextStyle = Typeface.defaultFromStyle(textStyle);
- break;
- }
+ case R.styleable.BaseKeyboardView_keyLetterStyle:
+ mKeyLetterStyle = Typeface.defaultFromStyle(a.getInt(attr, Typeface.NORMAL));
break;
case R.styleable.BaseKeyboardView_colorScheme:
mColorScheme = a.getInt(attr, COLOR_SCHEME_WHITE);
@@ -787,7 +779,6 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
final boolean isManualTemporaryUpperCase = (mKeyboard instanceof LatinKeyboard
&& ((LatinKeyboard)mKeyboard).isManualTemporaryUpperCase());
- paint.setColor(mKeyTextColor);
boolean drawSingleKey = false;
if (invalidKey != null && canvas.getClipBounds(clipRegion)) {
// TODO we should use Rect.inset and Rect.contains here.
@@ -820,7 +811,6 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
keyBackground.draw(canvas);
final int rowHeight = padding.top + key.height;
- boolean drawHintIcon = true;
// Draw key label
if (label != null) {
// For characters, use large font. For labels like "Done", use small font.
@@ -858,6 +848,11 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
if (DEBUG_SHOW_ALIGN && label.length() > 1)
drawVerticalLine(canvas, positionX, rowHeight, 0xc0008080, new Paint());
}
+ if (key.manualTemporaryUpperCaseHintIcon != null && isManualTemporaryUpperCase) {
+ paint.setColor(mKeyTextColorDisabled);
+ } else {
+ paint.setColor(mKeyTextColor);
+ }
// Set a drop shadow for the text
paint.setShadowLayer(mShadowRadius, 0, 0, mShadowColor);
canvas.drawText(label, positionX, baseline, paint);
@@ -892,7 +887,7 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
drawRectangle(canvas, drawableX, drawableY, drawableWidth, drawableHeight,
0x80c00000, new Paint());
}
- if (key.hintIcon != null && drawHintIcon) {
+ if (key.hintIcon != null) {
final int drawableWidth = key.width;
final int drawableHeight = key.height;
final int drawableX = 0;
@@ -954,18 +949,20 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
private int getLabelSizeAndSetPaint(CharSequence label, Key key, Paint paint) {
// For characters, use large font. For labels like "Done", use small font.
final int labelSize;
+ final Typeface labelStyle;
if (label.length() > 1 && key.codes.length < 2) {
labelSize = mLabelTextSize;
if ((key.labelOption & KEY_LABEL_OPTION_FONT_NORMAL) != 0) {
- paint.setTypeface(Typeface.DEFAULT);
+ labelStyle = Typeface.DEFAULT;
} else {
- paint.setTypeface(Typeface.DEFAULT_BOLD);
+ labelStyle = Typeface.DEFAULT_BOLD;
}
} else {
- labelSize = mKeyTextSize;
- paint.setTypeface(mKeyTextStyle);
+ labelSize = mKeyLetterSize;
+ labelStyle = mKeyLetterStyle;
}
paint.setTextSize(labelSize);
+ paint.setTypeface(labelStyle);
return labelSize;
}
@@ -1061,11 +1058,11 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
mPreviewText.setCompoundDrawables(null, null, null, null);
mPreviewText.setText(adjustCase(tracker.getPreviewText(key)));
if (key.label.length() > 1 && key.codes.length < 2) {
- mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize);
+ mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyLetterSize);
mPreviewText.setTypeface(Typeface.DEFAULT_BOLD);
} else {
mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
- mPreviewText.setTypeface(mKeyTextStyle);
+ mPreviewText.setTypeface(mKeyLetterStyle);
}
} else {
mPreviewText.setCompoundDrawables(null, null, null,
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 4e02f84d9..95c773855 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -45,7 +45,6 @@ public class BinaryDictionary extends Dictionary {
private static final int MAX_BIGRAMS = 60;
private static final int TYPED_LETTER_MULTIPLIER = 2;
- private static final boolean ENABLE_MISSED_CHARACTERS = true;
private int mDicTypeId;
private int mNativeDict;
@@ -199,27 +198,11 @@ public class BinaryDictionary extends Dictionary {
Arrays.fill(mOutputChars, (char) 0);
Arrays.fill(mFrequencies, 0);
- int count = getSuggestionsNative(mNativeDict, mInputCodes, codesSize,
- mOutputChars, mFrequencies,
- MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES, -1,
+ int count = getSuggestionsNative(mNativeDict, mInputCodes, codesSize, mOutputChars,
+ mFrequencies, MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES, -1,
nextLettersFrequencies,
nextLettersFrequencies != null ? nextLettersFrequencies.length : 0);
- // If there aren't sufficient suggestions, search for words by allowing wild cards at
- // the different character positions. This feature is not ready for prime-time as we need
- // to figure out the best ranking for such words compared to proximity corrections and
- // completions.
- if (ENABLE_MISSED_CHARACTERS && count < 5) {
- for (int skip = 0; skip < codesSize; skip++) {
- int tempCount = getSuggestionsNative(mNativeDict, mInputCodes, codesSize,
- mOutputChars, mFrequencies,
- MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES, skip,
- null, 0);
- count = Math.max(count, tempCount);
- if (tempCount > 0) break;
- }
- }
-
for (int j = 0; j < count; j++) {
if (mFrequencies[j] < 1) break;
int start = j * MAX_WORD_LENGTH;
diff --git a/java/src/com/android/inputmethod/latin/LatinIMESettings.java b/java/src/com/android/inputmethod/latin/LatinIMESettings.java
index 669192f59..ae6646113 100644
--- a/java/src/com/android/inputmethod/latin/LatinIMESettings.java
+++ b/java/src/com/android/inputmethod/latin/LatinIMESettings.java
@@ -32,7 +32,10 @@ import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup;
import android.speech.SpeechRecognizer;
import android.text.AutoText;
+import android.text.TextUtils;
+import android.text.method.LinkMovementMethod;
import android.util.Log;
+import android.widget.TextView;
import java.util.Locale;
@@ -60,6 +63,8 @@ public class LatinIMESettings extends PreferenceActivity
private CheckBoxPreference mBigramSuggestion;
private boolean mVoiceOn;
+ private AlertDialog mDialog;
+
private VoiceInputLogger mLogger;
private boolean mOkClicked = false;
@@ -91,8 +96,15 @@ public class LatinIMESettings extends PreferenceActivity
final boolean showSettingsKeyOption = getResources().getBoolean(
R.bool.config_enable_show_settings_key_option);
- if (!showSettingsKeyOption)
+ if (!showSettingsKeyOption) {
getPreferenceScreen().removePreference(mSettingsKeyPreference);
+ }
+
+ final boolean showVoiceKeyOption = getResources().getBoolean(
+ R.bool.config_enable_show_voice_key_option);
+ if (!showVoiceKeyOption) {
+ getPreferenceScreen().removePreference(mVoicePreference);
+ }
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
if (vibrator == null || !vibrator.hasVibrator()) {
@@ -149,6 +161,13 @@ public class LatinIMESettings extends PreferenceActivity
private void showVoiceConfirmation() {
mOkClicked = false;
showDialog(VOICE_INPUT_CONFIRM_DIALOG);
+ // Make URL in the dialog message clickable
+ if (mDialog != null) {
+ TextView textView = (TextView) mDialog.findViewById(android.R.id.message);
+ if (textView != null) {
+ textView.setMovementMethod(LinkMovementMethod.getInstance());
+ }
+ }
}
private void updateVoiceModeSummary() {
@@ -184,18 +203,20 @@ public class LatinIMESettings extends PreferenceActivity
boolean localeSupported = SubtypeSwitcher.getInstance().isVoiceSupported(
Locale.getDefault().toString());
+ final CharSequence message;
if (localeSupported) {
- String message = getString(R.string.voice_warning_may_not_understand) + "\n\n" +
- getString(R.string.voice_hint_dialog_message);
- builder.setMessage(message);
+ message = TextUtils.concat(
+ getText(R.string.voice_warning_may_not_understand), "\n\n",
+ getText(R.string.voice_hint_dialog_message));
} else {
- String message = getString(R.string.voice_warning_locale_not_supported) +
- "\n\n" + getString(R.string.voice_warning_may_not_understand) + "\n\n" +
- getString(R.string.voice_hint_dialog_message);
- builder.setMessage(message);
+ message = TextUtils.concat(
+ getText(R.string.voice_warning_locale_not_supported), "\n\n",
+ getText(R.string.voice_warning_may_not_understand), "\n\n",
+ getText(R.string.voice_hint_dialog_message));
}
-
+ builder.setMessage(message);
AlertDialog dialog = builder.create();
+ mDialog = dialog;
dialog.setOnDismissListener(this);
mLogger.settingsWarningDialogShown();
return dialog;
diff --git a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java
index fd9559dae..5574a21de 100644
--- a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java
+++ b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java
@@ -27,11 +27,23 @@ import com.android.inputmethod.latin.SubtypeSwitcher;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.SharedPreferences;
+import android.net.Uri;
import android.os.IBinder;
import android.preference.PreferenceManager;
+import android.provider.Browser;
import android.speech.SpeechRecognizer;
+import android.text.Layout;
+import android.text.Selection;
+import android.text.Spannable;
+import android.text.TextUtils;
+import android.text.method.LinkMovementMethod;
+import android.text.method.MovementMethod;
+import android.text.style.ClickableSpan;
+import android.text.style.URLSpan;
import android.view.LayoutInflater;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
@@ -41,6 +53,7 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
+import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashMap;
@@ -173,7 +186,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
switchToLastInputMethod();
}
});
- // When the dialog is dismissed by user's cancellation, swith back to the last input method.
+ // When the dialog is dismissed by user's cancellation, switch back to the last input method
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
@@ -182,16 +195,18 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
}
});
+ final CharSequence message;
if (mLocaleSupportedForVoiceInput) {
- String message = mContext.getString(R.string.voice_warning_may_not_understand)
- + "\n\n" + mContext.getString(R.string.voice_warning_how_to_turn_off);
- builder.setMessage(message);
+ message = TextUtils.concat(
+ mContext.getText(R.string.voice_warning_may_not_understand), "\n\n",
+ mContext.getText(R.string.voice_warning_how_to_turn_off));
} else {
- String message = mContext.getString(R.string.voice_warning_locale_not_supported)
- + "\n\n" + mContext.getString(R.string.voice_warning_may_not_understand)
- + "\n\n" + mContext.getString(R.string.voice_warning_how_to_turn_off);
- builder.setMessage(message);
+ message = TextUtils.concat(
+ mContext.getText(R.string.voice_warning_locale_not_supported), "\n\n",
+ mContext.getText(R.string.voice_warning_may_not_understand), "\n\n",
+ mContext.getText(R.string.voice_warning_how_to_turn_off));
}
+ builder.setMessage(message);
builder.setTitle(R.string.voice_warning_title);
mVoiceWarningDialog = builder.create();
@@ -203,6 +218,79 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
mVoiceInput.logKeyboardWarningDialogShown();
mVoiceWarningDialog.show();
+ // Make URL in the dialog message clickable
+ TextView textView = (TextView) mVoiceWarningDialog.findViewById(android.R.id.message);
+ if (textView != null) {
+ final CustomLinkMovementMethod method = CustomLinkMovementMethod.getInstance();
+ method.setVoiceWarningDialog(mVoiceWarningDialog);
+ textView.setMovementMethod(method);
+ }
+ }
+
+ private static class CustomLinkMovementMethod extends LinkMovementMethod {
+ private static CustomLinkMovementMethod sInstance = new CustomLinkMovementMethod();
+ private AlertDialog mAlertDialog;
+
+ public void setVoiceWarningDialog(AlertDialog alertDialog) {
+ mAlertDialog = alertDialog;
+ }
+
+ public static CustomLinkMovementMethod getInstance() {
+ return sInstance;
+ }
+
+ // Almost the same as LinkMovementMethod.onTouchEvent(), but overrides it for
+ // FLAG_ACTIVITY_NEW_TASK and mAlertDialog.cancel().
+ @Override
+ public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
+ int action = event.getAction();
+
+ if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
+ int x = (int) event.getX();
+ int y = (int) event.getY();
+
+ x -= widget.getTotalPaddingLeft();
+ y -= widget.getTotalPaddingTop();
+
+ x += widget.getScrollX();
+ y += widget.getScrollY();
+
+ Layout layout = widget.getLayout();
+ int line = layout.getLineForVertical(y);
+ int off = layout.getOffsetForHorizontal(line, x);
+
+ ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
+
+ if (link.length != 0) {
+ if (action == MotionEvent.ACTION_UP) {
+ if (link[0] instanceof URLSpan) {
+ URLSpan urlSpan = (URLSpan) link[0];
+ Uri uri = Uri.parse(urlSpan.getURL());
+ Context context = widget.getContext();
+ Intent intent = new Intent(Intent.ACTION_VIEW, uri);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
+ if (mAlertDialog != null) {
+ // Go back to the previous IME for now.
+ // TODO: If we can find a way to bring the new activity to front
+ // while keeping the warning dialog, we don't need to cancel here.
+ mAlertDialog.cancel();
+ }
+ context.startActivity(intent);
+ } else {
+ link[0].onClick(widget);
+ }
+ } else if (action == MotionEvent.ACTION_DOWN) {
+ Selection.setSelection(buffer, buffer.getSpanStart(link[0]),
+ buffer.getSpanEnd(link[0]));
+ }
+ return true;
+ } else {
+ Selection.removeSelection(buffer);
+ }
+ }
+ return super.onTouchEvent(widget, buffer, event);
+ }
}
public void showPunctuationHintIfNecessary() {