Merge pull request #2282 from open-keychain/option-self-encrypt
Option self encrypt
This commit is contained in:
@@ -129,7 +129,9 @@ public final class Constants {
|
||||
public static final String USE_NUMKEYPAD_FOR_SECURITY_TOKEN_PIN = "useNumKeypadForYubikeyPin";
|
||||
public static final String ENCRYPT_FILENAMES = "encryptFilenames";
|
||||
public static final String FILE_USE_COMPRESSION = "useFileCompression";
|
||||
public static final String FILE_SELF_ENCRYPT = "fileSelfEncrypt";
|
||||
public static final String TEXT_USE_COMPRESSION = "useTextCompression";
|
||||
public static final String TEXT_SELF_ENCRYPT = "textSelfEncrypt";
|
||||
public static final String USE_ARMOR = "useArmor";
|
||||
// proxy settings
|
||||
public static final String USE_NORMAL_PROXY = "useNormalProxy";
|
||||
|
||||
@@ -87,6 +87,7 @@ public class EncryptFilesFragment
|
||||
public static final String ARG_DELETE_AFTER_ENCRYPT = "delete_after_encrypt";
|
||||
public static final String ARG_ENCRYPT_FILENAMES = "encrypt_filenames";
|
||||
public static final String ARG_USE_COMPRESSION = "use_compression";
|
||||
public static final String ARG_SELF_ENCRYPT = "self_encrypt";
|
||||
public static final String ARG_USE_ASCII_ARMOR = "use_ascii_armor";
|
||||
public static final String ARG_URIS = "uris";
|
||||
|
||||
@@ -96,6 +97,7 @@ public class EncryptFilesFragment
|
||||
|
||||
private boolean mUseArmor;
|
||||
private boolean mUseCompression;
|
||||
private boolean mSelfEncrypt;
|
||||
private boolean mDeleteAfterEncrypt;
|
||||
private boolean mEncryptFilenames;
|
||||
private boolean mHiddenRecipients = false;
|
||||
@@ -176,6 +178,7 @@ public class EncryptFilesFragment
|
||||
outState.putBoolean(ARG_DELETE_AFTER_ENCRYPT, mDeleteAfterEncrypt);
|
||||
outState.putBoolean(ARG_USE_ASCII_ARMOR, mUseArmor);
|
||||
outState.putBoolean(ARG_USE_COMPRESSION, mUseCompression);
|
||||
outState.putBoolean(ARG_SELF_ENCRYPT, mSelfEncrypt);
|
||||
outState.putBoolean(ARG_ENCRYPT_FILENAMES, mEncryptFilenames);
|
||||
|
||||
outState.putParcelableArrayList(ARG_URIS, mFilesAdapter.getAsArrayList());
|
||||
@@ -202,6 +205,12 @@ public class EncryptFilesFragment
|
||||
mUseCompression = prefs.getFilesUseCompression();
|
||||
}
|
||||
|
||||
if (args.containsKey(ARG_SELF_ENCRYPT)) {
|
||||
mSelfEncrypt = args.getBoolean(ARG_SELF_ENCRYPT, true);
|
||||
} else {
|
||||
mSelfEncrypt = prefs.getFilesEncryptToSelf();
|
||||
}
|
||||
|
||||
if (args.containsKey(ARG_ENCRYPT_FILENAMES)) {
|
||||
mEncryptFilenames = args.getBoolean(ARG_ENCRYPT_FILENAMES, false);
|
||||
} else {
|
||||
@@ -335,6 +344,7 @@ public class EncryptFilesFragment
|
||||
menu.findItem(R.id.check_delete_after_encrypt).setChecked(mDeleteAfterEncrypt);
|
||||
menu.findItem(R.id.check_use_armor).setChecked(mUseArmor);
|
||||
menu.findItem(R.id.check_enable_compression).setChecked(mUseCompression);
|
||||
menu.findItem(R.id.check_enable_self_encrypt).setChecked(mSelfEncrypt);
|
||||
menu.findItem(R.id.check_encrypt_filenames).setChecked(mEncryptFilenames);
|
||||
}
|
||||
|
||||
@@ -372,6 +382,10 @@ public class EncryptFilesFragment
|
||||
toggleEnableCompression(item, !item.isChecked());
|
||||
break;
|
||||
}
|
||||
case R.id.check_enable_self_encrypt: {
|
||||
toggleEnableSelfEncrypt(item, !item.isChecked());
|
||||
break;
|
||||
}
|
||||
case R.id.check_encrypt_filenames: {
|
||||
toggleEncryptFilenamesCheck(item, !item.isChecked());
|
||||
break;
|
||||
@@ -421,6 +435,28 @@ public class EncryptFilesFragment
|
||||
|
||||
}
|
||||
|
||||
public void toggleEnableSelfEncrypt(MenuItem item, final boolean selfEncrypt) {
|
||||
|
||||
mSelfEncrypt = selfEncrypt;
|
||||
item.setChecked(selfEncrypt);
|
||||
|
||||
Notify.create(getActivity(), selfEncrypt
|
||||
? R.string.snack_self_encrypt_on
|
||||
: R.string.snack_self_encrypt_off,
|
||||
Notify.LENGTH_LONG, Style.OK, new ActionListener() {
|
||||
@Override
|
||||
public void onAction() {
|
||||
Preferences.getPreferences(getActivity()).setFilesEncryptToSelf(selfEncrypt);
|
||||
Notify.create(getActivity(), selfEncrypt
|
||||
? R.string.snack_self_encrypt_on
|
||||
: R.string.snack_self_encrypt_off,
|
||||
Notify.LENGTH_SHORT, Style.OK, null, R.string.btn_saved)
|
||||
.show(EncryptFilesFragment.this, false);
|
||||
}
|
||||
}, R.string.btn_save_default).show(this);
|
||||
|
||||
}
|
||||
|
||||
public void toggleEnableCompression(MenuItem item, final boolean compress) {
|
||||
|
||||
mUseCompression = compress;
|
||||
@@ -648,7 +684,7 @@ public class EncryptFilesFragment
|
||||
|
||||
data.setEncryptionMasterKeyIds(encryptionKeyIds);
|
||||
data.setSignatureMasterKeyId(signingKeyId);
|
||||
if (signingKeyId != Constants.key.none) {
|
||||
if (signingKeyId != Constants.key.none && mSelfEncrypt) {
|
||||
data.setAdditionalEncryptId(signingKeyId);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -59,11 +59,13 @@ public class EncryptTextFragment
|
||||
|
||||
public static final String ARG_TEXT = "text";
|
||||
public static final String ARG_USE_COMPRESSION = "use_compression";
|
||||
public static final String ARG_SELF_ENCRYPT = "self_encrypt";
|
||||
public static final String ARG_RETURN_PROCESS_TEXT = "return_process_text";
|
||||
|
||||
private boolean mShareAfterEncrypt;
|
||||
private boolean mReturnProcessTextAfterEncrypt;
|
||||
private boolean mUseCompression;
|
||||
private boolean mSelfEncrypt;
|
||||
private boolean mHiddenRecipients = false;
|
||||
|
||||
private String mMessage = "";
|
||||
@@ -128,6 +130,7 @@ public class EncryptTextFragment
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(ARG_USE_COMPRESSION, mUseCompression);
|
||||
outState.putBoolean(ARG_SELF_ENCRYPT, mSelfEncrypt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,13 +145,18 @@ public class EncryptTextFragment
|
||||
|
||||
Bundle args = savedInstanceState == null ? getArguments() : savedInstanceState;
|
||||
|
||||
mUseCompression = args.getBoolean(ARG_USE_COMPRESSION, true);
|
||||
if (args.containsKey(ARG_USE_COMPRESSION)) {
|
||||
mUseCompression = args.getBoolean(ARG_USE_COMPRESSION, true);
|
||||
} else {
|
||||
mUseCompression = prefs.getTextUseCompression();
|
||||
}
|
||||
|
||||
if (args.containsKey(ARG_SELF_ENCRYPT)) {
|
||||
mSelfEncrypt = args.getBoolean(ARG_SELF_ENCRYPT, true);
|
||||
} else {
|
||||
mSelfEncrypt = prefs.getTextSelfEncrypt();
|
||||
}
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
}
|
||||
@@ -159,6 +167,7 @@ public class EncryptTextFragment
|
||||
inflater.inflate(R.menu.encrypt_text_fragment, menu);
|
||||
|
||||
menu.findItem(R.id.check_enable_compression).setChecked(mUseCompression);
|
||||
menu.findItem(R.id.check_enable_self_encrypt).setChecked(mSelfEncrypt);
|
||||
|
||||
if (mReturnProcessTextAfterEncrypt) {
|
||||
menu.findItem(R.id.encrypt_paste).setVisible(true);
|
||||
@@ -174,6 +183,10 @@ public class EncryptTextFragment
|
||||
toggleEnableCompression(item, !item.isChecked());
|
||||
break;
|
||||
}
|
||||
case R.id.check_enable_self_encrypt: {
|
||||
toggleEnableSelfEncrypt(item, !item.isChecked());
|
||||
break;
|
||||
}
|
||||
// case R.id.check_hidden_recipients: {
|
||||
// mHiddenRecipients = item.isChecked();
|
||||
// notifyUpdate();
|
||||
@@ -203,6 +216,28 @@ public class EncryptTextFragment
|
||||
return true;
|
||||
}
|
||||
|
||||
public void toggleEnableSelfEncrypt(MenuItem item, final boolean selfEncrypt) {
|
||||
|
||||
mSelfEncrypt = selfEncrypt;
|
||||
item.setChecked(selfEncrypt);
|
||||
|
||||
Notify.create(getActivity(), selfEncrypt
|
||||
? R.string.snack_self_encrypt_on
|
||||
: R.string.snack_self_encrypt_off,
|
||||
Notify.LENGTH_LONG, Style.OK, new ActionListener() {
|
||||
@Override
|
||||
public void onAction() {
|
||||
Preferences.getPreferences(getActivity()).setTextSelfEncrypt(selfEncrypt);
|
||||
Notify.create(getActivity(), selfEncrypt
|
||||
? R.string.snack_self_encrypt_on
|
||||
: R.string.snack_self_encrypt_off,
|
||||
Notify.LENGTH_SHORT, Style.OK, null, R.string.btn_saved)
|
||||
.show(EncryptTextFragment.this, false);
|
||||
}
|
||||
}, R.string.btn_save_default).show(this);
|
||||
|
||||
}
|
||||
|
||||
public void toggleEnableCompression(MenuItem item, final boolean compress) {
|
||||
|
||||
mUseCompression = compress;
|
||||
@@ -264,7 +299,7 @@ public class EncryptTextFragment
|
||||
|
||||
data.setEncryptionMasterKeyIds(encryptionKeyIds);
|
||||
data.setSignatureMasterKeyId(signingKeyId);
|
||||
if (signingKeyId != Constants.key.none) {
|
||||
if (signingKeyId != Constants.key.none && mSelfEncrypt) {
|
||||
data.setAdditionalEncryptId(signingKeyId);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -197,6 +197,16 @@ public class Preferences {
|
||||
return mSharedPreferences.getBoolean(Pref.FILE_USE_COMPRESSION, true);
|
||||
}
|
||||
|
||||
public void setFilesEncryptToSelf(boolean selfEncrypt) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putBoolean(Pref.FILE_SELF_ENCRYPT, selfEncrypt);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public boolean getFilesEncryptToSelf() {
|
||||
return mSharedPreferences.getBoolean(Pref.FILE_SELF_ENCRYPT, true);
|
||||
}
|
||||
|
||||
public void setTextUseCompression(boolean compress) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putBoolean(Pref.TEXT_USE_COMPRESSION, compress);
|
||||
@@ -207,6 +217,16 @@ public class Preferences {
|
||||
return mSharedPreferences.getBoolean(Pref.TEXT_USE_COMPRESSION, true);
|
||||
}
|
||||
|
||||
public void setTextSelfEncrypt(boolean selfEncrypt) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putBoolean(Pref.TEXT_SELF_ENCRYPT, selfEncrypt);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public boolean getTextSelfEncrypt() {
|
||||
return mSharedPreferences.getBoolean(Pref.TEXT_SELF_ENCRYPT, true);
|
||||
}
|
||||
|
||||
public String getTheme() {
|
||||
return mSharedPreferences.getString(Pref.THEME, Pref.Theme.LIGHT);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,12 @@
|
||||
android:orderInCategory="1"
|
||||
android:checkable="true" />
|
||||
|
||||
<item
|
||||
android:id="@+id/check_enable_self_encrypt"
|
||||
android:title="@string/label_enable_self_encrypt"
|
||||
android:orderInCategory="1"
|
||||
android:checkable="true" />
|
||||
|
||||
<item
|
||||
android:id="@+id/check_encrypt_filenames"
|
||||
android:title="@string/label_encrypt_filenames"
|
||||
|
||||
@@ -31,6 +31,12 @@
|
||||
android:checked="true"
|
||||
android:checkable="true" />
|
||||
|
||||
<item
|
||||
android:id="@+id/check_enable_self_encrypt"
|
||||
android:title="@string/label_enable_self_encrypt"
|
||||
android:orderInCategory="1"
|
||||
android:checked="true"
|
||||
android:checkable="true" />
|
||||
<!--<item-->
|
||||
<!--android:id="@+id/check_hidden_recipients"-->
|
||||
<!--android:title="@string/label_hidden_recipients"-->
|
||||
|
||||
@@ -187,6 +187,7 @@
|
||||
<string name="label_selected_smartpgp_authority_title">"Selected authority"</string>
|
||||
<string name="label_preferred">"preferred"</string>
|
||||
<string name="label_enable_compression">"Enable compression"</string>
|
||||
<string name="label_enable_self_encrypt">"Encrypt to signer"</string>
|
||||
<string name="label_encrypt_filenames">"Encrypt filenames"</string>
|
||||
<string name="label_hidden_recipients">"Hide recipients"</string>
|
||||
<string name="label_smartpgp_verify">SmartPGP: Verify certificates</string>
|
||||
@@ -1603,6 +1604,8 @@
|
||||
<string name="snack_armor_off">"Output encoded as Binary."</string>
|
||||
<string name="snack_compression_on">"Compression <b>enabled</b>."</string>
|
||||
<string name="snack_compression_off">"Compression <b>disabled</b>."</string>
|
||||
<string name="snack_self_encrypt_on">"Encrypt to signer <b>enabled</b>."</string>
|
||||
<string name="snack_self_encrypt_off">"Encrypt to signer <b>disabled</b>."</string>
|
||||
<string name="error_loading_keys">"Error loading keys!"</string>
|
||||
<string name="error_empty_log">"(error, empty log)"</string>
|
||||
<string name="error_reading_text">"Could not read input to decrypt!"</string>
|
||||
|
||||
Reference in New Issue
Block a user