android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:text="@string/user_dict_settings_add_shortcut_option_name" />
- <EditText android:id="@+id/user_dictionary_settings_add_dialog_shortcut"
+ <EditText android:id="@+id/user_dictionary_add_shortcut"
android:maxLength="@integer/maximum_user_dictionary_word_length"
android:layout_width="wrap_content"
android:layout_gravity="fill_horizontal|center_vertical"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:text="@string/user_dict_settings_add_locale_option_name" />
- <Spinner android:id="@+id/user_dictionary_settings_add_dialog_locale"
+ <Spinner android:id="@+id/user_dictionary_add_locale"
android:layout_marginLeft="8dip"
android:layout_marginBottom="8dip"
android:layout_marginTop="8dip"
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
- String word = getWord(position);
+ final String word = getWord(position);
+ final String shortcut = getShortcut(position);
if (word != null) {
- showAddOrEditDialog(word);
+ showAddOrEditDialog(word, shortcut);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == OPTIONS_MENU_ADD) {
- showAddOrEditDialog(null);
+ showAddOrEditDialog(null, null);
return true;
}
return false;
/**
* Add or edit a word. If editingWord is null, it's an add; otherwise, it's an edit.
* @param editingWord the word to edit, or null if it's an add.
+ * @param editingShortcut the shortcut for this entry, or null if none.
*/
- private void showAddOrEditDialog(final String editingWord) {
+ private void showAddOrEditDialog(final String editingWord, final String editingShortcut) {
final Bundle args = new Bundle();
args.putInt(UserDictionaryAddWordContents.EXTRA_MODE, null == editingWord
? UserDictionaryAddWordContents.MODE_INSERT
: UserDictionaryAddWordContents.MODE_EDIT);
args.putString(UserDictionaryAddWordContents.EXTRA_WORD, editingWord);
+ args.putString(UserDictionaryAddWordContents.EXTRA_SHORTCUT, editingShortcut);
args.putString(UserDictionaryAddWordContents.EXTRA_LOCALE, mLocale);
android.preference.PreferenceActivity pa =
(android.preference.PreferenceActivity)getActivity();
args, R.string.details_title, null, null, 0);
}
- private String getWord(int position) {
+ private String getWord(final int position) {
if (null == mCursor) return null;
mCursor.moveToPosition(position);
// Handle a possible race-condition
mCursor.getColumnIndexOrThrow(UserDictionary.Words.WORD));
}
+ private String getShortcut(final int position) {
+ if (null == mCursor) return null;
+ mCursor.moveToPosition(position);
+ // Handle a possible race-condition
+ if (mCursor.isAfterLast()) return null;
+
+ return mCursor.getString(
+ mCursor.getColumnIndexOrThrow(UserDictionary.Words.SHORTCUT));
+ }
+
public static void deleteWord(final String word, final ContentResolver resolver) {
resolver.delete(
UserDictionary.Words.CONTENT_URI, DELETE_SELECTION, new String[] { word });
public class UserDictionaryAddWordContents {
public static final String EXTRA_MODE = "mode";
public static final String EXTRA_WORD = "word";
+ public static final String EXTRA_SHORTCUT = "shortcut";
public static final String EXTRA_LOCALE = "locale";
public static final int MODE_EDIT = 0;
private static final int FREQUENCY_FOR_USER_DICTIONARY_ADDS = 250;
private final int mMode; // Either MODE_EDIT or MODE_INSERT
- private final EditText mEditText;
+ private final EditText mWordEditText;
+ private final EditText mShortcutEditText;
private String mLocale;
private final String mOldWord;
+ private final String mOldShortcut;
/* package */ UserDictionaryAddWordContents(final View view, final Bundle args) {
- mEditText = (EditText)view.findViewById(R.id.user_dictionary_add_word_text);
+ mWordEditText = (EditText)view.findViewById(R.id.user_dictionary_add_word_text);
+ mShortcutEditText = (EditText)view.findViewById(R.id.user_dictionary_add_shortcut);
final String word = args.getString(EXTRA_WORD);
if (null != word) {
- mEditText.setText(word);
- mEditText.setSelection(word.length());
+ mWordEditText.setText(word);
+ mWordEditText.setSelection(word.length());
+ }
+ final String shortcut = args.getString(EXTRA_SHORTCUT);
+ if (null != shortcut && null != mShortcutEditText) {
+ mShortcutEditText.setText(shortcut);
}
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));
}
}
/* package */ void saveStateIntoBundle(final Bundle outState) {
- outState.putString(EXTRA_WORD, mEditText.getText().toString());
+ outState.putString(EXTRA_WORD, mWordEditText.getText().toString());
+ if (null != mShortcutEditText) {
+ outState.putString(EXTRA_SHORTCUT, mShortcutEditText.getText().toString());
+ }
outState.putString(EXTRA_LOCALE, mLocale);
}
if (UserDictionaryAddWordContents.MODE_EDIT == mMode && !TextUtils.isEmpty(mOldWord)) {
UserDictionarySettings.deleteWord(mOldWord, resolver);
}
- final String newWord = mEditText.getText().toString();
+ final String newWord = mWordEditText.getText().toString();
if (TextUtils.isEmpty(newWord)) {
// If the word is somehow empty, don't insert it.
return;
// 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, null /* shortcut */,
+ FREQUENCY_FOR_USER_DICTIONARY_ADDS,
+ null == mShortcutEditText ? null : mShortcutEditText.getText().toString(),
TextUtils.isEmpty(mLocale) ? null : Utils.createLocaleFromString(mLocale));
}
final ArrayList<LocaleRenderer> localesList = mContents.getLocalesList(getActivity());
final Spinner localeSpinner =
- (Spinner)mRootView.findViewById(R.id.user_dictionary_settings_add_dialog_locale);
+ (Spinner)mRootView.findViewById(R.id.user_dictionary_add_locale);
final ArrayAdapter<LocaleRenderer> adapter = new ArrayAdapter<LocaleRenderer>(getActivity(),
android.R.layout.simple_spinner_item, localesList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);