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