diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
8 files changed, 88 insertions, 115 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index bf6abcd6f..e93d717e1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -38,7 +38,7 @@ import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListKeybaseLoader; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListServerLoader; import org.sufficientlysecure.keychain.util.InputData; -import org.sufficientlysecure.keychain.keyimport.KeyServer; +import org.sufficientlysecure.keychain.keyimport.Keyserver; import org.sufficientlysecure.keychain.util.Log; import java.io.ByteArrayInputStream; @@ -280,13 +280,13 @@ public class ImportKeysListFragment extends ListFragment implements mAdapter.getCount(), mAdapter.getCount()), AppMsg.STYLE_INFO ).show(); - } else if (error instanceof KeyServer.InsufficientQuery) { + } else if (error instanceof Keyserver.InsufficientQuery) { AppMsg.makeText(getActivity(), R.string.error_keyserver_insufficient_query, AppMsg.STYLE_ALERT).show(); - } else if (error instanceof KeyServer.QueryException) { + } else if (error instanceof Keyserver.QueryException) { AppMsg.makeText(getActivity(), R.string.error_keyserver_query, AppMsg.STYLE_ALERT).show(); - } else if (error instanceof KeyServer.TooManyResponses) { + } else if (error instanceof Keyserver.TooManyResponses) { AppMsg.makeText(getActivity(), R.string.error_keyserver_too_many_responses, AppMsg.STYLE_ALERT).show(); } @@ -300,7 +300,7 @@ public class ImportKeysListFragment extends ListFragment implements mAdapter.getCount(), mAdapter.getCount()), AppMsg.STYLE_INFO ).show(); - } else if (error instanceof KeyServer.QueryException) { + } else if (error instanceof Keyserver.QueryException) { AppMsg.makeText(getActivity(), R.string.error_keyserver_query, AppMsg.STYLE_ALERT).show(); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index a3f4b0753..9c90b5eb7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -34,6 +34,7 @@ import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.ActionBarActivity; +import android.support.v4.widget.CursorAdapter; import android.support.v7.widget.SearchView; import android.text.TextUtils; import android.view.ActionMode; @@ -61,8 +62,8 @@ import org.sufficientlysecure.keychain.helper.ExportHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.ui.adapter.HighlightQueryCursorAdapter; import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment; +import org.sufficientlysecure.keychain.util.Highlighter; import org.sufficientlysecure.keychain.util.Log; import java.util.Date; @@ -82,7 +83,7 @@ public class KeyListFragment extends LoaderFragment private KeyListAdapter mAdapter; private StickyListHeadersListView mStickyList; - private String mCurQuery; + private String mQuery; private SearchView mSearchView; // empty list layout private BootstrapButton mButtonEmptyCreate; @@ -130,7 +131,7 @@ public class KeyListFragment extends LoaderFragment /** * Define Adapter and Loader on create of Activity */ - @SuppressLint("NewApi") + @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -141,8 +142,7 @@ public class KeyListFragment extends LoaderFragment mStickyList.setFastScrollEnabled(true); /* - * ActionBarSherlock does not support MultiChoiceModeListener. Thus multi-selection is only - * available for Android >= 3.0 + * Multi-selection is only available for Android >= 3.0 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mStickyList.setFastScrollAlwaysVisible(true); @@ -263,9 +263,18 @@ public class KeyListFragment extends LoaderFragment Uri baseUri = KeyRings.buildUnifiedKeyRingsUri(); String where = null; String whereArgs[] = null; - if (mCurQuery != null) { - where = KeyRings.USER_ID + " LIKE ?"; - whereArgs = new String[]{"%" + mCurQuery + "%"}; + if (mQuery != null) { + String[] words = mQuery.trim().split("\\s+"); + whereArgs = new String[words.length]; + for (int i = 0; i < words.length; ++i) { + if (where == null) { + where = ""; + } else { + where += " AND "; + } + where += KeyRings.USER_ID + " LIKE ?"; + whereArgs[i] = "%" + words[i] + "%"; + } } // Now create and return a CursorLoader that will take care of @@ -277,7 +286,7 @@ public class KeyListFragment extends LoaderFragment public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take care of closing the // old cursor once we return.) - mAdapter.setSearchQuery(mCurQuery); + mAdapter.setSearchQuery(mQuery); mAdapter.swapCursor(data); mStickyList.setAdapter(mAdapter); @@ -312,7 +321,7 @@ public class KeyListFragment extends LoaderFragment startActivity(viewIntent); } - @TargetApi(11) + @TargetApi(Build.VERSION_CODES.HONEYCOMB) protected void encrypt(ActionMode mode, long[] masterKeyIds) { Intent intent = new Intent(getActivity(), EncryptActivity.class); intent.setAction(EncryptActivity.ACTION_ENCRYPT); @@ -329,7 +338,7 @@ public class KeyListFragment extends LoaderFragment * @param masterKeyIds * @param hasSecret must contain whether the list of masterKeyIds contains a secret key or not */ - @TargetApi(11) + @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void showDeleteKeyDialog(final ActionMode mode, long[] masterKeyIds, boolean hasSecret) { // Can only work on singular secret keys if(hasSecret && masterKeyIds.length > 1) { @@ -379,7 +388,7 @@ public class KeyListFragment extends LoaderFragment @Override public boolean onMenuItemActionCollapse(MenuItem item) { - mCurQuery = null; + mQuery = null; mSearchView.setQuery("", true); getLoaderManager().restartLoader(0, null, KeyListFragment.this); return true; @@ -399,7 +408,7 @@ public class KeyListFragment extends LoaderFragment // Called when the action bar search text has changed. Update // the search filter, and restart the loader to do a new query // with this filter. - mCurQuery = !TextUtils.isEmpty(s) ? s : null; + mQuery = !TextUtils.isEmpty(s) ? s : null; getLoaderManager().restartLoader(0, null, this); return true; } @@ -407,7 +416,8 @@ public class KeyListFragment extends LoaderFragment /** * Implements StickyListHeadersAdapter from library */ - private class KeyListAdapter extends HighlightQueryCursorAdapter implements StickyListHeadersAdapter { + private class KeyListAdapter extends CursorAdapter implements StickyListHeadersAdapter { + private String mQuery; private LayoutInflater mInflater; private HashMap<Integer, Boolean> mSelection = new HashMap<Integer, Boolean>(); @@ -418,6 +428,10 @@ public class KeyListFragment extends LoaderFragment mInflater = LayoutInflater.from(context); } + public void setSearchQuery(String query) { + mQuery = query; + } + @Override public Cursor swapCursor(Cursor newCursor) { return super.swapCursor(newCursor); @@ -456,18 +470,19 @@ public class KeyListFragment extends LoaderFragment */ @Override public void bindView(View view, Context context, Cursor cursor) { + Highlighter highlighter = new Highlighter(context, mQuery); ItemViewHolder h = (ItemViewHolder) view.getTag(); { // set name and stuff, common to both key types String userId = cursor.getString(INDEX_USER_ID); String[] userIdSplit = PgpKeyHelper.splitUserId(userId); if (userIdSplit[0] != null) { - h.mMainUserId.setText(highlightSearchQuery(userIdSplit[0])); + h.mMainUserId.setText(highlighter.highlight(userIdSplit[0])); } else { h.mMainUserId.setText(R.string.user_id_no_name); } if (userIdSplit[1] != null) { - h.mMainUserIdRest.setText(highlightSearchQuery(userIdSplit[1])); + h.mMainUserIdRest.setText(highlighter.highlight(userIdSplit[1])); h.mMainUserIdRest.setVisibility(View.VISIBLE); } else { h.mMainUserIdRest.setVisibility(View.GONE); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java index 2ad769b00..9343b166a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java @@ -55,7 +55,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T private SelectKeyCursorAdapter mAdapter; private EditText mSearchView; private long mSelectedMasterKeyIds[]; - private String mCurQuery; + private String mQuery; // copied from ListFragment static final int INTERNAL_EMPTY_ID = 0x00ff0001; @@ -281,9 +281,18 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T } String where = null; String whereArgs[] = null; - if (mCurQuery != null) { - where = KeyRings.USER_ID + " LIKE ?"; - whereArgs = new String[]{"%" + mCurQuery + "%"}; + if (mQuery != null) { + String[] words = mQuery.trim().split("\\s+"); + whereArgs = new String[words.length]; + for (int i = 0; i < words.length; ++i) { + if (where == null) { + where = ""; + } else { + where += " AND "; + } + where += KeyRings.USER_ID + " LIKE ?"; + whereArgs[i] = "%" + words[i] + "%"; + } } // Now create and return a CursorLoader that will take care of @@ -295,7 +304,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take care of closing the // old cursor once we return.) - mAdapter.setSearchQuery(mCurQuery); + mAdapter.setSearchQuery(mQuery); mAdapter.swapCursor(data); // The list should now be shown. @@ -329,7 +338,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T @Override public void afterTextChanged(Editable editable) { - mCurQuery = !TextUtils.isEmpty(editable.toString()) ? editable.toString() : null; + mQuery = !TextUtils.isEmpty(editable.toString()) ? editable.toString() : null; getLoaderManager().restartLoader(0, null, this); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/HighlightQueryCursorAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/HighlightQueryCursorAdapter.java deleted file mode 100644 index fd7a2dc30..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/HighlightQueryCursorAdapter.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package org.sufficientlysecure.keychain.ui.adapter; - -import android.content.Context; -import android.database.Cursor; -import android.support.v4.widget.CursorAdapter; -import android.text.Spannable; -import android.text.style.ForegroundColorSpan; - -import org.sufficientlysecure.keychain.R; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public abstract class HighlightQueryCursorAdapter extends CursorAdapter { - - private String mCurQuery; - - public HighlightQueryCursorAdapter(Context context, Cursor c, int flags) { - super(context, c, flags); - mCurQuery = null; - } - - public void setSearchQuery(String searchQuery) { - mCurQuery = searchQuery; - } - - public String getSearchQuery() { - return mCurQuery; - } - - protected Spannable highlightSearchQuery(String text) { - Spannable highlight = Spannable.Factory.getInstance().newSpannable(text); - - if (mCurQuery != null) { - Pattern pattern = Pattern.compile("(?i)" + mCurQuery); - Matcher matcher = pattern.matcher(text); - if (matcher.find()) { - highlight.setSpan( - new ForegroundColorSpan(mContext.getResources().getColor(R.color.emphasis)), - matcher.start(), - matcher.end(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } - return highlight; - } else { - return highlight; - } - } -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 9d323c822..9573efdfe 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -33,6 +33,7 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; +import org.sufficientlysecure.keychain.util.Highlighter; import java.util.ArrayList; import java.util.Iterator; @@ -99,6 +100,7 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { public View getView(int position, View convertView, ViewGroup parent) { ImportKeysListEntry entry = mData.get(position); + Highlighter highlighter = new Highlighter(mActivity, entry.getQuery()); ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); @@ -128,7 +130,7 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { + " " + userIdSplit[0]); holder.mainUserId.setTextColor(Color.RED); } else { - holder.mainUserId.setText(userIdSplit[0]); + holder.mainUserId.setText(highlighter.highlight(userIdSplit[0])); holder.mainUserId.setTextColor(Color.BLACK); } } else { @@ -139,21 +141,26 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { // email if (userIdSplit[1] != null) { holder.mainUserIdRest.setVisibility(View.VISIBLE); - holder.mainUserIdRest.setText(userIdSplit[1]); + holder.mainUserIdRest.setText(highlighter.highlight(userIdSplit[1])); } else { holder.mainUserIdRest.setVisibility(View.GONE); } holder.keyId.setText(entry.keyIdHex); - if (entry.fingerPrintHex != null) { + if (entry.fingerprintHex != null) { holder.fingerprint.setVisibility(View.VISIBLE); - holder.fingerprint.setText(PgpKeyHelper.colorizeFingerprint(entry.fingerPrintHex)); + holder.fingerprint.setText(PgpKeyHelper.colorizeFingerprint(entry.fingerprintHex)); } else { holder.fingerprint.setVisibility(View.GONE); } - holder.algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm); + if (entry.bitStrength != 0 && entry.algorithm != null) { + holder.algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm); + holder.algorithm.setVisibility(View.VISIBLE); + } else { + holder.algorithm.setVisibility(View.INVISIBLE); + } if (entry.revoked) { holder.status.setVisibility(View.VISIBLE); @@ -177,7 +184,7 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { String uid = it.next(); TextView uidView = (TextView) mInflater.inflate( R.layout.import_keys_list_entry_user_id, null); - uidView.setText(uid); + uidView.setText(highlighter.highlight(uid)); holder.userIdsList.addView(uidView); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java index 420880522..0fdc019d0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java @@ -22,8 +22,8 @@ import android.support.v4.content.AsyncTaskLoader; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; -import org.sufficientlysecure.keychain.keyimport.KeyServer; -import org.sufficientlysecure.keychain.keyimport.KeybaseKeyServer; +import org.sufficientlysecure.keychain.keyimport.Keyserver; +import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserver; import org.sufficientlysecure.keychain.util.Log; import java.util.ArrayList; @@ -86,7 +86,7 @@ public class ImportKeysListKeybaseLoader */ private void queryServer(String query) { - KeybaseKeyServer server = new KeybaseKeyServer(); + KeybaseKeyserver server = new KeybaseKeyserver(); try { ArrayList<ImportKeysListEntry> searchResult = server.search(query); @@ -94,11 +94,11 @@ public class ImportKeysListKeybaseLoader mEntryList.addAll(searchResult); mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null); - } catch (KeyServer.InsufficientQuery e) { + } catch (Keyserver.InsufficientQuery e) { mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); - } catch (KeyServer.QueryException e) { + } catch (Keyserver.QueryException e) { mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); - } catch (KeyServer.TooManyResponses e) { + } catch (Keyserver.TooManyResponses e) { mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java index 4175592d6..1b8d7d30e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java @@ -21,9 +21,9 @@ import android.content.Context; import android.support.v4.content.AsyncTaskLoader; import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.keyimport.HkpKeyServer; +import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; -import org.sufficientlysecure.keychain.keyimport.KeyServer; +import org.sufficientlysecure.keychain.keyimport.Keyserver; import org.sufficientlysecure.keychain.util.Log; import java.util.ArrayList; @@ -92,7 +92,7 @@ public class ImportKeysListServerLoader * Query keyserver */ private void queryServer(String query, String keyServer, boolean enforceFingerprint) { - HkpKeyServer server = new HkpKeyServer(keyServer); + HkpKeyserver server = new HkpKeyserver(keyServer); try { ArrayList<ImportKeysListEntry> searchResult = server.search(query); @@ -108,7 +108,7 @@ public class ImportKeysListServerLoader * set fingerprint explicitly after query * to enforce a check when the key is imported by KeychainIntentService */ - uniqueEntry.setFingerPrintHex(fingerprint); + uniqueEntry.setFingerprintHex(fingerprint); uniqueEntry.setSelected(true); mEntryList.add(uniqueEntry); } @@ -116,11 +116,11 @@ public class ImportKeysListServerLoader mEntryList.addAll(searchResult); } mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null); - } catch (KeyServer.InsufficientQuery e) { + } catch (Keyserver.InsufficientQuery e) { mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); - } catch (KeyServer.QueryException e) { + } catch (Keyserver.QueryException e) { mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); - } catch (KeyServer.TooManyResponses e) { + } catch (Keyserver.TooManyResponses e) { mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java index cde008175..00cd554b9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java @@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui.adapter; import android.content.Context; import android.database.Cursor; +import android.support.v4.widget.CursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -29,6 +30,7 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; +import org.sufficientlysecure.keychain.util.Highlighter; import java.util.Date; @@ -36,8 +38,9 @@ import java.util.Date; /** * Yes this class is abstract! */ -abstract public class SelectKeyCursorAdapter extends HighlightQueryCursorAdapter { +abstract public class SelectKeyCursorAdapter extends CursorAdapter { + private String mQuery; private LayoutInflater mInflater; protected int mIndexUserId, mIndexMasterKeyId, mIndexRevoked, mIndexExpiry; @@ -48,6 +51,10 @@ abstract public class SelectKeyCursorAdapter extends HighlightQueryCursorAdapter initIndex(c); } + public void setSearchQuery(String query) { + mQuery = query; + } + @Override public Cursor swapCursor(Cursor newCursor) { initIndex(newCursor); @@ -101,19 +108,20 @@ abstract public class SelectKeyCursorAdapter extends HighlightQueryCursorAdapter @Override public void bindView(View view, Context context, Cursor cursor) { + Highlighter highlighter = new Highlighter(context, mQuery); ViewHolderItem h = (ViewHolderItem) view.getTag(); String userId = cursor.getString(mIndexUserId); String[] userIdSplit = PgpKeyHelper.splitUserId(userId); if (userIdSplit[0] != null) { - h.mainUserId.setText(highlightSearchQuery(userIdSplit[0])); + h.mainUserId.setText(highlighter.highlight(userIdSplit[0])); } else { h.mainUserId.setText(R.string.user_id_no_name); } if (userIdSplit[1] != null) { h.mainUserIdRest.setVisibility(View.VISIBLE); - h.mainUserIdRest.setText(highlightSearchQuery(userIdSplit[1])); + h.mainUserIdRest.setText(highlighter.highlight(userIdSplit[1])); } else { h.mainUserIdRest.setVisibility(View.GONE); } |