diff options
Diffstat (limited to 'java/src')
7 files changed, 77 insertions, 50 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 4d7fe3d8e..c3f5e7da2 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -571,9 +571,13 @@ public class Key { return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY) != 0; } - public Drawable getIcon(KeyboardIconsSet iconSet) { + public Drawable getIcon(KeyboardIconsSet iconSet, int alpha) { final int iconId = mEnabled ? mIconId : mDisabledIconId; - return iconSet.getIconDrawable(iconId); + final Drawable icon = iconSet.getIconDrawable(iconId); + if (icon != null) { + icon.setAlpha(alpha); + } + return icon; } public Drawable getPreviewIcon(KeyboardIconsSet iconSet) { diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 9be193ba7..c0d5b6772 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -560,10 +560,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } // Draw key label. - final Drawable icon = key.getIcon(mKeyboard.mIconsSet); - if (icon != null) { - icon.setAlpha(params.mAnimAlpha); - } + final Drawable icon = key.getIcon(mKeyboard.mIconsSet, params.mAnimAlpha); float positionX = centerX; if (key.mLabel != null) { final String label = key.mLabel; diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 337ae9c17..cb3767297 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -459,7 +459,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke mMoreKeysPanelCache.clear(); mSpaceKey = keyboard.getKey(Keyboard.CODE_SPACE); - mSpaceIcon = (mSpaceKey != null) ? mSpaceKey.getIcon(keyboard.mIconsSet) : null; + mSpaceIcon = (mSpaceKey != null) + ? mSpaceKey.getIcon(keyboard.mIconsSet, ALPHA_OPAQUE) : null; final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap; mSpacebarTextSize = keyHeight * mSpacebarTextRatio; if (ProductionFlag.IS_EXPERIMENTAL) { diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java index b6a06e136..a3741a2d8 100644 --- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java @@ -289,8 +289,6 @@ public class MoreKeysKeyboard extends Keyboard { final int dividerWidth; if (parentKey.needsDividersInMoreKeys()) { mDivider = mResources.getDrawable(R.drawable.more_keys_divider); - // TODO: Drawable itself should have an alpha value. - mDivider.setAlpha(128); dividerWidth = (int)(width * DIVIDER_RATIO); } else { mDivider = null; @@ -333,8 +331,11 @@ public class MoreKeysKeyboard extends Keyboard { } @Override - public Drawable getIcon(KeyboardIconsSet iconSet) { - // KeyboardIconsSet is unused. Use the icon that has been passed to the constructor. + public Drawable getIcon(KeyboardIconsSet iconSet, int alpha) { + // KeyboardIconsSet and alpha are unused. Use the icon that has been passed to the + // constructor. + // TODO: Drawable itself should have an alpha value. + mIcon.setAlpha(128); return mIcon; } } diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java index 0bde2c011..a8115fb82 100644 --- a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java +++ b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java @@ -22,6 +22,7 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Parcel; @@ -41,6 +42,8 @@ import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.SpinnerAdapter; +import com.android.inputmethod.compat.CompatUtils; + import java.util.TreeSet; public class AdditionalSubtypeSettings extends PreferenceFragment { @@ -49,9 +52,14 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { private KeyboardLayoutSetAdapter mKeyboardLayoutSetAdapter; private boolean mIsAddingNewSubtype; + private AlertDialog mSubtypeEnablerNotificationDialog; + private String mSubtypePreferenceKeyForSubtypeEnabler; private static final int MENU_ADD_SUBTYPE = Menu.FIRST; - private static final String SAVE_IS_ADDING_NEW_SUBTYPE = "is_adding_new_subtype"; + private static final String KEY_IS_ADDING_NEW_SUBTYPE = "is_adding_new_subtype"; + private static final String KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN = + "is_subtype_enabler_notification_dialog_open"; + private static final String KEY_SUBTYPE_FOR_SUBTYPE_ENABLER = "subtype_for_subtype_enabler"; static class SubtypeLocaleItem extends Pair<String, String> implements Comparable<SubtypeLocaleItem> { @@ -368,20 +376,36 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { setPrefSubtypes(prefSubtypes, context); mIsAddingNewSubtype = (savedInstanceState != null) - && savedInstanceState.containsKey(SAVE_IS_ADDING_NEW_SUBTYPE); + && savedInstanceState.containsKey(KEY_IS_ADDING_NEW_SUBTYPE); if (mIsAddingNewSubtype) { getPreferenceScreen().addPreference( SubtypePreference.newIncompleteSubtypePreference(context, mSubtypeProxy)); } super.onActivityCreated(savedInstanceState); + + if (savedInstanceState != null && savedInstanceState.containsKey( + KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN)) { + mSubtypePreferenceKeyForSubtypeEnabler = savedInstanceState.getString( + KEY_SUBTYPE_FOR_SUBTYPE_ENABLER); + final SubtypePreference subtypePref = (SubtypePreference)findPreference( + mSubtypePreferenceKeyForSubtypeEnabler); + mSubtypeEnablerNotificationDialog = createDialog(subtypePref); + mSubtypeEnablerNotificationDialog.show(); + } } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (mIsAddingNewSubtype) { - outState.putBoolean(SAVE_IS_ADDING_NEW_SUBTYPE, true); + outState.putBoolean(KEY_IS_ADDING_NEW_SUBTYPE, true); + } + if (mSubtypeEnablerNotificationDialog != null + && mSubtypeEnablerNotificationDialog.isShowing()) { + outState.putBoolean(KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN, true); + outState.putString( + KEY_SUBTYPE_FOR_SUBTYPE_ENABLER, mSubtypePreferenceKeyForSubtypeEnabler); } } @@ -398,6 +422,10 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { @Override public void onAddPressed(SubtypePreference subtypePref) { mIsAddingNewSubtype = false; + setAdditionalInputMethodSubtypes(getPrefSubtypes()); + mSubtypePreferenceKeyForSubtypeEnabler = subtypePref.getKey(); + mSubtypeEnablerNotificationDialog = createDialog(subtypePref); + mSubtypeEnablerNotificationDialog.show(); } @Override @@ -411,6 +439,29 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { } }; + private AlertDialog createDialog(SubtypePreference subtypePref) { + final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle(R.string.custom_input_styles_title) + .setMessage(R.string.custom_input_style_note_message) + .setNegativeButton(R.string.not_now, null) + .setPositiveButton(R.string.enable, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + final Intent intent = CompatUtils.getInputLanguageSelectionIntent( + ImfUtils.getInputMethodIdOfThisIme(getActivity()), + Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED + | Intent.FLAG_ACTIVITY_CLEAR_TOP); + // TODO: Add newly adding subtype to extra value of the intent as a hint + // for the input language selection activity. + // intent.putExtra("newlyAddedSubtype", subtypePref.getSubtype()); + startActivity(intent); + } + }); + + return builder.create(); + } + private void setPrefSubtypes(String prefSubtypes, Context context) { final PreferenceGroup group = getPreferenceScreen(); group.removeAll(); @@ -458,6 +509,10 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { } finally { editor.apply(); } + setAdditionalInputMethodSubtypes(prefSubtypes); + } + + private void setAdditionalInputMethodSubtypes(final String prefSubtypes) { final InputMethodSubtype[] subtypes = AdditionalSubtype.createAdditionalSubtypesArray(prefSubtypes); ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), subtypes); diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index c4877316e..7832cb522 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -43,20 +43,6 @@ public class Suggest implements Dictionary.WordCallback { public static final int CORRECTION_FULL = 1; public static final int CORRECTION_FULL_BIGRAM = 2; - /** - * Words that appear in both bigram and unigram data gets multiplier ranging from - * BIGRAM_MULTIPLIER_MIN to BIGRAM_MULTIPLIER_MAX depending on the score from - * bigram data. - */ - public static final double BIGRAM_MULTIPLIER_MIN = 1.2; - public static final double BIGRAM_MULTIPLIER_MAX = 1.5; - - /** - * Maximum possible bigram frequency. Will depend on how many bits are being used in data - * structure. Maximum bigram frequency will get the BIGRAM_MULTIPLIER_MAX as the multiplier. - */ - public static final int MAXIMUM_BIGRAM_FREQUENCY = 127; - // It seems the following values are only used for logging. public static final int DIC_USER_TYPED = 0; public static final int DIC_MAIN = 1; @@ -478,25 +464,6 @@ public class Suggest implements Dictionary.WordCallback { } } } else { - if (dataType == Dictionary.UNIGRAM) { - // Check if the word was already added before (by bigram data) - int bigramSuggestion = searchBigramSuggestion(word,offset,length); - if(bigramSuggestion >= 0) { - dataTypeForLog = Dictionary.BIGRAM; - // turn freq from bigram into multiplier specified above - double multiplier = (((double) mBigramSuggestions.get(bigramSuggestion).mScore) - / MAXIMUM_BIGRAM_FREQUENCY) - * (BIGRAM_MULTIPLIER_MAX - BIGRAM_MULTIPLIER_MIN) - + BIGRAM_MULTIPLIER_MIN; - /* Log.d(TAG,"bigram num: " + bigramSuggestion - + " wordB: " + mBigramSuggestions.get(bigramSuggestion).toString() - + " currentScore: " + score + " bigramScore: " - + mBigramScores[bigramSuggestion] - + " multiplier: " + multiplier); */ - score = (int)Math.round((score * multiplier)); - } - } - // Check the last one's score and bail if (suggestions.size() >= prefMaxSuggestions && suggestions.get(prefMaxSuggestions - 1).mScore >= score) return true; diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java index dd83a0c4e..c6fe43b69 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java @@ -56,8 +56,6 @@ public class MoreSuggestions extends Keyboard { clearKeys(); final Resources res = view.getContext().getResources(); mDivider = res.getDrawable(R.drawable.more_suggestions_divider); - // TODO: Drawable itself should have an alpha value. - mDivider.setAlpha(128); mDividerWidth = mDivider.getIntrinsicWidth(); final int padding = (int) res.getDimension( R.dimen.more_suggestions_key_horizontal_padding); @@ -195,7 +193,11 @@ public class MoreSuggestions extends Keyboard { } @Override - public Drawable getIcon(KeyboardIconsSet iconSet) { + public Drawable getIcon(KeyboardIconsSet iconSet, int alpha) { + // KeyboardIconsSet and alpha are unused. Use the icon that has been passed to the + // constructor. + // TODO: Drawable itself should have an alpha value. + mIcon.setAlpha(128); return mIcon; } } |