Merge branch 'master' of github.com:open-keychain/open-keychain

This commit is contained in:
Vincent Breitmoser 2014-08-20 22:38:28 +02:00
commit 945764b30f
7 changed files with 48 additions and 32 deletions

View File

@ -24,8 +24,10 @@ import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.util.Log;
import java.io.DataOutputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
@ -352,24 +354,35 @@ public class HkpKeyserver extends Keyserver {
@Override
public void add(String armoredKey) throws AddKeyException {
try {
String query = getUrlPrefix() + mHost + ":" + mPort + "/pks/add";
String request = "/pks/add";
String params;
try {
params = "keytext=" + URLEncoder.encode(armoredKey, "utf8");
params = "keytext=" + URLEncoder.encode(armoredKey, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new AddKeyException();
}
Log.d(Constants.TAG, "hkp keyserver add: " + query);
URL url = new URL(getUrlPrefix() + mHost + ":" + mPort + request);
HttpURLConnection connection = openConnection(new URL(query));
connection.setRequestMethod("POST");
connection.addRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length));
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(params);
wr.flush();
wr.close();
Log.d(Constants.TAG, "hkp keyserver add: " + url.toString());
HttpURLConnection conn = openConnection(url);
conn.setRequestMethod("POST");
conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length));
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(params);
writer.flush();
writer.close();
os.close();
conn.connect();
Log.d(Constants.TAG, "response code: " + conn.getResponseCode());
Log.d(Constants.TAG, "answer: " + readAll(conn.getInputStream(), conn.getContentEncoding()));
} catch (IOException e) {
throw new AddKeyException();
}

View File

@ -1127,9 +1127,7 @@ public class ProviderHelper {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
String version = PgpHelper.getVersionForHeader(mContext);
if (version != null) {
keyRing.encodeArmored(bos, version);
}
keyRing.encodeArmored(bos, version);
String armoredKey = bos.toString("UTF-8");
Log.d(Constants.TAG, "armoredKey:" + armoredKey);

View File

@ -30,6 +30,7 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ActionBarHelper;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.remote.AccountSettings;
import org.sufficientlysecure.keychain.service.OperationResultParcel;
import org.sufficientlysecure.keychain.util.Log;
public class AccountSettingsActivity extends ActionBarActivity {
@ -106,4 +107,15 @@ public class AccountSettingsActivity extends ActionBarActivity {
finish();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if a result has been returned, display a notify
if (data != null && data.hasExtra(OperationResultParcel.EXTRA_RESULT)) {
OperationResultParcel result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT);
result.createNotify(this).show();
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
}

View File

@ -155,10 +155,8 @@ public class OperationResultParcel implements Parcelable {
if ((resultType & OperationResultParcel.RESULT_ERROR) == 0) {
if (getLog().containsWarnings()) {
duration = 0;
color = Style.ORANGE;
} else {
duration = SuperToast.Duration.LONG;
color = Style.GREEN;
}
@ -167,7 +165,6 @@ public class OperationResultParcel implements Parcelable {
} else {
duration = 0;
color = Style.RED;
str = "operation failed";
@ -180,8 +177,8 @@ public class OperationResultParcel implements Parcelable {
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
Style.getStyle(color, SuperToast.Animations.POPUP));
toast.setText(str);
toast.setDuration(duration);
toast.setIndeterminate(duration == 0);
toast.setDuration(SuperToast.Duration.EXTRA_LONG);
toast.setIndeterminate(false);
toast.setSwipeToDismiss(true);
// If we have a log and it's non-empty, show a View Log button
if (button) {

View File

@ -92,7 +92,9 @@ public class FirstTimeActivity extends ActionBarActivity {
prefs.setFirstTime(false);
Intent intent = new Intent(this, KeyListActivity.class);
// give intent through to display notify
intent.putExtras(srcData);
if (srcData != null) {
intent.putExtras(srcData);
}
startActivityForResult(intent, 0);
finish();
}

View File

@ -463,7 +463,8 @@ public class ImportKeysActivity extends ActionBarActivity {
return;
}
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(getIntent().getAction())) {
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(getIntent().getAction())
|| ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(getIntent().getAction())) {
Intent intent = new Intent();
intent.putExtra(ImportKeyResult.EXTRA_RESULT, result);
ImportKeysActivity.this.setResult(RESULT_OK, intent);
@ -475,11 +476,6 @@ public class ImportKeysActivity extends ActionBarActivity {
ImportKeysActivity.this.finish();
return;
}
if (ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(getIntent().getAction())) {
ImportKeysActivity.this.setResult(RESULT_OK);
ImportKeysActivity.this.finish();
return;
}
result.createNotify(ImportKeysActivity.this).show();
}

View File

@ -88,8 +88,6 @@ public class KeyListFragment extends LoaderFragment
private Button mButtonEmptyCreate;
private Button mButtonEmptyImport;
public static final int REQUEST_CODE_CREATE_OR_IMPORT_KEY = 0x00007012;
/**
* Load custom layout with StickyListView from library
*/
@ -108,7 +106,7 @@ public class KeyListFragment extends LoaderFragment
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), CreateKeyActivity.class);
startActivityForResult(intent, REQUEST_CODE_CREATE_OR_IMPORT_KEY);
startActivityForResult(intent, 0);
}
});
mButtonEmptyImport = (Button) view.findViewById(R.id.key_list_empty_button_import);
@ -118,7 +116,7 @@ public class KeyListFragment extends LoaderFragment
public void onClick(View v) {
Intent intent = new Intent(getActivity(), ImportKeysActivity.class);
intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN);
startActivityForResult(intent, REQUEST_CODE_CREATE_OR_IMPORT_KEY);
startActivityForResult(intent, 0);
}
});