Merge remote-tracking branch 'goog/master' into merge

This commit is contained in:
satok 2011-04-21 19:11:48 +09:00
commit bbb42bff9e
30 changed files with 148 additions and 92 deletions

View file

@ -33,7 +33,7 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="InputLanguageSelection" <activity android:name="com.android.inputmethod.deprecated.languageswitcher.InputLanguageSelection"
android:label="@string/language_selection_title"> android:label="@string/language_selection_title">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

View file

@ -91,6 +91,8 @@
<attr name="verticalGap" format="dimension|fraction" /> <attr name="verticalGap" format="dimension|fraction" />
<!-- Popup keyboard layout template --> <!-- Popup keyboard layout template -->
<attr name="popupKeyboardTemplate" format="reference" /> <attr name="popupKeyboardTemplate" format="reference" />
<!-- Locale of the keyboard layout -->
<attr name="keyboardLocale" format="string" />
</declare-styleable> </declare-styleable>
<declare-styleable name="Keyboard_Key"> <declare-styleable name="Keyboard_Key">

View file

@ -48,8 +48,8 @@
<string name="alternates_for_currency_euro">¢,£,$,¥,₱</string> <string name="alternates_for_currency_euro">¢,£,$,¥,₱</string>
<string name="alternates_for_currency_pound">¢,$,€,¥,₱</string> <string name="alternates_for_currency_pound">¢,$,€,¥,₱</string>
<string name="alternates_for_smiley">":-)|:-) ,:-(|:-( ,;-)|;-) ,:-P|:-P ,=-O|=-O ,:-*|:-* ,:O|:O ,B-)|B-) ,:-$|:-$ ,:-!|:-! ,:-[|:-[ ,O:-)|O:-) ,:-\\\\\\\\|:-\\\\\\\\ ,:\'(|:\'( ,:-D|:-D "</string> <string name="alternates_for_smiley">":-)|:-) ,:-(|:-( ,;-)|;-) ,:-P|:-P ,=-O|=-O ,:-*|:-* ,:O|:O ,B-)|B-) ,:-$|:-$ ,:-!|:-! ,:-[|:-[ ,O:-)|O:-) ,:-\\\\\\\\|:-\\\\\\\\ ,:\'(|:\'( ,:-D|:-D "</string>
<string name="alternates_for_punctuation">"\?,!,\\,,:,-,\',\",(,),/,;,+,&amp;,\@"</string> <string name="alternates_for_punctuation">"\\,,\?,!,:,-,\',\",(,),/,;,+,&amp;,\@"</string>
<string name="alternates_for_web_tab_punctuation">".,\?,!,\\,,:,-,\',\",(,),/,;,+,&amp;,\@"</string> <string name="alternates_for_web_tab_punctuation">".,\\,,\?,!,:,-,\',\",(,),/,;,+,&amp;,\@"</string>
<string name="keylabel_for_popular_domain">".com"</string> <string name="keylabel_for_popular_domain">".com"</string>
<!-- popular web domains for the locale - most popular, displayed on the keyboard --> <!-- popular web domains for the locale - most popular, displayed on the keyboard -->
<string name="alternates_for_popular_domain">".net,.org,.gov,.edu"</string> <string name="alternates_for_popular_domain">".net,.org,.gov,.edu"</string>

View file

@ -28,6 +28,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="ar"
> >
<include <include
latin:keyboardLayout="@xml/kbd_ar_rows" /> latin:keyboardLayout="@xml/kbd_ar_rows" />

View file

@ -28,6 +28,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="cs"
> >
<include <include
latin:keyboardLayout="@xml/kbd_qwertz_rows" /> latin:keyboardLayout="@xml/kbd_qwertz_rows" />

View file

@ -27,6 +27,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="da"
> >
<include <include
latin:keyboardLayout="@xml/kbd_qwerty_rows_scandinavia" /> latin:keyboardLayout="@xml/kbd_qwerty_rows_scandinavia" />

View file

@ -28,6 +28,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="de"
> >
<include <include
latin:keyboardLayout="@xml/kbd_qwertz_rows" /> latin:keyboardLayout="@xml/kbd_qwertz_rows" />

View file

@ -27,6 +27,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="fi"
> >
<include <include
latin:keyboardLayout="@xml/kbd_qwerty_rows_scandinavia" /> latin:keyboardLayout="@xml/kbd_qwerty_rows_scandinavia" />

