added a context menu item to update public keys via key server, adding a key id look up Intent for the key server query

Update issue 9
Status: Fixed
Added public key update via key server. Considering this issue fixed now. More key server features will be added, but general support is added.
This commit is contained in:
Thialfihar 2010-08-18 00:23:28 +00:00
parent c57c36b3a5
commit 4f25edbe97
6 changed files with 97 additions and 12 deletions

View File

@ -90,6 +90,7 @@
<string name="menu_search">Search</string>
<string name="menu_help">Help</string>
<string name="menu_keyServer">Key Server</string>
<string name="menu_updateKey">Update</string>
<!-- label_lowerCase: capitalized words, no punctuation -->
<string name="label_sign">Sign</string>

View File

@ -115,6 +115,7 @@ public class Apg {
public static final String SELECT_PUBLIC_KEYS = "org.thialfihar.android.apg.intent.SELECT_PUBLIC_KEYS";
public static final String SELECT_SECRET_KEY = "org.thialfihar.android.apg.intent.SELECT_SECRET_KEY";
public static final String IMPORT = "org.thialfihar.android.apg.intent.IMPORT";
public static final String LOOK_UP_KEY_ID = "org.thialfihar.android.apg.intent.LOOK_UP_KEY_ID";
}
public static final String EXTRA_TEXT = "text";

View File

@ -23,6 +23,7 @@ public final class Id {
public static final int export = 0x21070001;
public static final int delete = 0x21070002;
public static final int edit = 0x21070003;
public static final int update = 0x21070004;
public static final class option {
public static final int new_pass_phrase = 0x21070001;
@ -58,6 +59,7 @@ public final class Id {
public static final int filename = 0x21070003;
public static final int output_filename = 0x21070004;
public static final int key_server_preference = 0x21070005;
public static final int look_up_key_id = 0x21070006;
}
public static final class dialog {

View File

@ -98,16 +98,6 @@ public class KeyListActivity extends BaseActivity {
});
handleIntent(getIntent());
Intent intent = getIntent();
if (Apg.Intent.IMPORT.equals(intent.getAction())) {
if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
mImportFilename = Uri.decode(intent.getDataString().replace("file://", ""));
} else {
mImportData = intent.getStringExtra(Apg.EXTRA_TEXT);
}
importKeys();
}
}
@Override
@ -116,7 +106,7 @@ public class KeyListActivity extends BaseActivity {
handleIntent(intent);
}
private void handleIntent(Intent intent) {
protected void handleIntent(Intent intent) {
String searchString = null;
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
searchString = intent.getStringExtra(SearchManager.QUERY);
@ -137,6 +127,15 @@ public class KeyListActivity extends BaseActivity {
}
mListAdapter = new KeyListAdapter(this, searchString);
mList.setAdapter(mListAdapter);
if (Apg.Intent.IMPORT.equals(intent.getAction())) {
if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
mImportFilename = Uri.decode(intent.getDataString().replace("file://", ""));
} else {
mImportData = intent.getStringExtra(Apg.EXTRA_TEXT);
}
importKeys();
}
}
@Override

View File

@ -84,6 +84,16 @@ public class KeyServerQueryActivity extends BaseActivity {
search(query);
}
});
Intent intent = getIntent();
if (Apg.Intent.LOOK_UP_KEY_ID.equals(intent.getAction())) {
long keyId = intent.getLongExtra(Apg.EXTRA_KEY_ID, 0);
if (keyId != 0) {
String query = "0x" + Apg.keyToHex(keyId);
mQuery.setText(query);
search(query);
}
}
}
private void search(String query) {
@ -162,7 +172,13 @@ public class KeyServerQueryActivity extends BaseActivity {
Intent intent = new Intent(this, PublicKeyListActivity.class);
intent.setAction(Apg.Intent.IMPORT);
intent.putExtra(Apg.EXTRA_TEXT, mKeyData);
startActivity(intent);
Intent orgIntent = getIntent();
if (Apg.Intent.LOOK_UP_KEY_ID.equals(orgIntent.getAction())) {
setResult(RESULT_OK, intent);
finish();
} else {
startActivity(intent);
}
}
}
}

View File

@ -16,12 +16,17 @@
package org.thialfihar.android.apg;
import org.bouncycastle2.openpgp.PGPPublicKeyRing;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
public class PublicKeyListActivity extends KeyListActivity {
@Override
@ -57,6 +62,67 @@ public class PublicKeyListActivity extends KeyListActivity {
// TODO: user id? menu.setHeaderTitle("Key");
menu.add(0, Id.menu.export, 0, R.string.menu_exportKey);
menu.add(0, Id.menu.delete, 1, R.string.menu_deleteKey);
menu.add(0, Id.menu.update, 1, R.string.menu_updateKey);
}
}
@Override
public boolean onContextItemSelected(MenuItem menuItem) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuItem.getMenuInfo();
int type = ExpandableListView.getPackedPositionType(info.packedPosition);
int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
if (type != ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
return super.onContextItemSelected(menuItem);
}
switch (menuItem.getItemId()) {
case Id.menu.update: {
mSelectedItem = groupPosition;
final int keyRingId = mListAdapter.getKeyRingId(groupPosition);
long keyId = 0;
Object keyRing = Apg.getKeyRing(keyRingId);
if (keyRing != null && keyRing instanceof PGPPublicKeyRing) {
keyId = Apg.getMasterKey((PGPPublicKeyRing) keyRing).getKeyID();
}
if (keyId == 0) {
// this shouldn't happen
return true;
}
Intent intent = new Intent(this, KeyServerQueryActivity.class);
intent.setAction(Apg.Intent.LOOK_UP_KEY_ID);
intent.putExtra(Apg.EXTRA_KEY_ID, keyId);
startActivityForResult(intent, Id.request.look_up_key_id);
return true;
}
default: {
return super.onContextItemSelected(menuItem);
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case Id.request.look_up_key_id: {
if (resultCode == RESULT_CANCELED || data == null ||
data.getStringExtra(Apg.EXTRA_TEXT) == null) {
return;
}
Intent intent = new Intent(this, PublicKeyListActivity.class);
intent.setAction(Apg.Intent.IMPORT);
intent.putExtra(Apg.EXTRA_TEXT, data.getStringExtra(Apg.EXTRA_TEXT));
handleIntent(intent);
break;
}
default: {
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
}
}