Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Unified Diff: ui/android/java/src/org/chromium/ui/UiUtils.java

Issue 913033002: Extend ShareHelper#share to share a screenshot as a stream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix findbugs Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/android/java/src/org/chromium/ui/UiUtils.java
diff --git a/ui/android/java/src/org/chromium/ui/UiUtils.java b/ui/android/java/src/org/chromium/ui/UiUtils.java
index 10f33162d47aa04b78f5b8ff402f35dd3098f090..c164641a1cf486d860bd9b52ee55f7704d7b1e38 100644
--- a/ui/android/java/src/org/chromium/ui/UiUtils.java
+++ b/ui/android/java/src/org/chromium/ui/UiUtils.java
@@ -8,6 +8,9 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
+import android.net.Uri;
+import android.os.Build;
+import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.SurfaceView;
@@ -15,6 +18,10 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
+import org.chromium.base.ContentUriUtils;
+
+import java.io.File;
+import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -27,6 +34,10 @@ public class UiUtils {
private static final int KEYBOARD_RETRY_ATTEMPTS = 10;
private static final long KEYBOARD_RETRY_DELAY_MS = 100;
+ public static final String EXTERNAL_IMAGE_FILE_PATH = "browser-images";
+ // Keep this variable in sync with the value defined in file_paths.xml.
+ public static final String IMAGE_FILE_PATH = "images";
+
/**
* Guards this class from being instantiated.
*/
@@ -239,4 +250,45 @@ public class UiUtils {
view.setWillNotDraw(!takingScreenshot);
}
}
+
+ /**
+ * Get a directory for the image capture operation. For devices with JB MR2
+ * or latter android versions, the directory is IMAGE_FILE_PATH directory.
+ * For ICS devices, the directory is CAPTURE_IMAGE_DIRECTORY.
+ *
+ * @param context The application context.
+ * @return directory for the captured image to be stored.
+ */
+ public static File getDirectoryForImageCapture(Context context) throws IOException {
+ File path;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ path = new File(context.getFilesDir(), IMAGE_FILE_PATH);
+ if (!path.exists() && !path.mkdir()) {
+ throw new IOException("Folder cannot be created.");
+ }
+ } else {
+ File externalDataDir =
+ Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
+ path = new File(
+ externalDataDir.getAbsolutePath() + File.separator + EXTERNAL_IMAGE_FILE_PATH);
+ if (!path.exists() && !path.mkdirs()) {
+ path = externalDataDir;
+ }
+ }
+ return path;
+ }
+
+ /**
+ * Get a URI for |file| which has the image capture. This function assumes that path of |file|
+ * is based on the result of UiUtils.getDirectoryForImageCapture().
+ *
+ * @param context The application context.
+ * @param file image capture file.
+ * @return URI for |file|.
+ */
+ public static Uri getUriForImageCaptureFile(Context context, File file) {
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2
+ ? ContentUriUtils.getContentUriFromFile(context, file)
+ : Uri.fromFile(file);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698