Merge pull request #600 from thi/rename-progressdialogupdater

Rename progressdialogupdater
This commit is contained in:
Dominik Schürmann 2014-04-29 19:50:30 +02:00
commit 5c145cf44d
8 changed files with 57 additions and 54 deletions

View File

@ -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<Long> 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<Long> 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);
}
}

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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;
* <p/>
* Note that no android specific stuff should be done here, ie no imports from com.android.
* <p/>
* 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;
}

View File

@ -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);
}
}

View File

@ -15,9 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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);

View File

@ -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();

View File

@ -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);