aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-09-28 18:50:20 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-09-28 18:50:20 +0200
commitc630fe651f0fe7e4bf0cc8155ede6bd4f26df157 (patch)
treea30a3bc6556be10a6661777c7b62b817cf9bff54 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util
parent0e613aff2e617ca12c1b2e1032b21334c2ca674a (diff)
downloadopen-keychain-c630fe651f0fe7e4bf0cc8155ede6bd4f26df157.tar.gz
open-keychain-c630fe651f0fe7e4bf0cc8155ede6bd4f26df157.tar.bz2
open-keychain-c630fe651f0fe7e4bf0cc8155ede6bd4f26df157.zip
use annotations for android sdk constraints
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java58
1 files changed, 25 insertions, 33 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java
index fea3e65b6..902af3932 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java
@@ -17,6 +17,16 @@
package org.sufficientlysecure.keychain.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.text.DecimalFormat;
+
import android.annotation.TargetApi;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
@@ -31,21 +41,11 @@ import android.os.Build.VERSION_CODES;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.OpenableColumns;
-import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.widget.Toast;
import org.sufficientlysecure.keychain.R;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.text.DecimalFormat;
-
/** This class offers a number of helper functions for saving documents.
*
@@ -73,24 +73,27 @@ import java.text.DecimalFormat;
*/
public class FileHelper {
- public static void openDocument(Fragment fragment, Uri last, String mimeType, boolean multiple, int requestCode) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- openDocumentKitKat(fragment, mimeType, multiple, requestCode);
- } else {
- openDocumentPreKitKat(fragment, last, mimeType, multiple, requestCode);
- }
- }
-
+ @TargetApi(VERSION_CODES.KITKAT)
public static void saveDocument(Fragment fragment, String targetName, int requestCode) {
saveDocument(fragment, targetName, "*/*", requestCode);
}
- public static void saveDocument(Fragment fragment, String targetName, String mimeType,
- int requestCode) {
+ /** Opens the storage browser on Android 4.4 or later for saving a file. */
+ @TargetApi(VERSION_CODES.KITKAT)
+ public static void saveDocument(Fragment fragment, String mimeType, String suggestedName, int requestCode) {
+ Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
+ intent.setType(mimeType);
+ intent.putExtra("android.content.extra.SHOW_ADVANCED", true); // Note: This is not documented, but works
+ intent.putExtra(Intent.EXTRA_TITLE, suggestedName);
+ fragment.startActivityForResult(intent, requestCode);
+ }
+
+ public static void openDocument(Fragment fragment, Uri last, String mimeType, boolean multiple, int requestCode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- saveDocumentKitKat(fragment, mimeType, targetName, requestCode);
+ openDocumentKitKat(fragment, mimeType, multiple, requestCode);
} else {
- throw new RuntimeException("saveDocument does not support Android < 4.4!");
+ openDocumentPreKitKat(fragment, last, mimeType, multiple, requestCode);
}
}
@@ -127,17 +130,6 @@ public class FileHelper {
fragment.startActivityForResult(intent, requestCode);
}
- /** Opens the storage browser on Android 4.4 or later for saving a file. */
- @TargetApi(Build.VERSION_CODES.KITKAT)
- public static void saveDocumentKitKat(Fragment fragment, String mimeType, String suggestedName, int requestCode) {
- Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
- intent.addCategory(Intent.CATEGORY_OPENABLE);
- intent.setType(mimeType);
- intent.putExtra("android.content.extra.SHOW_ADVANCED", true); // Note: This is not documented, but works
- intent.putExtra(Intent.EXTRA_TITLE, suggestedName);
- fragment.startActivityForResult(intent, requestCode);
- }
-
public static String getFilename(Context context, Uri uri) {
String filename = null;
try {