aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/userdictionary
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/userdictionary')
-rw-r--r--java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordContents.java18
-rw-r--r--java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordFragment.java24
-rw-r--r--java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java12
-rw-r--r--java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java4
-rw-r--r--java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettingsUtils.java42
5 files changed, 92 insertions, 8 deletions
diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordContents.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordContents.java
index dad72963d..21426d1eb 100644
--- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordContents.java
+++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordContents.java
@@ -65,6 +65,8 @@ public class UserDictionaryAddWordContents {
private String mLocale;
private final String mOldWord;
private final String mOldShortcut;
+ private String mSavedWord;
+ private String mSavedShortcut;
/* package */ UserDictionaryAddWordContents(final View view, final Bundle args) {
mWordEditText = (EditText)view.findViewById(R.id.user_dictionary_add_word_text);
@@ -96,6 +98,16 @@ public class UserDictionaryAddWordContents {
updateLocale(args.getString(EXTRA_LOCALE));
}
+ /* 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);
+ mMode = MODE_EDIT;
+ mOldWord = oldInstanceToBeEdited.mSavedWord;
+ mOldShortcut = oldInstanceToBeEdited.mSavedShortcut;
+ updateLocale(mLocale);
+ }
+
// locale may be null, this means default locale
// It may also be the empty string, which means "all locales"
/* package */ void updateLocale(final String locale) {
@@ -149,6 +161,8 @@ public class UserDictionaryAddWordContents {
// If the word is somehow empty, don't insert it.
return CODE_CANCEL;
}
+ mSavedWord = newWord;
+ mSavedShortcut = newShortcut;
// If there is no shortcut, and the word already exists in the database, then we
// should not insert, because either A. the word exists with no shortcut, in which
// case the exact same thing we want to insert is already there, or B. the word
@@ -260,4 +274,8 @@ public class UserDictionaryAddWordContents {
localesList.add(new LocaleRenderer(activity, null)); // meaning: select another locale
return localesList;
}
+
+ public String getCurrentUserDictionaryLocale() {
+ return mLocale;
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordFragment.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordFragment.java
index 58c8f266c..4fc132f68 100644
--- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordFragment.java
+++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordFragment.java
@@ -57,23 +57,39 @@ public class UserDictionaryAddWordFragment extends Fragment
private boolean mIsDeleting = false;
@Override
- public void onActivityCreated(Bundle savedInstanceState) {
+ public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
+ getActivity().getActionBar().setTitle(R.string.edit_personal_dictionary);
+ // Keep the instance so that we remember mContents when configuration changes (eg rotation)
+ setRetainInstance(true);
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
+ public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
+ final Bundle savedState) {
mRootView = inflater.inflate(R.layout.user_dictionary_add_word_fullscreen, null);
mIsDeleting = false;
+ // If we have a non-null mContents object, it's the old value before a configuration
+ // change (eg rotation) so we need to use its values. Otherwise, read from the arguments.
if (null == mContents) {
mContents = new UserDictionaryAddWordContents(mRootView, getArguments());
+ } else {
+ // We create a new mContents object to account for the new situation : a word has
+ // been added to the user dictionary when we started rotating, and we are now editing
+ // it. That means in particular if the word undergoes any change, the old version should
+ // be updated, so the mContents object needs to switch to EDIT mode if it was in
+ // INSERT mode.
+ mContents = new UserDictionaryAddWordContents(mRootView,
+ mContents /* oldInstanceToBeEdited */);
}
+ getActivity().getActionBar().setSubtitle(UserDictionarySettingsUtils.getLocaleDisplayName(
+ getActivity(), mContents.getCurrentUserDictionaryLocale()));
return mRootView;
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
final MenuItem actionItemAdd = menu.add(0, OPTIONS_MENU_ADD, 0,
R.string.user_dict_settings_add_menu_title).setIcon(R.drawable.ic_menu_add);
actionItemAdd.setShowAsAction(
@@ -87,7 +103,7 @@ public class UserDictionaryAddWordFragment extends Fragment
/**
* Callback for the framework when a menu option is pressed.
*
- * @param MenuItem the item that was pressed
+ * @param item the item that was pressed
* @return false to allow normal menu processing to proceed, true to consume it here
*/
@Override
diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java
index 37c390d13..32c4950da 100644
--- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java
+++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java
@@ -107,13 +107,19 @@ public class UserDictionaryList extends PreferenceFragment {
protected void createUserDictSettings(PreferenceGroup userDictGroup) {
final Activity activity = getActivity();
userDictGroup.removeAll();
- final TreeSet<String> localeList =
+ final TreeSet<String> localeSet =
UserDictionaryList.getUserDictionaryLocalesSet(activity);
- if (localeList.isEmpty()) {
+ if (localeSet.size() > 1) {
+ // Have an "All languages" entry in the languages list if there are two or more active
+ // languages
+ localeSet.add("");
+ }
+
+ if (localeSet.isEmpty()) {
userDictGroup.addPreference(createUserDictionaryPreference(null, activity));
} else {
- for (String locale : localeList) {
+ for (String locale : localeSet) {
userDictGroup.addPreference(createUserDictionaryPreference(locale, activity));
}
}
diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java
index 64f860e7d..7571e87c5 100644
--- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java
+++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java
@@ -150,7 +150,9 @@ public class UserDictionarySettings extends ListFragment {
listView.setEmptyView(emptyView);
setHasOptionsMenu(true);
-
+ // Show the language as a subtitle of the action bar
+ getActivity().getActionBar().setSubtitle(
+ UserDictionarySettingsUtils.getLocaleDisplayName(getActivity(), mLocale));
}
@SuppressWarnings("deprecation")
diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettingsUtils.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettingsUtils.java
new file mode 100644
index 000000000..e58727ec4
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettingsUtils.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin.userdictionary;
+
+import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.utils.LocaleUtils;
+
+import android.content.Context;
+import android.text.TextUtils;
+
+import java.util.Locale;
+
+/**
+ * Utilities of the user dictionary settings
+ * TODO: We really want to move these utilities to a static library.
+ */
+public class UserDictionarySettingsUtils {
+ public static String getLocaleDisplayName(Context context, String localeStr) {
+ if (TextUtils.isEmpty(localeStr)) {
+ // CAVEAT: localeStr should not be null because a null locale stands for the system
+ // locale in UserDictionary.Words.addWord.
+ return context.getResources().getString(R.string.user_dict_settings_all_languages);
+ }
+ final Locale locale = LocaleUtils.constructLocaleFromString(localeStr);
+ final Locale systemLocale = context.getResources().getConfiguration().locale;
+ return locale.getDisplayName(systemLocale);
+ }
+}