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

Side by Side Diff: ui/android/java/src/org/chromium/ui/UiUtils.java

Issue 2737393002: Implement the new Photo picker, part one. (Closed)
Patch Set: Address Theresa's comments Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 */ 49 */
50 private UiUtils() { 50 private UiUtils() {
51 } 51 }
52 52
53 /** The minimum size of the bottom margin below the app to detect a keyboard . */ 53 /** The minimum size of the bottom margin below the app to detect a keyboard . */
54 private static final float KEYBOARD_DETECT_BOTTOM_THRESHOLD_DP = 100; 54 private static final float KEYBOARD_DETECT_BOTTOM_THRESHOLD_DP = 100;
55 55
56 /** A delegate that allows disabling keyboard visibility detection. */ 56 /** A delegate that allows disabling keyboard visibility detection. */
57 private static KeyboardShowingDelegate sKeyboardShowingDelegate; 57 private static KeyboardShowingDelegate sKeyboardShowingDelegate;
58 58
59 /** A delegate for the photo picker. */
60 private static PhotoPickerDelegate sPhotoPickerDelegate;
61
59 /** 62 /**
60 * A delegate that can be implemented to override whether or not keyboard de tection will be 63 * A delegate that can be implemented to override whether or not keyboard de tection will be
61 * used. 64 * used.
62 */ 65 */
63 public interface KeyboardShowingDelegate { 66 public interface KeyboardShowingDelegate {
64 /** 67 /**
65 * Will be called to determine whether or not to detect if the keyboard is visible. 68 * Will be called to determine whether or not to detect if the keyboard is visible.
66 * @param context A {@link Context} instance. 69 * @param context A {@link Context} instance.
67 * @param view A {@link View}. 70 * @param view A {@link View}.
68 * @return Whether or not the keyboard check should be disabled. 71 * @return Whether or not the keyboard check should be disabled.
69 */ 72 */
70 boolean disableKeyboardCheck(Context context, View view); 73 boolean disableKeyboardCheck(Context context, View view);
71 } 74 }
72 75
73 /** 76 /**
77 * A delegate interface for the photo picker.
78 */
79 public interface PhotoPickerDelegate {
80 /**
81 * Called to display the photo picker.
82 * @param context The context to use.
83 * @param listener The listener that will be notified of the action the user took in the
84 * picker.
85 * @param allowMultiple Whether the dialog should allow multiple images to be selected.
86 */
87 void showPhotoPicker(Context context, PhotoPickerListener listener, bool ean allowMultiple);
88
89 /**
90 * Called when the photo picker dialog should be dismissed.
91 */
92 void dismissPhotoPicker();
93 }
94
95 // PhotoPickerDelegate:
96
97 /**
98 * Called to display the photo picker.
99 * @param context The context to use.
100 * @param listener The listener that will be notified of the action the user took in the
101 * picker.
102 * @param allowMultiple Whether the dialog should allow multiple images to b e selected.
103 */
104 public static boolean showPhotoPicker(
105 Context context, PhotoPickerListener listener, boolean allowMultiple ) {
106 if (sPhotoPickerDelegate == null) return false;
107 sPhotoPickerDelegate.showPhotoPicker(context, listener, allowMultiple);
108 return true;
109 }
110
111 /**
112 * Called when the photo picker dialog should be dismissed.
113 */
114 public static void dismissPhotoPicker() {
115 if (sPhotoPickerDelegate == null) return;
116 sPhotoPickerDelegate.dismissPhotoPicker();
117 }
118
119 // KeyboardShowingDelegate:
120
121 /**
74 * Allows setting a delegate to override the default software keyboard visib ility detection. 122 * Allows setting a delegate to override the default software keyboard visib ility detection.
75 * @param delegate A {@link KeyboardShowingDelegate} instance. 123 * @param delegate A {@link KeyboardShowingDelegate} instance.
76 */ 124 */
77 public static void setKeyboardShowingDelegate(KeyboardShowingDelegate delega te) { 125 public static void setKeyboardShowingDelegate(KeyboardShowingDelegate delega te) {
78 sKeyboardShowingDelegate = delegate; 126 sKeyboardShowingDelegate = delegate;
79 } 127 }
80 128
81 /** 129 /**
130 * Allows setting a delegate to override the default Android stock photo pic ker.
131 * @param delegate A {@link PhotoPickerDelegate} instance.
132 */
133 public static void setPhotoPickerDelegate(PhotoPickerDelegate delegate) {
Theresa 2017/03/16 16:26:17 nit: move this above showPhotoPicker()
Finnur 2017/03/17 10:11:45 Done.
134 sPhotoPickerDelegate = delegate;
135 }
136
137 /**
82 * Shows the software keyboard if necessary. 138 * Shows the software keyboard if necessary.
83 * @param view The currently focused {@link View}, which would receive soft keyboard input. 139 * @param view The currently focused {@link View}, which would receive soft keyboard input.
84 */ 140 */
85 public static void showKeyboard(final View view) { 141 public static void showKeyboard(final View view) {
86 final Handler handler = new Handler(); 142 final Handler handler = new Handler();
87 final AtomicInteger attempt = new AtomicInteger(); 143 final AtomicInteger attempt = new AtomicInteger();
88 Runnable openRunnable = new Runnable() { 144 Runnable openRunnable = new Runnable() {
89 @Override 145 @Override
90 public void run() { 146 public void run() {
91 // Not passing InputMethodManager.SHOW_IMPLICIT as it does not t rigger the 147 // Not passing InputMethodManager.SHOW_IMPLICIT as it does not t rigger the
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 * attached to the view hierarchy. 380 * attached to the view hierarchy.
325 * 381 *
326 * @param view The view to be removed from the parent. 382 * @param view The view to be removed from the parent.
327 */ 383 */
328 public static void removeViewFromParent(View view) { 384 public static void removeViewFromParent(View view) {
329 ViewGroup parent = (ViewGroup) view.getParent(); 385 ViewGroup parent = (ViewGroup) view.getParent();
330 if (parent == null) return; 386 if (parent == null) return;
331 parent.removeView(view); 387 parent.removeView(view);
332 } 388 }
333 } 389 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698