Fixed 140 - Multiline Entries in KeyServerQueryActivity

* EditText is now singleLine and has a hint
 * EditText has set inputType=text and imeOptions=actionSearch
 * Implemented listener for the actionSearch event
 * Reformated the source code according to the project specification. Sorry for
   the diff mess :-/

Signed-off-by: Bahtiar `kalkin-` Gadimov <bahtiar@gadimov.de>
This commit is contained in:
Bahtiar `kalkin-` Gadimov 2013-09-24 13:16:02 +02:00
parent 224faa42ac
commit 2fda5bfc97
No known key found for this signature in database
GPG Key ID: D9DDEA664F569891
3 changed files with 90 additions and 52 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (C) 2010 Thialfihar <thi@thialfihar.org> <!--
Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -14,40 +15,42 @@
limitations under the License. limitations under the License.
--> -->
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical"> android:orientation="vertical" >
<Spinner <Spinner
android:id="@+id/keyServer" android:id="@+id/keyServer"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content" />
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal" >
<EditText <EditText
android:id="@+id/query" android:id="@+id/query"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"/> android:layout_weight="1"
android:hint="@string/hint_secretKeys"
android:imeOptions="actionSearch"
android:inputType="textNoSuggestions"
android:singleLine="true" />
<Button <Button
android:id="@+id/btn_search" android:id="@+id/btn_search"
android:text="@string/btn_search"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"
android:text="@string/btn_search" />
</LinearLayout> </LinearLayout>
<ListView <ListView
android:id="@+id/list" android:id="@+id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="0dip" android:layout_height="0dip"
android:layout_weight="1"/> android:layout_weight="1" />
</LinearLayout> </LinearLayout>

View File

@ -314,6 +314,7 @@
<string name="action_importSecret">Import Secret Keys</string> <string name="action_importSecret">Import Secret Keys</string>
<string name="hint_publicKeys">Search Public Keys</string> <string name="hint_publicKeys">Search Public Keys</string>
<string name="hint_secretKeys">Search Secret Keys</string> <string name="hint_secretKeys">Search Secret Keys</string>
<string name="hint_query">Name, E-Mail or Key ID</string>
<string name="filterInfo">Filter: \"%s\"</string> <string name="filterInfo">Filter: \"%s\"</string>
<string name="shareKeyringWith">Share Key with…</string> <string name="shareKeyringWith">Share Key with…</string>

View File

