intent improvements

This commit is contained in:
Dominik 2012-09-12 20:09:38 +02:00
parent 054ad2bb97
commit cbc3b8ae4e
5 changed files with 47 additions and 25 deletions

View file

@ -28,7 +28,7 @@
- APG 2 starting with versionCode 20000! - APG 2 starting with versionCode 20000!
Registration of APG to file types Association of file types to APG
================================= =================================
General remarks about file ending conventions: General remarks about file ending conventions:
- *.gpg for binary files - *.gpg for binary files

View file

@ -286,7 +286,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
break; break;
case TARGET_STREAM: /* Encrypting stream from content uri */ case TARGET_STREAM: /* Encrypting stream from content uri */
Uri providerUri = Uri.parse(data.getString(PROVIDER_URI)); Uri providerUri = (Uri) data.getParcelable(PROVIDER_URI);
// InputStream // InputStream
InputStream in = getContentResolver().openInputStream(providerUri); InputStream in = getContentResolver().openInputStream(providerUri);
@ -440,7 +440,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
break; break;
case TARGET_STREAM: /* decrypting stream from content uri */ case TARGET_STREAM: /* decrypting stream from content uri */
Uri providerUri = Uri.parse(data.getString(PROVIDER_URI)); Uri providerUri = (Uri) data.getParcelable(PROVIDER_URI);
// InputStream // InputStream
InputStream in = getContentResolver().openInputStream(providerUri); InputStream in = getContentResolver().openInputStream(providerUri);

View file

