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

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

Issue 620263002: Update showKeyboard method to be more aggressive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e46e6fec402dba7bacb9adeded4f4d0543a08639..10f33162d47aa04b78f5b8ff402f35dd3098f090 100644
--- a/ui/android/java/src/org/chromium/ui/UiUtils.java
+++ b/ui/android/java/src/org/chromium/ui/UiUtils.java
@@ -8,12 +8,15 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
+import android.os.Handler;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
+import java.util.concurrent.atomic.AtomicInteger;
+
/**
* Utility functions for common Android UI tasks.
* This class is not supposed to be instantiated.
@@ -21,6 +24,9 @@ import android.view.inputmethod.InputMethodManager;
public class UiUtils {
private static final String TAG = "UiUtils";
+ private static final int KEYBOARD_RETRY_ATTEMPTS = 10;
+ private static final long KEYBOARD_RETRY_DELAY_MS = 100;
+
/**
* Guards this class from being instantiated.
*/
@@ -59,12 +65,29 @@ public class UiUtils {
* Shows the software keyboard if necessary.
* @param view The currently focused {@link View}, which would receive soft keyboard input.
*/
- public static void showKeyboard(View view) {
- InputMethodManager imm =
- (InputMethodManager) view.getContext().getSystemService(
- Context.INPUT_METHOD_SERVICE);
- // Only shows soft keyboard if there isn't an open physical keyboard.
- imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
+ public static void showKeyboard(final View view) {
+ final Handler handler = new Handler();
+ final AtomicInteger attempt = new AtomicInteger();
+ Runnable openRunnable = new Runnable() {
+ @Override
+ public void run() {
+ // Not passing InputMethodManager.SHOW_IMPLICIT as it does not trigger the
+ // keyboard in landscape mode.
+ InputMethodManager imm =
+ (InputMethodManager) view.getContext().getSystemService(
+ Context.INPUT_METHOD_SERVICE);
+ try {
+ imm.showSoftInput(view, 0);
+ } catch (IllegalArgumentException e) {
+ if (attempt.incrementAndGet() <= KEYBOARD_RETRY_ATTEMPTS) {
+ handler.postDelayed(this, KEYBOARD_RETRY_DELAY_MS);
+ } else {
+ Log.e(TAG, "Unable to open keyboard. Giving up.", e);
+ }
+ }
+ }
+ };
+ openRunnable.run();
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698