diff options
Diffstat (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui')
9 files changed, 207 insertions, 489 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java index c7b37dd9d..a803e4680 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java @@ -271,9 +271,9 @@ public class DecryptActivity extends DrawerActivity { PGPPublicKeyRing key = ProviderHelper.getPGPPublicKeyRingByKeyId( DecryptActivity.this, mSignatureKeyId); if (key != null) { - Intent intent = new Intent(DecryptActivity.this, KeyServerQueryActivity.class); - intent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID); - intent.putExtra(KeyServerQueryActivity.EXTRA_KEY_ID, mSignatureKeyId); + Intent intent = new Intent(DecryptActivity.this, ImportKeysActivity.class); + intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER); + intent.putExtra(ImportKeysActivity.EXTRA_KEY_ID, mSignatureKeyId); startActivity(intent); } } @@ -676,7 +676,7 @@ public class DecryptActivity extends DrawerActivity { data.putParcelable(KeychainIntentService.ENCRYPT_PROVIDER_URI, mContentUri); } else if (mDecryptTarget == Id.target.file) { - data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_FILE); + data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_URI); Log.d(Constants.TAG, "mInputFilename=" + mInputFilename + ", mOutputFilename=" + mOutputFilename); @@ -826,7 +826,7 @@ public class DecryptActivity extends DrawerActivity { } // this request is returned after LookupUnknownKeyDialogFragment started - // KeyServerQueryActivity and user looked uo key + // ImportKeysActivity and user looked uo key case Id.request.look_up_key_id: { Log.d(Constants.TAG, "Returning from Lookup Key..."); // decrypt again without lookup diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java index c067dadc5..2ba726bfe 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java @@ -628,7 +628,7 @@ public class EncryptActivity extends DrawerActivity { useAsciiArmor = mAsciiArmor.isChecked(); compressionId = ((Choice) mFileCompression.getSelectedItem()).getId(); - data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_FILE); + data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_URI); Log.d(Constants.TAG, "mInputFilename=" + mInputFilename + ", mOutputFilename=" + mOutputFilename); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index 1d26c071a..bf534012f 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -18,10 +18,10 @@ package org.sufficientlysecure.keychain.ui; import java.util.ArrayList; -import java.util.List; import java.util.Locale; import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; @@ -270,9 +270,9 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi return; } - Intent queryIntent = new Intent(this, KeyServerQueryActivity.class); - queryIntent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID); - queryIntent.putExtra(KeyServerQueryActivity.EXTRA_FINGERPRINT, fingerprint); + Intent queryIntent = new Intent(this, ImportKeysActivity.class); + queryIntent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER); + queryIntent.putExtra(ImportKeysActivity.EXTRA_FINGERPRINT, fingerprint); startActivity(queryIntent); } @@ -338,6 +338,63 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi // } // } + + // Message is received after importing is done in ApgService + KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this, + R.string.progress_importing, ProgressDialog.STYLE_HORIZONTAL) { + public void handleMessage(Message message) { + // handle messages by standard ApgHandler first + super.handleMessage(message); + + if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { + // get returned data bundle + Bundle returnData = message.getData(); + + int added = returnData.getInt(KeychainIntentService.RESULT_IMPORT_ADDED); + int updated = returnData + .getInt(KeychainIntentService.RESULT_IMPORT_UPDATED); + int bad = returnData.getInt(KeychainIntentService.RESULT_IMPORT_BAD); + String toastMessage; + if (added > 0 && updated > 0) { + String addedStr = getResources().getQuantityString( + R.plurals.keys_added_and_updated_1, added, added); + String updatedStr = getResources().getQuantityString( + R.plurals.keys_added_and_updated_2, updated, updated); + toastMessage = addedStr + updatedStr; + } else if (added > 0) { + toastMessage = getResources().getQuantityString(R.plurals.keys_added, + added, added); + } else if (updated > 0) { + toastMessage = getResources().getQuantityString(R.plurals.keys_updated, + updated, updated); + } else { + toastMessage = getString(R.string.no_keys_added_or_updated); + } + Toast.makeText(ImportKeysActivity.this, toastMessage, Toast.LENGTH_SHORT) + .show(); + if (bad > 0) { + AlertDialog.Builder alert = new AlertDialog.Builder( + ImportKeysActivity.this); + + alert.setIcon(android.R.drawable.ic_dialog_alert); + alert.setTitle(R.string.warning); + + alert.setMessage(ImportKeysActivity.this.getResources() + .getQuantityString(R.plurals.bad_keys_encountered, bad, bad)); + + alert.setPositiveButton(android.R.string.ok, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + alert.setCancelable(true); + alert.create().show(); + } + } + } + }; + /** * Import keys with mImportData */ @@ -353,84 +410,37 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi // fill values for this action Bundle data = new Bundle(); - // get selected key ids - List<ImportKeysListEntry> listEntries = mListFragment.getData(); - ArrayList<Long> selectedKeyIds = new ArrayList<Long>(); - for (ImportKeysListEntry entry : listEntries) { - if (entry.isSelected()) { - selectedKeyIds.add(entry.keyId); - } - } + // get selected key entries + ArrayList<ImportKeysListEntry> selectedEntries = mListFragment.getSelectedData(); + data.putParcelableArrayList(KeychainIntentService.IMPORT_KEY_LIST, selectedEntries); - data.putSerializable(KeychainIntentService.IMPORT_KEY_LIST, selectedKeyIds); + intent.putExtra(KeychainIntentService.EXTRA_DATA, data); - if (mListFragment.getKeyBytes() != null) { - data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_BYTES); - data.putByteArray(KeychainIntentService.IMPORT_BYTES, mListFragment.getKeyBytes()); - } else { - data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_FILE); - intent.setData(mListFragment.getDataUri()); - } + // Create a new Messenger for the communication back + Messenger messenger = new Messenger(saveHandler); + intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); - intent.putExtra(KeychainIntentService.EXTRA_DATA, data); + // show progress dialog + saveHandler.showProgressDialog(this); - // Message is received after importing is done in ApgService - KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this, - R.string.progress_importing, ProgressDialog.STYLE_HORIZONTAL) { - public void handleMessage(Message message) { - // handle messages by standard ApgHandler first - super.handleMessage(message); - - if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - // get returned data bundle - Bundle returnData = message.getData(); - - int added = returnData.getInt(KeychainIntentService.RESULT_IMPORT_ADDED); - int updated = returnData - .getInt(KeychainIntentService.RESULT_IMPORT_UPDATED); - int bad = returnData.getInt(KeychainIntentService.RESULT_IMPORT_BAD); - String toastMessage; - if (added > 0 && updated > 0) { - String addedStr = getResources().getQuantityString( - R.plurals.keys_added_and_updated_1, added, added); - String updatedStr = getResources().getQuantityString( - R.plurals.keys_added_and_updated_2, updated, updated); - toastMessage = addedStr + updatedStr; - } else if (added > 0) { - toastMessage = getResources().getQuantityString(R.plurals.keys_added, - added, added); - } else if (updated > 0) { - toastMessage = getResources().getQuantityString(R.plurals.keys_updated, - updated, updated); - } else { - toastMessage = getString(R.string.no_keys_added_or_updated); - } - Toast.makeText(ImportKeysActivity.this, toastMessage, Toast.LENGTH_SHORT) - .show(); - if (bad > 0) { - AlertDialog.Builder alert = new AlertDialog.Builder( - ImportKeysActivity.this); - - alert.setIcon(android.R.drawable.ic_dialog_alert); - alert.setTitle(R.string.warning); - - alert.setMessage(ImportKeysActivity.this.getResources() - .getQuantityString(R.plurals.bad_keys_encountered, bad, bad)); - - alert.setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - alert.setCancelable(true); - alert.create().show(); - } - } - } + // start service with intent + startService(intent); + } else if (mListFragment.getServerQuery() != null) { + // Send all information needed to service to query keys in other thread + Intent intent = new Intent(this, KeychainIntentService.class); - ; - }; + intent.setAction(KeychainIntentService.ACTION_DOWNLOAD_AND_IMPORT_KEYS); + + // fill values for this action + Bundle data = new Bundle(); + + data.putString(KeychainIntentService.DOWNLOAD_KEY_SERVER, mListFragment.getKeyServer()); + + // get selected key entries + ArrayList<ImportKeysListEntry> selectedEntries = mListFragment.getSelectedData(); + data.putParcelableArrayList(KeychainIntentService.DOWNLOAD_KEY_LIST, selectedEntries); + + intent.putExtra(KeychainIntentService.EXTRA_DATA, data); // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); @@ -441,8 +451,6 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi // start service with intent startService(intent); - } else if (mListFragment.getServerQuery() != null) { - // TODO! } else { Toast.makeText(this, R.string.error_nothing_import, Toast.LENGTH_LONG).show(); } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index 9c9dda0b4..ea9f507db 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.List; import org.sufficientlysecure.keychain.Constants; @@ -72,10 +73,18 @@ public class ImportKeysListFragment extends SherlockListFragment implements return mServerQuery; } + public String getKeyServer() { + return mKeyServer; + } + public List<ImportKeysListEntry> getData() { return mAdapter.getData(); } + public ArrayList<ImportKeysListEntry> getSelectedData() { + return mAdapter.getSelectedData(); + } + /** * Creates new instance of this fragment */ diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java deleted file mode 100644 index 4be096a7d..000000000 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de> - * Copyright (C) 2010 Thialfihar <thi@thialfihar.org> - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.sufficientlysecure.keychain.ui; - -import android.app.Activity; -import android.app.ProgressDialog; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.os.Message; -import android.os.Messenger; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.view.inputmethod.EditorInfo; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; -import android.widget.ArrayAdapter; -import android.widget.BaseAdapter; -import android.widget.Button; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.LinearLayout.LayoutParams; -import android.widget.ListView; -import android.widget.Spinner; -import android.widget.TextView; -import android.widget.TextView.OnEditorActionListener; -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 { - - // 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_AND_RETURN = Constants.INTENT_PREFIX - + "LOOK_UP_KEY_ID_AND_RETURN"; - - public static final String EXTRA_KEY_ID = "key_id"; - public static final String EXTRA_FINGERPRINT = "fingerprint"; - - public static final String RESULT_EXTRA_TEXT = "text"; - - private ListView mList; - private EditText mQuery; - private Button mSearch; - private Spinner mKeyServer; - - private KeyInfoListAdapter mAdapter; - - private int mQueryType; - private String mQueryString; - private long mQueryId; - - private volatile List<KeyInfo> mSearchResult; - - private volatile String mKeyData; - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - - case android.R.id.home: - // app icon in Action Bar clicked; go home - Intent intent = new Intent(this, KeyListPublicActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(intent); - return true; - - default: - break; - - } - return false; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.key_server_query); - - mQuery = (EditText) findViewById(R.id.query); - mSearch = (Button) findViewById(R.id.btn_search); - mList = (ListView) findViewById(R.id.list); - mAdapter = new KeyInfoListAdapter(this); - mList.setAdapter(mAdapter); - - mKeyServer = (Spinner) findViewById(R.id.sign_key_keyserver); - ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, - android.R.layout.simple_spinner_item, Preferences.getPreferences(this) - .getKeyServers()); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - mKeyServer.setAdapter(adapter); - if (adapter.getCount() > 0) { - mKeyServer.setSelection(0); - } else { - mSearch.setEnabled(false); - } - - mList.setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(AdapterView<?> adapter, View view, int position, long keyId) { - get(keyId); - } - }); - - mSearch.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - String query = mQuery.getText().toString(); - 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(); - String action = intent.getAction(); - if (ACTION_LOOK_UP_KEY_ID.equals(action) || ACTION_LOOK_UP_KEY_ID_AND_RETURN.equals(action)) { - long keyId = intent.getLongExtra(EXTRA_KEY_ID, 0); - if (keyId != 0) { - String query = "0x" + PgpKeyHelper.convertKeyToHex(keyId); - mQuery.setText(query); - search(query); - } - String fingerprint = intent.getStringExtra(EXTRA_FINGERPRINT); - if (fingerprint != null) { - fingerprint = "0x" + fingerprint; - mQuery.setText(fingerprint); - search(fingerprint); - } - } - } - - private void search(String query) { - mQueryType = Id.keyserver.search; - mQueryString = query; - mAdapter.setKeys(new ArrayList<KeyInfo>()); - - start(); - } - - private void get(long keyId) { - mQueryType = Id.keyserver.get; - mQueryId = keyId; - - start(); - } - - private void start() { - Log.d(Constants.TAG, "start search with service"); - - // Send all information needed to service to query keys in other thread - Intent intent = new Intent(this, KeychainIntentService.class); - - intent.setAction(KeychainIntentService.ACTION_QUERY_KEYRING); - - // fill values for this action - Bundle data = new Bundle(); - - String server = (String) mKeyServer.getSelectedItem(); - data.putString(KeychainIntentService.QUERY_KEY_SERVER, server); - -// data.putInt(KeychainIntentService.QUERY_KEY_TYPE, mQueryType); - -// if (mQueryType == Id.keyserver.search) { -// data.putString(KeychainIntentService.QUERY_KEY_STRING, mQueryString); -// } else if (mQueryType == Id.keyserver.get) { -// data.putLong(KeychainIntentService.QUERY_KEY_ID, mQueryId); -// } - - intent.putExtra(KeychainIntentService.EXTRA_DATA, data); - - // Message is received after querying is done in ApgService - KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this, - R.string.progress_querying, ProgressDialog.STYLE_SPINNER) { - @Override - public void handleMessage(Message message) { - // handle messages by standard ApgHandler first - super.handleMessage(message); - - if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - // get returned data bundle - Bundle returnData = message.getData(); - - if (mQueryType == Id.keyserver.search) { - mSearchResult = returnData - .getParcelableArrayList(KeychainIntentService.RESULT_QUERY_KEY_SEARCH_RESULT); - } else if (mQueryType == Id.keyserver.get) { - mKeyData = returnData - .getString(KeychainIntentService.RESULT_QUERY_KEY_DATA); - } - - // TODO: IMPROVE CODE!!! some global variables can be - // avoided!!! - if (mQueryType == Id.keyserver.search) { - if (mSearchResult != null) { - Toast.makeText( - KeyServerQueryActivity.this, - getResources().getQuantityString(R.plurals.keys_found, - mSearchResult.size(), mSearchResult.size()), - Toast.LENGTH_SHORT).show(); - mAdapter.setKeys(mSearchResult); - } - } else if (mQueryType == Id.keyserver.get) { - Intent orgIntent = getIntent(); - if (ACTION_LOOK_UP_KEY_ID_AND_RETURN.equals(orgIntent.getAction())) { - if (mKeyData != null) { - Intent intent = new Intent(); - intent.putExtra(RESULT_EXTRA_TEXT, mKeyData); - setResult(RESULT_OK, intent); - } else { - setResult(RESULT_CANCELED); - } - finish(); - } else { - if (mKeyData != null) { - Intent intent = new Intent(KeyServerQueryActivity.this, - ImportKeysActivity.class); - intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY); - intent.putExtra(ImportKeysActivity.EXTRA_KEY_BYTES, - mKeyData.getBytes()); - startActivity(intent); - } - } - } - - } - }; - }; - - // Create a new Messenger for the communication back - Messenger messenger = new Messenger(saveHandler); - intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); - - // show progress dialog - saveHandler.showProgressDialog(this); - - // start service with intent - startService(intent); - } - - public class KeyInfoListAdapter extends BaseAdapter { - protected LayoutInflater mInflater; - - protected Activity mActivity; - - protected List<KeyInfo> mKeys; - - public KeyInfoListAdapter(Activity activity) { - mActivity = activity; - mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - mKeys = new ArrayList<KeyInfo>(); - } - - public void setKeys(List<KeyInfo> keys) { - mKeys = keys; - notifyDataSetChanged(); - } - - @Override - public boolean hasStableIds() { - return true; - } - - @Override - public int getCount() { - return mKeys.size(); - } - - @Override - public Object getItem(int position) { - return mKeys.get(position); - } - - @Override - public long getItemId(int position) { - return mKeys.get(position).keyId; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - KeyInfo keyInfo = mKeys.get(position); - - View view = mInflater.inflate(R.layout.key_server_query_result_item, null); - - TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId); - mainUserId.setText(R.string.user_id_no_name); - TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); - mainUserIdRest.setText(""); - TextView keyId = (TextView) view.findViewById(R.id.keyId); - keyId.setText(R.string.no_key); - TextView algorithm = (TextView) view.findViewById(R.id.algorithm); - algorithm.setText(""); - TextView status = (TextView) view.findViewById(R.id.status); - status.setText(""); - - String userId = keyInfo.userIds.get(0); - if (userId != null) { - String chunks[] = userId.split(" <", 2); - userId = chunks[0]; - if (chunks.length > 1) { - mainUserIdRest.setText("<" + chunks[1]); - } - mainUserId.setText(userId); - } - - keyId.setText(PgpKeyHelper.convertKeyIdToHex(keyInfo.keyId)); - - if (mainUserIdRest.getText().length() == 0) { - mainUserIdRest.setVisibility(View.GONE); - } - - algorithm.setText("" + keyInfo.size + "/" + keyInfo.algorithm); - - if (keyInfo.revoked != null) { - status.setText("revoked"); - } else { - status.setVisibility(View.GONE); - } - - LinearLayout ll = (LinearLayout) view.findViewById(R.id.list); - if (keyInfo.userIds.size() == 1) { - ll.setVisibility(View.GONE); - } else { - boolean first = true; - boolean second = true; - for (String uid : keyInfo.userIds) { - if (first) { - first = false; - continue; - } - if (!second) { - View sep = new View(mActivity); - sep.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1)); - sep.setBackgroundResource(android.R.drawable.divider_horizontal_dark); - ll.addView(sep); - } - TextView uidView = (TextView) mInflater.inflate( - R.layout.key_server_query_result_user_id, null); - uidView.setText(uid); - ll.addView(uidView); - second = false; - } - } - - return view; - } - } -} diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 74aac1d3c..b837a09d0 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -397,9 +397,9 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements return; } - Intent queryIntent = new Intent(this, KeyServerQueryActivity.class); - queryIntent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID_AND_RETURN); - queryIntent.putExtra(KeyServerQueryActivity.EXTRA_KEY_ID, updateKeyId); + Intent queryIntent = new Intent(this, ImportKeysActivity.class); + queryIntent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER); + queryIntent.putExtra(ImportKeysActivity.EXTRA_KEY_ID, updateKeyId); // TODO: lookup?? startActivityForResult(queryIntent, Id.request.look_up_key_id); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 8170defe4..a850fc020 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -17,6 +17,7 @@ package org.sufficientlysecure.keychain.ui.adapter; +import java.util.ArrayList; import java.util.List; import org.sufficientlysecure.keychain.R; @@ -69,6 +70,15 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { return data; } + public ArrayList<ImportKeysListEntry> getSelectedData() { + ArrayList<ImportKeysListEntry> selectedData = new ArrayList<ImportKeysListEntry>(); + for (ImportKeysListEntry entry : data) { + if (entry.isSelected()) + selectedData.add(entry); + } + return selectedData; + } + @Override public boolean hasStableIds() { return true; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListEntry.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListEntry.java index 2ad9cc593..5094e8abd 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListEntry.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListEntry.java @@ -17,6 +17,10 @@ package org.sufficientlysecure.keychain.ui.adapter; +import android.os.Parcel; +import android.os.Parcelable; + +import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; @@ -24,15 +28,16 @@ import java.util.Date; import org.spongycastle.openpgp.PGPKeyRing; import org.spongycastle.openpgp.PGPPublicKey; import org.spongycastle.openpgp.PGPSecretKeyRing; +import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; -import org.sufficientlysecure.keychain.util.AlgorithmNames; import org.sufficientlysecure.keychain.util.IterableIterator; +import org.sufficientlysecure.keychain.util.Log; -public class ImportKeysListEntry implements Serializable { +public class ImportKeysListEntry implements Serializable, Parcelable { private static final long serialVersionUID = -7797972103284992662L; public ArrayList<String> userIds; - public long keyId; + public long keyId; public boolean revoked; public Date date; // TODO: not displayed public String fingerPrint; @@ -40,10 +45,82 @@ public class ImportKeysListEntry implements Serializable { public int bitStrength; public String algorithm; public boolean secretKey; - AlgorithmNames algorithmNames; private boolean selected; + private byte[] bytes = new byte[] {}; + + public ImportKeysListEntry(ImportKeysListEntry b) { + this.userIds = b.userIds; + this.keyId = b.keyId; + this.revoked = b.revoked; + this.date = b.date; + this.fingerPrint = b.fingerPrint; + this.hexKeyId = b.hexKeyId; + this.bitStrength = b.bitStrength; + this.algorithm = b.algorithm; + this.secretKey = b.secretKey; + this.selected = b.selected; + this.bytes = b.bytes; + } + + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeStringList(userIds); + dest.writeLong(keyId); + dest.writeByte((byte) (revoked ? 1 : 0)); + dest.writeSerializable(date); + dest.writeString(fingerPrint); + dest.writeString(hexKeyId); + dest.writeInt(bitStrength); + dest.writeString(algorithm); + dest.writeByte((byte) (secretKey ? 1 : 0)); + dest.writeByte((byte) (selected ? 1 : 0)); + dest.writeInt(bytes.length); + dest.writeByteArray(bytes); + } + + public static final Creator<ImportKeysListEntry> CREATOR = new Creator<ImportKeysListEntry>() { + public ImportKeysListEntry createFromParcel(final Parcel source) { + ImportKeysListEntry vr = new ImportKeysListEntry(); + vr.userIds = new ArrayList<String>(); + source.readStringList(vr.userIds); + vr.keyId = source.readLong(); + vr.revoked = source.readByte() == 1; + vr.date = (Date) source.readSerializable(); + vr.fingerPrint = source.readString(); + vr.hexKeyId = source.readString(); + vr.bitStrength = source.readInt(); + vr.algorithm = source.readString(); + vr.secretKey = source.readByte() == 1; + vr.selected = source.readByte() == 1; + vr.bytes = new byte[source.readInt()]; + source.readByteArray(vr.bytes); + + return vr; + } + + public ImportKeysListEntry[] newArray(final int size) { + return new ImportKeysListEntry[size]; + } + }; + + public long getKeyId() { + return keyId; + } + + public byte[] getBytes() { + return bytes; + } + + public void setBytes(byte[] bytes) { + this.bytes = bytes; + } + /** * Constructor for later querying from keyserver */ @@ -62,11 +139,16 @@ public class ImportKeysListEntry implements Serializable { /** * Constructor based on key object, used for import from NFC, QR Codes, files - * - * @param pgpKey */ @SuppressWarnings("unchecked") public ImportKeysListEntry(PGPKeyRing pgpKeyRing) { + // save actual key object into entry, used to import it later + try { + this.bytes = pgpKeyRing.getEncoded(); + } catch (IOException e) { + Log.e(Constants.TAG, "IOException on pgpKeyRing.getEncoded()", e); + } + // selected is default this.selected = true; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/LookupUnknownKeyDialogFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/LookupUnknownKeyDialogFragment.java index d018f4b8e..dbbc87a1a 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/LookupUnknownKeyDialogFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/LookupUnknownKeyDialogFragment.java @@ -21,7 +21,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; -import org.sufficientlysecure.keychain.ui.KeyServerQueryActivity; +import org.sufficientlysecure.keychain.ui.ImportKeysActivity; import org.sufficientlysecure.keychain.util.Log; import android.app.Activity; @@ -90,9 +90,9 @@ public class LookupUnknownKeyDialogFragment extends SherlockDialogFragment { sendMessageToHandler(MESSAGE_OKAY); - Intent intent = new Intent(activity, KeyServerQueryActivity.class); - intent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID); - intent.putExtra(KeyServerQueryActivity.EXTRA_KEY_ID, unknownKeyId); + Intent intent = new Intent(activity, ImportKeysActivity.class); + intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER); + intent.putExtra(ImportKeysActivity.EXTRA_KEY_ID, unknownKeyId); startActivityForResult(intent, Id.request.look_up_key_id); } }); |