aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain-API/example-app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'OpenPGP-Keychain-API/example-app/src/main')
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml34
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/AidlDemoActivity2.java168
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/BaseActivity.java87
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/Constants.java25
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java352
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/res/drawable-hdpi/ic_launcher.pngbin0 -> 2626 bytes
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/res/drawable-mdpi/ic_launcher.pngbin0 -> 1732 bytes
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/res/drawable-xhdpi/ic_launcher.pngbin0 -> 3517 bytes
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/res/drawable-xxhdpi/ic_launcher.pngbin0 -> 5717 bytes
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/res/layout/aidl_demo2.xml40
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/res/layout/crypto_provider_demo.xml83
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/res/layout/intent_demo.xml93
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/res/xml/base_preference.xml23
13 files changed, 905 insertions, 0 deletions
diff --git a/OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml b/OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..8b8c43776
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.sufficientlysecure.keychain.demo"
+ android:versionCode="2"
+ android:versionName="1.1" >
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="19" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="OpenPGP Keychain API Demo" >
+ <activity
+ android:name=".BaseActivity"
+ android:label="OpenPGP Keychain API Demo" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <activity
+ android:name=".OpenPgpProviderActivity"
+ android:label="OpenPGP Provider"
+ android:windowSoftInputMode="stateHidden" />
+ <activity
+ android:name=".AidlDemoActivity2"
+ android:label="Aidl Demo (ACCESS_KEYS permission)"
+ android:windowSoftInputMode="stateHidden" />
+ </application>
+
+</manifest> \ No newline at end of file
diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/AidlDemoActivity2.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/AidlDemoActivity2.java
new file mode 100644
index 000000000..b6e211955
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/AidlDemoActivity2.java
@@ -0,0 +1,168 @@
+///*
+// * Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
+// *
+// * 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.demo;
+//
+//import java.util.ArrayList;
+//import java.util.List;
+//
+//import org.sufficientlysecure.keychain.demo.R;
+//import org.sufficientlysecure.keychain.integration.KeychainData;
+//import org.sufficientlysecure.keychain.integration.KeychainIntentHelper;
+//import org.sufficientlysecure.keychain.service.IKeychainKeyService;
+//import org.sufficientlysecure.keychain.service.handler.IKeychainGetKeyringsHandler;
+//
+//import android.annotation.SuppressLint;
+//import android.app.Activity;
+//import android.app.AlertDialog;
+//import android.content.ComponentName;
+//import android.content.Context;
+//import android.content.Intent;
+//import android.content.ServiceConnection;
+//import android.os.Bundle;
+//import android.os.IBinder;
+//import android.os.RemoteException;
+//import android.util.Base64;
+//import android.view.View;
+//import android.widget.TextView;
+//
+//public class AidlDemoActivity2 extends Activity {
+// Activity mActivity;
+//
+// TextView mKeyringsTextView;
+//
+// KeychainIntentHelper mKeychainIntentHelper;
+// KeychainData mKeychainData;
+//
+// byte[] keysBytes;
+// ArrayList<String> keysStrings;
+//
+// private IKeychainKeyService service = null;
+// private ServiceConnection svcConn = new ServiceConnection() {
+// public void onServiceConnected(ComponentName className, IBinder binder) {
+// service = IKeychainKeyService.Stub.asInterface(binder);
+// }
+//
+// public void onServiceDisconnected(ComponentName className) {
+// service = null;
+// }
+// };
+//
+// @Override
+// public void onCreate(Bundle icicle) {
+// super.onCreate(icicle);
+// setContentView(R.layout.aidl_demo2);
+//
+// mActivity = this;
+//
+// mKeyringsTextView = (TextView) findViewById(R.id.aidl_demo_keyrings);
+//
+// mKeychainIntentHelper = new KeychainIntentHelper(mActivity);
+// mKeychainData = new KeychainData();
+//
+// bindService(new Intent(IKeychainKeyService.class.getName()), svcConn,
+// Context.BIND_AUTO_CREATE);
+// }
+//
+// public void getKeyringsStringsOnClick(View view) {
+// try {
+// service.getPublicKeyRings(mKeychainData.getPublicKeys(), true, getKeyringsHandler);
+// } catch (RemoteException e) {
+// exceptionImplementation(-1, e.toString());
+// }
+// }
+//
+// public void getKeyringsBytesOnClick(View view) {
+// try {
+// service.getPublicKeyRings(mKeychainData.getPublicKeys(), false, getKeyringsHandler);
+// } catch (RemoteException e) {
+// exceptionImplementation(-1, e.toString());
+// }
+// }
+//
+// @SuppressLint("NewApi")
+// private void updateView() {
+// if (keysBytes != null) {
+// mKeyringsTextView.setText(Base64.encodeToString(keysBytes, Base64.DEFAULT));
+// } else if (keysStrings != null) {
+// mKeyringsTextView.setText("");
+// for (String output : keysStrings) {
+// mKeyringsTextView.append(output);
+// }
+// }
+// }
+//
+// @Override
+// public void onDestroy() {
+// super.onDestroy();
+//
+// unbindService(svcConn);
+// }
+//
+// private void exceptionImplementation(int exceptionId, String error) {
+// AlertDialog.Builder builder = new AlertDialog.Builder(this);
+// builder.setTitle("Exception!").setMessage(error).setPositiveButton("OK", null).show();
+// }
+//
+// private final IKeychainGetKeyringsHandler.Stub getKeyringsHandler = new IKeychainGetKeyringsHandler.Stub() {
+//
+// @Override
+// public void onException(final int exceptionId, final String message) throws RemoteException {
+// runOnUiThread(new Runnable() {
+// public void run() {
+// exceptionImplementation(exceptionId, message);
+// }
+// });
+// }
+//
+// @Override
+// public void onSuccess(final byte[] outputBytes, final List<String> outputStrings)
+// throws RemoteException {
+// runOnUiThread(new Runnable() {
+// public void run() {
+// if (outputBytes != null) {
+// keysBytes = outputBytes;
+// keysStrings = null;
+// } else if (outputStrings != null) {
+// keysBytes = null;
+// keysStrings = (ArrayList<String>) outputStrings;
+// }
+// updateView();
+// }
+// });
+//
+// }
+//
+// };
+//
+// public void selectEncryptionKeysOnClick(View view) {
+// mKeychainIntentHelper.selectPublicKeys("user@example.com");
+// }
+//
+// @Override
+// protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+// // this updates the mKeychainData object to the result of the methods
+// boolean result = mKeychainIntentHelper.onActivityResult(requestCode, resultCode, data,
+// mKeychainData);
+// if (result) {
+// updateView();
+// }
+//
+// // continue with other activity results
+// super.onActivityResult(requestCode, resultCode, data);
+// }
+//
+//}
diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/BaseActivity.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/BaseActivity.java
new file mode 100644
index 000000000..5b286f208
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/BaseActivity.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * 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.demo;
+
+import org.sufficientlysecure.keychain.demo.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceActivity;
+import android.widget.Toast;
+
+public class BaseActivity extends PreferenceActivity {
+ private Activity mActivity;
+
+ private Preference mIntentDemo;
+ private Preference mContentProviderDemo;
+ private Preference mCryptoProvider;
+ private Preference mAidlDemo;
+ private Preference mAidlDemo2;
+
+ /**
+ * Called when the activity is first created.
+ */
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mActivity = this;
+
+ // load preferences from xml
+ addPreferencesFromResource(R.xml.base_preference);
+
+ // find preferences
+ mIntentDemo = (Preference) findPreference("intent_demo");
+ mContentProviderDemo = (Preference) findPreference("content_provider_demo");
+ mCryptoProvider = (Preference) findPreference("openpgp_provider_demo");
+ mAidlDemo = (Preference) findPreference("aidl_demo");
+ mAidlDemo2 = (Preference) findPreference("aidl_demo2");
+
+ mIntentDemo.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ // startActivity(new Intent(mActivity, IntentDemoActivity.class));
+ Toast.makeText(BaseActivity.this, "Not implemented!", Toast.LENGTH_LONG).show();
+
+ return false;
+ }
+ });
+
+ mCryptoProvider.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ startActivity(new Intent(mActivity, OpenPgpProviderActivity.class));
+
+ return false;
+ }
+ });
+
+ // mAidlDemo2.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ // @Override
+ // public boolean onPreferenceClick(Preference preference) {
+ // startActivity(new Intent(mActivity, AidlDemoActivity2.class));
+ //
+ // return false;
+ // }
+ // });
+
+ }
+
+}
diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/Constants.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/Constants.java
new file mode 100644
index 000000000..03e76254c
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/Constants.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * 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.demo;
+
+public final class Constants {
+
+ public static final boolean DEBUG = BuildConfig.DEBUG;
+
+ public static final String TAG = "Keychain";
+
+}
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
new file mode 100644
index 000000000..4a96de5a1
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java
@@ -0,0 +1,352 @@
+/*
+ * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * 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.demo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openintents.openpgp.IOpenPgpKeyIdsCallback;
+import org.openintents.openpgp.OpenPgpData;
+import org.openintents.openpgp.OpenPgpError;
+import org.openintents.openpgp.OpenPgpServiceConnection;
+import org.openintents.openpgp.OpenPgpSignatureResult;
+import org.openintents.openpgp.IOpenPgpCallback;
+import org.openintents.openpgp.IOpenPgpService;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.EditText;
+import android.widget.ListAdapter;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class OpenPgpProviderActivity extends Activity {
+ Activity mActivity;
+
+ EditText mMessage;
+ EditText mCiphertext;
+ EditText mEncryptUserIds;
+
+ private OpenPgpServiceConnection mCryptoServiceConnection;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ setContentView(R.layout.crypto_provider_demo);
+
+ mActivity = this;
+
+ mMessage = (EditText) findViewById(R.id.crypto_provider_demo_message);
+ mCiphertext = (EditText) findViewById(R.id.crypto_provider_demo_ciphertext);
+ mEncryptUserIds = (EditText) findViewById(R.id.crypto_provider_demo_encrypt_user_id);
+
+ selectCryptoProvider();
+ }
+
+ /**
+ * Callback from remote openpgp service
+ */
+ final IOpenPgpKeyIdsCallback.Stub getKeysEncryptCallback = new IOpenPgpKeyIdsCallback.Stub() {
+
+ @Override
+ public void onSuccess(final long[] keyIds) throws RemoteException {
+ Log.d(Constants.TAG, "getKeysEncryptCallback keyId " + keyIds[0]);
+ mActivity.runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ // encrypt after getting key ids
+ String inputStr = mMessage.getText().toString();
+ OpenPgpData input = new OpenPgpData(inputStr);
+
+ Log.d(Constants.TAG, "getKeysEncryptCallback inputStr " + inputStr);
+
+ try {
+ mCryptoServiceConnection.getService().encrypt(input,
+ new OpenPgpData(OpenPgpData.TYPE_STRING), keyIds, encryptCallback);
+ } catch (RemoteException e) {
+ Log.e(Constants.TAG, "CryptoProviderDemo", e);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onError(OpenPgpError error) throws RemoteException {
+ handleError(error);
+ }
+
+ };
+
+ final IOpenPgpKeyIdsCallback.Stub getKeysSignAndEncryptCallback = new IOpenPgpKeyIdsCallback.Stub() {
+
+ @Override
+ public void onSuccess(final long[] keyIds) throws RemoteException {
+ Log.d(Constants.TAG, "getKeysSignAndEncryptCallback keyId " + keyIds[0]);
+
+ mActivity.runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ // encrypt after getting key ids
+ String inputStr = mMessage.getText().toString();
+ OpenPgpData input = new OpenPgpData(inputStr);
+
+ try {
+ mCryptoServiceConnection.getService().signAndEncrypt(input,
+ new OpenPgpData(OpenPgpData.TYPE_STRING), keyIds, encryptCallback);
+ } catch (RemoteException e) {
+ Log.e(Constants.TAG, "CryptoProviderDemo", e);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onError(OpenPgpError error) throws RemoteException {
+ handleError(error);
+ }
+
+ };
+
+ final IOpenPgpCallback.Stub encryptCallback = new IOpenPgpCallback.Stub() {
+
+ @Override
+ public void onSuccess(final OpenPgpData output, OpenPgpSignatureResult signatureResult)
+ throws RemoteException {
+ Log.d(Constants.TAG, "encryptCallback");
+
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ mCiphertext.setText(output.getString());
+ }
+ });
+ }
+
+ @Override
+ public void onError(OpenPgpError error) throws RemoteException {
+ handleError(error);
+ }
+
+ };
+
+ final IOpenPgpCallback.Stub decryptAndVerifyCallback = new IOpenPgpCallback.Stub() {
+
+ @Override
+ public void onSuccess(final OpenPgpData output, final OpenPgpSignatureResult signatureResult)
+ throws RemoteException {
+ Log.d(Constants.TAG, "decryptAndVerifyCallback");
+
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ mMessage.setText(output.getString());
+ if (signatureResult != null) {
+ Toast.makeText(OpenPgpProviderActivity.this,
+ "signature result:\n" + signatureResult.toString(),
+ Toast.LENGTH_LONG).show();
+ }
+ }
+ });
+
+ }
+
+ @Override
+ public void onError(OpenPgpError error) throws RemoteException {
+ handleError(error);
+ }
+
+ };
+
+ private void handleError(final OpenPgpError error) {
+ mActivity.runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ Toast.makeText(mActivity,
+ "onError id:" + error.getErrorId() + "\n\n" + error.getMessage(),
+ Toast.LENGTH_LONG).show();
+ Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId());
+ Log.e(Constants.TAG, "onError getMessage:" + error.getMessage());
+ }
+ });
+ }
+
+ public void encryptOnClick(View view) {
+ try {
+ mCryptoServiceConnection.getService().getKeyIds(
+ mEncryptUserIds.getText().toString().split(","), true, getKeysEncryptCallback);
+ } catch (RemoteException e) {
+ Log.e(Constants.TAG, "CryptoProviderDemo", e);
+ }
+ }
+
+ public void signOnClick(View view) {
+ String inputStr = mMessage.getText().toString();
+ OpenPgpData input = new OpenPgpData(inputStr);
+
+ try {
+ mCryptoServiceConnection.getService().sign(input,
+ new OpenPgpData(OpenPgpData.TYPE_STRING), encryptCallback);
+ } catch (RemoteException e) {
+ Log.e(Constants.TAG, "CryptoProviderDemo", e);
+ }
+ }
+
+ public void signAndEncryptOnClick(View view) {
+ try {
+ mCryptoServiceConnection.getService().getKeyIds(
+ mEncryptUserIds.getText().toString().split(","), true,
+ getKeysSignAndEncryptCallback);
+ } catch (RemoteException e) {
+ Log.e(Constants.TAG, "CryptoProviderDemo", e);
+ }
+ }
+
+ public void decryptAndVerifyOnClick(View view) {
+ String inputStr = mCiphertext.getText().toString();
+ OpenPgpData input = new OpenPgpData(inputStr);
+
+ try {
+ mCryptoServiceConnection.getService().decryptAndVerify(input,
+ new OpenPgpData(OpenPgpData.TYPE_STRING), decryptAndVerifyCallback);
+ } catch (RemoteException e) {
+ Log.e(Constants.TAG, "CryptoProviderDemo", e);
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ if (mCryptoServiceConnection != null) {
+ mCryptoServiceConnection.unbindFromService();
+ }
+ }
+
+ private static class OpenPgpProviderElement {
+ private String packageName;
+ private String simpleName;
+ private Drawable icon;
+
+ public OpenPgpProviderElement(String packageName, String simpleName, Drawable icon) {
+ this.packageName = packageName;
+ this.simpleName = simpleName;
+ this.icon = icon;
+ }
+
+ @Override
+ public String toString() {
+ return simpleName;
+ }
+ }
+
+ private void selectCryptoProvider() {
+ Intent intent = new Intent(IOpenPgpService.class.getName());
+
+ final ArrayList<OpenPgpProviderElement> providerList = new ArrayList<OpenPgpProviderElement>();
+
+ List<ResolveInfo> resInfo = getPackageManager().queryIntentServices(intent, 0);
+ if (!resInfo.isEmpty()) {
+ for (ResolveInfo resolveInfo : resInfo) {
+ if (resolveInfo.serviceInfo == null)
+ continue;
+
+ String packageName = resolveInfo.serviceInfo.packageName;
+ String simpleName = String.valueOf(resolveInfo.serviceInfo
+ .loadLabel(getPackageManager()));
+ Drawable icon = resolveInfo.serviceInfo.loadIcon(getPackageManager());
+ providerList.add(new OpenPgpProviderElement(packageName, simpleName, icon));
+ }
+ }
+
+ AlertDialog.Builder alert = new AlertDialog.Builder(this);
+ alert.setTitle("Select OpenPGP Provider!");
+ alert.setCancelable(false);
+
+ if (!providerList.isEmpty()) {
+ // add "disable OpenPGP provider"
+ providerList.add(0, new OpenPgpProviderElement(null, "Disable OpenPGP Provider",
+ getResources().getDrawable(android.R.drawable.ic_menu_close_clear_cancel)));
+
+ // Init ArrayAdapter with OpenPGP Providers
+ ListAdapter adapter = new ArrayAdapter<OpenPgpProviderElement>(this,
+ android.R.layout.select_dialog_item, android.R.id.text1, providerList) {
+ public View getView(int position, View convertView, ViewGroup parent) {
+ // User super class to create the View
+ View v = super.getView(position, convertView, parent);
+ TextView tv = (TextView) v.findViewById(android.R.id.text1);
+
+ // Put the image on the TextView
+ tv.setCompoundDrawablesWithIntrinsicBounds(providerList.get(position).icon,
+ null, null, null);
+
+ // Add margin between image and text (support various screen densities)
+ int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
+ tv.setCompoundDrawablePadding(dp5);
+
+ return v;
+ }
+ };
+
+ alert.setSingleChoiceItems(adapter, -1, new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog, int position) {
+ String packageName = providerList.get(position).packageName;
+
+ if (packageName == null) {
+ dialog.cancel();
+ finish();
+ }
+
+ // bind to service
+ mCryptoServiceConnection = new OpenPgpServiceConnection(
+ OpenPgpProviderActivity.this, packageName);
+ mCryptoServiceConnection.bindToService();
+
+ dialog.dismiss();
+ }
+ });
+ } else {
+ alert.setMessage("No OpenPGP Provider installed!");
+ }
+
+ alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ finish();
+ }
+ });
+
+ AlertDialog ad = alert.create();
+ ad.show();
+ }
+}
diff --git a/OpenPGP-Keychain-API/example-app/src/main/res/drawable-hdpi/ic_launcher.png b/OpenPGP-Keychain-API/example-app/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 000000000..cf114d7db
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/OpenPGP-Keychain-API/example-app/src/main/res/drawable-mdpi/ic_launcher.png b/OpenPGP-Keychain-API/example-app/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 000000000..d55318843
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/OpenPGP-Keychain-API/example-app/src/main/res/drawable-xhdpi/ic_launcher.png b/OpenPGP-Keychain-API/example-app/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..13ed3d450
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/OpenPGP-Keychain-API/example-app/src/main/res/drawable-xxhdpi/ic_launcher.png b/OpenPGP-Keychain-API/example-app/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..831c993d4
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/OpenPGP-Keychain-API/example-app/src/main/res/layout/aidl_demo2.xml b/OpenPGP-Keychain-API/example-app/src/main/res/layout/aidl_demo2.xml
new file mode 100644
index 000000000..73abd9b5c
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/res/layout/aidl_demo2.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <Button
+ android:id="@+id/aidl_demo_select_encryption_key"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="selectEncryptionKeysOnClick"
+ android:text="Select encryption key(s)" />
+
+ <EditText
+ android:id="@+id/aidl_demo_keyrings"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="keyrings output"
+ android:textAppearance="@android:style/TextAppearance.Small" />
+
+ <Button
+ android:id="@+id/aidl_demo_get_keyrings_strings"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="getKeyringsStringsOnClick"
+ android:text="getKeyrings as Strings" />
+
+ <Button
+ android:id="@+id/aidl_demo_get_keyrings_bytes"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="getKeyringsBytesOnClick"
+ android:text="getKeyringsBytes" />
+ </LinearLayout>
+
+</ScrollView> \ No newline at end of file
diff --git a/OpenPGP-Keychain-API/example-app/src/main/res/layout/crypto_provider_demo.xml b/OpenPGP-Keychain-API/example-app/src/main/res/layout/crypto_provider_demo.xml
new file mode 100644
index 000000000..9f2a0e6ee
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/res/layout/crypto_provider_demo.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Encrypt UserIds (split with &apos;,&apos;)"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <EditText
+ android:id="@+id/crypto_provider_demo_encrypt_user_id"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="dominik@dominikschuermann.de"
+ android:textAppearance="@android:style/TextAppearance.Small" />
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Message"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <EditText
+ android:id="@+id/crypto_provider_demo_message"
+ android:layout_width="match_parent"
+ android:layout_height="100dip"
+ android:scrollHorizontally="true"
+ android:scrollbars="vertical"
+ android:text="message"
+ android:textAppearance="@android:style/TextAppearance.Small" />
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Ciphertext"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <EditText
+ android:id="@+id/crypto_provider_demo_ciphertext"
+ android:layout_width="match_parent"
+ android:layout_height="100dip"
+ android:text="ciphertext"
+ android:textAppearance="@android:style/TextAppearance.Small" />
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" >
+
+ <Button
+ android:id="@+id/crypto_provider_demo_encrypt"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:onClick="encryptOnClick"
+ android:text="Encrypt" />
+
+ <Button
+ android:id="@+id/crypto_provider_demo_sign"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:onClick="signOnClick"
+ android:text="Sign" />
+
+ <Button
+ android:id="@+id/crypto_provider_demo_encrypt_and_sign"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:onClick="signAndEncryptOnClick"
+ android:text="Sign and Encrypt" />
+ </LinearLayout>
+
+ <Button
+ android:id="@+id/crypto_provider_demo_decrypt_and_verify"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="decryptAndVerifyOnClick"
+ android:text="Decrypt and Verify" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/OpenPGP-Keychain-API/example-app/src/main/res/layout/intent_demo.xml b/OpenPGP-Keychain-API/example-app/src/main/res/layout/intent_demo.xml
new file mode 100644
index 000000000..a765343f9
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/res/layout/intent_demo.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <Button
+ android:id="@+id/Button02"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="encryptOnClick"
+ android:text="Encrypt" />
+
+ <Button
+ android:id="@+id/intent_demo_create_new_key"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="createNewKeyOnClick"
+ android:text="Create new key" />
+
+ <Button
+ android:id="@+id/intent_demo_select_secret_key"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="selectSecretKeyOnClick"
+ android:text="Select secret key" />
+
+ <Button
+ android:id="@+id/intent_demo_select_encryption_key"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="selectEncryptionKeysOnClick"
+ android:text="Select encryption key(s)" />
+
+ <EditText
+ android:id="@+id/intent_demo_message"
+ android:layout_width="match_parent"
+ android:layout_height="150dip"
+ android:text="message"
+ android:textAppearance="@android:style/TextAppearance.Small" />
+
+ <EditText
+ android:id="@+id/intent_demo_ciphertext"
+ android:layout_width="match_parent"
+ android:layout_height="150dip"
+ android:text="ciphertext"
+ android:textAppearance="@android:style/TextAppearance.Small" />
+
+ <Button
+ android:id="@+id/intent_demo_encrypt"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="encryptOnClick"
+ android:text="Encrypt" />
+
+ <Button
+ android:id="@+id/intent_demo_encrypt"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="encryptAndReturnOnClick"
+ android:text="Encrypt and return result" />
+
+ <Button
+ android:id="@+id/intent_demo_decrypt"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="decryptOnClick"
+ android:text="Decrypt" />
+
+ <Button
+ android:id="@+id/intent_demo_decrypt"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="decryptAndReturnOnClick"
+ android:text="Decrypt and return result" />
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:text="APG Data:" />
+
+ <TextView
+ android:id="@+id/intent_demo_data"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:minLines="10" />
+ </LinearLayout>
+
+</ScrollView> \ No newline at end of file
diff --git a/OpenPGP-Keychain-API/example-app/src/main/res/xml/base_preference.xml b/OpenPGP-Keychain-API/example-app/src/main/res/xml/base_preference.xml
new file mode 100644
index 000000000..5febfad44
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/res/xml/base_preference.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <PreferenceCategory android:title="Intent" >
+ <Preference
+ android:key="intent_demo"
+ android:title="Intent Demo" />
+ </PreferenceCategory>
+ <!-- <PreferenceCategory android:title="AIDL" > -->
+ <!-- <Preference -->
+ <!-- android:key="aidl_demo2" -->
+ <!-- android:title="AIDL Demo (ACCESS_KEYS permission)" /> -->
+ <!-- </PreferenceCategory> -->
+ <PreferenceCategory android:title="OpenPGP Provider" >
+ <org.openintents.openpgp.OpenPgpListPreference
+ android:key="openpgp_provider_list"
+ android:title="Select OpenPGP Provider!" />
+ <Preference
+ android:key="openpgp_provider_demo"
+ android:title="OpenPGP Provider" />
+ </PreferenceCategory>
+
+</PreferenceScreen> \ No newline at end of file