settings code cleanup

This commit is contained in:
Dominik Schürmann 2014-09-21 11:02:29 +02:00
parent 0335b99516
commit 08ad0cb305

View File

@ -88,6 +88,9 @@ public class PreferencesActivity extends PreferenceActivity {
initializeEncryptionAlgorithm( initializeEncryptionAlgorithm(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM)); (IntegerListPreference) findPreference(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM));
initializeHashAlgorithm(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_HASH_ALGORITHM));
int[] valueIds = new int[]{ int[] valueIds = new int[]{
CompressionAlgorithmTags.UNCOMPRESSED, CompressionAlgorithmTags.UNCOMPRESSED,
CompressionAlgorithmTags.ZIP, CompressionAlgorithmTags.ZIP,
@ -104,13 +107,9 @@ public class PreferencesActivity extends PreferenceActivity {
values[i] = "" + valueIds[i]; values[i] = "" + valueIds[i];
} }
initializeHashAlgorithm(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_HASH_ALGORITHM),
valueIds, entries, values);
initializeMessageCompression( initializeMessageCompression(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_MESSAGE_COMPRESSION), (IntegerListPreference) findPreference(Constants.Pref.DEFAULT_MESSAGE_COMPRESSION),
valueIds, entries, values); entries, values);
initializeFileCompression( initializeFileCompression(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_FILE_COMPRESSION), (IntegerListPreference) findPreference(Constants.Pref.DEFAULT_FILE_COMPRESSION),
@ -235,6 +234,9 @@ public class PreferencesActivity extends PreferenceActivity {
initializeEncryptionAlgorithm( initializeEncryptionAlgorithm(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM)); (IntegerListPreference) findPreference(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM));
initializeHashAlgorithm(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_HASH_ALGORITHM));
int[] valueIds = new int[]{ int[] valueIds = new int[]{
CompressionAlgorithmTags.UNCOMPRESSED, CompressionAlgorithmTags.UNCOMPRESSED,
CompressionAlgorithmTags.ZIP, CompressionAlgorithmTags.ZIP,
@ -254,13 +256,9 @@ public class PreferencesActivity extends PreferenceActivity {
values[i] = "" + valueIds[i]; values[i] = "" + valueIds[i];
} }
initializeHashAlgorithm(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_HASH_ALGORITHM),
valueIds, entries, values);
initializeMessageCompression( initializeMessageCompression(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_MESSAGE_COMPRESSION), (IntegerListPreference) findPreference(Constants.Pref.DEFAULT_MESSAGE_COMPRESSION),
valueIds, entries, values); entries, values);
initializeFileCompression( initializeFileCompression(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_FILE_COMPRESSION), (IntegerListPreference) findPreference(Constants.Pref.DEFAULT_FILE_COMPRESSION),
@ -324,14 +322,13 @@ public class PreferencesActivity extends PreferenceActivity {
}); });
} }
private static void initializeHashAlgorithm private static void initializeHashAlgorithm(final IntegerListPreference mHashAlgorithm) {
(final IntegerListPreference mHashAlgorithm, int[] valueIds, String[] entries, String[] values) { int[] valueIds = new int[]{HashAlgorithmTags.RIPEMD160,
valueIds = new int[]{HashAlgorithmTags.RIPEMD160,
HashAlgorithmTags.SHA1, HashAlgorithmTags.SHA224, HashAlgorithmTags.SHA256, HashAlgorithmTags.SHA1, HashAlgorithmTags.SHA224, HashAlgorithmTags.SHA256,
HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512,}; HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512,};
entries = new String[]{"RIPEMD-160", "SHA-1", "SHA-224", "SHA-256", "SHA-384", String[] entries = new String[]{"RIPEMD-160", "SHA-1", "SHA-224", "SHA-256", "SHA-384",
"SHA-512",}; "SHA-512",};
values = new String[valueIds.length]; String[] values = new String[valueIds.length];
for (int i = 0; i < values.length; ++i) { for (int i = 0; i < values.length; ++i) {
values[i] = "" + valueIds[i]; values[i] = "" + valueIds[i];
} }
@ -349,9 +346,8 @@ public class PreferencesActivity extends PreferenceActivity {
}); });
} }
private static void initializeMessageCompression( private static void initializeMessageCompression(final IntegerListPreference mMessageCompression,
final IntegerListPreference mMessageCompression, String[] entries, String[] values) {
int[] valueIds, String[] entries, String[] values) {
mMessageCompression.setEntries(entries); mMessageCompression.setEntries(entries);
mMessageCompression.setEntryValues(values); mMessageCompression.setEntryValues(values);
mMessageCompression.setValue("" + sPreferences.getDefaultMessageCompression()); mMessageCompression.setValue("" + sPreferences.getDefaultMessageCompression());