am 83e95e60: Remove SHORTCUT column in FROM clause.

* commit '83e95e601876a2f7938da8a3f773f9ef088a23ab':
  Remove SHORTCUT column in FROM clause.
This commit is contained in:
Dan Zivkovic 2015-03-04 18:20:47 +00:00 committed by Android Git Automerger
commit 34adcf9996

View file

@ -16,6 +16,12 @@
package com.android.inputmethod.latin.userdictionary; package com.android.inputmethod.latin.userdictionary;
import static com.android.inputmethod.latin.userdictionary.UserDictionaryAddWordContents.EXTRA_LOCALE;
import static com.android.inputmethod.latin.userdictionary.UserDictionaryAddWordContents.EXTRA_MODE;
import static com.android.inputmethod.latin.userdictionary.UserDictionaryAddWordContents.EXTRA_WORD;
import static com.android.inputmethod.latin.userdictionary.UserDictionaryAddWordContents.MODE_EDIT;
import static com.android.inputmethod.latin.userdictionary.UserDictionaryAddWordContents.MODE_INSERT;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import android.app.ListFragment; import android.app.ListFragment;
@ -25,7 +31,7 @@ import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.UserDictionary; import android.provider.UserDictionary.Words;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -48,32 +54,8 @@ import java.util.Locale;
public class UserDictionarySettings extends ListFragment { public class UserDictionarySettings extends ListFragment {
private static final String[] QUERY_PROJECTION = {
UserDictionary.Words._ID, UserDictionary.Words.WORD
};
private static final String[] ADAPTER_FROM = {
UserDictionary.Words.WORD, UserDictionary.Words.SHORTCUT
};
private static final int[] ADAPTER_TO = {
android.R.id.text1,
};
// Either the locale is empty (means the word is applicable to all locales)
// or the word equals our current locale
private static final String QUERY_SELECTION =
UserDictionary.Words.LOCALE + "=?";
private static final String QUERY_SELECTION_ALL_LOCALES =
UserDictionary.Words.LOCALE + " is null";
private static final String DELETE_SELECTION = UserDictionary.Words.WORD + "=?";
private static final int OPTIONS_MENU_ADD = Menu.FIRST;
private Cursor mCursor; private Cursor mCursor;
private String mLocale;
protected String mLocale;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -142,21 +124,30 @@ public class UserDictionarySettings extends ListFragment {
// TODO: it should be easy to make this more readable by making the special values // TODO: it should be easy to make this more readable by making the special values
// human-readable, like "all_locales" and "current_locales" strings, provided they // human-readable, like "all_locales" and "current_locales" strings, provided they
// can be guaranteed not to match locales that may exist. // can be guaranteed not to match locales that may exist.
if ("".equals(locale)) { if (TextUtils.isEmpty(locale)) {
// Case-insensitive sort // Case-insensitive sort
return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, return getActivity().managedQuery(
QUERY_SELECTION_ALL_LOCALES, null, Words.CONTENT_URI,
"UPPER(" + UserDictionary.Words.WORD + ")"); new String[] { Words._ID, Words.WORD },
Words.LOCALE + " is null",
null,
"UPPER(" + Words.WORD + ")");
} }
final String queryLocale = null != locale ? locale : Locale.getDefault().toString(); return getActivity().managedQuery(
return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, Words.CONTENT_URI,
QUERY_SELECTION, new String[] { queryLocale }, new String[] { Words._ID, Words.WORD },
"UPPER(" + UserDictionary.Words.WORD + ")"); Words.LOCALE + "=?",
new String[] { locale },
"UPPER(" + Words.WORD + ")");
} }
private ListAdapter createAdapter() { private ListAdapter createAdapter() {
return new MyAdapter(getActivity(), R.layout.user_dictionary_item, mCursor, return new MyAdapter(
ADAPTER_FROM, ADAPTER_TO); getActivity(),
R.layout.user_dictionary_item,
mCursor,
new String[] { Words.WORD },
new int[] { android.R.id.text1 });
} }
@Override @Override
@ -177,16 +168,15 @@ public class UserDictionarySettings extends ListFragment {
return; return;
} }
} }
MenuItem actionItem = menu.add(0, Menu.FIRST, 0, R.string.user_dict_settings_add_menu_title)
menu.add(0, OPTIONS_MENU_ADD, 0, R.string.user_dict_settings_add_menu_title) .setIcon(R.drawable.ic_menu_add)
.setIcon(R.drawable.ic_menu_add); .setShowAsAction(
actionItem.setShowAsAction(
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == OPTIONS_MENU_ADD) { if (item.getItemId() == Menu.FIRST) {
showAddOrEditDialog(null); showAddOrEditDialog(null);
return true; return true;
} }
@ -199,11 +189,9 @@ public class UserDictionarySettings extends ListFragment {
*/ */
private void showAddOrEditDialog(final String editingWord) { private void showAddOrEditDialog(final String editingWord) {
final Bundle args = new Bundle(); final Bundle args = new Bundle();
args.putInt(UserDictionaryAddWordContents.EXTRA_MODE, null == editingWord args.putInt(EXTRA_MODE, editingWord == null ? MODE_INSERT : MODE_EDIT);
? UserDictionaryAddWordContents.MODE_INSERT args.putString(EXTRA_WORD, editingWord);
: UserDictionaryAddWordContents.MODE_EDIT); args.putString(EXTRA_LOCALE, mLocale);
args.putString(UserDictionaryAddWordContents.EXTRA_WORD, editingWord);
args.putString(UserDictionaryAddWordContents.EXTRA_LOCALE, mLocale);
getActivity(); getActivity();
} }
@ -213,12 +201,11 @@ public class UserDictionarySettings extends ListFragment {
// Handle a possible race-condition // Handle a possible race-condition
if (mCursor.isAfterLast()) return null; if (mCursor.isAfterLast()) return null;
return mCursor.getString( return mCursor.getString(mCursor.getColumnIndexOrThrow(Words.WORD));
mCursor.getColumnIndexOrThrow(UserDictionary.Words.WORD));
} }
public static void deleteWord(final String word, final ContentResolver resolver) { public static void deleteWord(final String word, final ContentResolver resolver) {
resolver.delete(UserDictionary.Words.CONTENT_URI, DELETE_SELECTION, new String[] { word }); resolver.delete(Words.CONTENT_URI, Words.WORD + "=?", new String[] { word });
} }
private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer { private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer {
@ -239,7 +226,7 @@ public class UserDictionarySettings extends ListFragment {
if (null != c) { if (null != c) {
final String alphabet = context.getString(R.string.user_dict_fast_scroll_alphabet); final String alphabet = context.getString(R.string.user_dict_fast_scroll_alphabet);
final int wordColIndex = c.getColumnIndexOrThrow(UserDictionary.Words.WORD); final int wordColIndex = c.getColumnIndexOrThrow(Words.WORD);
mIndexer = new AlphabetIndexer(c, wordColIndex, alphabet); mIndexer = new AlphabetIndexer(c, wordColIndex, alphabet);
} }
setViewBinder(mViewBinder); setViewBinder(mViewBinder);