Allow encrypt of filenames via overflow menu

This commit is contained in:
Dominik Schürmann 2015-03-16 17:00:53 +01:00
parent 916ff0e0fa
commit a5271bf229
7 changed files with 44 additions and 11 deletions

View File

@ -29,6 +29,7 @@ public interface EncryptActivityInterface {
public boolean isUseArmor(); public boolean isUseArmor();
public boolean isUseCompression(); public boolean isUseCompression();
public boolean isEncryptFilenames();
public long getSignatureKey(); public long getSignatureKey();
public long[] getEncryptionKeys(); public long[] getEncryptionKeys();

View File

@ -70,6 +70,7 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
private boolean mUseCompression = true; private boolean mUseCompression = true;
private boolean mDeleteAfterEncrypt = false; private boolean mDeleteAfterEncrypt = false;
private boolean mShareAfterEncrypt = false; private boolean mShareAfterEncrypt = false;
private boolean mEncryptFilenames = true;
private ArrayList<Uri> mInputUris; private ArrayList<Uri> mInputUris;
private ArrayList<Uri> mOutputUris; private ArrayList<Uri> mOutputUris;
private String mMessage = ""; private String mMessage = "";
@ -88,6 +89,11 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
return mUseCompression; return mUseCompression;
} }
@Override
public boolean isEncryptFilenames() {
return mEncryptFilenames;
}
@Override @Override
public long getSignatureKey() { public long getSignatureKey() {
return mSigningKeyId; return mSigningKeyId;
@ -371,6 +377,12 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
notifyUpdate(); notifyUpdate();
break; break;
} }
case R.id.encrypt_filenames: {
mEncryptFilenames = item.isChecked();
notifyUpdate();
break;
}
default: { default: {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }

View File

@ -137,17 +137,17 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
throw new IllegalStateException(); throw new IllegalStateException();
} }
Uri inputUri = mEncryptInterface.getInputUris().get(0); Uri inputUri = mEncryptInterface.getInputUris().get(0);
String targetName =
(mEncryptInterface.isEncryptFilenames() ? "1" : FileHelper.getFilename(getActivity(), inputUri))
+ (mEncryptInterface.isUseArmor() ? ".asc" : ".gpg");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
File file = new File(inputUri.getPath()); File file = new File(inputUri.getPath());
File parentDir = file.exists() ? file.getParentFile() : Constants.Path.APP_DIR; File parentDir = file.exists() ? file.getParentFile() : Constants.Path.APP_DIR;
String targetName = FileHelper.getFilename(getActivity(), inputUri) +
(mEncryptInterface.isUseArmor() ? ".asc" : ".gpg");
File targetFile = new File(parentDir, targetName); File targetFile = new File(parentDir, targetName);
FileHelper.saveFile(this, getString(R.string.title_encrypt_to_file), FileHelper.saveFile(this, getString(R.string.title_encrypt_to_file),
getString(R.string.specify_file_to_encrypt_to), targetFile, REQUEST_CODE_OUTPUT); getString(R.string.specify_file_to_encrypt_to), targetFile, REQUEST_CODE_OUTPUT);
} else { } else {
FileHelper.saveDocument(this, "*/*", FileHelper.getFilename(getActivity(), inputUri) + FileHelper.saveDocument(this, "*/*", targetName, REQUEST_CODE_OUTPUT);
(mEncryptInterface.isUseArmor() ? ".asc" : ".gpg"), REQUEST_CODE_OUTPUT);
} }
} }
@ -158,10 +158,13 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
} }
if (share) { if (share) {
mEncryptInterface.getOutputUris().clear(); mEncryptInterface.getOutputUris().clear();
int filenameCounter = 1;
for (Uri uri : mEncryptInterface.getInputUris()) { for (Uri uri : mEncryptInterface.getInputUris()) {
String targetName = FileHelper.getFilename(getActivity(), uri) + String targetName =
(mEncryptInterface.isUseArmor() ? ".asc" : ".gpg"); (mEncryptInterface.isEncryptFilenames() ? String.valueOf(filenameCounter) : FileHelper.getFilename(getActivity(), uri))
+ (mEncryptInterface.isUseArmor() ? ".asc" : ".gpg");
mEncryptInterface.getOutputUris().add(TemporaryStorageProvider.createFile(getActivity(), targetName)); mEncryptInterface.getOutputUris().add(TemporaryStorageProvider.createFile(getActivity(), targetName));
filenameCounter++;
} }
mEncryptInterface.startEncrypt(true); mEncryptInterface.startEncrypt(true);
} else { } else {

View File

@ -82,6 +82,11 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
return true; return true;
} }
@Override
public boolean isEncryptFilenames() {
return false;
}
@Override @Override
public boolean isUseCompression() { public boolean isUseCompression() {
return mUseCompression; return mUseCompression;

View File

@ -18,17 +18,27 @@
android:id="@+id/check_use_symmetric" android:id="@+id/check_use_symmetric"
android:title="@string/label_symmetric" android:title="@string/label_symmetric"
android:checkable="true" /> android:checkable="true" />
<item
android:id="@+id/check_use_armor"
android:title="@string/label_file_ascii_armor"
android:checkable="true" />
<item <item
android:id="@+id/check_delete_after_encrypt" android:id="@+id/check_delete_after_encrypt"
android:title="@string/label_delete_after_encryption" android:title="@string/label_delete_after_encryption"
android:checkable="true" /> android:checkable="true" />
<item <item
android:id="@+id/check_enable_compression" android:id="@+id/check_enable_compression"
android:title="@string/label_enable_compression" android:title="@string/label_enable_compression"
android:checked="true" android:checked="true"
android:checkable="true" /> android:checkable="true" />
<item
android:id="@+id/encrypt_filenames"
android:title="@string/label_encrypt_filenames"
android:checked="true"
android:checkable="true" />
<item
android:id="@+id/check_use_armor"
android:title="@string/label_file_ascii_armor"
android:checkable="true" />
</menu> </menu>

View File

@ -18,6 +18,7 @@
android:id="@+id/check_use_symmetric" android:id="@+id/check_use_symmetric"
android:title="@string/label_symmetric" android:title="@string/label_symmetric"
android:checkable="true" /> android:checkable="true" />
<item <item
android:id="@+id/check_enable_compression" android:id="@+id/check_enable_compression"
android:title="@string/label_enable_compression" android:title="@string/label_enable_compression"

View File

@ -141,7 +141,7 @@
<string name="label_label_use_default_yubikey_pin_summary">"Uses default PIN (123456) to access YubiKeys over NFC"</string> <string name="label_label_use_default_yubikey_pin_summary">"Uses default PIN (123456) to access YubiKeys over NFC"</string>
<string name="label_asymmetric_from">"Signed by:"</string> <string name="label_asymmetric_from">"Signed by:"</string>
<string name="label_to">"Encrypt to:"</string> <string name="label_to">"Encrypt to:"</string>
<string name="label_delete_after_encryption">"Delete file after encryption"</string> <string name="label_delete_after_encryption">"Delete files after encryption"</string>
<string name="label_delete_after_decryption">"Delete after decryption"</string> <string name="label_delete_after_decryption">"Delete after decryption"</string>
<string name="label_encryption_algorithm">"Encryption algorithm"</string> <string name="label_encryption_algorithm">"Encryption algorithm"</string>
<string name="label_hash_algorithm">"Hash algorithm"</string> <string name="label_hash_algorithm">"Hash algorithm"</string>
@ -167,6 +167,7 @@
<string name="label_first_keyserver_is_used">"(First keyserver listed is preferred)"</string> <string name="label_first_keyserver_is_used">"(First keyserver listed is preferred)"</string>
<string name="label_preferred">"preferred"</string> <string name="label_preferred">"preferred"</string>
<string name="label_enable_compression">"Enable compression"</string> <string name="label_enable_compression">"Enable compression"</string>
<string name="label_encrypt_filenames">"Encrypt filenames"</string>
<string name="user_id_no_name">"&lt;no name&gt;"</string> <string name="user_id_no_name">"&lt;no name&gt;"</string>
<string name="none">"&lt;none&gt;"</string> <string name="none">"&lt;none&gt;"</string>