Pass the shortcut to the user dictionary provider.
Bug: 6026080 Change-Id: I87b7c8b1ae89856f393871e6d3440b43efc22a29
This commit is contained in:
@@ -49,7 +49,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="left|center_vertical"
|
android:layout_gravity="left|center_vertical"
|
||||||
android:text="@string/user_dict_settings_add_shortcut_option_name" />
|
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:maxLength="@integer/maximum_user_dictionary_word_length"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_gravity="fill_horizontal|center_vertical"
|
android:layout_gravity="fill_horizontal|center_vertical"
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="left|center_vertical"
|
android:layout_gravity="left|center_vertical"
|
||||||
android:text="@string/user_dict_settings_add_locale_option_name" />
|
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_marginLeft="8dip"
|
||||||
android:layout_marginBottom="8dip"
|
android:layout_marginBottom="8dip"
|
||||||
android:layout_marginTop="8dip"
|
android:layout_marginTop="8dip"
|
||||||
|
@@ -155,9 +155,10 @@ public class UserDictionarySettings extends ListFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
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) {
|
if (word != null) {
|
||||||
showAddOrEditDialog(word);
|
showAddOrEditDialog(word, shortcut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +174,7 @@ public class UserDictionarySettings extends ListFragment {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (item.getItemId() == OPTIONS_MENU_ADD) {
|
if (item.getItemId() == OPTIONS_MENU_ADD) {
|
||||||
showAddOrEditDialog(null);
|
showAddOrEditDialog(null, null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -182,13 +183,15 @@ public class UserDictionarySettings extends ListFragment {
|
|||||||
/**
|
/**
|
||||||
* Add or edit a word. If editingWord is null, it's an add; otherwise, it's an edit.
|
* 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 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();
|
final Bundle args = new Bundle();
|
||||||
args.putInt(UserDictionaryAddWordContents.EXTRA_MODE, null == editingWord
|
args.putInt(UserDictionaryAddWordContents.EXTRA_MODE, null == editingWord
|
||||||
? UserDictionaryAddWordContents.MODE_INSERT
|
? UserDictionaryAddWordContents.MODE_INSERT
|
||||||
: UserDictionaryAddWordContents.MODE_EDIT);
|
: UserDictionaryAddWordContents.MODE_EDIT);
|
||||||
args.putString(UserDictionaryAddWordContents.EXTRA_WORD, editingWord);
|
args.putString(UserDictionaryAddWordContents.EXTRA_WORD, editingWord);
|
||||||
|
args.putString(UserDictionaryAddWordContents.EXTRA_SHORTCUT, editingShortcut);
|
||||||
args.putString(UserDictionaryAddWordContents.EXTRA_LOCALE, mLocale);
|
args.putString(UserDictionaryAddWordContents.EXTRA_LOCALE, mLocale);
|
||||||
android.preference.PreferenceActivity pa =
|
android.preference.PreferenceActivity pa =
|
||||||
(android.preference.PreferenceActivity)getActivity();
|
(android.preference.PreferenceActivity)getActivity();
|
||||||
@@ -197,7 +200,7 @@ public class UserDictionarySettings extends ListFragment {
|
|||||||
args, R.string.details_title, null, null, 0);
|
args, R.string.details_title, null, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getWord(int position) {
|
private String getWord(final int position) {
|
||||||
if (null == mCursor) return null;
|
if (null == mCursor) return null;
|
||||||
mCursor.moveToPosition(position);
|
mCursor.moveToPosition(position);
|
||||||
// Handle a possible race-condition
|
// Handle a possible race-condition
|
||||||
@@ -207,6 +210,16 @@ public class UserDictionarySettings extends ListFragment {
|
|||||||
mCursor.getColumnIndexOrThrow(UserDictionary.Words.WORD));
|
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) {
|
public static void deleteWord(final String word, final ContentResolver resolver) {
|
||||||
resolver.delete(
|
resolver.delete(
|
||||||
UserDictionary.Words.CONTENT_URI, DELETE_SELECTION, new String[] { word });
|
UserDictionary.Words.CONTENT_URI, DELETE_SELECTION, new String[] { word });
|
||||||
|
@@ -40,6 +40,7 @@ import java.util.TreeSet;
|
|||||||
public class UserDictionaryAddWordContents {
|
public class UserDictionaryAddWordContents {
|
||||||
public static final String EXTRA_MODE = "mode";
|
public static final String EXTRA_MODE = "mode";
|
||||||
public static final String EXTRA_WORD = "word";
|
public static final String EXTRA_WORD = "word";
|
||||||
|
public static final String EXTRA_SHORTCUT = "shortcut";
|
||||||
public static final String EXTRA_LOCALE = "locale";
|
public static final String EXTRA_LOCALE = "locale";
|
||||||
|
|
||||||
public static final int MODE_EDIT = 0;
|
public static final int MODE_EDIT = 0;
|
||||||
@@ -48,19 +49,27 @@ public class UserDictionaryAddWordContents {
|
|||||||
private static final int FREQUENCY_FOR_USER_DICTIONARY_ADDS = 250;
|
private static final int FREQUENCY_FOR_USER_DICTIONARY_ADDS = 250;
|
||||||
|
|
||||||
private final int mMode; // Either MODE_EDIT or MODE_INSERT
|
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 String mLocale;
|
||||||
private final String mOldWord;
|
private final String mOldWord;
|
||||||
|
private final String mOldShortcut;
|
||||||
|
|
||||||
/* package */ UserDictionaryAddWordContents(final View view, final Bundle args) {
|
/* 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);
|
final String word = args.getString(EXTRA_WORD);
|
||||||
if (null != word) {
|
if (null != word) {
|
||||||
mEditText.setText(word);
|
mWordEditText.setText(word);
|
||||||
mEditText.setSelection(word.length());
|
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
|
mMode = args.getInt(EXTRA_MODE); // default return value for #getInt() is 0 = MODE_EDIT
|
||||||
mOldWord = args.getString(EXTRA_WORD);
|
mOldWord = args.getString(EXTRA_WORD);
|
||||||
|
mOldShortcut = args.getString(EXTRA_SHORTCUT);
|
||||||
updateLocale(args.getString(EXTRA_LOCALE));
|
updateLocale(args.getString(EXTRA_LOCALE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +80,10 @@ public class UserDictionaryAddWordContents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void saveStateIntoBundle(final Bundle outState) {
|
/* 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);
|
outState.putString(EXTRA_LOCALE, mLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +92,7 @@ public class UserDictionaryAddWordContents {
|
|||||||
if (UserDictionaryAddWordContents.MODE_EDIT == mMode && !TextUtils.isEmpty(mOldWord)) {
|
if (UserDictionaryAddWordContents.MODE_EDIT == mMode && !TextUtils.isEmpty(mOldWord)) {
|
||||||
UserDictionarySettings.deleteWord(mOldWord, resolver);
|
UserDictionarySettings.deleteWord(mOldWord, resolver);
|
||||||
}
|
}
|
||||||
final String newWord = mEditText.getText().toString();
|
final String newWord = mWordEditText.getText().toString();
|
||||||
if (TextUtils.isEmpty(newWord)) {
|
if (TextUtils.isEmpty(newWord)) {
|
||||||
// If the word is somehow empty, don't insert it.
|
// If the word is somehow empty, don't insert it.
|
||||||
return;
|
return;
|
||||||
@@ -92,7 +104,8 @@ public class UserDictionaryAddWordContents {
|
|||||||
// In this class we use the empty string to represent 'all locales' and mLocale cannot
|
// 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'.
|
// be null. However the addWord method takes null to mean 'all locales'.
|
||||||
UserDictionary.Words.addWord(context, newWord.toString(),
|
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));
|
TextUtils.isEmpty(mLocale) ? null : Utils.createLocaleFromString(mLocale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -74,7 +74,7 @@ public class UserDictionaryAddWordFragment extends Fragment
|
|||||||
final ArrayList<LocaleRenderer> localesList = mContents.getLocalesList(getActivity());
|
final ArrayList<LocaleRenderer> localesList = mContents.getLocalesList(getActivity());
|
||||||
|
|
||||||
final Spinner localeSpinner =
|
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(),
|
final ArrayAdapter<LocaleRenderer> adapter = new ArrayAdapter<LocaleRenderer>(getActivity(),
|
||||||
android.R.layout.simple_spinner_item, localesList);
|
android.R.layout.simple_spinner_item, localesList);
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
Reference in New Issue
Block a user