aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain-API
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-02-15 20:14:23 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-02-15 20:14:23 +0100
commit81b810e9f6cee2ac549758563fcd8987806828a4 (patch)
treefad63b5900e46f99b08cd45e241e560634a84aeb /OpenPGP-Keychain-API
parente70886e24253500cd4c93be6638c485fb93efd79 (diff)
downloadopen-keychain-81b810e9f6cee2ac549758563fcd8987806828a4.tar.gz
open-keychain-81b810e9f6cee2ac549758563fcd8987806828a4.tar.bz2
open-keychain-81b810e9f6cee2ac549758563fcd8987806828a4.zip
intent demo, fix some intents
Diffstat (limited to 'OpenPGP-Keychain-API')
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml3
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/BaseActivity.java5
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/IntentActivity.java209
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/res/xml/intent_preference.xml30
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpConstants.java1
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/sufficientlysecure/keychain/api/KeychainIntents.java37
6 files changed, 281 insertions, 4 deletions
diff --git a/OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml b/OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml
index 3658283ba..42465cef8 100644
--- a/OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml
+++ b/OpenPGP-Keychain-API/example-app/src/main/AndroidManifest.xml
@@ -25,6 +25,9 @@
android:name=".OpenPgpProviderActivity"
android:label="OpenPGP Provider"
android:windowSoftInputMode="stateHidden" />
+ <activity
+ android:name=".IntentActivity"
+ android:label="Intents" />
</application>
</manifest> \ No newline at end of file
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
index d37689afc..dd642d879 100644
--- 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
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2012-2014 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.
@@ -44,8 +44,7 @@ public class BaseActivity extends PreferenceActivity {
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();
+ startActivity(new Intent(BaseActivity.this, IntentActivity.class));
return false;
}
diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/IntentActivity.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/IntentActivity.java
new file mode 100644
index 000000000..8fe0d2d9c
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/IntentActivity.java
@@ -0,0 +1,209 @@
+/*
+ * Copyright (C) 2014 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 android.content.ActivityNotFoundException;
+import android.content.Intent;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceActivity;
+import android.provider.MediaStore;
+import android.util.Log;
+import android.widget.Toast;
+
+import org.sufficientlysecure.keychain.api.KeychainIntents;
+
+public class IntentActivity extends PreferenceActivity {
+
+ private static final int SELECT_PHOTO = 100;
+
+ /**
+ * Called when the activity is first created.
+ */
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // load preferences from xml
+ addPreferencesFromResource(R.xml.intent_preference);
+
+ // find preferences
+ Preference encrypt = (Preference) findPreference("ENCRYPT");
+ Preference encryptUri = (Preference) findPreference("ENCRYPT_URI");
+ Preference decrypt = (Preference) findPreference("DECRYPT");
+ Preference import_key = (Preference) findPreference("IMPORT_KEY");
+ Preference import_key_from_keyserver = (Preference) findPreference("IMPORT_KEY_FROM_KEYSERVER");
+ Preference import_key_from_qr_code = (Preference) findPreference("IMPORT_KEY_FROM_QR_CODE");
+ Preference openpgp4fpr = (Preference) findPreference("openpgp4fpr");
+
+ encrypt.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ try {
+ Intent intent = new Intent(KeychainIntents.ENCRYPT);
+ intent.putExtra(KeychainIntents.ENCRYPT_EXTRA_TEXT, "Hello world!");
+ startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(IntentActivity.this, "Activity not found!", Toast.LENGTH_LONG).show();
+ }
+
+ return false;
+ }
+ });
+
+ encryptUri.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
+ photoPickerIntent.setType("image/*");
+ startActivityForResult(photoPickerIntent, SELECT_PHOTO);
+
+ return false;
+ }
+ });
+
+ decrypt.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ String text = "-----BEGIN PGP SIGNED MESSAGE-----\n" +
+ "Hash: SHA1\n" +
+ "\n" +
+ "Hello world!\n" +
+ "-----BEGIN PGP SIGNATURE-----\n" +
+ "Version: GnuPG v1.4.12 (GNU/Linux)\n" +
+ "Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/\n" +
+ "\n" +
+ "iQEcBAEBAgAGBQJS/7vTAAoJEHGMBwEAASKCkGYH/2jBLzamVyqd61jrjMQM0jUv\n" +
+ "MkDcPUxPrYH3wZOO0HcgdBQEo66GZEC2ATmo8izJUMk35Q5jas99k0ac9pXhPUPE\n" +
+ "5qDXdQS10S07R6J0SeDYFWDSyrSiDTCZpFkVu3JGP/3S0SkMYXPzfYlh8Ciuxu7i\n" +
+ "FR5dmIiz3VQaBgTBSCBFEomNFM5ypynBJqKIzIty8v0NbV72Rtg6Xg76YqWQ/6MC\n" +
+ "/MlT3y3++HhfpEmLf5WLEXljbuZ4SfCybgYXG9gBzhJu3+gmBoSicdYTZDHSxBBR\n" +
+ "BwI+ueLbhgRz+gU+WJFE7xNw35xKtBp1C4PR0iKI8rZCSHLjsRVzor7iwDaR51M=\n" +
+ "=3Ydc\n" +
+ "-----END PGP SIGNATURE-----";
+ try {
+ Intent intent = new Intent(KeychainIntents.DECRYPT);
+ intent.putExtra(KeychainIntents.DECRYPT_EXTRA_TEXT, text);
+ startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(IntentActivity.this, "Activity not found!", Toast.LENGTH_LONG).show();
+ }
+
+ return false;
+ }
+ });
+
+ import_key.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ try {
+ Intent intent = new Intent(KeychainIntents.IMPORT_KEY);
+// intent.putExtra(KeychainIntents.IMPORT_KEY_EXTRA_KEY_BYTES, TODO);
+ startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(IntentActivity.this, "Activity not found!", Toast.LENGTH_LONG).show();
+ }
+
+ return false;
+ }
+ });
+
+ import_key_from_keyserver.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ try {
+ Intent intent = new Intent(KeychainIntents.IMPORT_KEY_FROM_KEYSERVER);
+ intent.putExtra(KeychainIntents.IMPORT_KEY_FROM_KEYSERVER_QUERY, "Richard Stallman");
+ startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(IntentActivity.this, "Activity not found!", Toast.LENGTH_LONG).show();
+ }
+
+ return false;
+ }
+ });
+
+ import_key_from_qr_code.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ try {
+ Intent intent = new Intent(KeychainIntents.IMPORT_KEY_FROM_QR_CODE);
+ startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(IntentActivity.this, "Activity not found!", Toast.LENGTH_LONG).show();
+ }
+
+ return false;
+ }
+ });
+
+ openpgp4fpr.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ try {
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setData(Uri.parse("openpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282"));
+ startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(IntentActivity.this, "Activity not found!", Toast.LENGTH_LONG).show();
+ }
+
+ return false;
+ }
+ });
+
+
+ }
+
+ protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
+ super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
+
+ switch (requestCode) {
+ case SELECT_PHOTO:
+ if (resultCode == RESULT_OK) {
+ Uri selectedImage = imageReturnedIntent.getData();
+
+ String[] filePathColumn = {MediaStore.Images.Media.DATA};
+
+ Cursor cursor = getContentResolver().query(
+ selectedImage, filePathColumn, null, null, null);
+ cursor.moveToFirst();
+
+ int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
+ String filePath = cursor.getString(columnIndex);
+ cursor.close();
+
+ // TODO: after fixing DECRYPT, we could use Uri selectedImage directly
+ Log.d(Constants.TAG, "filePath: " + filePath);
+
+ try {
+ Intent intent = new Intent(KeychainIntents.ENCRYPT);
+ Uri dataUri = Uri.parse("file://" + filePath);
+ Log.d(Constants.TAG, "Uri: " + dataUri);
+ intent.setData(dataUri);
+ startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(IntentActivity.this, "Activity not found!", Toast.LENGTH_LONG).show();
+ }
+ }
+ }
+ }
+
+}
diff --git a/OpenPGP-Keychain-API/example-app/src/main/res/xml/intent_preference.xml b/OpenPGP-Keychain-API/example-app/src/main/res/xml/intent_preference.xml
new file mode 100644
index 000000000..ffbf1c475
--- /dev/null
+++ b/OpenPGP-Keychain-API/example-app/src/main/res/xml/intent_preference.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <PreferenceCategory android:title="Intents (org.sufficientlysecure.keychain.action.)">
+ <Preference
+ android:key="ENCRYPT"
+ android:title="ENCRYPT" />
+ <Preference
+ android:key="ENCRYPT_URI"
+ android:title="ENCRYPT with Uri" />
+ <Preference
+ android:key="DECRYPT"
+ android:title="DECRYPT" />
+ <Preference
+ android:key="IMPORT_KEY"
+ android:title="IMPORT_KEY" />
+ <Preference
+ android:key="IMPORT_KEY_FROM_KEYSERVER"
+ android:title="IMPORT_KEY_FROM_KEYSERVER" />
+ <Preference
+ android:key="IMPORT_KEY_FROM_QR_CODE"
+ android:title="IMPORT_KEY_FROM_QR_CODE" />
+ </PreferenceCategory>
+ <PreferenceCategory android:title="Special Intents">
+ <org.openintents.openpgp.util.OpenPgpListPreference
+ android:key="openpgp4fpr"
+ android:title="VIEW openpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282" />
+ </PreferenceCategory>
+
+</PreferenceScreen> \ No newline at end of file
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpConstants.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpConstants.java
index 263b42aaa..9a2d3c054 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpConstants.java
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpConstants.java
@@ -23,7 +23,6 @@ public class OpenPgpConstants {
public static final int API_VERSION = 1;
public static final String SERVICE_INTENT = "org.openintents.openpgp.IOpenPgpService";
-
/* Bundle params */
public static final String PARAMS_API_VERSION = "api_version";
// request ASCII Armor for output
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/sufficientlysecure/keychain/api/KeychainIntents.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/sufficientlysecure/keychain/api/KeychainIntents.java
new file mode 100644
index 000000000..12e32933b
--- /dev/null
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/sufficientlysecure/keychain/api/KeychainIntents.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2014 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.api;
+
+public class KeychainIntents {
+
+ public static final String ENCRYPT = "org.sufficientlysecure.keychain.action.ENCRYPT";
+ public static final String ENCRYPT_EXTRA_TEXT = "text";
+ public static final String ENCRYPT_ASCII_ARMOR = "ascii_armor";
+
+ public static final String DECRYPT = "org.sufficientlysecure.keychain.action.DECRYPT";
+ public static final String DECRYPT_EXTRA_TEXT = "text";
+
+ public static final String IMPORT_KEY = "org.sufficientlysecure.keychain.action.IMPORT_KEY";
+ public static final String IMPORT_KEY_EXTRA_KEY_BYTES = "key_bytes";
+
+ public static final String IMPORT_KEY_FROM_KEYSERVER = "org.sufficientlysecure.keychain.action.IMPORT_KEY_FROM_KEYSERVER";
+ public static final String IMPORT_KEY_FROM_KEYSERVER_QUERY = "query";
+ public static final String IMPORT_KEY_FROM_KEYSERVER_FINGERPRINT = "fingerprint";
+
+ public static final String IMPORT_KEY_FROM_QR_CODE = "org.sufficientlysecure.keychain.action.IMPORT_KEY_FROM_QR_CODE";
+
+}