aboutsummaryrefslogtreecommitdiffstats
path: root/APG-API-Demo
diff options
context:
space:
mode:
authorDominik <dominik@dominikschuermann.de>2012-11-19 17:56:58 +0100
committerDominik <dominik@dominikschuermann.de>2012-11-19 17:56:58 +0100
commitbe569984b893e8cb412b9cc2b3826c92fd4c9d81 (patch)
tree150dc6b112aecde5d34b5d0cc23f4bb35b7fcb3f /APG-API-Demo
parente8ec4d280c75dc1aa5eb58dfaf49b35c9b6c8776 (diff)
downloadopen-keychain-be569984b893e8cb412b9cc2b3826c92fd4c9d81.tar.gz
open-keychain-be569984b893e8cb412b9cc2b3826c92fd4c9d81.tar.bz2
open-keychain-be569984b893e8cb412b9cc2b3826c92fd4c9d81.zip
rename main folders
Diffstat (limited to 'APG-API-Demo')
-rw-r--r--APG-API-Demo/.gitignore23
-rw-r--r--APG-API-Demo/AndroidManifest.xml36
-rw-r--r--APG-API-Demo/build.xml83
-rw-r--r--APG-API-Demo/proguard-project.txt20
-rw-r--r--APG-API-Demo/project.properties12
-rw-r--r--APG-API-Demo/res/drawable-hdpi/icon.pngbin0 -> 5308 bytes
-rw-r--r--APG-API-Demo/res/drawable-ldpi/icon.pngbin0 -> 2027 bytes
-rw-r--r--APG-API-Demo/res/drawable-mdpi/icon.pngbin0 -> 3035 bytes
-rw-r--r--APG-API-Demo/res/drawable-xhdpi/icon.pngbin0 -> 8165 bytes
-rw-r--r--APG-API-Demo/res/layout/aidl_demo.xml72
-rw-r--r--APG-API-Demo/res/layout/intent_demo.xml93
-rw-r--r--APG-API-Demo/res/xml/base_preference.xml15
-rw-r--r--APG-API-Demo/src/org/thialfihar/android/apg/demo/AidlDemoActivity.java185
-rw-r--r--APG-API-Demo/src/org/thialfihar/android/apg/demo/BaseActivity.java69
-rw-r--r--APG-API-Demo/src/org/thialfihar/android/apg/demo/IntentDemoActivity.java110
15 files changed, 718 insertions, 0 deletions
diff --git a/APG-API-Demo/.gitignore b/APG-API-Demo/.gitignore
new file mode 100644
index 000000000..2e423e1a3
--- /dev/null
+++ b/APG-API-Demo/.gitignore
@@ -0,0 +1,23 @@
+#Android generated
+bin
+gen
+obj
+libs/armeabi
+lint.xml
+local.properties
+
+#Eclipse
+.project
+.classpath
+.settings
+
+#IntelliJ IDEA
+.idea
+*.iml
+
+#Maven
+target
+release.properties
+
+#Mac
+.DS_Store \ No newline at end of file
diff --git a/APG-API-Demo/AndroidManifest.xml b/APG-API-Demo/AndroidManifest.xml
new file mode 100644
index 000000000..8d7a9e970
--- /dev/null
+++ b/APG-API-Demo/AndroidManifest.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.thialfihar.android.apg.demo"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-permission android:name="org.thialfihar.android.apg.permission.READ_KEY_DATABASE" />
+ <uses-permission android:name="org.thialfihar.android.apg.permission.ACCESS_API" />
+
+ <uses-sdk
+ android:minSdkVersion="7"
+ android:targetSdkVersion="14" />
+
+ <application
+ android:icon="@drawable/icon"
+ android:label="APG API Demo" >
+ <activity
+ android:name=".BaseActivity"
+ android:label="APG API Demo" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <activity
+ android:name=".IntentDemoActivity"
+ android:label="Intent Demo 1"
+ android:windowSoftInputMode="stateHidden" />
+ <activity
+ android:name=".AidlDemoActivity"
+ android:label="Aidl Demo"
+ android:windowSoftInputMode="stateHidden" />
+ </application>
+
+</manifest> \ No newline at end of file
diff --git a/APG-API-Demo/build.xml b/APG-API-Demo/build.xml
new file mode 100644
index 000000000..e72865c84
--- /dev/null
+++ b/APG-API-Demo/build.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="APG Integration Demo" default="help">
+
+ <!-- The local.properties file is created and updated by the 'android' tool.
+ It contains the path to the SDK. It should *NOT* be checked into
+ Version Control Systems. -->
+ <property file="local.properties" />
+
+ <!-- The ant.properties file can be created by you. It is only edited by the
+ 'android' tool to add properties to it.
+ This is the place to change some Ant specific build properties.
+ Here are some properties you may want to change/update:
+
+ source.dir
+ The name of the source directory. Default is 'src'.
+ out.dir
+ The name of the output directory. Default is 'bin'.
+
+ For other overridable properties, look at the beginning of the rules
+ files in the SDK, at tools/ant/build.xml
+
+ Properties related to the SDK location or the project target should
+ be updated using the 'android' tool with the 'update' action.
+
+ This file is an integral part of the build system for your
+ application and should be checked into Version Control Systems.
+
+ -->
+ <property file="ant.properties" />
+
+ <!-- The project.properties file is created and updated by the 'android'
+ tool, as well as ADT.
+
+ This contains project specific properties such as project target, and library
+ dependencies. Lower level build properties are stored in ant.properties
+ (or in .classpath for Eclipse projects).
+
+ This file is an integral part of the build system for your
+ application and should be checked into Version Control Systems. -->
+ <loadproperties srcFile="project.properties" />
+
+ <!-- quick check on sdk.dir -->
+ <fail
+ message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
+ unless="sdk.dir"
+ />
+
+ <!--
+ Import per project custom build rules if present at the root of the project.
+ This is the place to put custom intermediary targets such as:
+ -pre-build
+ -pre-compile
+ -post-compile (This is typically used for code obfuscation.
+ Compiled code location: ${out.classes.absolute.dir}
+ If this is not done in place, override ${out.dex.input.absolute.dir})
+ -post-package
+ -post-build
+ -pre-clean
+ -->
+ <import file="custom_rules.xml" optional="true" />
+
+ <!-- Import the actual build file.
+
+ To customize existing targets, there are two options:
+ - Customize only one target:
+ - copy/paste the target into this file, *before* the
+ <import> task.
+ - customize it to your needs.
+ - Customize the whole content of build.xml
+ - copy/paste the content of the rules files (minus the top node)
+ into this file, replacing the <import> task.
+ - customize to your needs.
+
+ ***********************
+ ****** IMPORTANT ******
+ ***********************
+ In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
+ in order to avoid having your file be overridden by tools such as "android update project"
+ -->
+ <!-- version-tag: 1 -->
+ <import file="${sdk.dir}/tools/ant/build.xml" />
+
+</project>
diff --git a/APG-API-Demo/proguard-project.txt b/APG-API-Demo/proguard-project.txt
new file mode 100644
index 000000000..f2fe1559a
--- /dev/null
+++ b/APG-API-Demo/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/APG-API-Demo/project.properties b/APG-API-Demo/project.properties
new file mode 100644
index 000000000..8abe35df9
--- /dev/null
+++ b/APG-API-Demo/project.properties
@@ -0,0 +1,12 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-15
+android.library.reference.1=../org_apg_integration_lib
diff --git a/APG-API-Demo/res/drawable-hdpi/icon.png b/APG-API-Demo/res/drawable-hdpi/icon.png
new file mode 100644
index 000000000..6b8cc3d73
--- /dev/null
+++ b/APG-API-Demo/res/drawable-hdpi/icon.png
Binary files differ
diff --git a/APG-API-Demo/res/drawable-ldpi/icon.png b/APG-API-Demo/res/drawable-ldpi/icon.png
new file mode 100644
index 000000000..a1adf6bcb
--- /dev/null
+++ b/APG-API-Demo/res/drawable-ldpi/icon.png
Binary files differ
diff --git a/APG-API-Demo/res/drawable-mdpi/icon.png b/APG-API-Demo/res/drawable-mdpi/icon.png
new file mode 100644
index 000000000..6b10a2ad3
--- /dev/null
+++ b/APG-API-Demo/res/drawable-mdpi/icon.png
Binary files differ
diff --git a/APG-API-Demo/res/drawable-xhdpi/icon.png b/APG-API-Demo/res/drawable-xhdpi/icon.png
new file mode 100644
index 000000000..03ee31bbd
--- /dev/null
+++ b/APG-API-Demo/res/drawable-xhdpi/icon.png
Binary files differ
diff --git a/APG-API-Demo/res/layout/aidl_demo.xml b/APG-API-Demo/res/layout/aidl_demo.xml
new file mode 100644
index 000000000..59977869d
--- /dev/null
+++ b/APG-API-Demo/res/layout/aidl_demo.xml
@@ -0,0 +1,72 @@
+<?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/aidl_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/aidl_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/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_message"
+ android:layout_width="match_parent"
+ android:layout_height="150dip"
+ android:text="message"
+ android:textAppearance="@android:style/TextAppearance.Small" />
+
+ <EditText
+ android:id="@+id/aidl_demo_ciphertext"
+ android:layout_width="match_parent"
+ android:layout_height="150dip"
+ android:text="ciphertext"
+ android:textAppearance="@android:style/TextAppearance.Small" />
+
+ <Button
+ android:id="@+id/aidl_demo_encrypt"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="encryptOnClick"
+ android:text="Encrypt" />
+
+ <Button
+ android:id="@+id/aidl_demo_decrypt"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="decryptOnClick"
+ android:text="Decrypt" />
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:text="APG Data:" />
+
+ <TextView
+ android:id="@+id/aidl_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/APG-API-Demo/res/layout/intent_demo.xml b/APG-API-Demo/res/layout/intent_demo.xml
new file mode 100644
index 000000000..a765343f9
--- /dev/null
+++ b/APG-API-Demo/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/APG-API-Demo/res/xml/base_preference.xml b/APG-API-Demo/res/xml/base_preference.xml
new file mode 100644
index 000000000..c56e54746
--- /dev/null
+++ b/APG-API-Demo/res/xml/base_preference.xml
@@ -0,0 +1,15 @@
+<?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_demo"
+ android:title="AIDL Demo" />
+ </PreferenceCategory>
+
+</PreferenceScreen> \ No newline at end of file
diff --git a/APG-API-Demo/src/org/thialfihar/android/apg/demo/AidlDemoActivity.java b/APG-API-Demo/src/org/thialfihar/android/apg/demo/AidlDemoActivity.java
new file mode 100644
index 000000000..f066e0957
--- /dev/null
+++ b/APG-API-Demo/src/org/thialfihar/android/apg/demo/AidlDemoActivity.java
@@ -0,0 +1,185 @@
+package org.thialfihar.android.apg.demo;
+
+import org.thialfihar.android.apg.integration.ApgData;
+import org.thialfihar.android.apg.integration.ApgIntentHelper;
+import org.thialfihar.android.apg.service.IApgEncryptDecryptHandler;
+import org.thialfihar.android.apg.service.IApgHelperHandler;
+import org.thialfihar.android.apg.service.IApgService;
+
+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.view.View;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class AidlDemoActivity extends Activity {
+ Activity mActivity;
+
+ TextView mMessageTextView;
+ TextView mCiphertextTextView;
+ TextView mDataTextView;
+
+ ApgIntentHelper mApgIntentHelper;
+ ApgData mApgData;
+
+ private IApgService service = null;
+ private ServiceConnection svcConn = new ServiceConnection() {
+ public void onServiceConnected(ComponentName className, IBinder binder) {
+ service = IApgService.Stub.asInterface(binder);
+ }
+
+ public void onServiceDisconnected(ComponentName className) {
+ service = null;
+ }
+ };
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ setContentView(R.layout.aidl_demo);
+
+ mActivity = this;
+
+ mMessageTextView = (TextView) findViewById(R.id.aidl_demo_message);
+ mCiphertextTextView = (TextView) findViewById(R.id.aidl_demo_ciphertext);
+ mDataTextView = (TextView) findViewById(R.id.aidl_demo_data);
+
+ mApgIntentHelper = new ApgIntentHelper(mActivity);
+ mApgData = new ApgData();
+
+ bindService(new Intent("org.thialfihar.android.apg.service.IApgService"), svcConn,
+ Context.BIND_AUTO_CREATE);
+ }
+
+ public void encryptOnClick(View view) {
+ byte[] inputBytes = mMessageTextView.getText().toString().getBytes();
+
+ try {
+ service.encryptAsymmetric(inputBytes, null, true, 0, mApgData.getEncryptionKeys(), 7,
+ encryptDecryptHandler);
+ } catch (RemoteException e) {
+ exceptionImplementation(-1, e.toString());
+ }
+ }
+
+ public void decryptOnClick(View view) {
+ byte[] inputBytes = mCiphertextTextView.getText().toString().getBytes();
+
+ try {
+ service.decryptAndVerifyAsymmetric(inputBytes, null, null, encryptDecryptHandler);
+ } catch (RemoteException e) {
+ exceptionImplementation(-1, e.toString());
+ }
+ }
+
+ private void updateView() {
+ if (mApgData.getDecryptedData() != null) {
+ mMessageTextView.setText(mApgData.getDecryptedData());
+ }
+ if (mApgData.getEncryptedData() != null) {
+ mCiphertextTextView.setText(mApgData.getEncryptedData());
+ }
+ mDataTextView.setText(mApgData.toString());
+ }
+
+ @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 IApgEncryptDecryptHandler.Stub encryptDecryptHandler = new IApgEncryptDecryptHandler.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 onSuccessEncrypt(final byte[] outputBytes, String outputUri)
+ throws RemoteException {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ mApgData.setEncryptedData(new String(outputBytes));
+ updateView();
+ }
+ });
+ }
+
+ @Override
+ public void onSuccessDecrypt(final byte[] outputBytes, String outputUri, boolean signature,
+ long signatureKeyId, String signatureUserId, boolean signatureSuccess,
+ boolean signatureUnknown) throws RemoteException {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ mApgData.setDecryptedData(new String(outputBytes));
+ updateView();
+ }
+ });
+
+ }
+
+ };
+
+ private final IApgHelperHandler.Stub helperHandler = new IApgHelperHandler.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 onSuccessGetDecryptionKey(long arg0, boolean arg1) throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ };
+
+ /**
+ * Selection is done with Intents, not AIDL!
+ *
+ * @param view
+ */
+ public void selectSecretKeyOnClick(View view) {
+ mApgIntentHelper.selectSecretKey();
+ }
+
+ public void selectEncryptionKeysOnClick(View view) {
+ mApgIntentHelper.selectEncryptionKeys("user@example.com");
+
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ // this updates the mApgData object to the result of the methods
+ boolean result = mApgIntentHelper.onActivityResult(requestCode, resultCode, data, mApgData);
+ if (result) {
+ updateView();
+ }
+
+ // continue with other activity results
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+}
diff --git a/APG-API-Demo/src/org/thialfihar/android/apg/demo/BaseActivity.java b/APG-API-Demo/src/org/thialfihar/android/apg/demo/BaseActivity.java
new file mode 100644
index 000000000..3f46b2e4d
--- /dev/null
+++ b/APG-API-Demo/src/org/thialfihar/android/apg/demo/BaseActivity.java
@@ -0,0 +1,69 @@
+/*
+ * 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.thialfihar.android.apg.demo;
+
+import org.thialfihar.android.apg.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;
+
+public class BaseActivity extends PreferenceActivity {
+ private Activity mActivity;
+
+ private Preference mIntentDemo;
+ private Preference mAidlDemo;
+
+ /**
+ * 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");
+ mAidlDemo = (Preference) findPreference("aidl_demo");
+
+ mIntentDemo.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ startActivity(new Intent(mActivity, IntentDemoActivity.class));
+
+ return false;
+ }
+ });
+
+ mAidlDemo.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ startActivity(new Intent(mActivity, AidlDemoActivity.class));
+
+ return false;
+ }
+ });
+ }
+
+}
diff --git a/APG-API-Demo/src/org/thialfihar/android/apg/demo/IntentDemoActivity.java b/APG-API-Demo/src/org/thialfihar/android/apg/demo/IntentDemoActivity.java
new file mode 100644
index 000000000..b707e48a8
--- /dev/null
+++ b/APG-API-Demo/src/org/thialfihar/android/apg/demo/IntentDemoActivity.java
@@ -0,0 +1,110 @@
+/*
+ * 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.thialfihar.android.apg.demo;
+
+import org.thialfihar.android.apg.demo.R;
+import org.thialfihar.android.apg.integration.ApgData;
+import org.thialfihar.android.apg.integration.ApgIntentHelper;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.TextView;
+
+public class IntentDemoActivity extends Activity {
+ Activity mActivity;
+
+ TextView mMessageTextView;
+ TextView mCiphertextTextView;
+ TextView mDataTextView;
+
+ ApgIntentHelper mApgIntentHelper;
+ ApgData mApgData;
+
+ /**
+ * Instantiate View for this Activity
+ */
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.intent_demo);
+
+ mActivity = this;
+
+ mMessageTextView = (TextView) findViewById(R.id.intent_demo_message);
+ mCiphertextTextView = (TextView) findViewById(R.id.intent_demo_ciphertext);
+ mDataTextView = (TextView) findViewById(R.id.intent_demo_data);
+
+ mApgIntentHelper = new ApgIntentHelper(mActivity);
+ mApgData = new ApgData();
+ }
+
+ public void createNewKeyOnClick(View view) {
+ // mApgIntentHelper.createNewKey();
+ mApgIntentHelper.createNewKey("test <user@example.com>", true, true);
+ }
+
+ public void selectSecretKeyOnClick(View view) {
+ mApgIntentHelper.selectSecretKey();
+ }
+
+ public void selectEncryptionKeysOnClick(View view) {
+ mApgIntentHelper.selectEncryptionKeys("user@example.com");
+ }
+
+ public void encryptOnClick(View view) {
+ mApgIntentHelper.encrypt(mMessageTextView.getText().toString(),
+ mApgData.getEncryptionKeys(), mApgData.getSignatureKeyId(), false);
+ }
+
+ public void encryptAndReturnOnClick(View view) {
+ mApgIntentHelper.encrypt(mMessageTextView.getText().toString(),
+ mApgData.getEncryptionKeys(), mApgData.getSignatureKeyId(), true);
+ }
+
+ public void decryptOnClick(View view) {
+ mApgIntentHelper.decrypt(mCiphertextTextView.getText().toString(), false);
+ }
+
+ public void decryptAndReturnOnClick(View view) {
+ mApgIntentHelper.decrypt(mCiphertextTextView.getText().toString(), true);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ // this updates the mApgData object to the result of the methods
+ boolean result = mApgIntentHelper.onActivityResult(requestCode, resultCode, data, mApgData);
+ if (result) {
+ updateView();
+ }
+
+ // continue with other activity results
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+
+ private void updateView() {
+ if (mApgData.getDecryptedData() != null) {
+ mMessageTextView.setText(mApgData.getDecryptedData());
+ }
+ if (mApgData.getEncryptedData() != null) {
+ mCiphertextTextView.setText(mApgData.getEncryptedData());
+ }
+ mDataTextView.setText(mApgData.toString());
+ }
+}