@ -17,22 +17,6 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
import java.util.ArrayList;
import java.util.List;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.KeyServer.KeyInfo;
import org.sufficientlysecure.keychain.R;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
@ -40,10 +24,12 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
@ -55,12 +41,27 @@ import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast; import android.widget.Toast;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
import java.util.ArrayList;
import java.util.List;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.util.KeyServer.KeyInfo;
import org.sufficientlysecure.keychain.util.Log;
public class KeyServerQueryActivity extends SherlockFragmentActivity { public class KeyServerQueryActivity extends SherlockFragmentActivity {
// possible intent actions for this activity // possible intent actions for this activity
public static final String ACTION_LOOK_UP_KEY_ID = Constants.INTENT_PREFIX + "LOOK_UP_KEY_ID"; public static final String ACTION_LOOK_UP_KEY_ID = Constants.INTENT_PREFIX + "LOOK_UP_KEY_ID";
public static final String ACTION_LOOK_UP_KEY_ID_AND_RETURN = Constants.INTENT_PREFIX public static final String ACTION_LOOK_UP_KEY_ID_AND_RETURN = Constants.INTENT_PREFIX
+ "LOOK_UP_KEY_ID_AND_RETURN"; + "LOOK_UP_KEY_ID_AND_RETURN";
@ -69,30 +70,38 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
public static final String RESULT_EXTRA_TEXT = "text"; public static final String RESULT_EXTRA_TEXT = "text";
private ListView mList; private ListView mList;
private EditText mQuery; private EditText mQuery;
private Button mSearch; private Button mSearch;
private KeyInfoListAdapter mAdapter; private KeyInfoListAdapter mAdapter;
private Spinner mKeyServer; private Spinner mKeyServer;
private int mQueryType; private int mQueryType;
private String mQueryString; private String mQueryString;
private long mQueryId; private long mQueryId;
private volatile List<KeyInfo> mSearchResult; private volatile List<KeyInfo> mSearchResult;
private volatile String mKeyData; private volatile String mKeyData;
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
// app icon in Action Bar clicked; go home // app icon in Action Bar clicked; go home
Intent intent = new Intent(this, KeyListPublicActivity.class); Intent intent = new Intent(this, KeyListPublicActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent); startActivity(intent);
return true; return true;
default: default:
break; break;
} }
return false; return false;
@ -104,13 +113,13 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
setContentView(R.layout.key_server_query_layout); setContentView(R.layout.key_server_query_layout);
mQuery = (EditText) findViewById(R.id.query); mQuery = (EditText)findViewById(R.id.query);
mSearch = (Button) findViewById(R.id.btn_search); mSearch = (Button)findViewById(R.id.btn_search);
mList = (ListView) findViewById(R.id.list); mList = (ListView)findViewById(R.id.list);
mAdapter = new KeyInfoListAdapter(this); mAdapter = new KeyInfoListAdapter(this);
mList.setAdapter(mAdapter); mList.setAdapter(mAdapter);
mKeyServer = (Spinner) findViewById(R.id.keyServer); mKeyServer = (Spinner)findViewById(R.id.keyServer);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, Preferences.getPreferences(this) android.R.layout.simple_spinner_item, Preferences.getPreferences(this)
.getKeyServers()); .getKeyServers());
@ -123,17 +132,32 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
} }
mList.setOnItemClickListener(new OnItemClickListener() { mList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long keyId) { public void onItemClick(AdapterView<?> adapter, View view, int position, long keyId) {
get(keyId); get(keyId);
} }
}); });
mSearch.setOnClickListener(new OnClickListener() { mSearch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) { public void onClick(View v) {
String query = mQuery.getText().toString(); String query = mQuery.getText().toString();
search(query); search(query);
} }
}); });
mQuery.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
String query = mQuery.getText().toString();
search(query);
return false; // FIXME This is a hack to hide a keyboard
// after search http://tinyurl.com/pwdc3q9
}
return false;
}
});
Intent intent = getIntent(); Intent intent = getIntent();
String action = intent.getAction(); String action = intent.getAction();
@ -173,7 +197,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();
String server = (String) mKeyServer.getSelectedItem(); String server = (String)mKeyServer.getSelectedItem();
data.putString(KeychainIntentService.QUERY_KEY_SERVER, server); data.putString(KeychainIntentService.QUERY_KEY_SERVER, server);
data.putInt(KeychainIntentService.QUERY_KEY_TYPE, mQueryType); data.putInt(KeychainIntentService.QUERY_KEY_TYPE, mQueryType);
@ -189,6 +213,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
// Message is received after querying is done in ApgService // Message is received after querying is done in ApgService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this, KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
R.string.progress_querying, ProgressDialog.STYLE_SPINNER) { R.string.progress_querying, ProgressDialog.STYLE_SPINNER) {
@Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
// handle messages by standard ApgHandler first // handle messages by standard ApgHandler first
super.handleMessage(message); super.handleMessage(message);
@ -201,10 +226,12 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
mSearchResult = returnData mSearchResult = returnData
.getParcelableArrayList(KeychainIntentService.RESULT_QUERY_KEY_SEARCH_RESULT); .getParcelableArrayList(KeychainIntentService.RESULT_QUERY_KEY_SEARCH_RESULT);
} else if (mQueryType == Id.keyserver.get) { } else if (mQueryType == Id.keyserver.get) {
mKeyData = returnData.getString(KeychainIntentService.RESULT_QUERY_KEY_DATA); mKeyData = returnData
.getString(KeychainIntentService.RESULT_QUERY_KEY_DATA);
} }
// TODO: IMPROVE CODE!!! some global variables can be avoided!!! // TODO: IMPROVE CODE!!! some global variables can be
// avoided!!!
if (mQueryType == Id.keyserver.search) { if (mQueryType == Id.keyserver.search) {
if (mSearchResult != null) { if (mSearchResult != null) {
Toast.makeText(KeyServerQueryActivity.this, Toast.makeText(KeyServerQueryActivity.this,
@ -228,7 +255,8 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
Intent intent = new Intent(KeyServerQueryActivity.this, Intent intent = new Intent(KeyServerQueryActivity.this,
ImportKeysActivity.class); ImportKeysActivity.class);
intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY); intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY);
intent.putExtra(ImportKeysActivity.EXTRA_KEY_BYTES, mKeyData.getBytes()); intent.putExtra(ImportKeysActivity.EXTRA_KEY_BYTES,
mKeyData.getBytes());
startActivity(intent); startActivity(intent);
} }
} }
@ -251,12 +279,14 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
public class KeyInfoListAdapter extends BaseAdapter { public class KeyInfoListAdapter extends BaseAdapter {
protected LayoutInflater mInflater; protected LayoutInflater mInflater;
protected Activity mActivity; protected Activity mActivity;
protected List<KeyInfo> mKeys; protected List<KeyInfo> mKeys;
public KeyInfoListAdapter(Activity activity) { public KeyInfoListAdapter(Activity activity) {
mActivity = activity; mActivity = activity;
mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mInflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mKeys = new ArrayList<KeyInfo>(); mKeys = new ArrayList<KeyInfo>();
} }
@ -270,32 +300,36 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
return true; return true;
} }
@Override
public int getCount() { public int getCount() {
return mKeys.size(); return mKeys.size();
} }
@Override
public Object getItem(int position) { public Object getItem(int position) {
return mKeys.get(position); return mKeys.get(position);
} }
@Override
public long getItemId(int position) { public long getItemId(int position) {
return mKeys.get(position).keyId; return mKeys.get(position).keyId;
} }
@Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
KeyInfo keyInfo = mKeys.get(position); KeyInfo keyInfo = mKeys.get(position);
View view = mInflater.inflate(R.layout.key_server_query_result_item, null); View view = mInflater.inflate(R.layout.key_server_query_result_item, null);
TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId); TextView mainUserId = (TextView)view.findViewById(R.id.mainUserId);
mainUserId.setText(R.string.unknownUserId); mainUserId.setText(R.string.unknownUserId);
TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); TextView mainUserIdRest = (TextView)view.findViewById(R.id.mainUserIdRest);
mainUserIdRest.setText(""); mainUserIdRest.setText("");
TextView keyId = (TextView) view.findViewById(R.id.keyId); TextView keyId = (TextView)view.findViewById(R.id.keyId);
keyId.setText(R.string.noKey); keyId.setText(R.string.noKey);
TextView algorithm = (TextView) view.findViewById(R.id.algorithm); TextView algorithm = (TextView)view.findViewById(R.id.algorithm);
algorithm.setText(""); algorithm.setText("");
TextView status = (TextView) view.findViewById(R.id.status); TextView status = (TextView)view.findViewById(R.id.status);
status.setText(""); status.setText("");
String userId = keyInfo.userIds.get(0); String userId = keyInfo.userIds.get(0);
@ -322,7 +356,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
status.setVisibility(View.GONE); status.setVisibility(View.GONE);
} }
LinearLayout ll = (LinearLayout) view.findViewById(R.id.list); LinearLayout ll = (LinearLayout)view.findViewById(R.id.list);
if (keyInfo.userIds.size() == 1) { if (keyInfo.userIds.size() == 1) {
ll.setVisibility(View.GONE); ll.setVisibility(View.GONE);
} else { } else {
@ -339,7 +373,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
sep.setBackgroundResource(android.R.drawable.divider_horizontal_dark); sep.setBackgroundResource(android.R.drawable.divider_horizontal_dark);
ll.addView(sep); ll.addView(sep);
} }
TextView uidView = (TextView) mInflater.inflate( TextView uidView = (TextView)mInflater.inflate(
R.layout.key_server_query_result_user_id, null); R.layout.key_server_query_result_user_id, null);
uidView.setText(uid); uidView.setText(uid);
ll.addView(uidView); ll.addView(uidView);