Fragmentize UserDictionary.
Depending on I2c962726b0adc8811c18dd6df7ff7bdc93c31a07, which implements DialogCreatable. Change-Id: I9857e592218731bfbddc578c15180cc681fa4d20
This commit is contained in:
@@ -34,20 +34,16 @@
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="hardkeyboard_category"
|
||||
android:title="@string/builtin_keyboard_settings_title"
|
||||
android:summary="@string/builtin_keyboard_settings_summary">
|
||||
<intent android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="com.android.settings"
|
||||
android:targetClass="com.android.settings.PhysicalKeyboardSettings"/>
|
||||
android:fragment="com.android.settings.PhysicalKeyboardSettings"
|
||||
android:key="hardkeyboard_category"
|
||||
android:title="@string/builtin_keyboard_settings_title"
|
||||
android:summary="@string/builtin_keyboard_settings_summary">
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
android:title="@string/user_dict_settings_title"
|
||||
android:summary="@string/user_dict_settings_summary">
|
||||
<intent android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="com.android.settings"
|
||||
android:targetClass="com.android.settings.UserDictionarySettings" />
|
||||
android:fragment="com.android.settings.UserDictionarySettings"
|
||||
android:title="@string/user_dict_settings_title"
|
||||
android:summary="@string/user_dict_settings_summary">
|
||||
</PreferenceScreen>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@@ -295,7 +295,8 @@ public class LanguageSettings extends SettingsPreferenceFragment {
|
||||
if (preference.getFragment() != null) {
|
||||
// Fragment will be handled correctly by the super class.
|
||||
} else if (KEY_INPUT_METHOD.equals(preference.getKey())) {
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
final InputMethodManager imm = (InputMethodManager)
|
||||
getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showInputMethodPicker();
|
||||
} else if (preference.getIntent() == null) {
|
||||
PreferenceScreen pref = (PreferenceScreen) preference;
|
||||
|
@@ -20,12 +20,11 @@ import android.content.ContentResolver;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings.System;
|
||||
|
||||
public class PhysicalKeyboardSettings extends PreferenceActivity {
|
||||
|
||||
public class PhysicalKeyboardSettings extends SettingsPreferenceFragment {
|
||||
|
||||
private final String[] mSettingsUiKey = {
|
||||
"auto_caps",
|
||||
"auto_replace",
|
||||
@@ -47,14 +46,14 @@ public class PhysicalKeyboardSettings extends PreferenceActivity {
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.keyboard_settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
ContentResolver resolver = getContentResolver();
|
||||
for (int i = 0; i < mSettingsUiKey.length; i++) {
|
||||
@@ -66,7 +65,8 @@ public class PhysicalKeyboardSettings extends PreferenceActivity {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||
public boolean onPreferenceTreeClick(
|
||||
PreferenceScreen preferenceScreen, Preference preference) {
|
||||
|
||||
// Physical keyboard stuff
|
||||
for (int i = 0; i < mSettingsUiKey.length; i++) {
|
||||
|
@@ -32,6 +32,11 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
|
||||
/**
|
||||
* Letting the class, assumed to be Fragment, create a Dialog on it. Should be useful
|
||||
* you want to utilize some capability in {@link SettingsPreferenceFragment} but don't want
|
||||
* the class inherit the class itself (See {@link ProxySelector} for example).
|
||||
*/
|
||||
interface DialogCreatable {
|
||||
public Dialog onCreateDialog(int dialogId);
|
||||
}
|
||||
|
@@ -16,21 +16,30 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import com.android.settings.SettingsPreferenceFragment.SettingsDialogFragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.ListActivity;
|
||||
import android.app.ListFragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.provider.UserDictionary;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
import android.widget.AlphabetIndexer;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListAdapter;
|
||||
@@ -38,11 +47,11 @@ import android.widget.ListView;
|
||||
import android.widget.SectionIndexer;
|
||||
import android.widget.SimpleCursorAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class UserDictionarySettings extends ListActivity {
|
||||
public class UserDictionarySettings extends ListFragment implements DialogCreatable {
|
||||
private static final String TAG = "UserDictionarySettings";
|
||||
|
||||
private static final String INSTANCE_KEY_DIALOG_EDITING_WORD = "DIALOG_EDITING_WORD";
|
||||
private static final String INSTANCE_KEY_ADDED_WORD = "DIALOG_ADDED_WORD";
|
||||
@@ -69,52 +78,65 @@ public class UserDictionarySettings extends ListActivity {
|
||||
|
||||
/** The word being edited in the dialog (null means the user is adding a word). */
|
||||
private String mDialogEditingWord;
|
||||
|
||||
|
||||
private View mView;
|
||||
private Cursor mCursor;
|
||||
|
||||
private boolean mAddedWordAlready;
|
||||
private boolean mAutoReturn;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.list_content_with_empty_view);
|
||||
|
||||
private SettingsDialogFragment mDialogFragment;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
mView = inflater.inflate(R.layout.list_content_with_empty_view, container, false);
|
||||
return mView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
mCursor = createCursor();
|
||||
setListAdapter(createAdapter());
|
||||
|
||||
TextView emptyView = (TextView) findViewById(R.id.empty);
|
||||
TextView emptyView = (TextView)mView.findViewById(R.id.empty);
|
||||
emptyView.setText(R.string.user_dict_settings_empty_text);
|
||||
|
||||
ListView listView = getListView();
|
||||
|
||||
final ListView listView = getListView();
|
||||
listView.setAdapter(createAdapter());
|
||||
listView.setFastScrollEnabled(true);
|
||||
listView.setEmptyView(emptyView);
|
||||
|
||||
registerForContextMenu(listView);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mDialogEditingWord = savedInstanceState.getString(INSTANCE_KEY_DIALOG_EDITING_WORD);
|
||||
mAddedWordAlready = savedInstanceState.getBoolean(INSTANCE_KEY_ADDED_WORD, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
final Intent intent = getActivity().getIntent();
|
||||
if (!mAddedWordAlready
|
||||
&& getIntent().getAction().equals("com.android.settings.USER_DICTIONARY_INSERT")) {
|
||||
String word = getIntent().getStringExtra(EXTRA_WORD);
|
||||
&& intent.getAction().equals("com.android.settings.USER_DICTIONARY_INSERT")) {
|
||||
final String word = intent.getStringExtra(EXTRA_WORD);
|
||||
mAutoReturn = true;
|
||||
if (word != null) {
|
||||
showAddOrEditDialog(word);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle state) {
|
||||
super.onRestoreInstanceState(state);
|
||||
mDialogEditingWord = state.getString(INSTANCE_KEY_DIALOG_EDITING_WORD);
|
||||
mAddedWordAlready = state.getBoolean(INSTANCE_KEY_ADDED_WORD, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(INSTANCE_KEY_DIALOG_EDITING_WORD, mDialogEditingWord);
|
||||
outState.putBoolean(INSTANCE_KEY_ADDED_WORD, mAddedWordAlready);
|
||||
@@ -123,21 +145,21 @@ public class UserDictionarySettings extends ListActivity {
|
||||
private Cursor createCursor() {
|
||||
String currentLocale = Locale.getDefault().toString();
|
||||
// Case-insensitive sort
|
||||
return managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION,
|
||||
return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION,
|
||||
QUERY_SELECTION, new String[] { currentLocale },
|
||||
"UPPER(" + UserDictionary.Words.WORD + ")");
|
||||
}
|
||||
|
||||
private ListAdapter createAdapter() {
|
||||
return new MyAdapter(this,
|
||||
return new MyAdapter(getActivity(),
|
||||
android.R.layout.simple_list_item_1, mCursor,
|
||||
new String[] { UserDictionary.Words.WORD },
|
||||
new int[] { android.R.id.text1 });
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
openContextMenu(v);
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
getActivity().openContextMenu(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,10 +197,9 @@ public class UserDictionarySettings extends ListActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.add(0, OPTIONS_MENU_ADD, 0, R.string.user_dict_settings_add_menu_title)
|
||||
.setIcon(R.drawable.ic_menu_add);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,7 +212,7 @@ public class UserDictionarySettings extends ListActivity {
|
||||
mDialogEditingWord = editingWord;
|
||||
showDialog(DIALOG_ADD_OR_EDIT);
|
||||
}
|
||||
|
||||
|
||||
private String getWord(int position) {
|
||||
mCursor.moveToPosition(position);
|
||||
// Handle a possible race-condition
|
||||
@@ -202,14 +223,16 @@ public class UserDictionarySettings extends ListActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
View content = getLayoutInflater().inflate(R.layout.dialog_edittext, null);
|
||||
public Dialog onCreateDialog(int id) {
|
||||
final Activity activity = getActivity();
|
||||
final View content = activity.getLayoutInflater().inflate(R.layout.dialog_edittext, null);
|
||||
final EditText editText = (EditText) content.findViewById(R.id.edittext);
|
||||
editText.setText(mDialogEditingWord);
|
||||
// No prediction in soft keyboard mode. TODO: Create a better way to disable prediction
|
||||
editText.setInputType(InputType.TYPE_CLASS_TEXT
|
||||
| InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(this)
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(activity)
|
||||
.setTitle(mDialogEditingWord != null
|
||||
? R.string.user_dict_settings_edit_dialog_title
|
||||
: R.string.user_dict_settings_add_dialog_title)
|
||||
@@ -217,11 +240,11 @@ public class UserDictionarySettings extends ListActivity {
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
onAddOrEditFinished(editText.getText().toString());
|
||||
if (mAutoReturn) finish();
|
||||
if (mAutoReturn) activity.onBackPressed();
|
||||
}})
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (mAutoReturn) finish();
|
||||
if (mAutoReturn) activity.onBackPressed();
|
||||
}})
|
||||
.create();
|
||||
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
|
||||
@@ -229,14 +252,12 @@ public class UserDictionarySettings extends ListActivity {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialog(int id, Dialog d) {
|
||||
AlertDialog dialog = (AlertDialog) d;
|
||||
d.setTitle(mDialogEditingWord != null
|
||||
? R.string.user_dict_settings_edit_dialog_title
|
||||
: R.string.user_dict_settings_add_dialog_title);
|
||||
EditText editText = (EditText) dialog.findViewById(R.id.edittext);
|
||||
editText.setText(mDialogEditingWord);
|
||||
private void showDialog(int dialogId) {
|
||||
if (mDialogFragment != null) {
|
||||
Log.e(TAG, "Old dialog fragment not null!");
|
||||
}
|
||||
mDialogFragment = new SettingsDialogFragment(this, dialogId);
|
||||
mDialogFragment.show(getActivity().getFragmentManager(), Integer.toString(dialogId));
|
||||
}
|
||||
|
||||
private void onAddOrEditFinished(String word) {
|
||||
@@ -249,7 +270,7 @@ public class UserDictionarySettings extends ListActivity {
|
||||
deleteWord(word);
|
||||
|
||||
// TODO: present UI for picking whether to add word to all locales, or current.
|
||||
UserDictionary.Words.addWord(this, word.toString(),
|
||||
UserDictionary.Words.addWord(getActivity(), word.toString(),
|
||||
250, UserDictionary.Words.LOCALE_TYPE_ALL);
|
||||
if (!mCursor.requery()) {
|
||||
throw new IllegalStateException("can't requery on already-closed cursor.");
|
||||
@@ -258,10 +279,10 @@ public class UserDictionarySettings extends ListActivity {
|
||||
}
|
||||
|
||||
private void deleteWord(String word) {
|
||||
getContentResolver().delete(UserDictionary.Words.CONTENT_URI, DELETE_SELECTION,
|
||||
new String[] { word });
|
||||
getActivity().getContentResolver().delete(
|
||||
UserDictionary.Words.CONTENT_URI, DELETE_SELECTION, new String[] { word });
|
||||
}
|
||||
|
||||
|
||||
private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer {
|
||||
private AlphabetIndexer mIndexer;
|
||||
|
||||
|
Reference in New Issue
Block a user