mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-25 00:18:51 -05:00
Cleanup of API demo
This commit is contained in:
parent
439c7a66f2
commit
286b27522e
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
|
* Copyright (C) 2013-2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -17,9 +17,5 @@
|
|||||||
package org.sufficientlysecure.keychain.demo;
|
package org.sufficientlysecure.keychain.demo;
|
||||||
|
|
||||||
public final class Constants {
|
public final class Constants {
|
||||||
|
|
||||||
public static final boolean DEBUG = BuildConfig.DEBUG;
|
|
||||||
|
|
||||||
public static final String TAG = "Keychain";
|
public static final String TAG = "Keychain";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,15 @@ import org.sufficientlysecure.keychain.api.OpenKeychainIntents;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
public class IntentActivity extends PreferenceActivity {
|
public class IntentActivity extends PreferenceActivity {
|
||||||
|
private Preference mEncrypt;
|
||||||
|
private Preference mEncryptUri;
|
||||||
|
private Preference mDecrypt;
|
||||||
|
private Preference mImportKey;
|
||||||
|
private Preference mImportKeyFromKeyserver;
|
||||||
|
private Preference mImportKeyFromQrCode;
|
||||||
|
private Preference mOpenpgp4fpr;
|
||||||
|
|
||||||
private static final int SELECT_PHOTO = 100;
|
private static final int REQUEST_CODE_SELECT_PHOTO = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the activity is first created.
|
* Called when the activity is first created.
|
||||||
@ -47,24 +54,16 @@ public class IntentActivity extends PreferenceActivity {
|
|||||||
addPreferencesFromResource(R.xml.intent_preference);
|
addPreferencesFromResource(R.xml.intent_preference);
|
||||||
|
|
||||||
// find preferences
|
// find preferences
|
||||||
Preference encrypt = (Preference) findPreference("ENCRYPT");
|
mEncrypt = (Preference) findPreference("ENCRYPT");
|
||||||
Preference encryptUri = (Preference) findPreference("ENCRYPT_URI");
|
mEncryptUri = (Preference) findPreference("ENCRYPT_URI");
|
||||||
Preference decrypt = (Preference) findPreference("DECRYPT");
|
mDecrypt = (Preference) findPreference("DECRYPT");
|
||||||
Preference import_key = (Preference) findPreference("IMPORT_KEY");
|
mImportKey = (Preference) findPreference("IMPORT_KEY");
|
||||||
Preference import_key_from_keyserver = (Preference) findPreference("IMPORT_KEY_FROM_KEYSERVER");
|
mImportKeyFromKeyserver = (Preference) findPreference("IMPORT_KEY_FROM_KEYSERVER");
|
||||||
Preference import_key_from_qr_code = (Preference) findPreference("IMPORT_KEY_FROM_QR_CODE");
|
mImportKeyFromQrCode = (Preference) findPreference("IMPORT_KEY_FROM_QR_CODE");
|
||||||
Preference openpgp4fpr = (Preference) findPreference("openpgp4fpr");
|
mOpenpgp4fpr = (Preference) findPreference("mOpenpgp4fpr");
|
||||||
|
|
||||||
// To prevent Android Studio from complaining...
|
|
||||||
assert encrypt != null;
|
|
||||||
assert encryptUri != null;
|
|
||||||
assert decrypt != null;
|
|
||||||
assert import_key != null;
|
|
||||||
assert import_key_from_keyserver != null;
|
|
||||||
assert import_key_from_qr_code != null;
|
|
||||||
assert openpgp4fpr != null;
|
|
||||||
|
|
||||||
encrypt.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
mEncrypt.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
try {
|
try {
|
||||||
@ -79,18 +78,18 @@ public class IntentActivity extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
encryptUri.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
mEncryptUri.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
|
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
|
||||||
photoPickerIntent.setType("image/*");
|
photoPickerIntent.setType("image/*");
|
||||||
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
|
startActivityForResult(photoPickerIntent, REQUEST_CODE_SELECT_PHOTO);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
decrypt.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
mDecrypt.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
try {
|
try {
|
||||||
@ -105,7 +104,7 @@ public class IntentActivity extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
import_key.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
mImportKey.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
try {
|
try {
|
||||||
@ -126,7 +125,7 @@ public class IntentActivity extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
import_key_from_keyserver.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
mImportKeyFromKeyserver.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
try {
|
try {
|
||||||
@ -141,7 +140,7 @@ public class IntentActivity extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
import_key_from_qr_code.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
mImportKeyFromQrCode.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
try {
|
try {
|
||||||
@ -155,12 +154,12 @@ public class IntentActivity extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
openpgp4fpr.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
mOpenpgp4fpr.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
try {
|
try {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setData(Uri.parse("openpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282"));
|
intent.setData(Uri.parse("mOpenpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282"));
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
Toast.makeText(IntentActivity.this, "Activity not found!", Toast.LENGTH_LONG).show();
|
Toast.makeText(IntentActivity.this, "Activity not found!", Toast.LENGTH_LONG).show();
|
||||||
@ -177,7 +176,7 @@ public class IntentActivity extends PreferenceActivity {
|
|||||||
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
|
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
|
||||||
|
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case SELECT_PHOTO:
|
case REQUEST_CODE_SELECT_PHOTO:
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
Uri selectedImage = imageReturnedIntent.getData();
|
Uri selectedImage = imageReturnedIntent.getData();
|
||||||
|
|
||||||
|
@ -41,15 +41,15 @@ import java.io.InputStream;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
public class OpenPgpProviderActivity extends Activity {
|
public class OpenPgpProviderActivity extends Activity {
|
||||||
EditText mMessage;
|
private EditText mMessage;
|
||||||
EditText mCiphertext;
|
private EditText mCiphertext;
|
||||||
EditText mEncryptUserIds;
|
private EditText mEncryptUserIds;
|
||||||
Button mSign;
|
private Button mSign;
|
||||||
Button mEncrypt;
|
private Button mEncrypt;
|
||||||
Button mSignAndEncrypt;
|
private Button mSignAndEncrypt;
|
||||||
Button mDecryptAndVerify;
|
private Button mDecryptAndVerify;
|
||||||
|
|
||||||
OpenPgpServiceConnection mServiceConnection;
|
private OpenPgpServiceConnection mServiceConnection;
|
||||||
|
|
||||||
public static final int REQUEST_CODE_SIGN = 9910;
|
public static final int REQUEST_CODE_SIGN = 9910;
|
||||||
public static final int REQUEST_CODE_ENCRYPT = 9911;
|
public static final int REQUEST_CODE_ENCRYPT = 9911;
|
||||||
@ -138,7 +138,7 @@ public class OpenPgpProviderActivity extends Activity {
|
|||||||
}
|
}
|
||||||
is = new ByteArrayInputStream(inputStr.getBytes("UTF-8"));
|
is = new ByteArrayInputStream(inputStr.getBytes("UTF-8"));
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
e.printStackTrace();
|
Log.e(Constants.TAG, "UnsupportedEncodingException", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is;
|
return is;
|
||||||
@ -237,11 +237,17 @@ public class OpenPgpProviderActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
Log.d(Constants.TAG, "onActivityResult resultCode: " + resultCode);
|
Log.d(Constants.TAG, "onActivityResult resultCode: " + resultCode);
|
||||||
|
|
||||||
// try again after user interaction
|
// try again after user interaction
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
|
/*
|
||||||
|
* The params originally given to the pgp method are are again
|
||||||
|
* returned here to be used when calling again after user interaction.
|
||||||
|
*
|
||||||
|
* They also contain results from the user interaction which happened,
|
||||||
|
* for example selected key ids.
|
||||||
|
*/
|
||||||
Bundle params = data.getBundleExtra(OpenPgpConstants.PI_RESULT_PARAMS);
|
Bundle params = data.getBundleExtra(OpenPgpConstants.PI_RESULT_PARAMS);
|
||||||
|
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
|
Loading…
Reference in New Issue
Block a user