Changed layout to have source on bottom in encrypt and decrypt, fixes for decrypt methods

This commit is contained in:
Dominik 2012-11-22 12:12:06 +01:00
parent 8abfb5a6f4
commit 8f686e67f3
6 changed files with 358 additions and 351 deletions

View File

@ -34,6 +34,57 @@
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="10dp" > android:paddingRight="10dp" >
<LinearLayout
android:id="@+id/signature"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="horizontal"
android:padding="4dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/ic_signature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/signed_large" />
<ImageView
android:id="@+id/ic_signature_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/overlay_error" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dip" >
<TextView
android:id="@+id/mainUserId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Main User Id"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/mainUserIdRest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Main User Id Rest"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -124,57 +175,6 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ViewFlipper> </ViewFlipper>
<LinearLayout
android:id="@+id/signature"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="horizontal"
android:padding="4dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/ic_signature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/signed_large" />
<ImageView
android:id="@+id/ic_signature_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/overlay_error" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dip" >
<TextView
android:id="@+id/mainUserId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Main User Id"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/mainUserIdRest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Main User Id Rest"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -27,132 +27,6 @@
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="10dp" > android:paddingRight="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp" >
<ImageView
android:id="@+id/sourcePrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_previous" />
<TextView
android:id="@+id/sourceLabel"
style="@style/SectionHeader"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:text="@string/label_message"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/sourceNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_next" />
</LinearLayout>
<ViewFlipper
android:id="@+id/source"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<LinearLayout
android:id="@+id/sourceMessage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="4dp" >
<EditText
android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:inputType="text|textCapSentences|textMultiLine|textLongMessage" />
</LinearLayout>
<LinearLayout
android:id="@+id/sourceFile"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="4dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/filename"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textNoSuggestions" />
<ImageButton
android:id="@+id/btn_browse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_filebrowser" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/label_fileCompression"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:paddingRight="10dip"
android:text="@string/label_fileCompression"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Spinner
android:id="@+id/fileCompression"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/deleteAfterEncryption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/label_deleteAfterEncryption" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/asciiArmour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/label_asciiArmour" />
</LinearLayout>
</LinearLayout>
</ViewFlipper>
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -301,6 +175,132 @@
</TableRow> </TableRow>
</TableLayout> </TableLayout>
</ViewFlipper> </ViewFlipper>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp" >
<ImageView
android:id="@+id/sourcePrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_previous" />
<TextView
android:id="@+id/sourceLabel"
style="@style/SectionHeader"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:text="@string/label_message"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/sourceNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_next" />
</LinearLayout>
<ViewFlipper
android:id="@+id/source"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<LinearLayout
android:id="@+id/sourceMessage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="4dp" >
<EditText
android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:inputType="text|textCapSentences|textMultiLine|textLongMessage" />
</LinearLayout>
<LinearLayout
android:id="@+id/sourceFile"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="4dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/filename"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textNoSuggestions" />
<ImageButton
android:id="@+id/btn_browse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_filebrowser" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/label_fileCompression"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:paddingRight="10dip"
android:text="@string/label_fileCompression"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Spinner
android:id="@+id/fileCompression"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/deleteAfterEncryption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/label_deleteAfterEncryption" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/asciiArmour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/label_asciiArmour" />
</LinearLayout>
</LinearLayout>
</ViewFlipper>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -112,7 +112,7 @@
<string name="label_passPhrase">Passphrase</string> <string name="label_passPhrase">Passphrase</string>
<string name="label_passPhraseAgain">Again</string> <string name="label_passPhraseAgain">Again</string>
<string name="label_algorithm">Algorithm</string> <string name="label_algorithm">Algorithm</string>
<string name="label_asciiArmour">ASCII Armour</string> <string name="label_asciiArmour">ASCII Armor</string>
<string name="label_selectPublicKeys">Public Key(s)</string> <string name="label_selectPublicKeys">Public Key(s)</string>
<string name="label_deleteAfterEncryption">Delete After Encryption</string> <string name="label_deleteAfterEncryption">Delete After Encryption</string>
<string name="label_deleteAfterDecryption">Delete After Decryption</string> <string name="label_deleteAfterDecryption">Delete After Decryption</string>

View File