@ -254,10 +254,12 @@ public class DecryptActivity extends SherlockFragmentActivity {
String action = intent.getAction(); String action = intent.getAction();
String type = intent.getType(); String type = intent.getType();
mContentUri = intent.getData();
if (Intent.ACTION_VIEW.equals(action)) { if (Intent.ACTION_VIEW.equals(action)) {
// Android's Action when opening file associated to APG (see AndroidManifest.xml)
// TODO: old implementation of ACTION_VIEW. Is this used in K9? // TODO: old implementation of ACTION_VIEW. Is this used in K9?
// Uri uri = mIntent.getData(); // Uri uri = mIntent.getData();
// try { // try {
// InputStream attachment = getContentResolver().openInputStream(uri); // InputStream attachment = getContentResolver().openInputStream(uri);
@ -280,7 +282,10 @@ public class DecryptActivity extends SherlockFragmentActivity {
handleActionDecryptFile(intent); handleActionDecryptFile(intent);
decryptImmediately = true; decryptImmediately = true;
} else if (Intent.ACTION_SEND.equals(action) && type != null) { } else if (Intent.ACTION_SEND.equals(action) && type != null) {
// Android's Action when sending to APG Decrypt
if ("text/plain".equals(type)) { if ("text/plain".equals(type)) {
// plain text
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) { if (sharedText != null) {
intent.putExtra(EXTRA_TEXT, sharedText); intent.putExtra(EXTRA_TEXT, sharedText);
@ -288,10 +293,10 @@ public class DecryptActivity extends SherlockFragmentActivity {
decryptImmediately = true; decryptImmediately = true;
} }
} else { } else {
// binary via content provider (could also be files)
Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) { if (uri != null) {
// TODO: Implement for binary mContentUri = uri;
} }
} }
} else if (ACTION_DECRYPT.equals(action)) { } else if (ACTION_DECRYPT.equals(action)) {
@ -440,7 +445,6 @@ public class DecryptActivity extends SherlockFragmentActivity {
* @param intent * @param intent
*/ */
private void handleActionDecryptAndReturn(Intent intent) { private void handleActionDecryptAndReturn(Intent intent) {
mContentUri = intent.getData();
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
if (extras == null) { if (extras == null) {
extras = new Bundle(); extras = new Bundle();
@ -745,7 +749,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
if (mContentUri != null) { if (mContentUri != null) {
data.putInt(ApgService.TARGET, ApgService.TARGET_STREAM); data.putInt(ApgService.TARGET, ApgService.TARGET_STREAM);
data.putString(ApgService.PROVIDER_URI, mContentUri.toString()); data.putParcelable(ApgService.PROVIDER_URI, mContentUri);
} else if (mDecryptTarget == Id.target.file) { } else if (mDecryptTarget == Id.target.file) {
data.putInt(ApgService.TARGET, ApgService.TARGET_FILE); data.putInt(ApgService.TARGET, ApgService.TARGET_FILE);

View file

@ -346,9 +346,13 @@ public class EncryptActivity extends SherlockFragmentActivity {
Intent intent = getIntent(); Intent intent = getIntent();
String action = intent.getAction(); String action = intent.getAction();
String type = intent.getType(); String type = intent.getType();
mContentUri = intent.getData();
if (Intent.ACTION_SEND.equals(action) && type != null) { if (Intent.ACTION_SEND.equals(action) && type != null) {
// Android's Action when sending to APG Encrypt
if ("text/plain".equals(type)) { if ("text/plain".equals(type)) {
// plain text
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) { if (sharedText != null) {
intent.setAction(ACTION_ENCRYPT); intent.setAction(ACTION_ENCRYPT);
@ -357,15 +361,18 @@ public class EncryptActivity extends SherlockFragmentActivity {
handleActionEncryptSign(intent); handleActionEncryptSign(intent);
} }
} else { } else {
// binary via content provider (could also be files)
Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) { if (uri != null) {
// TODO: Implement for binary mContentUri = uri;
handleActionEncryptSign(intent);
} }
} }
} else if (ACTION_ENCRYPT.equals(action) || ACTION_ENCRYPT_FILE.equals(action) } else if (ACTION_ENCRYPT.equals(action) || ACTION_ENCRYPT_FILE.equals(action)
|| ACTION_ENCRYPT_AND_RETURN.equals(action) || ACTION_ENCRYPT_AND_RETURN.equals(action)
|| ACTION_GENERATE_SIGNATURE.equals(action)) { || ACTION_GENERATE_SIGNATURE.equals(action)) {
// APG's own Actions
handleActionEncryptSign(intent); handleActionEncryptSign(intent);
} }
@ -402,8 +409,6 @@ public class EncryptActivity extends SherlockFragmentActivity {
*/ */
private void handleActionEncryptSign(Intent intent) { private void handleActionEncryptSign(Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
mContentUri = intent.getData();
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
if (extras == null) { if (extras == null) {
extras = new Bundle(); extras = new Bundle();
@ -790,7 +795,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
// choose default settings, target and data bundle by target // choose default settings, target and data bundle by target
if (mContentUri != null) { if (mContentUri != null) {
data.putInt(ApgService.TARGET, ApgService.TARGET_STREAM); data.putInt(ApgService.TARGET, ApgService.TARGET_STREAM);
data.putString(ApgService.PROVIDER_URI, mContentUri.toString()); data.putParcelable(ApgService.PROVIDER_URI, mContentUri);
} else if (mEncryptTarget == Id.target.file) { } else if (mEncryptTarget == Id.target.file) {
useAsciiArmour = mAsciiArmour.isChecked(); useAsciiArmour = mAsciiArmour.isChecked();

View file

@ -142,13 +142,27 @@ public class KeyListActivity extends SherlockFragmentActivity {
mListAdapter = new KeyListAdapter(this, searchString); mListAdapter = new KeyListAdapter(this, searchString);
mList.setAdapter(mListAdapter); mList.setAdapter(mListAdapter);
// handled separately from other actions as it uses intent.setAction() // Get intent, action
if (Intent.ACTION_VIEW.equals(intent.getAction())) { // Intent intent = getIntent();
// same as ACTION_IMPORT invoked from a file manager String action = intent.getAction();
intent.setAction(ACTION_IMPORT);
if (Intent.ACTION_VIEW.equals(action)) {
// Android's Action when opening file associated to APG (see AndroidManifest.xml)
handleActionImport(intent);
} else if (ACTION_IMPORT.equals(action)) {
// APG's own Actions
handleActionImport(intent);
}
} }
if (ACTION_IMPORT.equals(intent.getAction())) { /**
* Handles import action
*
* @param intent
*/
private void handleActionImport(Intent intent) {
if ("file".equals(intent.getScheme()) && intent.getDataString() != null) { if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
mImportFilename = intent.getData().getPath(); mImportFilename = intent.getData().getPath();
} else { } else {
@ -156,7 +170,6 @@ public class KeyListActivity extends SherlockFragmentActivity {
} }
importKeys(); importKeys();
} }
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {