From cf28da39c49497e2585611eb9dc0553b4646ba25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 26 Oct 2015 20:21:35 +0100 Subject: Update tokenautocomplete --- .../ui/widget/EncryptKeyCompletionView.java | 28 ++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java index 48e6c2cee..7fec47533 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java @@ -23,6 +23,7 @@ import android.database.Cursor; import android.graphics.Rect; import android.net.Uri; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.app.FragmentActivity; import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager.LoaderCallbacks; @@ -46,14 +47,14 @@ import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem; import org.sufficientlysecure.keychain.util.Log; -public class EncryptKeyCompletionView extends TokenCompleteTextView +public class EncryptKeyCompletionView extends TokenCompleteTextView implements LoaderCallbacks { public static final String ARG_QUERY = "query"; private KeyAdapter mAdapter; private LoaderManager mLoaderManager; - private String mPrefix; + private CharSequence mPrefix; public EncryptKeyCompletionView(Context context) { super(context); @@ -79,30 +80,27 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView } @Override - public void setPrefix(String p) { + public void setPrefix(CharSequence p) { // this one is private in the superclass, but we need it here mPrefix = p; super.setPrefix(p); } @Override - protected View getViewForObject(Object object) { - if (object instanceof KeyItem) { - LayoutInflater l = LayoutInflater.from(getContext()); - View view = l.inflate(R.layout.recipient_box_entry, null); - ((TextView) view.findViewById(android.R.id.text1)).setText(((KeyItem) object).getReadableName()); - return view; - } - return null; + protected View getViewForObject(KeyItem keyItem) { + LayoutInflater l = LayoutInflater.from(getContext()); + View view = l.inflate(R.layout.recipient_box_entry, null); + ((TextView) view.findViewById(android.R.id.text1)).setText(keyItem.getReadableName()); + return view; } @Override - protected Object defaultObject(String completionText) { + protected KeyItem defaultObject(String completionText) { // TODO: We could try to automagically download the key if it's unknown but a key id /*if (completionText.startsWith("0x")) { }*/ - return ""; + return null; } @Override @@ -128,7 +126,7 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView // These are the rows that we will retrieve. Uri baseUri = KeyRings.buildUnifiedKeyRingsUri(); - String[] projection = KeyAdapter.getProjectionWith(new String[] { + String[] projection = KeyAdapter.getProjectionWith(new String[]{ KeychainContract.KeyRings.HAS_ENCRYPT, }); @@ -179,7 +177,7 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView } @Override - protected void performFiltering(CharSequence text, int start, int end, int keyCode) { + protected void performFiltering(@NonNull CharSequence text, int start, int end, int keyCode) { super.performFiltering(text, start, end, keyCode); if (start < mPrefix.length()) { start = mPrefix.length(); -- cgit v1.2.3 From e89dba8f245f59afd9e4e3da9c62f98befcb4d47 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 26 Oct 2015 21:57:08 +0100 Subject: prevent crashes in EncryptKeyCompletionView (2) --- .../ui/widget/EncryptKeyCompletionView.java | 29 ++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java index 7fec47533..01d51af48 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java @@ -29,6 +29,7 @@ import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; @@ -134,18 +135,19 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView + KeyRings.IS_EXPIRED + " = 0 AND " + Tables.KEYS + "." + KeyRings.IS_REVOKED + " = 0"; - if (args != null && args.containsKey(ARG_QUERY)) { - String query = args.getString(ARG_QUERY); - mAdapter.setSearchQuery(query); + if (args == null || !args.containsKey(ARG_QUERY)) { + // mAdapter.setSearchQuery(null); + // return new CursorLoader(getContext(), baseUri, projection, where, null, null); + return null; + } - where += " AND " + KeyRings.USER_ID + " LIKE ?"; + String query = args.getString(ARG_QUERY); + mAdapter.setSearchQuery(query); - return new CursorLoader(getContext(), baseUri, projection, where, - new String[]{"%" + query + "%"}, null); - } + where += " AND " + KeyRings.USER_ID + " LIKE ?"; - mAdapter.setSearchQuery(null); - return new CursorLoader(getContext(), baseUri, projection, where, null, null); + return new CursorLoader(getContext(), baseUri, projection, where, + new String[]{"%" + query + "%"}, null); } @@ -167,6 +169,8 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView super.showDropDown(); } + + @Override public void onFocusChanged(boolean hasFocus, int direction, Rect previous) { super.onFocusChanged(hasFocus, direction, previous); @@ -182,8 +186,13 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView if (start < mPrefix.length()) { start = mPrefix.length(); } + String query = text.subSequence(start, end).toString(); + if (TextUtils.isEmpty(query) || query.length() < 2) { + mLoaderManager.destroyLoader(0); + return; + } Bundle args = new Bundle(); - args.putString(ARG_QUERY, text.subSequence(start, end).toString()); + args.putString(ARG_QUERY, query); mLoaderManager.restartLoader(0, args, this); } -- cgit v1.2.3