From a0868ffd5ddcb1fa23c5b6e4b1043e40611bbd34 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 8 May 2012 20:08:39 +0900 Subject: Move the spinner code to the fragment. Bug: 6026080 Change-Id: I49e1aa1839266ca169982b6a4800ee9923451be5 --- .../inputmethod/UserDictionaryAddWordActivity.java | 30 +---------------- .../inputmethod/UserDictionaryAddWordFragment.java | 39 +++++++++++++++++++--- 2 files changed, 36 insertions(+), 33 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java b/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java index 087574e..0190f0d 100644 --- a/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java +++ b/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java @@ -21,7 +21,6 @@ import com.android.settings.UserDictionarySettings; import com.android.settings.Utils; import com.android.settings.inputmethod.UserDictionaryAddWordContents.LocaleRenderer; -import java.util.ArrayList; import java.util.Locale; import android.animation.LayoutTransition; @@ -33,13 +32,9 @@ import android.provider.UserDictionary; import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; import android.widget.EditText; -import android.widget.Spinner; -public class UserDictionaryAddWordActivity extends Activity - implements AdapterView.OnItemSelectedListener { +public class UserDictionaryAddWordActivity extends Activity { private static final String STATE_KEY_IS_OPEN = "isOpen"; @@ -129,15 +124,6 @@ public class UserDictionaryAddWordActivity extends Activity findViewById(R.id.user_dictionary_settings_add_dialog_less_options) .setVisibility(View.VISIBLE); - final ArrayList localesList = mContents.getLocalesList(this); - - final Spinner localeSpinner = - (Spinner)findViewById(R.id.user_dictionary_settings_add_dialog_locale); - final ArrayAdapter adapter = new ArrayAdapter(this, - android.R.layout.simple_spinner_item, localesList); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - localeSpinner.setAdapter(adapter); - localeSpinner.setOnItemSelectedListener(this); mIsShowingMoreOptions = true; } @@ -152,18 +138,4 @@ public class UserDictionaryAddWordActivity extends Activity .setVisibility(View.GONE); mIsShowingMoreOptions = false; } - - @Override - public void onItemSelected(final AdapterView parent, final View view, final int pos, - final long id) { - final LocaleRenderer locale = (LocaleRenderer)parent.getItemAtPosition(pos); - mContents.updateLocale(locale.getLocaleString()); - } - - @Override - public void onNothingSelected(AdapterView parent) { - // I'm not sure we can come here, but if we do, that's the right thing to do. - final Intent intent = getIntent(); - mContents.updateLocale(intent.getStringExtra(UserDictionaryAddWordContents.EXTRA_LOCALE)); - } } diff --git a/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java b/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java index f4a39a2..7ab8ae6 100644 --- a/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java +++ b/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java @@ -23,8 +23,14 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; import com.android.settings.R; +import com.android.settings.inputmethod.UserDictionaryAddWordContents.LocaleRenderer; + +import java.util.ArrayList; /** * Fragment to add a word/shortcut to the user dictionary. @@ -32,11 +38,13 @@ import com.android.settings.R; * As opposed to the UserDictionaryActivity, this is only invoked within Settings * from the UserDictionarySettings. */ -public class UserDictionaryAddWordFragment extends Fragment { +public class UserDictionaryAddWordFragment extends Fragment + implements AdapterView.OnItemSelectedListener { private static final int OPTIONS_MENU_DELETE = Menu.FIRST; private UserDictionaryAddWordContents mContents; + private View mRootView; @Override public void onActivityCreated(Bundle savedInstanceState) { @@ -46,9 +54,8 @@ public class UserDictionaryAddWordFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { - final View view = inflater.inflate(R.layout.user_dictionary_add_word_fullscreen, null); - mContents = new UserDictionaryAddWordContents(view, getArguments()); - return view; + mRootView = inflater.inflate(R.layout.user_dictionary_add_word_fullscreen, null); + return mRootView; } @Override @@ -63,6 +70,16 @@ public class UserDictionaryAddWordFragment extends Fragment { public void onResume() { super.onResume(); // We are being shown: display the word + mContents = new UserDictionaryAddWordContents(mRootView, getArguments()); + final ArrayList localesList = mContents.getLocalesList(getActivity()); + + final Spinner localeSpinner = + (Spinner)mRootView.findViewById(R.id.user_dictionary_settings_add_dialog_locale); + final ArrayAdapter adapter = new ArrayAdapter(getActivity(), + android.R.layout.simple_spinner_item, localesList); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + localeSpinner.setAdapter(adapter); + localeSpinner.setOnItemSelectedListener(this); } @Override @@ -71,4 +88,18 @@ public class UserDictionaryAddWordFragment extends Fragment { mContents.apply(getActivity()); // We are being hidden: commit changes to the user dictionary } + + @Override + public void onItemSelected(final AdapterView parent, final View view, final int pos, + final long id) { + final LocaleRenderer locale = (LocaleRenderer)parent.getItemAtPosition(pos); + mContents.updateLocale(locale.getLocaleString()); + } + + @Override + public void onNothingSelected(final AdapterView parent) { + // I'm not sure we can come here, but if we do, that's the right thing to do. + final Bundle args = getArguments(); + mContents.updateLocale(args.getString(UserDictionaryAddWordContents.EXTRA_LOCALE)); + } } -- cgit v1.1