Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit adbafa1a authored by Satoshi Kataoka's avatar Satoshi Kataoka Committed by Android (Google) Code Review
Browse files

Merge "Support ICS on the user dictionary settings"

parents 4bb312c7 dcef9416
Loading
Loading
Loading
Loading
+30 −31
Original line number Diff line number Diff line
@@ -13,40 +13,39 @@
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:background="?android:attr/selectableItemBackground"
    android:gravity="center_vertical"
    android:paddingEnd="?android:attr/scrollbarSize"
    android:background="?android:attr/selectableItemBackground" >
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:paddingEnd="?android:attr/scrollbarSize" >

  <RelativeLayout android:layout_width="wrap_content"
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
                  android:layout_marginStart="15dip"
                  android:layout_marginEnd="6dip"
                  android:layout_marginTop="6dip"
                  android:layout_marginBottom="6dip"
        android:padding="6dip"
        android:layout_weight="1" >

    <TextView android:id="@+android:id/text1"
        <TextView
            android:id="@+android:id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
              android:singleLine="true"
              android:textAppearance="?android:attr/textAppearanceMedium"
            android:ellipsize="marquee"
              android:fadingEdge="horizontal" />
            android:fadingEdge="horizontal"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView android:id="@+android:id/text2"
        <TextView
            android:id="@+android:id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
              android:layout_below="@android:id/text1"
            android:layout_alignStart="@android:id/text1"
            android:layout_below="@android:id/text1"
            android:maxLines="1"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"
              android:maxLines="1" />

            android:visibility="gone" />
    </RelativeLayout>

