mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-17 14:25:08 -05:00
Automcomplete names and emails in keyserver tab
This commit is contained in:
parent
62f7bf6215
commit
9ad09a3982
@ -234,6 +234,24 @@ public class ContactHelper {
|
||||
return new ArrayList<String>(mails);
|
||||
}
|
||||
|
||||
public static List<String> getContactNames(Context context) {
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
Cursor cursor = resolver.query(ContactsContract.Contacts.CONTENT_URI,
|
||||
new String[]{ContactsContract.Contacts.DISPLAY_NAME},
|
||||
null, null, null);
|
||||
if (cursor == null) return null;
|
||||
|
||||
Set<String> names = new HashSet<String>();
|
||||
while (cursor.moveToNext()) {
|
||||
String name = cursor.getString(0);
|
||||
if (name != null) {
|
||||
names.add(name);
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
return new ArrayList<String>(names);
|
||||
}
|
||||
|
||||
public static Uri dataUriFromContactUri(Context context, Uri contactUri) {
|
||||
Cursor contactMasterKey = context.getContentResolver().query(contactUri,
|
||||
new String[]{ContactsContract.Data.DATA2}, null, null, null, null);
|
||||
|
@ -29,15 +29,19 @@ import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.helper.ContactHelper;
|
||||
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ImportKeysServerFragment extends Fragment {
|
||||
public static final String ARG_QUERY = "query";
|
||||
public static final String ARG_KEYSERVER = "keyserver";
|
||||
@ -46,7 +50,7 @@ public class ImportKeysServerFragment extends Fragment {
|
||||
private ImportKeysActivity mImportActivity;
|
||||
|
||||
private View mSearchButton;
|
||||
private EditText mQueryEditText;
|
||||
private AutoCompleteTextView mQueryEditText;
|
||||
private View mConfigButton;
|
||||
private View mConfigLayout;
|
||||
private Spinner mServerSpinner;
|
||||
@ -75,7 +79,7 @@ public class ImportKeysServerFragment extends Fragment {
|
||||
View view = inflater.inflate(R.layout.import_keys_server_fragment, container, false);
|
||||
|
||||
mSearchButton = view.findViewById(R.id.import_server_search);
|
||||
mQueryEditText = (EditText) view.findViewById(R.id.import_server_query);
|
||||
mQueryEditText = (AutoCompleteTextView) view.findViewById(R.id.import_server_query);
|
||||
mConfigButton = view.findViewById(R.id.import_server_config_button);
|
||||
mConfigLayout = view.findViewById(R.id.import_server_config);
|
||||
mServerSpinner = (Spinner) view.findViewById(R.id.import_server_spinner);
|
||||
@ -93,6 +97,16 @@ public class ImportKeysServerFragment extends Fragment {
|
||||
mSearchButton.setEnabled(false);
|
||||
}
|
||||
|
||||
List<String> namesAndEmails = ContactHelper.getContactNames(getActivity());
|
||||
namesAndEmails.addAll(ContactHelper.getContactMails(getActivity()));
|
||||
mQueryEditText.setThreshold(3);
|
||||
mQueryEditText.setAdapter(
|
||||
new ArrayAdapter<String>
|
||||
(getActivity(), android.R.layout.simple_spinner_dropdown_item,
|
||||
namesAndEmails
|
||||
)
|
||||
);
|
||||
|
||||
mSearchButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -10,7 +10,7 @@
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/import_server_query"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
|
Loading…
Reference in New Issue
Block a user