aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/AlgorithmNames.java1
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Choice.java13
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java33
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressFixedScaler.java29
4 files changed, 60 insertions, 16 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/AlgorithmNames.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/AlgorithmNames.java
index 9acc7a73b..99db634ac 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/AlgorithmNames.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/AlgorithmNames.java
@@ -50,7 +50,6 @@ public class AlgorithmNames {
mEncryptionNames.put(PGPEncryptedData.TRIPLE_DES, "Triple DES");
mEncryptionNames.put(PGPEncryptedData.IDEA, "IDEA");
- mHashNames.put(HashAlgorithmTags.MD5, "MD5");
mHashNames.put(HashAlgorithmTags.RIPEMD160, "RIPEMD-160");
mHashNames.put(HashAlgorithmTags.SHA1, "SHA-1");
mHashNames.put(HashAlgorithmTags.SHA224, "SHA-224");
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Choice.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Choice.java
index 70c7d80fe..48f10d4b9 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Choice.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Choice.java
@@ -17,21 +17,16 @@
package org.sufficientlysecure.keychain.util;
-public class Choice {
+public class Choice <E> {
private String mName;
- private int mId;
+ private E mId;
- public Choice() {
- mId = -1;
- mName = "";
- }
-
- public Choice(int id, String name) {
+ public Choice(E id, String name) {
mId = id;
mName = name;
}
- public int getId() {
+ public E getId() {
return mId;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java
index 5a4bf5311..09275fc95 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileImportCache.java
@@ -46,10 +46,11 @@ public class FileImportCache<E extends Parcelable> {
private Context mContext;
- private static final String FILENAME = "key_import.pcl";
+ private final String mFilename;
- public FileImportCache(Context context) {
- this.mContext = context;
+ public FileImportCache(Context context, String filename) {
+ mContext = context;
+ mFilename = filename;
}
public void writeCache(ArrayList<E> selectedEntries) throws IOException {
@@ -64,7 +65,7 @@ public class FileImportCache<E extends Parcelable> {
throw new IOException("cache dir is null!");
}
- File tempFile = new File(mContext.getCacheDir(), FILENAME);
+ File tempFile = new File(mContext.getCacheDir(), mFilename);
DataOutputStream oos = new DataOutputStream(new FileOutputStream(tempFile));
@@ -91,6 +92,10 @@ public class FileImportCache<E extends Parcelable> {
}
public Iterator<E> readCache() throws IOException {
+ return readCache(true);
+ }
+
+ public Iterator<E> readCache(final boolean deleteAfterRead) throws IOException {
File cacheDir = mContext.getCacheDir();
if (cacheDir == null) {
@@ -98,7 +103,7 @@ public class FileImportCache<E extends Parcelable> {
throw new IOException("cache dir is null!");
}
- final File tempFile = new File(cacheDir, FILENAME);
+ final File tempFile = new File(cacheDir, mFilename);
final DataInputStream ois = new DataInputStream(new FileInputStream(tempFile));
return new Iterator<E>() {
@@ -165,7 +170,10 @@ public class FileImportCache<E extends Parcelable> {
if (!closed) {
try {
ois.close();
- tempFile.delete();
+ if (deleteAfterRead) {
+ //noinspection ResultOfMethodCallIgnored
+ tempFile.delete();
+ }
} catch (IOException e) {
// nvm
}
@@ -176,4 +184,17 @@ public class FileImportCache<E extends Parcelable> {
};
}
+
+ public boolean delete() throws IOException {
+
+ File cacheDir = mContext.getCacheDir();
+ if (cacheDir == null) {
+ // https://groups.google.com/forum/#!topic/android-developers/-694j87eXVU
+ throw new IOException("cache dir is null!");
+ }
+
+ final File tempFile = new File(cacheDir, mFilename);
+ return tempFile.delete();
+ }
+
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressFixedScaler.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressFixedScaler.java
new file mode 100644
index 000000000..4bb4ca5de
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressFixedScaler.java
@@ -0,0 +1,29 @@
+package org.sufficientlysecure.keychain.util;
+
+import org.sufficientlysecure.keychain.pgp.Progressable;
+
+/** This is a simple variant of ProgressScaler which shows a fixed progress message, ignoring
+ * the provided ones.
+ */
+public class ProgressFixedScaler extends ProgressScaler {
+
+ final int mResId;
+
+ public ProgressFixedScaler(Progressable wrapped, int from, int to, int max, int resId) {
+ super(wrapped, from, to, max);
+ mResId = resId;
+ }
+
+ public void setProgress(int resourceId, int progress, int max) {
+ if (mWrapped != null) {
+ mWrapped.setProgress(mResId, mFrom + progress * (mTo - mFrom) / max, mMax);
+ }
+ }
+
+ public void setProgress(String message, int progress, int max) {
+ if (mWrapped != null) {
+ mWrapped.setProgress(mResId, mFrom + progress * (mTo - mFrom) / max, mMax);
+ }
+ }
+
+}