From 9e6bf2abbb1395798c7b6957b193d738940a2b57 Mon Sep 17 00:00:00 2001 From: Thialfihar Date: Tue, 29 Apr 2014 18:44:44 +0200 Subject: Rename ProgressDialogUpdater to Progressable Also fix some inconsistent usages of "progress", now using "progressable" in all builders. --- .../keychain/pgp/PgpDecryptVerify.java | 20 +++++++++--------- .../sufficientlysecure/keychain/pgp/PgpHelper.java | 10 ++++----- .../keychain/pgp/PgpImportExport.java | 24 +++++++++++----------- .../keychain/pgp/PgpKeyOperation.java | 8 ++++---- .../keychain/pgp/PgpSignEncrypt.java | 20 +++++++++--------- .../keychain/pgp/Progressable.java | 4 ++-- .../keychain/service/KeychainIntentService.java | 12 +++++------ .../keychain/util/ProgressScaler.java | 13 +++++++----- 8 files changed, 57 insertions(+), 54 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java index 0d005a4ef..71900d002 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java @@ -52,12 +52,12 @@ import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; @@ -79,7 +79,7 @@ public class PgpDecryptVerify { private InputData mData; private OutputStream mOutStream; - private ProgressDialogUpdater mProgressDialogUpdater; + private Progressable mProgressable; private boolean mAllowSymmetricDecryption; private String mPassphrase; private Set mAllowedKeyIds; @@ -91,7 +91,7 @@ public class PgpDecryptVerify { this.mData = builder.mData; this.mOutStream = builder.mOutStream; - this.mProgressDialogUpdater = builder.mProgressDialogUpdater; + this.mProgressable = builder.mProgressable; this.mAllowSymmetricDecryption = builder.mAllowSymmetricDecryption; this.mPassphrase = builder.mPassphrase; this.mAllowedKeyIds = builder.mAllowedKeyIds; @@ -105,7 +105,7 @@ public class PgpDecryptVerify { private OutputStream mOutStream; // optional - private ProgressDialogUpdater mProgressDialogUpdater = null; + private Progressable mProgressable = null; private boolean mAllowSymmetricDecryption = true; private String mPassphrase = null; private Set mAllowedKeyIds = null; @@ -118,8 +118,8 @@ public class PgpDecryptVerify { this.mOutStream = outStream; } - public Builder progressDialogUpdater(ProgressDialogUpdater progressDialogUpdater) { - this.mProgressDialogUpdater = progressDialogUpdater; + public Builder progressable(Progressable progressable) { + this.mProgressable = progressable; return this; } @@ -151,14 +151,14 @@ public class PgpDecryptVerify { } public void updateProgress(int message, int current, int total) { - if (mProgressDialogUpdater != null) { - mProgressDialogUpdater.setProgress(message, current, total); + if (mProgressable != null) { + mProgressable.setProgress(message, current, total); } } public void updateProgress(int current, int total) { - if (mProgressDialogUpdater != null) { - mProgressDialogUpdater.setProgress(current, total); + if (mProgressable != null) { + mProgressable.setProgress(current, total); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpHelper.java index 692764393..013361782 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpHelper.java @@ -24,8 +24,8 @@ import android.content.pm.PackageManager.NameNotFoundException; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import java.io.File; import java.io.IOException; @@ -140,11 +140,11 @@ public class PgpHelper { * TODO: Does this really help on flash storage? * * @param context - * @param progress + * @param progressable * @param file * @throws IOException */ - public static void deleteFileSecurely(Context context, ProgressDialogUpdater progress, File file) + public static void deleteFileSecurely(Context context, Progressable progressable, File file) throws IOException { long length = file.length(); SecureRandom random = new SecureRandom(); @@ -155,8 +155,8 @@ public class PgpHelper { int pos = 0; String msg = context.getString(R.string.progress_deleting_securely, file.getName()); while (pos < length) { - if (progress != null) { - progress.setProgress(msg, (int) (100 * pos / length), 100); + if (progressable != null) { + progressable.setProgress(msg, (int) (100 * pos / length), 100); } random.nextBytes(data); raf.write(data); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java index 5b85d82a6..bfbcd582e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -32,6 +32,7 @@ import org.spongycastle.openpgp.PGPSecretKeyRing; import org.spongycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; @@ -41,7 +42,6 @@ import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.KeyServer.AddKeyException; import org.sufficientlysecure.keychain.util.KeychainServiceListener; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -52,7 +52,7 @@ import java.util.List; public class PgpImportExport { private Context mContext; - private ProgressDialogUpdater mProgress; + private Progressable mProgressable; private KeychainServiceListener mKeychainServiceListener; @@ -63,37 +63,37 @@ public class PgpImportExport { public static final int RETURN_BAD = -2; public static final int RETURN_UPDATED = 1; - public PgpImportExport(Context context, ProgressDialogUpdater progress) { + public PgpImportExport(Context context, Progressable progressable) { super(); this.mContext = context; - this.mProgress = progress; + this.mProgressable = progressable; this.mProviderHelper = new ProviderHelper(context); } public PgpImportExport(Context context, - ProgressDialogUpdater progress, KeychainServiceListener keychainListener) { + Progressable progressable, KeychainServiceListener keychainListener) { super(); this.mContext = context; - this.mProgress = progress; + this.mProgressable = progressable; this.mProviderHelper = new ProviderHelper(context); this.mKeychainServiceListener = keychainListener; } public void updateProgress(int message, int current, int total) { - if (mProgress != null) { - mProgress.setProgress(message, current, total); + if (mProgressable != null) { + mProgressable.setProgress(message, current, total); } } public void updateProgress(String message, int current, int total) { - if (mProgress != null) { - mProgress.setProgress(message, current, total); + if (mProgressable != null) { + mProgressable.setProgress(message, current, total); } } public void updateProgress(int current, int total) { - if (mProgress != null) { - mProgress.setProgress(current, total); + if (mProgressable != null) { + mProgressable.setProgress(current, total); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index adbce496e..9dd9f660b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -48,11 +48,11 @@ import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Primes; -import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import java.io.IOException; import java.math.BigInteger; @@ -75,11 +75,11 @@ import java.util.TimeZone; *

* Note that no android specific stuff should be done here, ie no imports from com.android. *

- * All operations support progress reporting to a ProgressDialogUpdater passed on initialization. + * All operations support progress reporting to a Progressable passed on initialization. * This indicator may be null. */ public class PgpKeyOperation { - private ProgressDialogUpdater mProgress; + private Progressable mProgress; private static final int[] PREFERRED_SYMMETRIC_ALGORITHMS = new int[]{ SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192, @@ -91,7 +91,7 @@ public class PgpKeyOperation { CompressionAlgorithmTags.ZLIB, CompressionAlgorithmTags.BZIP2, CompressionAlgorithmTags.ZIP}; - public PgpKeyOperation(ProgressDialogUpdater progress) { + public PgpKeyOperation(Progressable progress) { super(); this.mProgress = progress; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java index 2437cb0f0..4b1ecc0f1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java @@ -42,11 +42,11 @@ import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import java.io.BufferedReader; import java.io.IOException; @@ -69,7 +69,7 @@ public class PgpSignEncrypt { private InputData mData; private OutputStream mOutStream; - private ProgressDialogUpdater mProgress; + private Progressable mProgressable; private boolean mEnableAsciiArmorOutput; private int mCompressionId; private long[] mEncryptionMasterKeyIds; @@ -99,7 +99,7 @@ public class PgpSignEncrypt { this.mData = builder.mData; this.mOutStream = builder.mOutStream; - this.mProgress = builder.mProgress; + this.mProgressable = builder.mProgressable; this.mEnableAsciiArmorOutput = builder.mEnableAsciiArmorOutput; this.mCompressionId = builder.mCompressionId; this.mEncryptionMasterKeyIds = builder.mEncryptionMasterKeyIds; @@ -121,7 +121,7 @@ public class PgpSignEncrypt { private OutputStream mOutStream; // optional - private ProgressDialogUpdater mProgress = null; + private Progressable mProgressable = null; private boolean mEnableAsciiArmorOutput = false; private int mCompressionId = Constants.choice.compression.none; private long[] mEncryptionMasterKeyIds = null; @@ -141,8 +141,8 @@ public class PgpSignEncrypt { this.mOutStream = outStream; } - public Builder progress(ProgressDialogUpdater progress) { - this.mProgress = progress; + public Builder progressable(Progressable progressable) { + this.mProgressable = progressable; return this; } @@ -219,14 +219,14 @@ public class PgpSignEncrypt { } public void updateProgress(int message, int current, int total) { - if (mProgress != null) { - mProgress.setProgress(message, current, total); + if (mProgressable != null) { + mProgressable.setProgress(message, current, total); } } public void updateProgress(int current, int total) { - if (mProgress != null) { - mProgress.setProgress(current, total); + if (mProgressable != null) { + mProgressable.setProgress(current, total); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java index 5f046e4c6..fd3e2db8f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -package org.sufficientlysecure.keychain.util; +package org.sufficientlysecure.keychain.pgp; -public interface ProgressDialogUpdater { +public interface Progressable { void setProgress(String message, int current, int total); void setProgress(int resourceId, int current, int total); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index c883dee0e..7b12f525c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -47,6 +47,7 @@ import org.sufficientlysecure.keychain.pgp.PgpImportExport; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt; +import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; @@ -57,7 +58,6 @@ import org.sufficientlysecure.keychain.util.HkpKeyServer; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.KeychainServiceListener; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import org.sufficientlysecure.keychain.util.ProgressScaler; import java.io.BufferedInputStream; @@ -79,7 +79,7 @@ import java.util.List; * after doing them. */ public class KeychainIntentService extends IntentService - implements ProgressDialogUpdater, KeychainServiceListener { + implements Progressable, KeychainServiceListener { /* extras that can be given by intent */ public static final String EXTRA_MESSENGER = "messenger"; @@ -313,7 +313,7 @@ public class KeychainIntentService extends IntentService new ProviderHelper(this), PgpHelper.getFullVersion(this), inputData, outStream); - builder.progress(this); + builder.progressable(this); builder.enableAsciiArmorOutput(useAsciiArmor) .compressionId(compressionId) @@ -457,7 +457,7 @@ public class KeychainIntentService extends IntentService } }, inputData, outStream); - builder.progressDialogUpdater(this); + builder.progressable(this); builder.allowSymmetricDecryption(true) .passphrase(passphrase); @@ -925,10 +925,10 @@ public class KeychainIntentService extends IntentService } /** - * Set progressDialogUpdater of ProgressDialog by sending message to handler on UI thread + * Set progress of ProgressDialog by sending message to handler on UI thread */ public void setProgress(String message, int progress, int max) { - Log.d(Constants.TAG, "Send message by setProgress with progressDialogUpdater=" + progress + ", max=" + Log.d(Constants.TAG, "Send message by setProgress with progress=" + progress + ", max=" + max); Bundle data = new Bundle(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java index 23961c05f..5553ea5d2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java @@ -17,15 +17,18 @@ package org.sufficientlysecure.keychain.util; -/** This is a simple class that wraps a ProgressDialogUpdater, scaling the progress +import org.sufficientlysecure.keychain.pgp.Progressable; + +/** + * This is a simple class that wraps a Progressable, scaling the progress * values into a specified range. */ -public class ProgressScaler implements ProgressDialogUpdater { +public class ProgressScaler implements Progressable { - final ProgressDialogUpdater mWrapped; + final Progressable mWrapped; final int mFrom, mTo, mMax; - public ProgressScaler(ProgressDialogUpdater wrapped, int from, int to, int max) { + public ProgressScaler(Progressable wrapped, int from, int to, int max) { this.mWrapped = wrapped; this.mFrom = from; this.mTo = to; @@ -33,7 +36,7 @@ public class ProgressScaler implements ProgressDialogUpdater { } /** - * Set progressDialogUpdater of ProgressDialog by sending message to handler on UI thread + * Set progress of ProgressDialog by sending message to handler on UI thread */ public void setProgress(String message, int progress, int max) { mWrapped.setProgress(message, mFrom + progress * (mTo - mFrom) / max, mMax); -- cgit v1.2.3