</LinearLayout>
+8 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ public final class UserDictionaryCompatUtils {
    private static final Method METHOD_addWord = CompatUtils.getMethod(Words.class, "addWord",
            Context.class, String.class, Integer.TYPE, String.class, Locale.class);

    @SuppressWarnings("deprecation")
    public static void addWord(final Context context, final String word, final int freq,
            final String shortcut, final Locale locale) {
        if (hasNewerAddWord()) {
@@ -39,13 +40,18 @@ public final class UserDictionaryCompatUtils {
            if (null == locale) {
                localeType = Words.LOCALE_TYPE_ALL;
            } else {
                final Locale currentLocale = context.getResources().getConfiguration().locale;
                if (locale.equals(currentLocale)) {
                    localeType = Words.LOCALE_TYPE_CURRENT;
                } else {
                    localeType = Words.LOCALE_TYPE_ALL;
                }
            }
            Words.addWord(context, word, freq, localeType);
        }
    }

    private static final boolean hasNewerAddWord() {
    public static final boolean hasNewerAddWord() {
        return null != METHOD_addWord;
    }
}
+3 −9
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
@@ -46,7 +45,7 @@ import com.android.inputmethodcommon.InputMethodSettingsFragment;

public final class SettingsFragment extends InputMethodSettingsFragment
        implements SharedPreferences.OnSharedPreferenceChangeListener {
    private static final boolean DBG_USE_INTERNAL_USER_SETTINGS = false;
    private static final boolean DBG_USE_INTERNAL_USER_DICTIONARY_SETTINGS = false;

    private ListPreference mVoicePreference;
    private ListPreference mShowCorrectionSuggestionsPreference;
@@ -202,13 +201,8 @@ public final class SettingsFragment extends InputMethodSettingsFragment
        final Intent editPersonalDictionaryIntent = editPersonalDictionary.getIntent();
        final ResolveInfo ri = context.getPackageManager().resolveActivity(
                editPersonalDictionaryIntent, PackageManager.MATCH_DEFAULT_ONLY);
        if (DBG_USE_INTERNAL_USER_SETTINGS || ri == null) {
            // TODO: Support ICS
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (DBG_USE_INTERNAL_USER_DICTIONARY_SETTINGS || ri == null) {
            updateUserDictionaryPreference(editPersonalDictionary);
            } else {
                removePreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY, getPreferenceScreen());
            }
        }

        if (!Settings.readFromBuildConfigIfGestureInputEnabled(res)) {
+23 −9
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.inputmethod.latin.userdictionary;

import com.android.inputmethod.compat.UserDictionaryCompatUtils;
import com.android.inputmethod.latin.LocaleUtils;
import com.android.inputmethod.latin.R;

@@ -68,18 +69,28 @@ public class UserDictionaryAddWordContents {
    /* package */ UserDictionaryAddWordContents(final View view, final Bundle args) {
        mWordEditText = (EditText)view.findViewById(R.id.user_dictionary_add_word_text);
        mShortcutEditText = (EditText)view.findViewById(R.id.user_dictionary_add_shortcut);
        if (!UserDictionarySettings.IS_SHORTCUT_API_SUPPORTED) {
            mShortcutEditText.setVisibility(View.GONE);
            view.findViewById(R.id.user_dictionary_add_shortcut_label).setVisibility(View.GONE);
        }
        final String word = args.getString(EXTRA_WORD);
        if (null != word) {
            mWordEditText.setText(word);
            mWordEditText.setSelection(word.length());
        }
        final String shortcut = args.getString(EXTRA_SHORTCUT);
        final String shortcut;
        if (UserDictionarySettings.IS_SHORTCUT_API_SUPPORTED) {
            shortcut = args.getString(EXTRA_SHORTCUT);
            if (null != shortcut && null != mShortcutEditText) {
                mShortcutEditText.setText(shortcut);
            }
            mOldShortcut = args.getString(EXTRA_SHORTCUT);
        } else {
            shortcut = null;
            mOldShortcut = null;
        }
        mMode = args.getInt(EXTRA_MODE); // default return value for #getInt() is 0 = MODE_EDIT
        mOldWord = args.getString(EXTRA_WORD);
        mOldShortcut = args.getString(EXTRA_SHORTCUT);
        updateLocale(args.getString(EXTRA_LOCALE));
    }

@@ -110,7 +121,8 @@ public class UserDictionaryAddWordContents {
        // If we are in add mode, nothing was added, so we don't need to do anything.
    }

    /* package */ int apply(final Context context, final Bundle outParameters) {
    /* package */
    int apply(final Context context, final Bundle outParameters) {
        if (null != outParameters) saveStateIntoBundle(outParameters);
        final ContentResolver resolver = context.getContentResolver();
        if (MODE_EDIT == mMode && !TextUtils.isEmpty(mOldWord)) {
@@ -119,7 +131,9 @@ public class UserDictionaryAddWordContents {
        }
        final String newWord = mWordEditText.getText().toString();
        final String newShortcut;
        if (null == mShortcutEditText) {
        if (!UserDictionarySettings.IS_SHORTCUT_API_SUPPORTED) {
            newShortcut = null;
        } else if (null == mShortcutEditText) {
            newShortcut = null;
        } else {
            final String tmpShortcut = mShortcutEditText.getText().toString();
@@ -150,9 +164,9 @@ public class UserDictionaryAddWordContents {

        // In this class we use the empty string to represent 'all locales' and mLocale cannot
        // be null. However the addWord method takes null to mean 'all locales'.
        UserDictionary.Words.addWord(context, newWord.toString(),
                FREQUENCY_FOR_USER_DICTIONARY_ADDS, newShortcut,
                TextUtils.isEmpty(mLocale) ? null : LocaleUtils.constructLocaleFromString(mLocale));
        UserDictionaryCompatUtils.addWord(context, newWord.toString(),
                FREQUENCY_FOR_USER_DICTIONARY_ADDS, newShortcut, TextUtils.isEmpty(mLocale) ?
                        null : LocaleUtils.constructLocaleFromString(mLocale));

        return CODE_WORD_ADDED;
    }
+14 −5
Original line number Diff line number Diff line
@@ -49,7 +49,8 @@ import java.util.Locale;
public class UserDictionaryAddWordFragment extends Fragment
        implements AdapterView.OnItemSelectedListener, LocationChangedListener {

    private static final int OPTIONS_MENU_DELETE = Menu.FIRST;
    private static final int OPTIONS_MENU_ADD = Menu.FIRST;
    private static final int OPTIONS_MENU_DELETE = Menu.FIRST + 1;

    private UserDictionaryAddWordContents mContents;
    private View mRootView;
@@ -73,21 +74,29 @@ public class UserDictionaryAddWordFragment extends Fragment

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        MenuItem actionItem = menu.add(0, OPTIONS_MENU_DELETE, 0,
        final MenuItem actionItemDelete = menu.add(0, OPTIONS_MENU_DELETE, 0,
                R.string.user_dict_settings_delete).setIcon(android.R.drawable.ic_menu_delete);
        actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
                MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        actionItemDelete.setShowAsAction(
                MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        final MenuItem actionItemAdd = menu.add(0, OPTIONS_MENU_ADD, 0,
                R.string.user_dict_settings_delete).setIcon(R.drawable.ic_menu_add);
        actionItemAdd.setShowAsAction(
                MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    }

    /**
     * Callback for the framework when a menu option is pressed.
     *
     * This class only supports the delete menu item.
     * @param MenuItem the item that was pressed
     * @return false to allow normal menu processing to proceed, true to consume it here
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == OPTIONS_MENU_ADD) {
            // added the entry in "onPause"
            getActivity().onBackPressed();
            return true;
        }
        if (item.getItemId() == OPTIONS_MENU_DELETE) {
            mContents.delete(getActivity());
            mIsDeleting = true;
Loading