View file

@ -28,6 +28,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="fr_CA"
> >
<include <include
latin:keyboardLayout="@xml/kbd_qwerty_rows" /> latin:keyboardLayout="@xml/kbd_qwerty_rows" />

View file

@ -28,6 +28,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="fr_CH"
> >
<include <include
latin:keyboardLayout="@xml/kbd_qwertz_rows" /> latin:keyboardLayout="@xml/kbd_qwertz_rows" />

View file

@ -28,6 +28,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="fr"
> >
<include <include
latin:keyboardLayout="@xml/kbd_azerty_rows" /> latin:keyboardLayout="@xml/kbd_azerty_rows" />

View file

@ -28,6 +28,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="hu"
> >
<include <include
latin:keyboardLayout="@xml/kbd_qwertz_rows" /> latin:keyboardLayout="@xml/kbd_qwertz_rows" />

View file

@ -28,6 +28,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="iw"
> >
<include <include
latin:keyboardLayout="@xml/kbd_iw_rows" /> latin:keyboardLayout="@xml/kbd_iw_rows" />

View file

@ -27,6 +27,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="nb"
> >
<include <include
latin:keyboardLayout="@xml/kbd_qwerty_rows_scandinavia" /> latin:keyboardLayout="@xml/kbd_qwerty_rows_scandinavia" />

View file

@ -27,6 +27,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="ru"
> >
<include <include
latin:keyboardLayout="@xml/kbd_ru_rows" /> latin:keyboardLayout="@xml/kbd_ru_rows" />

View file

@ -27,6 +27,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="sr"
> >
<include <include
latin:keyboardLayout="@xml/kbd_sr_rows" /> latin:keyboardLayout="@xml/kbd_sr_rows" />

View file

@ -27,6 +27,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="sv"
> >
<include <include
latin:keyboardLayout="@xml/kbd_qwerty_rows_scandinavia" /> latin:keyboardLayout="@xml/kbd_qwerty_rows_scandinavia" />

View file

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2010, The Android Open Source Project
**
** 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.
*/
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
latin:keyboardHeight="@dimen/keyboardHeight"
latin:maxKeyboardHeight="50%p"
latin:rowHeight="25%p"
latin:horizontalGap="@dimen/key_horizontal_gap"
latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
>
<include
latin:keyboardLayout="@xml/kbd_qwerty_rows" />
</Keyboard>

View file

@ -28,6 +28,7 @@
latin:verticalGap="@dimen/key_bottom_gap" latin:verticalGap="@dimen/key_bottom_gap"
latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:popupKeyboardTemplate="@xml/kbd_popup_template"
latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column"
latin:keyboardLocale="en"
> >
<include <include
latin:keyboardLayout="@xml/kbd_qwerty_rows" /> latin:keyboardLayout="@xml/kbd_qwerty_rows" />

View file

@ -64,6 +64,13 @@
android:key="subtype_settings" android:key="subtype_settings"
android:title="@string/language_selection_title" android:title="@string/language_selection_title"
android:summary="@string/language_selection_summary" /> android:summary="@string/language_selection_summary" />
<PreferenceScreen
android:key="language_selection"
android:title="@string/language_selection_title"
android:summary="@string/language_selection_summary">
<intent
android:action="com.android.inputmethod.latin.INPUT_LANGUAGE_SELECTION"/>
</PreferenceScreen>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/prediction_category" android:title="@string/prediction_category"

View file

