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!
Registration of APG to file types
Association of file types to APG
=================================
General remarks about file ending conventions:
- *.gpg for binary files

View File

@ -286,7 +286,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
break;
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 in = getContentResolver().openInputStream(providerUri);
@ -440,7 +440,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
break;
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 in = getContentResolver().openInputStream(providerUri);

View File

@ -254,10 +254,12 @@ public class DecryptActivity extends SherlockFragmentActivity {
String action = intent.getAction();
String type = intent.getType();
mContentUri = intent.getData();
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?
// Uri uri = mIntent.getData();
// try {
// InputStream attachment = getContentResolver().openInputStream(uri);
@ -280,7 +282,10 @@ public class DecryptActivity extends SherlockFragmentActivity {
handleActionDecryptFile(intent);
decryptImmediately = true;
} else if (Intent.ACTION_SEND.equals(action) && type != null) {
// Android's Action when sending to APG Decrypt
if ("text/plain".equals(type)) {
// plain text
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
intent.putExtra(EXTRA_TEXT, sharedText);
@ -288,10 +293,10 @@ public class DecryptActivity extends SherlockFragmentActivity {
decryptImmediately = true;
}
} else {
// binary via content provider (could also be files)
Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
// TODO: Implement for binary
mContentUri = uri;
}
}
} else if (ACTION_DECRYPT.equals(action)) {
@ -440,7 +445,6 @@ public class DecryptActivity extends SherlockFragmentActivity {
* @param intent
*/
private void handleActionDecryptAndReturn(Intent intent) {
mContentUri = intent.getData();
Bundle extras = intent.getExtras();
if (extras == null) {
extras = new Bundle();
@ -745,7 +749,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
if (mContentUri != null) {
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) {
data.putInt(ApgService.TARGET, ApgService.TARGET_FILE);

View File

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

View File

@ -142,22 +142,35 @@ public class KeyListActivity extends SherlockFragmentActivity {
mListAdapter = new KeyListAdapter(this, searchString);
mList.setAdapter(mListAdapter);
// handled separately from other actions as it uses intent.setAction()
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
// same as ACTION_IMPORT invoked from a file manager
intent.setAction(ACTION_IMPORT);
}
// Get intent, action
// Intent intent = getIntent();
String action = intent.getAction();
if (ACTION_IMPORT.equals(intent.getAction())) {
if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
mImportFilename = intent.getData().getPath();
} else {
mImportData = intent.getStringExtra(EXTRA_TEXT);
}
importKeys();
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);
}
}
/**
* Handles import action
*
* @param intent
*/
private void handleActionImport(Intent intent) {
if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
mImportFilename = intent.getData().getPath();
} else {
mImportData = intent.getStringExtra(EXTRA_TEXT);
}
importKeys();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {