Fix a bug with multiple word insertion.
Bug: 7903831 Change-Id: I5202bc529a570292dd78d8503d8e2cc93b43d354
This commit is contained in:
@@ -57,6 +57,8 @@ public class UserDictionaryAddWordContents {
|
|||||||
private String mLocale;
|
private String mLocale;
|
||||||
private final String mOldWord;
|
private final String mOldWord;
|
||||||
private final String mOldShortcut;
|
private final String mOldShortcut;
|
||||||
|
private String mSavedWord;
|
||||||
|
private String mSavedShortcut;
|
||||||
|
|
||||||
/* package */ UserDictionaryAddWordContents(final View view, final Bundle args) {
|
/* package */ UserDictionaryAddWordContents(final View view, final Bundle args) {
|
||||||
mWordEditText = (EditText)view.findViewById(R.id.user_dictionary_add_word_text);
|
mWordEditText = (EditText)view.findViewById(R.id.user_dictionary_add_word_text);
|
||||||
@@ -78,6 +80,16 @@ public class UserDictionaryAddWordContents {
|
|||||||
updateLocale(args.getString(EXTRA_LOCALE));
|
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
|
// locale may be null, this means default locale
|
||||||
// It may also be the empty string, which means "all locales"
|
// It may also be the empty string, which means "all locales"
|
||||||
/* package */ void updateLocale(final String locale) {
|
/* package */ void updateLocale(final String locale) {
|
||||||
@@ -128,6 +140,8 @@ public class UserDictionaryAddWordContents {
|
|||||||
// If the word is somehow empty, don't insert it.
|
// If the word is somehow empty, don't insert it.
|
||||||
return UserDictionaryAddWordActivity.CODE_CANCEL;
|
return UserDictionaryAddWordActivity.CODE_CANCEL;
|
||||||
}
|
}
|
||||||
|
mSavedWord = newWord;
|
||||||
|
mSavedShortcut = newShortcut;
|
||||||
// If there is no shortcut, and the word already exists in the database, then we
|
// 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
|
// 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
|
// case the exact same thing we want to insert is already there, or B. the word
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
@@ -51,18 +52,31 @@ public class UserDictionaryAddWordFragment extends Fragment
|
|||||||
private boolean mIsDeleting = false;
|
private boolean mIsDeleting = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(final Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
getActivity().getActionBar().setTitle(R.string.user_dict_settings_title);
|
getActivity().getActionBar().setTitle(R.string.user_dict_settings_title);
|
||||||
|
// Keep the instance so that we remember mContents when configuration changes (eg rotation)
|
||||||
|
setRetainInstance(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
mRootView = inflater.inflate(R.layout.user_dictionary_add_word_fullscreen, null);
|
||||||
mIsDeleting = false;
|
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) {
|
if (null == mContents) {
|
||||||
mContents = new UserDictionaryAddWordContents(mRootView, getArguments());
|
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().getActionBar().setSubtitle(UserDictionarySettingsUtils.getLocaleDisplayName(
|
||||||
getActivity(), mContents.getCurrentUserDictionaryLocale()));
|
getActivity(), mContents.getCurrentUserDictionaryLocale()));
|
||||||
@@ -70,7 +84,7 @@ public class UserDictionaryAddWordFragment extends Fragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
|
||||||
MenuItem actionItem = menu.add(0, OPTIONS_MENU_DELETE, 0, R.string.delete)
|
MenuItem actionItem = menu.add(0, OPTIONS_MENU_DELETE, 0, R.string.delete)
|
||||||
.setIcon(android.R.drawable.ic_menu_delete);
|
.setIcon(android.R.drawable.ic_menu_delete);
|
||||||
actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
|
actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
|
||||||
|
Reference in New Issue
Block a user