@ -379,10 +379,9 @@ public class ApgProvider extends ContentProvider {
qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "(" qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "("
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "." + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
+ KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "." + KeysColumns.KEY_RING_ROW_ID + ") " + " INNER JOIN " + Tables.USER_IDS + " ON "
+ KeysColumns.IS_MASTER_KEY + " = '1') " + " INNER JOIN " + Tables.USER_IDS + "(" + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.USER_IDS + "."
+ " ON " + "(" + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.USER_IDS + UserIdsColumns.KEY_RING_ROW_ID + " AND " + Tables.USER_IDS + "."
+ "." + UserIdsColumns.KEY_RING_ROW_ID + " AND " + Tables.USER_IDS + "."
+ UserIdsColumns.RANK + " = '0')"); + UserIdsColumns.RANK + " = '0')");
qb.setProjectionMap(getProjectionMapForKeyRings()); qb.setProjectionMap(getProjectionMapForKeyRings());

View File

@ -70,10 +70,13 @@ public class DecryptActivity extends SherlockFragmentActivity {
// possible intent actions for this activity // possible intent actions for this activity
public static final String ACTION_DECRYPT = Constants.INTENT_PREFIX + "DECRYPT"; public static final String ACTION_DECRYPT = Constants.INTENT_PREFIX + "DECRYPT";
public static final String ACTION_DECRYPT_FILE = Constants.INTENT_PREFIX + "DECRYPT_FILE";
public static final String ACTION_DECRYPT_AND_RETURN = Constants.INTENT_PREFIX public static final String ACTION_DECRYPT_AND_RETURN = Constants.INTENT_PREFIX
+ "DECRYPT_AND_RETURN"; + "DECRYPT_AND_RETURN";
public static final String ACTION_DECRYPT_FILE = Constants.INTENT_PREFIX + "DECRYPT_FILE";
public static final String ACTION_DECRYPT_STREAM_AND_RETURN = Constants.INTENT_PREFIX
+ "DECRYPT_STREAM_AND_RETURN";
// possible extra keys // possible extra keys
public static final String EXTRA_TEXT = "text"; public static final String EXTRA_TEXT = "text";
public static final String EXTRA_DATA = "data"; public static final String EXTRA_DATA = "data";
@ -126,6 +129,8 @@ public class DecryptActivity extends SherlockFragmentActivity {
private boolean mLookupUnknownKey = true; private boolean mLookupUnknownKey = true;
private boolean mDecryptImmediately = false;
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
@ -169,20 +174,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
} }
} }
@Override private void initView() {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// check permissions for intent actions without user interaction
String[] restrictedActions = new String[] { ACTION_DECRYPT_AND_RETURN };
OtherHelper.checkPackagePermissionForActions(this, this.getCallingPackage(),
Constants.PERMISSION_ACCESS_API, getIntent().getAction(), restrictedActions);
setContentView(R.layout.decrypt);
// set actionbar without home button if called from another app
OtherHelper.setActionBarBackButton(this);
mSource = (ViewFlipper) findViewById(R.id.source); mSource = (ViewFlipper) findViewById(R.id.source);
mSourceLabel = (TextView) findViewById(R.id.sourceLabel); mSourceLabel = (TextView) findViewById(R.id.sourceLabel);
mSourcePrevious = (ImageView) findViewById(R.id.sourcePrevious); mSourcePrevious = (ImageView) findViewById(R.id.sourcePrevious);
@ -246,68 +238,27 @@ public class DecryptActivity extends SherlockFragmentActivity {
while (mSource.getCurrentView().getId() != R.id.sourceMessage) { while (mSource.getCurrentView().getId() != R.id.sourceMessage) {
mSource.showNext(); mSource.showNext();
} }
boolean decryptImmediately = false;
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_VIEW.equals(action)) {
// Android's Action when opening file associated to APG (see AndroidManifest.xml)
// This gets the Uri, where an inputStream can be opened from
mContentUri = intent.getData();
// TODO: old implementation of ACTION_VIEW. Is this used in K9?
// Uri uri = mIntent.getData();
// try {
// InputStream attachment = getContentResolver().openInputStream(uri);
// ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
// byte bytes[] = new byte[1 << 16];
// int length;
// while ((length = attachment.read(bytes)) > 0) {
// byteOut.write(bytes, 0, length);
// }
// byteOut.close();
// String data = new String(byteOut.toByteArray());
// mMessage.setText(data);
// } catch (FileNotFoundException e) {
// // ignore, then
// } catch (IOException e) {
// // ignore, then
// }
// same as ACTION_DECRYPT_FILE but decrypt it immediately
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);
handleActionDecrypt(intent);
decryptImmediately = true;
}
} else {
// binary via content provider (could also be files)
Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
mContentUri = uri;
}
}
} else if (ACTION_DECRYPT.equals(action)) {
handleActionDecrypt(intent);
} else if (ACTION_DECRYPT_FILE.equals(action)) {
handleActionDecryptFile(intent);
} else if (ACTION_DECRYPT_AND_RETURN.equals(action)) {
handleActionDecryptAndReturn(intent);
} }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// check permissions for intent actions without user interaction
String[] restrictedActions = new String[] { ACTION_DECRYPT_AND_RETURN };
OtherHelper.checkPackagePermissionForActions(this, this.getCallingPackage(),
Constants.PERMISSION_ACCESS_API, getIntent().getAction(), restrictedActions);
setContentView(R.layout.decrypt);
// set actionbar without home button if called from another app
OtherHelper.setActionBarBackButton(this);
initView();
// Handle intent actions
handleActions(getIntent());
if (mSource.getCurrentView().getId() == R.id.sourceMessage if (mSource.getCurrentView().getId() == R.id.sourceMessage
&& mMessage.getText().length() == 0) { && mMessage.getText().length() == 0) {
@ -364,7 +315,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
updateSource(); updateSource();
if (decryptImmediately if (mDecryptImmediately
|| (mSource.getCurrentView().getId() == R.id.sourceMessage && (mMessage.getText() || (mSource.getCurrentView().getId() == R.id.sourceMessage && (mMessage.getText()
.length() > 0 || mDataBytes != null || mContentUri != null))) { .length() > 0 || mDataBytes != null || mContentUri != null))) {
decryptClicked(); decryptClicked();
@ -372,21 +323,78 @@ public class DecryptActivity extends SherlockFragmentActivity {
} }
/** /**
* Handles activity intent with ACTION_DECRYPT * Handles all actions with this intent
* *
* @param intent * @param intent
*/ */
private void handleActionDecrypt(Intent intent) { private void handleActions(Intent intent) {
Log.d(Constants.TAG, "Apg Intent DECRYPT startet"); String action = intent.getAction();
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
String type = intent.getType();
Uri uri = intent.getData();
if (extras == null) { if (extras == null) {
Log.d(Constants.TAG, "extra bundle was null");
extras = new Bundle(); extras = new Bundle();
} else {
Log.d(Constants.TAG, "got extras");
} }
/*
* Android's Action
*/
if (Intent.ACTION_SEND.equals(action) && type != null) {
// When sending to APG Encrypt via share menu
if ("text/plain".equals(type)) {
// Plain text
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// handle like normal text decryption, override action and extras to later
// execute ACTION_DECRYPT in main actions
extras.putString(EXTRA_TEXT, sharedText);
action = ACTION_DECRYPT;
}
} else {
// Binary via content provider (could also be files)
// override uri to get stream from send
uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
action = ACTION_DECRYPT_FILE;
}
} else if (Intent.ACTION_VIEW.equals(action)) {
// Android's Action when opening file associated to APG (see AndroidManifest.xml)
// override action
action = ACTION_DECRYPT_FILE;
// EVERYTHING ELSE IS OLD CODE
// This gets the Uri, where an inputStream can be opened from
// mContentUri = intent.getData();
// TODO: old implementation of ACTION_VIEW. Is this used in K9?
// Uri uri = mIntent.getData();
// try {
// InputStream attachment = getContentResolver().openInputStream(uri);
// ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
// byte bytes[] = new byte[1 << 16];
// int length;
// while ((length = attachment.read(bytes)) > 0) {
// byteOut.write(bytes, 0, length);
// }
// byteOut.close();
// String data = new String(byteOut.toByteArray());
// mMessage.setText(data);
// } catch (FileNotFoundException e) {
// // ignore, then
// } catch (IOException e) {
// // ignore, then
// }
// same as ACTION_DECRYPT_FILE but decrypt it immediately
// handleActionDecryptFile(intent);
// mDecryptImmediately = true;
}
/**
* Main Actions
*/
if (ACTION_DECRYPT.equals(action)) {
mDataBytes = extras.getByteArray(EXTRA_DATA); mDataBytes = extras.getByteArray(EXTRA_DATA);
String textData = null; String textData = null;
if (mDataBytes == null) { if (mDataBytes == null) {
@ -423,15 +431,12 @@ public class DecryptActivity extends SherlockFragmentActivity {
} }
mReplyTo = extras.getString(EXTRA_REPLY_TO); mReplyTo = extras.getString(EXTRA_REPLY_TO);
mSubject = extras.getString(EXTRA_SUBJECT); mSubject = extras.getString(EXTRA_SUBJECT);
} } else if (ACTION_DECRYPT_FILE.equals(action)) {
// get file path from uri
String path = FileHelper.getPath(this, uri);
/** if (path != null) {
* Handles activity intent with ACTION_DECRYPT_FILE mInputFilename = path;
*
* @param intent
*/
private void handleActionDecryptFile(Intent intent) {
mInputFilename = intent.getData().getPath();
mFilename.setText(mInputFilename); mFilename.setText(mInputFilename);
guessOutputFilename(); guessOutputFilename();
mSource.setInAnimation(null); mSource.setInAnimation(null);
@ -439,19 +444,15 @@ public class DecryptActivity extends SherlockFragmentActivity {
while (mSource.getCurrentView().getId() != R.id.sourceFile) { while (mSource.getCurrentView().getId() != R.id.sourceFile) {
mSource.showNext(); mSource.showNext();
} }
} else {
Log.e(Constants.TAG,
"Direct binary data without actual file in filesystem is not supported. This is only supported by ACTION_DECRYPT_STREAM_AND_RETURN.");
Toast.makeText(this, R.string.error_onlyFilesAreSupported, Toast.LENGTH_LONG)
.show();
// end activity
finish();
} }
} else if (ACTION_DECRYPT_AND_RETURN.equals(action)) {
/**
* Handles activity intent with ACTION_DECRYPT_AND_RETURN
*
* @param intent
*/
private void handleActionDecryptAndReturn(Intent intent) {
Bundle extras = intent.getExtras();
if (extras == null) {
extras = new Bundle();
}
mReturnBinary = extras.getBoolean(EXTRA_BINARY, false); mReturnBinary = extras.getBoolean(EXTRA_BINARY, false);
if (mContentUri == null) { if (mContentUri == null) {
@ -480,6 +481,9 @@ public class DecryptActivity extends SherlockFragmentActivity {
} }
} }
mReturnResult = true; mReturnResult = true;
} else if (ACTION_DECRYPT_STREAM_AND_RETURN.equals(action)) {
// TODO: Implement decrypt stream
}
} }
private void guessOutputFilename() { private void guessOutputFilename() {

View File

@ -95,7 +95,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
private long mEncryptionKeyIds[] = null; private long mEncryptionKeyIds[] = null;
private boolean mReturnResult = false; private boolean mEncryptImmediately = false;
private EditText mMessage = null; private EditText mMessage = null;
private Button mSelectKeysButton = null; private Button mSelectKeysButton = null;
@ -213,7 +213,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
updateSource(); updateSource();
updateMode(); updateMode();
if (mReturnResult) { if (mEncryptImmediately) {
mSourcePrevious.setClickable(false); mSourcePrevious.setClickable(false);
mSourcePrevious.setEnabled(false); mSourcePrevious.setEnabled(false);
mSourcePrevious.setVisibility(View.INVISIBLE); mSourcePrevious.setVisibility(View.INVISIBLE);
@ -228,7 +228,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
updateActionBarButtons(); updateActionBarButtons();
if (mReturnResult if (mEncryptImmediately
&& (mMessage.getText().length() > 0 || mData != null) && (mMessage.getText().length() > 0 || mData != null)
&& ((mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0) || mSecretKeyId != 0)) { && ((mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0) || mSecretKeyId != 0)) {
encryptClicked(); encryptClicked();
@ -250,20 +250,23 @@ public class EncryptActivity extends SherlockFragmentActivity {
extras = new Bundle(); extras = new Bundle();
} }
/*
* Android's Action
*/
if (Intent.ACTION_SEND.equals(action) && type != null) { if (Intent.ACTION_SEND.equals(action) && type != null) {
// Android's Action when sending to APG Encrypt // When sending to APG Encrypt via share menu
if ("text/plain".equals(type)) { if ("text/plain".equals(type)) {
// plain text // Plain text
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) { if (sharedText != null) {
// handle like normal text encryption, override action and extras // handle like normal text encryption, override action and extras to later
action = ACTION_ENCRYPT; // execute ACTION_ENCRYPT in main actions
extras.putString(EXTRA_TEXT, sharedText); extras.putString(EXTRA_TEXT, sharedText);
extras.putBoolean(EXTRA_ASCII_ARMOUR, true); extras.putBoolean(EXTRA_ASCII_ARMOUR, true);
action = ACTION_ENCRYPT;
} }
} else { } else {
// files via content provider, override uri and action // Files via content provider, override uri and action
uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
action = ACTION_ENCRYPT_FILE; action = ACTION_ENCRYPT_FILE;
} }
@ -271,7 +274,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
if (ACTION_ENCRYPT_AND_RETURN.equals(action) if (ACTION_ENCRYPT_AND_RETURN.equals(action)
|| ACTION_GENERATE_SIGNATURE_AND_RETURN.equals(action)) { || ACTION_GENERATE_SIGNATURE_AND_RETURN.equals(action)) {
mReturnResult = true; mEncryptImmediately = true;
} }
if (ACTION_GENERATE_SIGNATURE_AND_RETURN.equals(action)) { if (ACTION_GENERATE_SIGNATURE_AND_RETURN.equals(action)) {
@ -299,6 +302,9 @@ public class EncryptActivity extends SherlockFragmentActivity {
// preselect keys given by intent // preselect keys given by intent
preselectKeys(signatureKeyId, encryptionKeyIds); preselectKeys(signatureKeyId, encryptionKeyIds);
/**
* Main Actions
*/
if (ACTION_ENCRYPT.equals(action) || ACTION_ENCRYPT_AND_RETURN.equals(action) if (ACTION_ENCRYPT.equals(action) || ACTION_ENCRYPT_AND_RETURN.equals(action)
|| ACTION_GENERATE_SIGNATURE_AND_RETURN.equals(action)) { || ACTION_GENERATE_SIGNATURE_AND_RETURN.equals(action)) {
if (textData != null) { if (textData != null) {
@ -330,10 +336,8 @@ public class EncryptActivity extends SherlockFragmentActivity {
// end activity // end activity
finish(); finish();
} }
} else if (ACTION_ENCRYPT_STREAM_AND_RETURN.equals(action)) { } else if (ACTION_ENCRYPT_STREAM_AND_RETURN.equals(action)) {
// use mIntentDataUri to encrypt any stream and return // TODO: Set mStreamAndReturnUri that is used later to encrypt a stream!
// TODO
mStreamAndReturnUri = null; mStreamAndReturnUri = null;
} }
@ -461,7 +465,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
mSourceLabel.setText(R.string.label_message); mSourceLabel.setText(R.string.label_message);
if (mMode.getCurrentView().getId() == R.id.modeSymmetric) { if (mMode.getCurrentView().getId() == R.id.modeSymmetric) {
if (mReturnResult) { if (mEncryptImmediately) {
setActionbarButtons(true, R.string.btn_encrypt, false, 0); setActionbarButtons(true, R.string.btn_encrypt, false, 0);
} else { } else {
setActionbarButtons(true, R.string.btn_encryptAndEmail, true, setActionbarButtons(true, R.string.btn_encryptAndEmail, true,
@ -472,7 +476,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
if (mSecretKeyId == 0) { if (mSecretKeyId == 0) {
setActionbarButtons(false, 0, false, 0); setActionbarButtons(false, 0, false, 0);
} else { } else {
if (mReturnResult) { if (mEncryptImmediately) {
setActionbarButtons(true, R.string.btn_sign, false, 0); setActionbarButtons(true, R.string.btn_sign, false, 0);
} else { } else {
setActionbarButtons(true, R.string.btn_signAndEmail, true, setActionbarButtons(true, R.string.btn_signAndEmail, true,
@ -480,7 +484,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
} }
} }
} else { } else {
if (mReturnResult) { if (mEncryptImmediately) {
setActionbarButtons(true, R.string.btn_encrypt, false, 0); setActionbarButtons(true, R.string.btn_encrypt, false, 0);
} else { } else {
setActionbarButtons(true, R.string.btn_encryptAndEmail, true, setActionbarButtons(true, R.string.btn_encryptAndEmail, true,
@ -716,7 +720,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
data.putByteArray(ApgIntentService.MESSAGE_BYTES, mData); data.putByteArray(ApgIntentService.MESSAGE_BYTES, mData);
} else { } else {
String message = mMessage.getText().toString(); String message = mMessage.getText().toString();
if (signOnly && !mReturnResult) { if (signOnly && !mEncryptImmediately) {
fixBadCharactersForGmail(message); fixBadCharactersForGmail(message);
} }
data.putByteArray(ApgIntentService.MESSAGE_BYTES, message.getBytes()); data.putByteArray(ApgIntentService.MESSAGE_BYTES, message.getBytes());
@ -759,7 +763,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
break; break;
case Id.target.email: case Id.target.email:
if (mReturnResult) { if (mEncryptImmediately) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtras(data); intent.putExtras(data);
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);