Add an option to show the whole language list
The option is not functional yet. Also, this change simplifies a little the inner workings by preventing mLocale from being null. Step 9 Bug: 5306641 Change-Id: Id2284976d34d9d8ac61cbdb2348893989c47da84
This commit is contained in:
@@ -2622,6 +2622,8 @@ found in the list of installed apps.</string>
|
|||||||
<string name="user_dict_settings_empty_text">You don\'t have any words in the user dictionary. Add a word by touching the Add (+) button.</string>
|
<string name="user_dict_settings_empty_text">You don\'t have any words in the user dictionary. Add a word by touching the Add (+) button.</string>
|
||||||
<!-- User dictionary settings. The text to show to describe the dictionary common to all languages -->
|
<!-- User dictionary settings. The text to show to describe the dictionary common to all languages -->
|
||||||
<string name="user_dict_settings_all_languages">All languages</string>
|
<string name="user_dict_settings_all_languages">All languages</string>
|
||||||
|
<!-- User dictionary settings. The text to show for the option that shows the entire list of supported locales to choose one [CHAR LIMIT=30] -->
|
||||||
|
<string name="user_dict_settings_more_languages">More languages…</string>
|
||||||
|
|
||||||
<!-- This is for diagnostics screen. The title of a screen with various items realted to launching screens that will giev the user info. For example, it contains "Phone information" and "Battery information" -->
|
<!-- This is for diagnostics screen. The title of a screen with various items realted to launching screens that will giev the user info. For example, it contains "Phone information" and "Battery information" -->
|
||||||
<string name="testing">Testing</string>
|
<string name="testing">Testing</string>
|
||||||
|
@@ -32,6 +32,7 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.UserDictionary;
|
import android.provider.UserDictionary;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
@@ -53,7 +54,7 @@ public class UserDictionaryAddWordActivity extends Activity
|
|||||||
private EditText mEditText;
|
private EditText mEditText;
|
||||||
private int mMode; // Either MODE_EDIT or MODE_INSERT
|
private int mMode; // Either MODE_EDIT or MODE_INSERT
|
||||||
private String mOldWord;
|
private String mOldWord;
|
||||||
private String mLocale; // may be null
|
private String mLocale; // may not be null: will be converted to default locale if received null
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
@@ -70,7 +71,8 @@ public class UserDictionaryAddWordActivity extends Activity
|
|||||||
throw new RuntimeException("Unsupported action: " + action);
|
throw new RuntimeException("Unsupported action: " + action);
|
||||||
}
|
}
|
||||||
mOldWord = intent.getStringExtra(EXTRA_WORD);
|
mOldWord = intent.getStringExtra(EXTRA_WORD);
|
||||||
mLocale = intent.getStringExtra(EXTRA_LOCALE); // this may be null
|
final String locale = intent.getStringExtra(EXTRA_LOCALE); // this may be null
|
||||||
|
mLocale = null == locale ? Locale.getDefault().toString() : locale;
|
||||||
mEditText = (EditText)findViewById(R.id.user_dictionary_add_word_text);
|
mEditText = (EditText)findViewById(R.id.user_dictionary_add_word_text);
|
||||||
if (null != mOldWord) {
|
if (null != mOldWord) {
|
||||||
mEditText.setText(mOldWord);
|
mEditText.setText(mOldWord);
|
||||||
@@ -107,11 +109,7 @@ public class UserDictionaryAddWordActivity extends Activity
|
|||||||
// TODO: Redefine the logic when we support shortcuts.
|
// TODO: Redefine the logic when we support shortcuts.
|
||||||
UserDictionarySettings.deleteWord(newWord, this.getContentResolver());
|
UserDictionarySettings.deleteWord(newWord, this.getContentResolver());
|
||||||
|
|
||||||
if (null == mLocale) {
|
if (TextUtils.isEmpty(mLocale)) {
|
||||||
// Null means insert with the default system locale.
|
|
||||||
UserDictionary.Words.addWord(this, newWord.toString(),
|
|
||||||
FREQUENCY_FOR_USER_DICTIONARY_ADDS, UserDictionary.Words.LOCALE_TYPE_CURRENT);
|
|
||||||
} else if ("".equals(mLocale)) {
|
|
||||||
// Empty string means insert for all languages.
|
// Empty string means insert for all languages.
|
||||||
UserDictionary.Words.addWord(this, newWord.toString(),
|
UserDictionary.Words.addWord(this, newWord.toString(),
|
||||||
FREQUENCY_FOR_USER_DICTIONARY_ADDS, UserDictionary.Words.LOCALE_TYPE_ALL);
|
FREQUENCY_FOR_USER_DICTIONARY_ADDS, UserDictionary.Words.LOCALE_TYPE_ALL);
|
||||||
@@ -133,7 +131,9 @@ public class UserDictionaryAddWordActivity extends Activity
|
|||||||
// LocaleString may NOT be null.
|
// LocaleString may NOT be null.
|
||||||
public LocaleRenderer(final Context context, final String localeString) {
|
public LocaleRenderer(final Context context, final String localeString) {
|
||||||
mLocaleString = localeString;
|
mLocaleString = localeString;
|
||||||
if ("".equals(localeString)) {
|
if (null == localeString) {
|
||||||
|
mDescription = context.getString(R.string.user_dict_settings_more_languages);
|
||||||
|
} else if ("".equals(localeString)) {
|
||||||
mDescription = context.getString(R.string.user_dict_settings_all_languages);
|
mDescription = context.getString(R.string.user_dict_settings_all_languages);
|
||||||
} else {
|
} else {
|
||||||
mDescription = Utils.createLocaleFromString(localeString).getDisplayName();
|
mDescription = Utils.createLocaleFromString(localeString).getDisplayName();
|
||||||
@@ -162,26 +162,25 @@ public class UserDictionaryAddWordActivity extends Activity
|
|||||||
findViewById(R.id.user_dictionary_settings_add_dialog_manage).setVisibility(View.VISIBLE);
|
findViewById(R.id.user_dictionary_settings_add_dialog_manage).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
final Set<String> locales = UserDictionaryList.getUserDictionaryLocalesList(this);
|
final Set<String> locales = UserDictionaryList.getUserDictionaryLocalesList(this);
|
||||||
if (null != mLocale && locales.contains(mLocale)) {
|
// Remove our locale if it's in, because we're always gonna put it at the top
|
||||||
// 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
|
||||||
locales.remove(mLocale);
|
|
||||||
}
|
|
||||||
final String systemLocale = Locale.getDefault().toString();
|
final String systemLocale = Locale.getDefault().toString();
|
||||||
if (null != systemLocale && locales.contains(systemLocale)) {
|
// The system locale should be inside. We want it at the 2nd spot.
|
||||||
// The system locale should be inside. We want it at the 2nd spot.
|
locales.remove(systemLocale); // system locale may not be null
|
||||||
locales.remove(systemLocale);
|
locales.remove(""); // Remove the empty string if it's there
|
||||||
}
|
|
||||||
final ArrayList<LocaleRenderer> localesList = new ArrayList<LocaleRenderer>();
|
final ArrayList<LocaleRenderer> localesList = new ArrayList<LocaleRenderer>();
|
||||||
// Add the passed locale, then the system locale at the top of the list. Add an
|
// Add the passed locale, then the system locale at the top of the list. Add an
|
||||||
// "all languages" entry at the bottom of the list.
|
// "all languages" entry at the bottom of the list.
|
||||||
addLocaleDisplayNameToList(this, localesList, mLocale);
|
addLocaleDisplayNameToList(this, localesList, mLocale);
|
||||||
addLocaleDisplayNameToList(this, localesList, systemLocale);
|
if (!systemLocale.equals(mLocale)) {
|
||||||
|
addLocaleDisplayNameToList(this, localesList, systemLocale);
|
||||||
|
}
|
||||||
for (final String l : locales) {
|
for (final String l : locales) {
|
||||||
// TODO: sort in unicode order
|
// TODO: sort in unicode order
|
||||||
addLocaleDisplayNameToList(this, localesList, l);
|
addLocaleDisplayNameToList(this, localesList, l);
|
||||||
}
|
}
|
||||||
localesList.add(new LocaleRenderer(this, ""));
|
localesList.add(new LocaleRenderer(this, "")); // meaning: all languages
|
||||||
//TODO: Do we need an option "more..." to show all locales in the world?
|
localesList.add(new LocaleRenderer(this, null)); // meaning: select another locale
|
||||||
final Spinner localeSpinner =
|
final Spinner localeSpinner =
|
||||||
(Spinner)findViewById(R.id.user_dictionary_settings_add_dialog_locale);
|
(Spinner)findViewById(R.id.user_dictionary_settings_add_dialog_locale);
|
||||||
final ArrayAdapter<LocaleRenderer> adapter = new ArrayAdapter<LocaleRenderer>(this,
|
final ArrayAdapter<LocaleRenderer> adapter = new ArrayAdapter<LocaleRenderer>(this,
|
||||||
@@ -201,6 +200,8 @@ public class UserDictionaryAddWordActivity extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
// I'm not sure we can come here, but if we do, that's the right thing to do.
|
// I'm not sure we can come here, but if we do, that's the right thing to do.
|
||||||
mLocale = null;
|
final Intent intent = getIntent();
|
||||||
|
final String locale = intent.getStringExtra(EXTRA_LOCALE); // this may be null
|
||||||
|
mLocale = null == locale ? Locale.getDefault().toString() : locale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user