summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-05-10 00:28:15 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-05-10 00:28:15 -0700
commitcfed94a65607fe9bb3387104c5368df31d73d04e (patch)
treefe1a24abcf36e0c77f7246e8c3cb93dc2fd5edef
parent7ff82ad4e06c8cf0339cc0bce0b54df9a2993a4f (diff)
parent5bdde7f93960d4f08a45aec14caaa88a310cca8c (diff)
downloadpackages_apps_Settings-cfed94a65607fe9bb3387104c5368df31d73d04e.zip
packages_apps_Settings-cfed94a65607fe9bb3387104c5368df31d73d04e.tar.gz
packages_apps_Settings-cfed94a65607fe9bb3387104c5368df31d73d04e.tar.bz2
Merge "Implement the delete button for user words" into jb-dev
-rw-r--r--src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java11
-rw-r--r--src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java26
2 files changed, 34 insertions, 3 deletions
diff --git a/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java b/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java
index 1e8bf74..d33f8c3 100644
--- a/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java
+++ b/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java
@@ -87,9 +87,18 @@ public class UserDictionaryAddWordContents {
outState.putString(EXTRA_LOCALE, mLocale);
}
+ /* package */ void delete(final Context context) {
+ if (MODE_EDIT == mMode && !TextUtils.isEmpty(mOldWord)) {
+ // Mode edit: remove the old entry.
+ final ContentResolver resolver = context.getContentResolver();
+ UserDictionarySettings.deleteWord(mOldWord, mOldShortcut, resolver);
+ }
+ // If we are in add mode, nothing was added, so we don't need to do anything.
+ }
+
/* package */ void apply(final Context context) {
final ContentResolver resolver = context.getContentResolver();
- if (UserDictionaryAddWordContents.MODE_EDIT == mMode && !TextUtils.isEmpty(mOldWord)) {
+ if (MODE_EDIT == mMode && !TextUtils.isEmpty(mOldWord)) {
// Mode edit: remove the old entry.
UserDictionarySettings.deleteWord(mOldWord, mOldShortcut, resolver);
}
diff --git a/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java b/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java
index 0a9738f..676ef7d 100644
--- a/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java
+++ b/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java
@@ -45,6 +45,7 @@ public class UserDictionaryAddWordFragment extends Fragment
private UserDictionaryAddWordContents mContents;
private View mRootView;
+ private boolean mIsDeleting = false;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
@@ -55,6 +56,7 @@ public class UserDictionaryAddWordFragment extends Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
mRootView = inflater.inflate(R.layout.user_dictionary_add_word_fullscreen, null);
+ mIsDeleting = false;
return mRootView;
}
@@ -66,6 +68,24 @@ public class UserDictionaryAddWordFragment extends Fragment
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
+ /**
+ * Callback for the framework when a menu option is pressed.
+ *
+ * This class only supports the delete menu item.
+ * @param MenuItem the item that was pressed
+ * @return false to allow normal menu processing to proceed, true to consume it here
+ */
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == OPTIONS_MENU_DELETE) {
+ mContents.delete(getActivity());
+ mIsDeleting = true;
+ getFragmentManager().popBackStack();
+ return true;
+ }
+ return false;
+ }
+
@Override
public void onResume() {
super.onResume();
@@ -85,8 +105,10 @@ public class UserDictionaryAddWordFragment extends Fragment
@Override
public void onPause() {
super.onPause();
- mContents.apply(getActivity());
- // We are being hidden: commit changes to the user dictionary
+ // We are being hidden: commit changes to the user dictionary, unless we were deleting it
+ if (!mIsDeleting) {
+ mContents.apply(getActivity());
+ }
}
@Override