@ -1,12 +1,12 @@
/* /*
* Copyright (C) 2008-2009 Google Inc. * Copyright (C) 2008-2009 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * 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 * use this file except in compliance with the License. You may obtain a copy of
* the License at * the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@ -14,7 +14,18 @@
* the License. * the License.
*/ */
package com.android.inputmethod.latin; package com.android.inputmethod.deprecated.languageswitcher;
import com.android.inputmethod.keyboard.KeyboardParser;
import com.android.inputmethod.latin.BinaryDictionary;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Settings;
import com.android.inputmethod.latin.SharedPreferencesCompat;
import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.Suggest;
import com.android.inputmethod.latin.Utils;
import org.xmlpull.v1.XmlPullParserException;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
@ -26,7 +37,9 @@ import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup; import android.preference.PreferenceGroup;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Pair;
import java.io.IOException;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -37,9 +50,6 @@ public class InputLanguageSelection extends PreferenceActivity {
private SharedPreferences mPrefs; private SharedPreferences mPrefs;
private String mSelectedLanguages; private String mSelectedLanguages;
private ArrayList<Loc> mAvailableLanguages = new ArrayList<Loc>(); private ArrayList<Loc> mAvailableLanguages = new ArrayList<Loc>();
private static final String[] BLACKLIST_LANGUAGES = {
"ko", "ja", "zh", "el", "zz"
};
private static class Loc implements Comparable<Object> { private static class Loc implements Comparable<Object> {
private static Collator sCollator = Collator.getInstance(); private static Collator sCollator = Collator.getInstance();
@ -78,12 +88,18 @@ public class InputLanguageSelection extends PreferenceActivity {
mAvailableLanguages = getUniqueLocales(); mAvailableLanguages = getUniqueLocales();
PreferenceGroup parent = getPreferenceScreen(); PreferenceGroup parent = getPreferenceScreen();
for (int i = 0; i < mAvailableLanguages.size(); i++) { for (int i = 0; i < mAvailableLanguages.size(); i++) {
CheckBoxPreference pref = new CheckBoxPreference(this);
Locale locale = mAvailableLanguages.get(i).mLocale; Locale locale = mAvailableLanguages.get(i).mLocale;
final Pair<Boolean, Boolean> hasDictionaryOrLayout = hasDictionaryOrLayout(locale);
final boolean hasDictionary = hasDictionaryOrLayout.first;
final boolean hasLayout = hasDictionaryOrLayout.second;
if (!hasDictionary && !hasLayout) {
continue;
}
CheckBoxPreference pref = new CheckBoxPreference(this);
pref.setTitle(SubtypeSwitcher.getFullDisplayName(locale, true)); pref.setTitle(SubtypeSwitcher.getFullDisplayName(locale, true));
boolean checked = isLocaleIn(locale, languageList); boolean checked = isLocaleIn(locale, languageList);
pref.setChecked(checked); pref.setChecked(checked);
if (hasDictionary(locale)) { if (hasDictionary) {
pref.setSummary(R.string.has_dictionary); pref.setSummary(R.string.has_dictionary);
} }
parent.addPreference(pref); parent.addPreference(pref);
@ -98,26 +114,39 @@ public class InputLanguageSelection extends PreferenceActivity {
return false; return false;
} }
private boolean hasDictionary(Locale locale) { private Pair<Boolean, Boolean> hasDictionaryOrLayout(Locale locale) {
if (locale == null) return new Pair<Boolean, Boolean>(false, false);
final Resources res = getResources(); final Resources res = getResources();
final Configuration conf = res.getConfiguration(); final Configuration conf = res.getConfiguration();
final Locale saveLocale = conf.locale; final Locale saveLocale = conf.locale;
boolean haveDictionary = false;
conf.locale = locale; conf.locale = locale;
res.updateConfiguration(conf, res.getDisplayMetrics()); res.updateConfiguration(conf, res.getDisplayMetrics());
boolean hasDictionary = false;
boolean hasLayout = false;
BinaryDictionary bd = BinaryDictionary.initDictionaryFromManager(this, Suggest.DIC_MAIN, try {
locale, Utils.getMainDictionaryResourceId(res)); BinaryDictionary bd = BinaryDictionary.initDictionaryFromManager(this, Suggest.DIC_MAIN,
locale, Utils.getMainDictionaryResourceId(res));
// Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of // Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of
// 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words. // 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words.
if (bd.getSize() > Suggest.LARGE_DICTIONARY_THRESHOLD / 4) { if (bd.getSize() > Suggest.LARGE_DICTIONARY_THRESHOLD / 4) {
haveDictionary = true; hasDictionary = true;
}
bd.close();
final String countryCode = locale.getLanguage();
final String layoutCountryCode = KeyboardParser.parseKeyboardLocale(
this, R.xml.kbd_qwerty);
if (!TextUtils.isEmpty(countryCode) && !TextUtils.isEmpty(layoutCountryCode)) {
hasLayout = countryCode.subSequence(0, 2).equals(layoutCountryCode.substring(0, 2));
}
} catch (XmlPullParserException e) {
} catch (IOException e) {
} }
bd.close();
conf.locale = saveLocale; conf.locale = saveLocale;
res.updateConfiguration(conf, res.getDisplayMetrics()); res.updateConfiguration(conf, res.getDisplayMetrics());
return haveDictionary; return new Pair<Boolean, Boolean>(hasDictionary, hasLayout);
} }
private String get5Code(Locale locale) { private String get5Code(Locale locale) {
@ -173,7 +202,7 @@ public class InputLanguageSelection extends PreferenceActivity {
Locale l = new Locale(language, country); Locale l = new Locale(language, country);
// Exclude languages that are not relevant to LatinIME // Exclude languages that are not relevant to LatinIME
if (arrayContains(BLACKLIST_LANGUAGES, language) || TextUtils.isEmpty(language)) { if (TextUtils.isEmpty(language)) {
continue; continue;
} }
@ -207,11 +236,4 @@ public class InputLanguageSelection extends PreferenceActivity {
} }
return uniqueLocales; return uniqueLocales;
} }
private boolean arrayContains(String[] array, String value) {
for (int i = 0; i < array.length; i++) {
if (array[i].equalsIgnoreCase(value)) return true;
}
return false;
}
} }

View file

@ -338,10 +338,6 @@ public class Key {
mPressed = false; mPressed = false;
} }
public boolean isInside(int x, int y) {
return mKeyboard.isInside(this, x, y);
}
/** /**
* Detects if a point falls on this key. * Detects if a point falls on this key.
* @param x the x-coordinate of the point * @param x the x-coordinate of the point

View file

@ -174,7 +174,7 @@ public class KeyDetector {
int primaryIndex = NOT_A_KEY; int primaryIndex = NOT_A_KEY;
for (final int index : mKeyboard.getNearestKeys(touchX, touchY)) { for (final int index : mKeyboard.getNearestKeys(touchX, touchY)) {
final Key key = keys.get(index); final Key key = keys.get(index);
final boolean isInside = key.isInside(touchX, touchY); final boolean isInside = mKeyboard.isInside(key, touchX, touchY);
final int distance = key.squaredDistanceToEdge(touchX, touchY); final int distance = key.squaredDistanceToEdge(touchX, touchY);
if (isInside || (mProximityCorrectOn && distance < mProximityThresholdSquare)) { if (isInside || (mProximityCorrectOn && distance < mProximityThresholdSquare)) {
final int insertedPosition = sortNearbyKeys(index, distance); final int insertedPosition = sortNearbyKeys(index, distance);

View file

@ -22,6 +22,7 @@ import com.android.inputmethod.latin.R;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
@ -163,6 +164,27 @@ public class KeyboardParser {
} }
} }
public static String parseKeyboardLocale(
Context context, int resId) throws XmlPullParserException, IOException {
final Resources res = context.getResources();
final XmlResourceParser parser = res.getXml(resId);
if (parser == null) return "";
int event;
while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (event == XmlPullParser.START_TAG) {
final String tag = parser.getName();
if (TAG_KEYBOARD.equals(tag)) {
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
return keyboardAttr.getString(R.styleable.Keyboard_keyboardLocale);
} else {
throw new IllegalStartTag(parser, TAG_KEYBOARD);
}
}
}
return "";
}
private void parseKeyboardAttributes(XmlResourceParser parser) { private void parseKeyboardAttributes(XmlResourceParser parser) {
final Keyboard keyboard = mKeyboard; final Keyboard keyboard = mKeyboard;
final TypedArray keyboardAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), final TypedArray keyboardAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),

View file

@ -889,8 +889,11 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
@Override @Override
public void showKeyPreview(int keyIndex, PointerTracker tracker) { public void showKeyPreview(int keyIndex, PointerTracker tracker) {
if (mShowKeyPreview || mKeyboard.needSpacebarPreview(keyIndex)) { if (mShowKeyPreview) {
mHandler.showKeyPreview(mDelayBeforePreview, keyIndex, tracker); mHandler.showKeyPreview(mDelayBeforePreview, keyIndex, tracker);
} else if (mKeyboard.needSpacebarPreview(keyIndex)) {
// Show key preview (in this case, slide language switcher) without any delay.
showKey(keyIndex, tracker);
} }
} }
@ -899,6 +902,9 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
if (mShowKeyPreview) { if (mShowKeyPreview) {
mHandler.cancelShowKeyPreview(tracker); mHandler.cancelShowKeyPreview(tracker);
mHandler.dismissKeyPreview(mDelayAfterPreview, tracker); mHandler.dismissKeyPreview(mDelayAfterPreview, tracker);
} else if (mKeyboard.needSpacebarPreview(KeyDetector.NOT_A_KEY)) {
// Dismiss key preview (in this case, slide language switcher) without any delay.
mPreviewText.setVisibility(View.INVISIBLE);
} }
} }

View file

@ -392,7 +392,7 @@ public class PointerTracker {
startLongPressTimer(keyIndex); startLongPressTimer(keyIndex);
showKeyPreview(keyIndex); showKeyPreview(keyIndex);
setPressedKeyGraphics(keyIndex); setPressedKeyGraphics(keyIndex);
} else if (!isMinorMoveBounce(x, y, keyIndex)) { } else if (isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) {
// The pointer has been slid in to the new key from the previous key, we must call // The pointer has been slid in to the new key from the previous key, we must call
// onRelease() first to notify that the previous key has been released, then call // onRelease() first to notify that the previous key has been released, then call
// onPress() to notify that the new key is being pressed. // onPress() to notify that the new key is being pressed.
@ -430,9 +430,12 @@ public class PointerTracker {
} }
return; return;
} }
} else if (mKeyboard.needSpacebarPreview(keyIndex)) {
// Display spacebar slide language switcher.
showKeyPreview(keyIndex);
} }
} else { } else {
if (oldKey != null && !isMinorMoveBounce(x, y, keyIndex)) { if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) {
// The pointer has been slid out from the previous key, we must call onRelease() to // The pointer has been slid out from the previous key, we must call onRelease() to
// notify that the previous key has been released. // notify that the previous key has been released.
setReleasedKeyGraphics(oldKeyIndex); setReleasedKeyGraphics(oldKeyIndex);
@ -483,7 +486,7 @@ public class PointerTracker {
mIsInSlidingKeyInput = false; mIsInSlidingKeyInput = false;
final PointerTrackerKeyState keyState = mKeyState; final PointerTrackerKeyState keyState = mKeyState;
final int keyX, keyY; final int keyX, keyY;
if (!isMinorMoveBounce(x, y, keyState.onMoveKey(x, y))) { if (isMajorEnoughMoveToBeOnNewKey(x, y, keyState.onMoveKey(x, y))) {
keyX = x; keyX = x;
keyY = y; keyY = y;
} else { } else {
@ -544,28 +547,37 @@ public class PointerTracker {
return mKeyState.getDownTime(); return mKeyState.getDownTime();
} }
private boolean isMinorMoveBounce(int x, int y, int newKey) { private boolean isMajorEnoughMoveToBeOnNewKey(int x, int y, int newKey) {
if (mKeys == null || mKeyHysteresisDistanceSquared < 0) if (mKeys == null || mKeyHysteresisDistanceSquared < 0)
throw new IllegalStateException("keyboard and/or hysteresis not set"); throw new IllegalStateException("keyboard and/or hysteresis not set");
int curKey = mKeyState.getKeyIndex(); int curKey = mKeyState.getKeyIndex();
if (newKey == curKey) { if (newKey == curKey) {
return true;
} else if (isValidKeyIndex(curKey)) {
return mKeys.get(curKey).squaredDistanceToEdge(x, y) < mKeyHysteresisDistanceSquared;
} else {
return false; return false;
} else if (isValidKeyIndex(curKey)) {
return mKeys.get(curKey).squaredDistanceToEdge(x, y) >= mKeyHysteresisDistanceSquared;
} else {
return true;
} }
} }
private void showKeyPreview(int keyIndex) { // The modifier key, such as shift key, should not show its key preview. If accessibility is
// turned on, the modifier key should show its key preview.
private boolean isKeyPreviewNotRequired(int keyIndex) {
final Key key = getKey(keyIndex); final Key key = getKey(keyIndex);
if (key != null && !key.mEnabled) if (!key.mEnabled)
return; return true;
// The modifier key, such as shift key, should not be shown as preview when multi-touch is if (mIsAccessibilityEnabled)
// supported. On the other hand, if multi-touch is not supported, the modifier key should return false;
// be shown as preview. If accessibility is turned on, the modifier key should be shown as // Such as spacebar sliding language switch.
// preview. if (mKeyboard.needSpacebarPreview(keyIndex))
if (mHasDistinctMultitouch && isModifier() && !mIsAccessibilityEnabled) return false;
final int code = key.mCode;
return isModifierCode(code) || code == Keyboard.CODE_DELETE
|| code == Keyboard.CODE_ENTER || code == Keyboard.CODE_SPACE;
}
private void showKeyPreview(int keyIndex) {
if (isKeyPreviewNotRequired(keyIndex))
return; return;
mProxy.showKeyPreview(keyIndex, this); mProxy.showKeyPreview(keyIndex, this);
} }

View file

@ -27,7 +27,6 @@ import android.provider.BaseColumns;
import android.util.Log; import android.util.Log;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;

View file

@ -901,15 +901,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
public void onComputeInsets(InputMethodService.Insets outInsets) { public void onComputeInsets(InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets); super.onComputeInsets(outInsets);
final KeyboardView inputView = mKeyboardSwitcher.getInputView(); final KeyboardView inputView = mKeyboardSwitcher.getInputView();
if (inputView == null)
return;
final int containerHeight = mCandidateViewContainer.getHeight();
int touchY = containerHeight;
// Need to set touchable region only if input view is being shown // Need to set touchable region only if input view is being shown
if (inputView != null && mKeyboardSwitcher.isInputViewShown()) { if (mKeyboardSwitcher.isInputViewShown()) {
final int containerHeight = mCandidateViewContainer.getHeight();
int touchY = containerHeight;
if (mCandidateViewContainer.getVisibility() == View.VISIBLE) { if (mCandidateViewContainer.getVisibility() == View.VISIBLE) {
touchY -= mCandidateStripHeight; touchY -= mCandidateStripHeight;
} }
outInsets.contentTopInsets = touchY;
outInsets.visibleTopInsets = touchY;
final int touchWidth = inputView.getWidth(); final int touchWidth = inputView.getWidth();
final int touchHeight = inputView.getHeight() + containerHeight final int touchHeight = inputView.getHeight() + containerHeight
// Extend touchable region below the keyboard. // Extend touchable region below the keyboard.
@ -920,6 +920,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
setTouchableRegionCompat(outInsets, 0, touchY, touchWidth, touchHeight); setTouchableRegionCompat(outInsets, 0, touchY, touchWidth, touchHeight);
} }
outInsets.contentTopInsets = touchY;
outInsets.visibleTopInsets = touchY;
} }
@Override @Override

View file

@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
import com.android.inputmethod.compat.CompatUtils; import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.compat.VibratorCompatWrapper;
@ -67,6 +68,7 @@ public class Settings extends PreferenceActivity
public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold"; public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold";
public static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion"; public static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion";
public static final String PREF_DEBUG_SETTINGS = "debug_settings"; public static final String PREF_DEBUG_SETTINGS = "debug_settings";
public static final String PREF_LANGUAGE_SELECTION = "language_selection";
public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";
@ -183,6 +185,10 @@ public class Settings extends PreferenceActivity
if (!showUsabilityModeStudyOption) { if (!showUsabilityModeStudyOption) {
getPreferenceScreen().removePreference(findPreference(PREF_USABILITY_STUDY_MODE)); getPreferenceScreen().removePreference(findPreference(PREF_USABILITY_STUDY_MODE));
} }
if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
generalSettings.removePreference(findPreference(PREF_LANGUAGE_SELECTION));
}
} }
@Override @Override

View file

@ -75,7 +75,7 @@ public class Suggest implements Dictionary.WordCallback {
public static final String DICT_KEY_USER_BIGRAM = "user_bigram"; public static final String DICT_KEY_USER_BIGRAM = "user_bigram";
public static final String DICT_KEY_WHITELIST ="whitelist"; public static final String DICT_KEY_WHITELIST ="whitelist";
static final int LARGE_DICTIONARY_THRESHOLD = 200 * 1000; public static final int LARGE_DICTIONARY_THRESHOLD = 200 * 1000;
private static final boolean DBG = LatinImeLogger.sDBG; private static final boolean DBG = LatinImeLogger.sDBG;