OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.ui; | 5 package org.chromium.ui; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
9 import android.graphics.Canvas; | 9 import android.graphics.Canvas; |
10 import android.graphics.Rect; | 10 import android.graphics.Rect; |
| 11 import android.net.Uri; |
| 12 import android.os.Build; |
| 13 import android.os.Environment; |
11 import android.os.Handler; | 14 import android.os.Handler; |
12 import android.util.Log; | 15 import android.util.Log; |
13 import android.view.SurfaceView; | 16 import android.view.SurfaceView; |
14 import android.view.View; | 17 import android.view.View; |
15 import android.view.ViewGroup; | 18 import android.view.ViewGroup; |
16 import android.view.inputmethod.InputMethodManager; | 19 import android.view.inputmethod.InputMethodManager; |
17 | 20 |
| 21 import org.chromium.base.ContentUriUtils; |
| 22 |
| 23 import java.io.File; |
| 24 import java.io.IOException; |
18 import java.util.concurrent.atomic.AtomicInteger; | 25 import java.util.concurrent.atomic.AtomicInteger; |
19 | 26 |
20 /** | 27 /** |
21 * Utility functions for common Android UI tasks. | 28 * Utility functions for common Android UI tasks. |
22 * This class is not supposed to be instantiated. | 29 * This class is not supposed to be instantiated. |
23 */ | 30 */ |
24 public class UiUtils { | 31 public class UiUtils { |
25 private static final String TAG = "UiUtils"; | 32 private static final String TAG = "UiUtils"; |
26 | 33 |
27 private static final int KEYBOARD_RETRY_ATTEMPTS = 10; | 34 private static final int KEYBOARD_RETRY_ATTEMPTS = 10; |
28 private static final long KEYBOARD_RETRY_DELAY_MS = 100; | 35 private static final long KEYBOARD_RETRY_DELAY_MS = 100; |
29 | 36 |
| 37 public static final String EXTERNAL_IMAGE_FILE_PATH = "browser-images"; |
| 38 // Keep this variable in sync with the value defined in file_paths.xml. |
| 39 public static final String IMAGE_FILE_PATH = "images"; |
| 40 |
30 /** | 41 /** |
31 * Guards this class from being instantiated. | 42 * Guards this class from being instantiated. |
32 */ | 43 */ |
33 private UiUtils() { | 44 private UiUtils() { |
34 } | 45 } |
35 | 46 |
36 /** The minimum size of the bottom margin below the app to detect a keyboard
. */ | 47 /** The minimum size of the bottom margin below the app to detect a keyboard
. */ |
37 private static final float KEYBOARD_DETECT_BOTTOM_THRESHOLD_DP = 100; | 48 private static final float KEYBOARD_DETECT_BOTTOM_THRESHOLD_DP = 100; |
38 | 49 |
39 /** A delegate that allows disabling keyboard visibility detection. */ | 50 /** A delegate that allows disabling keyboard visibility detection. */ |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 private static void prepareViewHierarchyForScreenshot(View view, boolean tak
ingScreenshot) { | 243 private static void prepareViewHierarchyForScreenshot(View view, boolean tak
ingScreenshot) { |
233 if (view instanceof ViewGroup) { | 244 if (view instanceof ViewGroup) { |
234 ViewGroup viewGroup = (ViewGroup) view; | 245 ViewGroup viewGroup = (ViewGroup) view; |
235 for (int i = 0; i < viewGroup.getChildCount(); i++) { | 246 for (int i = 0; i < viewGroup.getChildCount(); i++) { |
236 prepareViewHierarchyForScreenshot(viewGroup.getChildAt(i), takin
gScreenshot); | 247 prepareViewHierarchyForScreenshot(viewGroup.getChildAt(i), takin
gScreenshot); |
237 } | 248 } |
238 } else if (view instanceof SurfaceView) { | 249 } else if (view instanceof SurfaceView) { |
239 view.setWillNotDraw(!takingScreenshot); | 250 view.setWillNotDraw(!takingScreenshot); |
240 } | 251 } |
241 } | 252 } |
| 253 |
| 254 /** |
| 255 * Get a directory for the image capture operation. For devices with JB MR2 |
| 256 * or latter android versions, the directory is IMAGE_FILE_PATH directory. |
| 257 * For ICS devices, the directory is CAPTURE_IMAGE_DIRECTORY. |
| 258 * |
| 259 * @param context The application context. |
| 260 * @return directory for the captured image to be stored. |
| 261 */ |
| 262 public static File getDirectoryForImageCapture(Context context) throws IOExc
eption { |
| 263 File path; |
| 264 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { |
| 265 path = new File(context.getFilesDir(), IMAGE_FILE_PATH); |
| 266 if (!path.exists() && !path.mkdir()) { |
| 267 throw new IOException("Folder cannot be created."); |
| 268 } |
| 269 } else { |
| 270 File externalDataDir = |
| 271 Environment.getExternalStoragePublicDirectory(Environment.DI
RECTORY_DCIM); |
| 272 path = new File( |
| 273 externalDataDir.getAbsolutePath() + File.separator + EXTERNA
L_IMAGE_FILE_PATH); |
| 274 if (!path.exists() && !path.mkdirs()) { |
| 275 path = externalDataDir; |
| 276 } |
| 277 } |
| 278 return path; |
| 279 } |
| 280 |
| 281 /** |
| 282 * Get a URI for |file| which has the image capture. This function assumes t
hat path of |file| |
| 283 * is based on the result of UiUtils.getDirectoryForImageCapture(). |
| 284 * |
| 285 * @param context The application context. |
| 286 * @param file image capture file. |
| 287 * @return URI for |file|. |
| 288 */ |
| 289 public static Uri getUriForImageCaptureFile(Context context, File file) { |
| 290 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 |
| 291 ? ContentUriUtils.getContentUriFromFile(context, file) |
| 292 : Uri.fromFile(file); |
| 293 } |
242 } | 294 } |
OLD | NEW |