mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
Use underscore in extras, cleanup code
This commit is contained in:
parent
4ca7a12751
commit
75672fa5b3
@ -19,7 +19,6 @@ package org.sufficientlysecure.keychain.helper;
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
@ -27,7 +26,6 @@ import org.spongycastle.openpgp.PGPKeyRing;
|
|||||||
import org.spongycastle.openpgp.PGPObjectFactory;
|
import org.spongycastle.openpgp.PGPObjectFactory;
|
||||||
import org.spongycastle.openpgp.PGPSecretKey;
|
import org.spongycastle.openpgp.PGPSecretKey;
|
||||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.spongycastle.openpgp.PGPUtil;
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
|
@ -24,21 +24,17 @@ import java.util.Locale;
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||||
import org.spongycastle.openpgp.PGPPrivateKey;
|
|
||||||
import org.spongycastle.openpgp.PGPPublicKey;
|
import org.spongycastle.openpgp.PGPPublicKey;
|
||||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.spongycastle.openpgp.PGPSecretKey;
|
import org.spongycastle.openpgp.PGPSecretKey;
|
||||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.spongycastle.openpgp.PGPSignature;
|
import org.spongycastle.openpgp.PGPSignature;
|
||||||
import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
|
import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
|
||||||
import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor;
|
|
||||||
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
|
|
||||||
import org.spongycastle.openpgp.PGPException;
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
@ -487,7 +483,7 @@ public class PgpHelper {
|
|||||||
PGPSecretKey secretKey = ProviderHelper.getPGPSecretKeyByKeyId(context, keyId);
|
PGPSecretKey secretKey = ProviderHelper.getPGPSecretKeyByKeyId(context, keyId);
|
||||||
if (secretKey == null) {
|
if (secretKey == null) {
|
||||||
Log.e(Constants.TAG, "Key could not be found!");
|
Log.e(Constants.TAG, "Key could not be found!");
|
||||||
return false; //could be a public key, assume it is not empty
|
return false; // could be a public key, assume it is not empty
|
||||||
}
|
}
|
||||||
return isSecretKeyPrivateEmpty(secretKey);
|
return isSecretKeyPrivateEmpty(secretKey);
|
||||||
}
|
}
|
||||||
|
@ -99,93 +99,93 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
|||||||
public static final int TARGET_STREAM = 3;
|
public static final int TARGET_STREAM = 3;
|
||||||
|
|
||||||
// encrypt
|
// encrypt
|
||||||
public static final String ENCRYPT_SECRET_KEY_ID = "secretKeyId";
|
public static final String ENCRYPT_SECRET_KEY_ID = "secret_key_id";
|
||||||
public static final String ENCRYPT_USE_ASCII_AMOR = "useAsciiAmor";
|
public static final String ENCRYPT_USE_ASCII_ARMOR = "use_ascii_armor";
|
||||||
public static final String ENCRYPT_ENCRYPTION_KEYS_IDS = "encryptionKeysIds";
|
public static final String ENCRYPT_ENCRYPTION_KEYS_IDS = "encryption_keys_ids";
|
||||||
public static final String ENCRYPT_COMPRESSION_ID = "compressionId";
|
public static final String ENCRYPT_COMPRESSION_ID = "compression_id";
|
||||||
public static final String ENCRYPT_GENERATE_SIGNATURE = "generateSignature";
|
public static final String ENCRYPT_GENERATE_SIGNATURE = "generate_signature";
|
||||||
public static final String ENCRYPT_SIGN_ONLY = "signOnly";
|
public static final String ENCRYPT_SIGN_ONLY = "sign_only";
|
||||||
public static final String ENCRYPT_MESSAGE_BYTES = "messageBytes";
|
public static final String ENCRYPT_MESSAGE_BYTES = "message_bytes";
|
||||||
public static final String ENCRYPT_INPUT_FILE = "inputFile";
|
public static final String ENCRYPT_INPUT_FILE = "input_file";
|
||||||
public static final String ENCRYPT_OUTPUT_FILE = "outputFile";
|
public static final String ENCRYPT_OUTPUT_FILE = "output_file";
|
||||||
public static final String ENCRYPT_PROVIDER_URI = "providerUri";
|
public static final String ENCRYPT_PROVIDER_URI = "provider_uri";
|
||||||
|
|
||||||
// decrypt/verify
|
// decrypt/verify
|
||||||
public static final String DECRYPT_SIGNED_ONLY = "signedOnly";
|
public static final String DECRYPT_SIGNED_ONLY = "signed_only";
|
||||||
public static final String DECRYPT_RETURN_BYTES = "returnBinary";
|
public static final String DECRYPT_RETURN_BYTES = "return_binary";
|
||||||
public static final String DECRYPT_CIPHERTEXT_BYTES = "ciphertextBytes";
|
public static final String DECRYPT_CIPHERTEXT_BYTES = "ciphertext_bytes";
|
||||||
public static final String DECRYPT_ASSUME_SYMMETRIC = "assumeSymmetric";
|
public static final String DECRYPT_ASSUME_SYMMETRIC = "assume_symmetric";
|
||||||
public static final String DECRYPT_LOOKUP_UNKNOWN_KEY = "lookupUnknownKey";
|
public static final String DECRYPT_LOOKUP_UNKNOWN_KEY = "lookup_unknownKey";
|
||||||
|
|
||||||
// save keyring
|
// save keyring
|
||||||
public static final String SAVE_KEYRING_NEW_PASSPHRASE = "newPassphrase";
|
public static final String SAVE_KEYRING_NEW_PASSPHRASE = "new_passphrase";
|
||||||
public static final String SAVE_KEYRING_CURRENT_PASSPHRASE = "currentPassphrase";
|
public static final String SAVE_KEYRING_CURRENT_PASSPHRASE = "current_passphrase";
|
||||||
public static final String SAVE_KEYRING_USER_IDS = "userIds";
|
public static final String SAVE_KEYRING_USER_IDS = "user_ids";
|
||||||
public static final String SAVE_KEYRING_KEYS = "keys";
|
public static final String SAVE_KEYRING_KEYS = "keys";
|
||||||
public static final String SAVE_KEYRING_KEYS_USAGES = "keysUsages";
|
public static final String SAVE_KEYRING_KEYS_USAGES = "keys_usages";
|
||||||
public static final String SAVE_KEYRING_MASTER_KEY_ID = "masterKeyId";
|
public static final String SAVE_KEYRING_MASTER_KEY_ID = "master_key_id";
|
||||||
public static final String SAVE_KEYRING_CAN_SIGN = "can_sign";
|
public static final String SAVE_KEYRING_CAN_SIGN = "can_sign";
|
||||||
|
|
||||||
// generate key
|
// generate key
|
||||||
public static final String GENERATE_KEY_ALGORITHM = "algorithm";
|
public static final String GENERATE_KEY_ALGORITHM = "algorithm";
|
||||||
public static final String GENERATE_KEY_KEY_SIZE = "keySize";
|
public static final String GENERATE_KEY_KEY_SIZE = "key_size";
|
||||||
public static final String GENERATE_KEY_SYMMETRIC_PASSPHRASE = "passphrase";
|
public static final String GENERATE_KEY_SYMMETRIC_PASSPHRASE = "passphrase";
|
||||||
public static final String GENERATE_KEY_MASTER_KEY = "masterKey";
|
public static final String GENERATE_KEY_MASTER_KEY = "master_key";
|
||||||
|
|
||||||
// delete file securely
|
// delete file securely
|
||||||
public static final String DELETE_FILE = "deleteFile";
|
public static final String DELETE_FILE = "deleteFile";
|
||||||
|
|
||||||
// import key
|
// import key
|
||||||
public static final String IMPORT_INPUT_STREAM = "importInputStream";
|
public static final String IMPORT_INPUT_STREAM = "import_input_stream";
|
||||||
public static final String IMPORT_FILENAME = "importFilename";
|
public static final String IMPORT_FILENAME = "import_filename";
|
||||||
public static final String IMPORT_BYTES = "importBytes";
|
public static final String IMPORT_BYTES = "import_bytes";
|
||||||
// public static final String IMPORT_KEY_TYPE = "importKeyType";
|
// public static final String IMPORT_KEY_TYPE = "importKeyType";
|
||||||
|
|
||||||
// export key
|
// export key
|
||||||
public static final String EXPORT_OUTPUT_STREAM = "exportOutputStream";
|
public static final String EXPORT_OUTPUT_STREAM = "export_output_stream";
|
||||||
public static final String EXPORT_FILENAME = "exportFilename";
|
public static final String EXPORT_FILENAME = "export_filename";
|
||||||
public static final String EXPORT_KEY_TYPE = "exportKeyType";
|
public static final String EXPORT_KEY_TYPE = "export_key_type";
|
||||||
public static final String EXPORT_ALL = "exportAll";
|
public static final String EXPORT_ALL = "export_all";
|
||||||
public static final String EXPORT_KEY_RING_MASTER_KEY_ID = "exportKeyRingId";
|
public static final String EXPORT_KEY_RING_MASTER_KEY_ID = "export_key_ring_id";
|
||||||
|
|
||||||
// upload key
|
// upload key
|
||||||
public static final String UPLOAD_KEY_SERVER = "uploadKeyServer";
|
public static final String UPLOAD_KEY_SERVER = "upload_key_server";
|
||||||
public static final String UPLOAD_KEY_KEYRING_ROW_ID = "uploadKeyRingId";
|
public static final String UPLOAD_KEY_KEYRING_ROW_ID = "upload_key_ring_id";
|
||||||
|
|
||||||
// query key
|
// query key
|
||||||
public static final String QUERY_KEY_SERVER = "queryKeyServer";
|
public static final String QUERY_KEY_SERVER = "query_key_server";
|
||||||
public static final String QUERY_KEY_TYPE = "queryKeyType";
|
public static final String QUERY_KEY_TYPE = "query_key_type";
|
||||||
public static final String QUERY_KEY_STRING = "queryKeyString";
|
public static final String QUERY_KEY_STRING = "query_key_string";
|
||||||
public static final String QUERY_KEY_ID = "queryKeyId";
|
public static final String QUERY_KEY_ID = "query_key_id";
|
||||||
|
|
||||||
// sign key
|
// sign key
|
||||||
public static final String SIGN_KEY_MASTER_KEY_ID = "signKeyMasterKeyId";
|
public static final String SIGN_KEY_MASTER_KEY_ID = "sign_key_master_key_id";
|
||||||
public static final String SIGN_KEY_PUB_KEY_ID = "signKeyPubKeyId";
|
public static final String SIGN_KEY_PUB_KEY_ID = "sign_key_pub_key_id";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* possible data keys as result send over messenger
|
* possible data keys as result send over messenger
|
||||||
*/
|
*/
|
||||||
// keys
|
// keys
|
||||||
public static final String RESULT_NEW_KEY = "newKey";
|
public static final String RESULT_NEW_KEY = "new_key";
|
||||||
public static final String RESULT_NEW_KEY2 = "newKey2";
|
public static final String RESULT_NEW_KEY2 = "new_key2";
|
||||||
|
|
||||||
// encrypt
|
// encrypt
|
||||||
public static final String RESULT_SIGNATURE_BYTES = "signatureData";
|
public static final String RESULT_SIGNATURE_BYTES = "signature_data";
|
||||||
public static final String RESULT_SIGNATURE_STRING = "signatureText";
|
public static final String RESULT_SIGNATURE_STRING = "signature_text";
|
||||||
public static final String RESULT_ENCRYPTED_STRING = "encryptedMessage";
|
public static final String RESULT_ENCRYPTED_STRING = "encrypted_message";
|
||||||
public static final String RESULT_ENCRYPTED_BYTES = "encryptedData";
|
public static final String RESULT_ENCRYPTED_BYTES = "encrypted_data";
|
||||||
public static final String RESULT_URI = "resultUri";
|
public static final String RESULT_URI = "result_uri";
|
||||||
|
|
||||||
// decrypt/verify
|
// decrypt/verify
|
||||||
public static final String RESULT_DECRYPTED_STRING = "decryptedMessage";
|
public static final String RESULT_DECRYPTED_STRING = "decrypted_message";
|
||||||
public static final String RESULT_DECRYPTED_BYTES = "decryptedData";
|
public static final String RESULT_DECRYPTED_BYTES = "decrypted_data";
|
||||||
public static final String RESULT_SIGNATURE = "signature";
|
public static final String RESULT_SIGNATURE = "signature";
|
||||||
public static final String RESULT_SIGNATURE_KEY_ID = "signatureKeyId";
|
public static final String RESULT_SIGNATURE_KEY_ID = "signature_key_id";
|
||||||
public static final String RESULT_SIGNATURE_USER_ID = "signatureUserId";
|
public static final String RESULT_SIGNATURE_USER_ID = "signature_user_id";
|
||||||
|
|
||||||
public static final String RESULT_SIGNATURE_SUCCESS = "signatureSuccess";
|
public static final String RESULT_SIGNATURE_SUCCESS = "signature_success";
|
||||||
public static final String RESULT_SIGNATURE_UNKNOWN = "signatureUnknown";
|
public static final String RESULT_SIGNATURE_UNKNOWN = "signature_unknown";
|
||||||
public static final String RESULT_SIGNATURE_LOOKUP_KEY = "lookupKey";
|
public static final String RESULT_SIGNATURE_LOOKUP_KEY = "lookup_key";
|
||||||
|
|
||||||
// import
|
// import
|
||||||
public static final String RESULT_IMPORT_ADDED = "added";
|
public static final String RESULT_IMPORT_ADDED = "added";
|
||||||
@ -196,8 +196,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
|||||||
public static final String RESULT_EXPORT = "exported";
|
public static final String RESULT_EXPORT = "exported";
|
||||||
|
|
||||||
// query
|
// query
|
||||||
public static final String RESULT_QUERY_KEY_KEY_DATA = "queryKeyKeyData";
|
public static final String RESULT_QUERY_KEY_DATA = "query_key_data";
|
||||||
public static final String RESULT_QUERY_KEY_SEARCH_RESULT = "queryKeySearchResult";
|
public static final String RESULT_QUERY_KEY_SEARCH_RESULT = "query_key_search_result";
|
||||||
|
|
||||||
Messenger mMessenger;
|
Messenger mMessenger;
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
|||||||
long secretKeyId = data.getLong(ENCRYPT_SECRET_KEY_ID);
|
long secretKeyId = data.getLong(ENCRYPT_SECRET_KEY_ID);
|
||||||
String encryptionPassphrase = data.getString(GENERATE_KEY_SYMMETRIC_PASSPHRASE);
|
String encryptionPassphrase = data.getString(GENERATE_KEY_SYMMETRIC_PASSPHRASE);
|
||||||
|
|
||||||
boolean useAsciiArmor = data.getBoolean(ENCRYPT_USE_ASCII_AMOR);
|
boolean useAsciiArmor = data.getBoolean(ENCRYPT_USE_ASCII_ARMOR);
|
||||||
long encryptionKeyIds[] = data.getLongArray(ENCRYPT_ENCRYPTION_KEYS_IDS);
|
long encryptionKeyIds[] = data.getLongArray(ENCRYPT_ENCRYPTION_KEYS_IDS);
|
||||||
int compressionId = data.getInt(ENCRYPT_COMPRESSION_ID);
|
int compressionId = data.getInt(ENCRYPT_COMPRESSION_ID);
|
||||||
boolean generateSignature = data.getBoolean(ENCRYPT_GENERATE_SIGNATURE);
|
boolean generateSignature = data.getBoolean(ENCRYPT_GENERATE_SIGNATURE);
|
||||||
@ -760,7 +760,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
|||||||
} else if (queryType == Id.keyserver.get) {
|
} else if (queryType == Id.keyserver.get) {
|
||||||
String keyData = server.get(keyId);
|
String keyData = server.get(keyId);
|
||||||
|
|
||||||
resultData.putString(RESULT_QUERY_KEY_KEY_DATA, keyData);
|
resultData.putString(RESULT_QUERY_KEY_DATA, keyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData);
|
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData);
|
||||||
|
@ -724,7 +724,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.putLong(KeychainIntentService.ENCRYPT_SECRET_KEY_ID, mSecretKeyIdToPass);
|
data.putLong(KeychainIntentService.ENCRYPT_SECRET_KEY_ID, mSecretKeyIdToPass);
|
||||||
data.putBoolean(KeychainIntentService.ENCRYPT_USE_ASCII_AMOR, useAsciiArmor);
|
data.putBoolean(KeychainIntentService.ENCRYPT_USE_ASCII_ARMOR, useAsciiArmor);
|
||||||
data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, encryptionKeyIds);
|
data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, encryptionKeyIds);
|
||||||
data.putInt(KeychainIntentService.ENCRYPT_COMPRESSION_ID, compressionId);
|
data.putInt(KeychainIntentService.ENCRYPT_COMPRESSION_ID, compressionId);
|
||||||
data.putBoolean(KeychainIntentService.ENCRYPT_GENERATE_SIGNATURE, mGenerateSignature);
|
data.putBoolean(KeychainIntentService.ENCRYPT_GENERATE_SIGNATURE, mGenerateSignature);
|
||||||
|
@ -64,7 +64,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
|
|||||||
public static final String ACTION_LOOK_UP_KEY_ID_AND_RETURN = Constants.INTENT_PREFIX
|
public static final String ACTION_LOOK_UP_KEY_ID_AND_RETURN = Constants.INTENT_PREFIX
|
||||||
+ "LOOK_UP_KEY_ID_AND_RETURN";
|
+ "LOOK_UP_KEY_ID_AND_RETURN";
|
||||||
|
|
||||||
public static final String EXTRA_KEY_ID = "keyId";
|
public static final String EXTRA_KEY_ID = "key_id";
|
||||||
|
|
||||||
public static final String RESULT_EXTRA_TEXT = "text";
|
public static final String RESULT_EXTRA_TEXT = "text";
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
|
|||||||
mSearchResult = returnData
|
mSearchResult = returnData
|
||||||
.getParcelableArrayList(KeychainIntentService.RESULT_QUERY_KEY_SEARCH_RESULT);
|
.getParcelableArrayList(KeychainIntentService.RESULT_QUERY_KEY_SEARCH_RESULT);
|
||||||
} else if (mQueryType == Id.keyserver.get) {
|
} else if (mQueryType == Id.keyserver.get) {
|
||||||
mKeyData = returnData.getString(KeychainIntentService.RESULT_QUERY_KEY_KEY_DATA);
|
mKeyData = returnData.getString(KeychainIntentService.RESULT_QUERY_KEY_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: IMPROVE CODE!!! some global variables can be avoided!!!
|
// TODO: IMPROVE CODE!!! some global variables can be avoided!!!
|
||||||
|
@ -49,7 +49,7 @@ public class KeyServerUploadActivity extends SherlockFragmentActivity {
|
|||||||
public static final String ACTION_EXPORT_KEY_TO_SERVER = Constants.INTENT_PREFIX
|
public static final String ACTION_EXPORT_KEY_TO_SERVER = Constants.INTENT_PREFIX
|
||||||
+ "EXPORT_KEY_TO_SERVER";
|
+ "EXPORT_KEY_TO_SERVER";
|
||||||
|
|
||||||
public static final String EXTRA_KEYRING_ROW_ID = "keyId";
|
public static final String EXTRA_KEYRING_ROW_ID = "key_id";
|
||||||
|
|
||||||
private Button export;
|
private Button export;
|
||||||
private Spinner keyServer;
|
private Spinner keyServer;
|
||||||
|
@ -38,7 +38,7 @@ import com.actionbarsherlock.app.SherlockActivity;
|
|||||||
public class PreferencesKeyServerActivity extends SherlockActivity implements OnClickListener,
|
public class PreferencesKeyServerActivity extends SherlockActivity implements OnClickListener,
|
||||||
EditorListener {
|
EditorListener {
|
||||||
|
|
||||||
public static final String EXTRA_KEY_SERVERS = "keyServers";
|
public static final String EXTRA_KEY_SERVERS = "key_servers";
|
||||||
|
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private ViewGroup mEditors;
|
private ViewGroup mEditors;
|
||||||
|
@ -50,7 +50,7 @@ public class ShareNfcBeamActivity extends SherlockFragmentActivity implements
|
|||||||
public static final String ACTION_SHARE_KEYRING_WITH_NFC = Constants.INTENT_PREFIX
|
public static final String ACTION_SHARE_KEYRING_WITH_NFC = Constants.INTENT_PREFIX
|
||||||
+ "SHARE_KEYRING_WITH_NFC";
|
+ "SHARE_KEYRING_WITH_NFC";
|
||||||
|
|
||||||
public static final String EXTRA_MASTER_KEY_ID = "masterKeyId";
|
public static final String EXTRA_MASTER_KEY_ID = "master_key_id";
|
||||||
|
|
||||||
NfcAdapter mNfcAdapter;
|
NfcAdapter mNfcAdapter;
|
||||||
|
|
||||||
|
@ -21,75 +21,74 @@ import android.preference.ListPreference;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list preference which persists its values as integers instead of strings.
|
* A list preference which persists its values as integers instead of strings. Code reading the
|
||||||
* Code reading the values should use
|
* values should use {@link android.content.SharedPreferences#getInt}. When using XML-declared
|
||||||
* {@link android.content.SharedPreferences#getInt}.
|
* arrays for entry values, the arrays should be regular string arrays containing valid integer
|
||||||
* When using XML-declared arrays for entry values, the arrays should be regular
|
* values.
|
||||||
* string arrays containing valid integer values.
|
*
|
||||||
*
|
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class IntegerListPreference extends ListPreference {
|
public class IntegerListPreference extends ListPreference {
|
||||||
|
|
||||||
public IntegerListPreference(Context context) {
|
public IntegerListPreference(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
verifyEntryValues(null);
|
verifyEntryValues(null);
|
||||||
}
|
|
||||||
|
|
||||||
public IntegerListPreference(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
|
|
||||||
verifyEntryValues(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEntryValues(CharSequence[] entryValues) {
|
|
||||||
CharSequence[] oldValues = getEntryValues();
|
|
||||||
super.setEntryValues(entryValues);
|
|
||||||
verifyEntryValues(oldValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEntryValues(int entryValuesResId) {
|
|
||||||
CharSequence[] oldValues = getEntryValues();
|
|
||||||
super.setEntryValues(entryValuesResId);
|
|
||||||
verifyEntryValues(oldValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getPersistedString(String defaultReturnValue) {
|
|
||||||
// During initial load, there's no known default value
|
|
||||||
int defaultIntegerValue = Integer.MIN_VALUE;
|
|
||||||
if (defaultReturnValue != null) {
|
|
||||||
defaultIntegerValue = Integer.parseInt(defaultReturnValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the list preference asks us to read a string, instead read an
|
public IntegerListPreference(Context context, AttributeSet attrs) {
|
||||||
// integer.
|
super(context, attrs);
|
||||||
int value = getPersistedInt(defaultIntegerValue);
|
|
||||||
return Integer.toString(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
verifyEntryValues(null);
|
||||||
protected boolean persistString(String value) {
|
|
||||||
// When asked to save a string, instead save an integer
|
|
||||||
return persistInt(Integer.parseInt(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void verifyEntryValues(CharSequence[] oldValues) {
|
|
||||||
CharSequence[] entryValues = getEntryValues();
|
|
||||||
if (entryValues == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CharSequence entryValue : entryValues) {
|
@Override
|
||||||
try {
|
public void setEntryValues(CharSequence[] entryValues) {
|
||||||
Integer.parseInt(entryValue.toString());
|
CharSequence[] oldValues = getEntryValues();
|
||||||
} catch (NumberFormatException nfe) {
|
super.setEntryValues(entryValues);
|
||||||
super.setEntryValues(oldValues);
|
verifyEntryValues(oldValues);
|
||||||
throw nfe;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void setEntryValues(int entryValuesResId) {
|
||||||
|
CharSequence[] oldValues = getEntryValues();
|
||||||
|
super.setEntryValues(entryValuesResId);
|
||||||
|
verifyEntryValues(oldValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getPersistedString(String defaultReturnValue) {
|
||||||
|
// During initial load, there's no known default value
|
||||||
|
int defaultIntegerValue = Integer.MIN_VALUE;
|
||||||
|
if (defaultReturnValue != null) {
|
||||||
|
defaultIntegerValue = Integer.parseInt(defaultReturnValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
// When the list preference asks us to read a string, instead read an
|
||||||
|
// integer.
|
||||||
|
int value = getPersistedInt(defaultIntegerValue);
|
||||||
|
return Integer.toString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean persistString(String value) {
|
||||||
|
// When asked to save a string, instead save an integer
|
||||||
|
return persistInt(Integer.parseInt(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyEntryValues(CharSequence[] oldValues) {
|
||||||
|
CharSequence[] entryValues = getEntryValues();
|
||||||
|
if (entryValues == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (CharSequence entryValue : entryValues) {
|
||||||
|
try {
|
||||||
|
Integer.parseInt(entryValue.toString());
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
super.setEntryValues(oldValues);
|
||||||
|
throw nfe;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -62,11 +62,12 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
|||||||
private int mDatePickerResultCount = 0;
|
private int mDatePickerResultCount = 0;
|
||||||
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
||||||
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||||
if(mDatePickerResultCount++ == 0) // Note: Ignore results after the first one - android sends multiples.
|
if (mDatePickerResultCount++ == 0) // Note: Ignore results after the first one - android
|
||||||
{
|
// sends multiples.
|
||||||
GregorianCalendar date = new GregorianCalendar(year, monthOfYear, dayOfMonth);
|
{
|
||||||
setExpiryDate(date);
|
GregorianCalendar date = new GregorianCalendar(year, monthOfYear, dayOfMonth);
|
||||||
}
|
setExpiryDate(date);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,10 +121,11 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
|||||||
dialog.setButton(Dialog.BUTTON_NEGATIVE, getContext()
|
dialog.setButton(Dialog.BUTTON_NEGATIVE, getContext()
|
||||||
.getString(R.string.btn_noDate), new DialogInterface.OnClickListener() {
|
.getString(R.string.btn_noDate), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
if(mDatePickerResultCount++ == 0) // Note: Ignore results after the first one - android sends multiples.
|
if (mDatePickerResultCount++ == 0) // Note: Ignore results after the first
|
||||||
{
|
// one - android sends multiples.
|
||||||
setExpiryDate(null);
|
{
|
||||||
}
|
setExpiryDate(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
@ -63,7 +63,7 @@ public class KeyServerEditor extends LinearLayout implements Editor, OnClickList
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final ViewGroup parent = (ViewGroup)getParent();
|
final ViewGroup parent = (ViewGroup) getParent();
|
||||||
if (v == mDeleteButton) {
|
if (v == mDeleteButton) {
|
||||||
parent.removeView(this);
|
parent.removeView(this);
|
||||||
if (mEditorListener != null) {
|
if (mEditorListener != null) {
|
||||||
|
@ -16,9 +16,13 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui.widget;
|
package org.sufficientlysecure.keychain.ui.widget;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.spongycastle.openpgp.PGPSecretKey;
|
import org.spongycastle.openpgp.PGPSecretKey;
|
||||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.sufficientlysecure.keychain.Id;
|
import org.sufficientlysecure.keychain.Id;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.helper.PgpConversionHelper;
|
import org.sufficientlysecure.keychain.helper.PgpConversionHelper;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
@ -26,9 +30,6 @@ import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
|||||||
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.Editor.EditorListener;
|
import org.sufficientlysecure.keychain.ui.widget.Editor.EditorListener;
|
||||||
import org.sufficientlysecure.keychain.util.Choice;
|
import org.sufficientlysecure.keychain.util.Choice;
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
@ -43,17 +44,13 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.AdapterView.OnItemSelectedListener;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
public class SectionView extends LinearLayout implements OnClickListener, EditorListener {
|
public class SectionView extends LinearLayout implements OnClickListener, EditorListener {
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
@ -189,31 +186,33 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Spinner keySize = (Spinner) view.findViewById(R.id.create_key_size);
|
final Spinner keySize = (Spinner) view.findViewById(R.id.create_key_size);
|
||||||
ArrayAdapter<CharSequence> keySizeAdapter = ArrayAdapter.createFromResource(getContext(), R.array.key_size_spinner_values, android.R.layout.simple_spinner_item);
|
ArrayAdapter<CharSequence> keySizeAdapter = ArrayAdapter.createFromResource(
|
||||||
keySizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
getContext(), R.array.key_size_spinner_values,
|
||||||
keySize.setAdapter(keySizeAdapter);
|
android.R.layout.simple_spinner_item);
|
||||||
keySize.setSelection(2); // Default to 2048 for the key length
|
keySizeAdapter
|
||||||
|
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
keySize.setAdapter(keySizeAdapter);
|
||||||
|
keySize.setSelection(2); // Default to 2048 for the key length
|
||||||
dialog.setPositiveButton(android.R.string.ok,
|
dialog.setPositiveButton(android.R.string.ok,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface di, int id) {
|
public void onClick(DialogInterface di, int id) {
|
||||||
di.dismiss();
|
di.dismiss();
|
||||||
try {
|
try {
|
||||||
int nKeyIndex = keySize.getSelectedItemPosition();
|
int nKeyIndex = keySize.getSelectedItemPosition();
|
||||||
switch(nKeyIndex)
|
switch (nKeyIndex) {
|
||||||
{
|
case 0:
|
||||||
case 0:
|
mNewKeySize = 512;
|
||||||
mNewKeySize = 512;
|
break;
|
||||||
break;
|
case 1:
|
||||||
case 1:
|
mNewKeySize = 1024;
|
||||||
mNewKeySize = 1024;
|
break;
|
||||||
break;
|
case 2:
|
||||||
case 2:
|
mNewKeySize = 2048;
|
||||||
mNewKeySize = 2048;
|
break;
|
||||||
break;
|
case 3:
|
||||||
case 3:
|
mNewKeySize = 4096;
|
||||||
mNewKeySize = 4096;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
mNewKeySize = 0;
|
mNewKeySize = 0;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ package org.sufficientlysecure.keychain.util;
|
|||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
|
||||||
public class InputData {
|
public class InputData {
|
||||||
private PositionAwareInputStream mInputStream;
|
private PositionAwareInputStream mInputStream;
|
||||||
private long mSize;
|
private long mSize;
|
||||||
|
Loading…
Reference in New Issue
Block a user