aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain-API/example-app
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-02-14 13:40:24 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-02-14 13:40:24 +0100
commitacad2ba95723a940467e89a07e91498188a88745 (patch)
treeaf2eac0d330c9995f9c64e98116ed2d84493dcd6 /OpenPGP-Keychain-API/example-app
parentee2fec17597c35ad2329f44cc697e18e3e4169cc (diff)
downloadopen-keychain-acad2ba95723a940467e89a07e91498188a88745.tar.gz
open-keychain-acad2ba95723a940467e89a07e91498188a88745.tar.bz2
open-keychain-acad2ba95723a940467e89a07e91498188a88745.zip
PendingIntent to handle user input
Diffstat (limited to 'OpenPGP-Keychain-API/example-app')
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java87
1 files changed, 70 insertions, 17 deletions
diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java
index 81f9eee68..39843eb82 100644
--- a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java
+++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java
@@ -18,11 +18,14 @@ package org.sufficientlysecure.keychain.demo;
import android.app.Activity;
import android.app.AlertDialog;
+import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.IntentSender;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.support.v4.app.TaskStackBuilder;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@@ -54,6 +57,11 @@ public class OpenPgpProviderActivity extends Activity {
private OpenPgpServiceConnection mCryptoServiceConnection;
+ public static final int REQUEST_CODE_SIGN = 9910;
+ public static final int REQUEST_CODE_ENCRYPT = 9911;
+ public static final int REQUEST_CODE_SIGN_AND_ENC = 9912;
+ public static final int REQUEST_CODE_DECRYPT = 9913;
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -210,30 +218,60 @@ public class OpenPgpProviderActivity extends Activity {
}
public void signOnClick(View view) {
+ InputStream is = null;
try {
String inputStr = mMessage.getText().toString();
- InputStream is = new ByteArrayInputStream(inputStr.getBytes("UTF-8"));
-
- final ByteArrayOutputStream os = new ByteArrayOutputStream();
-
- OpenPgpApi api = new OpenPgpApi(mCryptoServiceConnection.getService());
- api.sign(is, os);
+ is = new ByteArrayInputStream(inputStr.getBytes("UTF-8"));
- Log.d(OpenPgpConstants.TAG, "Test #1 read result: " + os.toByteArray().length
- + " str=" + os.toString("UTF-8"));
-
- mCiphertext.setText(os.toString("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
-// OpenPgpData input = new OpenPgpData(inputStr);
+ final ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ OpenPgpApi api = new OpenPgpApi(mCryptoServiceConnection.getService());
+ api.sign(new Bundle(), is, os, new OpenPgpApi.IOpenPgpCallback() {
+ @Override
+ public void onReturn(Bundle result) {
+ switch (result.getInt(OpenPgpConstants.RESULT_CODE)) {
+ case OpenPgpConstants.RESULT_CODE_SUCCESS: {
+ try {
+ Log.d(OpenPgpConstants.TAG, "result: " + os.toByteArray().length
+ + " str=" + os.toString("UTF-8"));
+
+ mCiphertext.setText(os.toString("UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ break;
+ }
+ case OpenPgpConstants.RESULT_CODE_USER_INTERACTION_REQUIRED: {
+ PendingIntent pi = result.getParcelable(OpenPgpConstants.RESULT_INTENT);
+ try {
+ OpenPgpProviderActivity.this.startIntentSenderForResult(pi.getIntentSender(),
+ REQUEST_CODE_SIGN, null, // or new Intent() (in billing)
+ 0, 0, 0);
+ } catch (IntentSender.SendIntentException e) {
+ e.printStackTrace();
+ }
+// try {
+// pi.send(OpenPgpProviderActivity.this, 42, null, new PendingIntent.OnFinished() {
//
-// try {
-// mCryptoServiceConnection.getService().sign(input,
-// new OpenPgpData(OpenPgpData.TYPE_STRING), encryptCallback);
-// } catch (RemoteException e) {
-// Log.e(Constants.TAG, "CryptoProviderDemo", e);
-// }
+// @Override
+// public void onSendFinished(PendingIntent pendingIntent, Intent intent, int resultCode, String resultData, Bundle resultExtras) {
+// Log.d(Constants.TAG, "onSendFinished");
+// Log.d(Constants.TAG, "resultCode: " + resultCode);
+//
+// }
+// }, null);
+// } catch (PendingIntent.CanceledException e) {
+// e.printStackTrace();
+// }
+ break;
+ }
+ }
+ }
+ });
+
}
public void signAndEncryptOnClick(View view) {
@@ -259,6 +297,21 @@ public class OpenPgpProviderActivity extends Activity {
}
@Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+// super.onActivityResult(requestCode, resultCode, data);
+ Log.d(Constants.TAG, "onActivityResult");
+ switch (requestCode) {
+ case REQUEST_CODE_SIGN: {
+ Log.d(Constants.TAG, "resultCode: " + resultCode);
+
+ if (resultCode == RESULT_OK) {
+ signOnClick(null);
+ }
+ }
+ }
+ }
+
+ @Override
public void onDestroy() {
super.onDestroy();