Migrate UserDictionaryList to DashboardFragment
- Build a controller to generate/manage a list of preferences. - Move some logics to the controller and add tests. Test: manual Test: make RunSettingsRoboTests -j atest UniquePreferenceTest SettingsGatewayTest Change-Id: Ia3d885cb8917c7d5498b87818e24b938f0d95dbb
This commit is contained in:
@@ -60,8 +60,8 @@ public class UserDictionaryAddWordContents {
|
||||
private String mSavedShortcut;
|
||||
|
||||
/* 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);
|
||||
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) {
|
||||
mWordEditText.setText(word);
|
||||
@@ -81,8 +81,8 @@ public class UserDictionaryAddWordContents {
|
||||
|
||||
/* package */ UserDictionaryAddWordContents(final View view,
|
||||
final UserDictionaryAddWordContents oldInstanceToBeEdited) {
|
||||
mWordEditText = (EditText)view.findViewById(R.id.user_dictionary_add_word_text);
|
||||
mShortcutEditText = (EditText)view.findViewById(R.id.user_dictionary_add_shortcut);
|
||||
mWordEditText = (EditText) view.findViewById(R.id.user_dictionary_add_word_text);
|
||||
mShortcutEditText = (EditText) view.findViewById(R.id.user_dictionary_add_shortcut);
|
||||
mMode = MODE_EDIT;
|
||||
mOldWord = oldInstanceToBeEdited.mSavedWord;
|
||||
mOldShortcut = oldInstanceToBeEdited.mSavedShortcut;
|
||||
@@ -167,23 +167,24 @@ public class UserDictionaryAddWordContents {
|
||||
return UserDictionaryAddWordActivity.CODE_WORD_ADDED;
|
||||
}
|
||||
|
||||
private static final String[] HAS_WORD_PROJECTION = { UserDictionary.Words.WORD };
|
||||
private static final String[] HAS_WORD_PROJECTION = {UserDictionary.Words.WORD};
|
||||
private static final String HAS_WORD_SELECTION_ONE_LOCALE = UserDictionary.Words.WORD
|
||||
+ "=? AND " + UserDictionary.Words.LOCALE + "=?";
|
||||
private static final String HAS_WORD_SELECTION_ALL_LOCALES = UserDictionary.Words.WORD
|
||||
+ "=? AND " + UserDictionary.Words.LOCALE + " is null";
|
||||
|
||||
private boolean hasWord(final String word, final Context context) {
|
||||
final Cursor cursor;
|
||||
// mLocale == "" indicates this is an entry for all languages. Here, mLocale can't
|
||||
// be null at all (it's ensured by the updateLocale method).
|
||||
if ("".equals(mLocale)) {
|
||||
cursor = context.getContentResolver().query(UserDictionary.Words.CONTENT_URI,
|
||||
HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ALL_LOCALES,
|
||||
new String[] { word }, null /* sort order */);
|
||||
HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ALL_LOCALES,
|
||||
new String[] {word}, null /* sort order */);
|
||||
} else {
|
||||
cursor = context.getContentResolver().query(UserDictionary.Words.CONTENT_URI,
|
||||
HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ONE_LOCALE,
|
||||
new String[] { word, mLocale }, null /* sort order */);
|
||||
HAS_WORD_PROJECTION, HAS_WORD_SELECTION_ONE_LOCALE,
|
||||
new String[] {word, mLocale}, null /* sort order */);
|
||||
}
|
||||
try {
|
||||
if (null == cursor) return false;
|
||||
@@ -196,6 +197,7 @@ public class UserDictionaryAddWordContents {
|
||||
public static class LocaleRenderer {
|
||||
private final String mLocaleString;
|
||||
private final String mDescription;
|
||||
|
||||
// LocaleString may NOT be null.
|
||||
public LocaleRenderer(final Context context, final String localeString) {
|
||||
mLocaleString = localeString;
|
||||
@@ -207,13 +209,16 @@ public class UserDictionaryAddWordContents {
|
||||
mDescription = Utils.createLocaleFromString(localeString).getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mDescription;
|
||||
}
|
||||
|
||||
public String getLocaleString() {
|
||||
return mLocaleString;
|
||||
}
|
||||
|
||||
// "More languages..." is null ; "All languages" is the empty string.
|
||||
public boolean isMoreLanguages() {
|
||||
return null == mLocaleString;
|
||||
@@ -229,7 +234,8 @@ public class UserDictionaryAddWordContents {
|
||||
|
||||
// Helper method to get the list of locales to display for this word
|
||||
public ArrayList<LocaleRenderer> getLocalesList(final Activity activity) {
|
||||
final TreeSet<String> locales = UserDictionaryList.getUserDictionaryLocalesSet(activity);
|
||||
final TreeSet<String> locales =
|
||||
UserDictionaryListPreferenceController.getUserDictionaryLocalesSet(activity);
|
||||
// Remove our locale if it's in, because we're always gonna put it at the top
|
||||
locales.remove(mLocale); // mLocale may not be null
|
||||
final String systemLocale = Locale.getDefault().toString();
|
||||
|
Reference in New Issue
Block a user