Back to project page xposed-keyboard-tweaks.
The source code is released under:
Apache License
If you think the Android project xposed-keyboard-tweaks listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package ca.spacek.gkdd; //from w w w .jav a 2 s. c o m import android.app.AlertDialog; import android.app.ListActivity; import android.app.LoaderManager.LoaderCallbacks; import android.content.ContentValues; import android.content.Context; import android.content.CursorLoader; import android.content.DialogInterface; import android.content.Loader; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.text.Editable; import android.text.InputType; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.EditText; import android.widget.SimpleCursorAdapter; import ca.spacek.gkdd.contentprovider.DictionaryWordContentProvider; import ca.spacek.gkdd.data.DictionaryWordTable; public class DictionaryWordsListActivity extends ListActivity implements LoaderCallbacks<Cursor> { // Seems like a weird way to define this private static final int DELETE_ID = Menu.FIRST + 1; private SimpleCursorAdapter adapter; private AlertDialog addWordDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dictionary_words_list); fillData(); createDialog(); registerForContextMenu(getListView()); } private void createDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Enter word"); final EditText input = new EditText(this); input.setInputType(InputType.TYPE_CLASS_TEXT); builder.setView(input); // Set up the buttons builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ContentValues values = new ContentValues(); Editable text = input.getText(); if (text == null) { Log.e("blacklist", "Can't insert blacklist word, input.getText() was null"); return; } text.clear(); values.put(DictionaryWordTable.COLUMN_WORD, text.toString()); getContentResolver().insert(DictionaryWordContentProvider.CONTENT_URI, values); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Editable text = input.getText(); if (text != null) { text.clear(); } dialog.cancel(); } } ); addWordDialog = builder.create(); } private void fillData() { String[] from = new String[]{DictionaryWordTable.COLUMN_WORD}; int[] to = new int[]{R.id.label}; getLoaderManager().initLoader(0, null, this); adapter = new SimpleCursorAdapter(this, R.layout.dictionary_word_row, null, from, to, 0); setListAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.dictionary_words_list, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.add: addWord(); return true; } return super.onOptionsItemSelected(item); } private void addWord() { addWordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); addWordDialog.show(); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.add(0, DELETE_ID, 0, R.string.delete_dictionary_word); } @Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case DELETE_ID: AdapterContextMenuInfo info = (AdapterContextMenuInfo) item .getMenuInfo(); if (info != null) { Uri uri = Uri.parse(DictionaryWordContentProvider.CONTENT_URI + "/" + info.id); getContentResolver().delete(uri, null, null); fillData(); return true; } } return super.onContextItemSelected(item); } @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { String[] projection = {DictionaryWordTable.COLUMN_ID, DictionaryWordTable.COLUMN_WORD}; return new CursorLoader(this, DictionaryWordContentProvider.CONTENT_URI, projection, null, null, null); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { adapter.swapCursor(data); } @Override public void onLoaderReset(Loader<Cursor> loader) { // data is not available anymore, delete reference adapter.swapCursor(null); } }