| Index: blimp/client/core/contents/android/java/src/org/chromium/blimp/core/contents/input/ImeHelperDialog.java
|
| diff --git a/blimp/client/core/contents/android/java/src/org/chromium/blimp/core/contents/input/ImeHelperDialog.java b/blimp/client/core/contents/android/java/src/org/chromium/blimp/core/contents/input/ImeHelperDialog.java
|
| index abc99467aacd38cbace61300691f74c7a364fca1..caa0085742dbc8fe5ff6a368ee8eabee0758a371 100644
|
| --- a/blimp/client/core/contents/android/java/src/org/chromium/blimp/core/contents/input/ImeHelperDialog.java
|
| +++ b/blimp/client/core/contents/android/java/src/org/chromium/blimp/core/contents/input/ImeHelperDialog.java
|
| @@ -5,14 +5,14 @@
|
| package org.chromium.blimp.core.contents.input;
|
|
|
| import android.app.Activity;
|
| +import android.app.Dialog;
|
| import android.content.Context;
|
| -import android.content.DialogInterface;
|
| -import android.support.v7.app.AlertDialog;
|
| import android.text.InputType;
|
| import android.view.KeyEvent;
|
| import android.view.View;
|
| import android.view.WindowManager;
|
| import android.view.inputmethod.EditorInfo;
|
| +import android.view.inputmethod.InputMethodManager;
|
| import android.widget.EditText;
|
| import android.widget.TextView;
|
|
|
| @@ -24,15 +24,19 @@ import org.chromium.ui.base.ime.TextInputType;
|
|
|
| /**
|
| * Helper class showing the UI that allows users to enter text into a web page.
|
| - * A pop up is created when user taps on a text area prompting user to start typing and closes as
|
| - * soon as user hits enter or presses back button.
|
| + * A pop up is created when user taps on a text area prompting user to start typing.
|
| + * As soon as user submits the text, a spinner is shown which is dismissed only after
|
| + * receiving a hide IME request from the engine.
|
| */
|
| @JNINamespace("blimp::client")
|
| -public class ImeHelperDialog {
|
| +public class ImeHelperDialog implements WebInputConfirmationPanel.Listener {
|
| private static final String TAG = "ImeHelperDialog";
|
| private final Context mContext;
|
|
|
| - private AlertDialog mAlertDialog;
|
| + private String mExistingText;
|
| + private Dialog mDialog;
|
| + private ImeEditText mEditText;
|
| +
|
| private long mNativeImeHelperDialog;
|
|
|
| @CalledByNative
|
| @@ -56,6 +60,20 @@ public class ImeHelperDialog {
|
| mNativeImeHelperDialog = 0;
|
| }
|
|
|
| + // WebInputConfirmationPanel.Listener implementation.
|
| + @Override
|
| + public void onConfirm() {
|
| + onImeTextEntered(mEditText.getText().toString(), false);
|
| + }
|
| +
|
| + // WebInputConfirmationPanel.Listener implementation.
|
| + @Override
|
| + public void onCancel() {
|
| + if (mDialog != null) {
|
| + mDialog.dismiss();
|
| + }
|
| + }
|
| +
|
| /**
|
| * Sends the text entered from IME to blimp engine.
|
| * @param text The text the user entered.
|
| @@ -64,13 +82,21 @@ public class ImeHelperDialog {
|
| private void onImeTextEntered(String text, boolean submit) {
|
| if (mNativeImeHelperDialog == 0) return;
|
|
|
| + // Hide the IME.
|
| + InputMethodManager imm =
|
| + (InputMethodManager) mContext.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
| + imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
|
| +
|
| + mEditText.setTextColor(R.color.disabled_text_color);
|
| + mEditText.setBackgroundResource(R.drawable.dotted_line);
|
| +
|
| nativeOnImeTextEntered(mNativeImeHelperDialog, text, submit);
|
| }
|
|
|
| @CalledByNative
|
| private void onShowImeRequested(int inputType, String text) {
|
| - if (mAlertDialog != null && mAlertDialog.isShowing()) {
|
| - mAlertDialog.dismiss();
|
| + if (mDialog != null && mDialog.isShowing()) {
|
| + mDialog.dismiss();
|
| }
|
|
|
| createTextInputPopup(inputType, text);
|
| @@ -78,43 +104,33 @@ public class ImeHelperDialog {
|
|
|
| @CalledByNative
|
| private void onHideImeRequested() {
|
| - if (mAlertDialog == null) return;
|
| + if (mDialog == null) return;
|
|
|
| - mAlertDialog.dismiss();
|
| + mDialog.dismiss();
|
| }
|
|
|
| private void createTextInputPopup(int inputType, String existingText) {
|
| - final View viewPopup =
|
| + mExistingText = existingText;
|
| + final View dialogView =
|
| ((Activity) mContext).getLayoutInflater().inflate(R.layout.text_input_popup, null);
|
| - final ImeEditText editText = (ImeEditText) viewPopup.findViewById(R.id.ime_edit_text);
|
| - mAlertDialog = new AlertDialog.Builder(mContext)
|
| - .setTitle(R.string.blimp_ime_dialog_title)
|
| - .setPositiveButton(R.string.blimp_form_input_ok,
|
| - new DialogInterface.OnClickListener() {
|
| - @Override
|
| - public void onClick(DialogInterface dialog, int which) {
|
| - onImeTextEntered(
|
| - editText.getText().toString(), false);
|
| - dialog.dismiss();
|
| - }
|
| - })
|
| - .setNegativeButton(R.string.blimp_form_input_cancel,
|
| - new DialogInterface.OnClickListener() {
|
| - @Override
|
| - public void onClick(DialogInterface dialog, int id) {
|
| - dialog.dismiss();
|
| - }
|
| - })
|
| - .create();
|
| - editText.initialize(mAlertDialog);
|
| - mAlertDialog.setView(viewPopup);
|
| - mAlertDialog.getWindow().setSoftInputMode(
|
| - WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
| - mAlertDialog.setCanceledOnTouchOutside(true);
|
| -
|
| - setEditorOptions(editText, inputType);
|
| - editText.setText(existingText);
|
| - editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
| +
|
| + final WebInputConfirmationPanel confirmPanel =
|
| + (WebInputConfirmationPanel) dialogView.findViewById(R.id.submit_panel);
|
| + confirmPanel.setListener(this);
|
| +
|
| + mDialog = new Dialog(mContext);
|
| + mDialog.setContentView(dialogView);
|
| + mDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
| + mDialog.setCanceledOnTouchOutside(true);
|
| +
|
| + final TextView tvLabel = (TextView) dialogView.findViewById(R.id.label);
|
| + tvLabel.setText(R.string.blimp_web_input_default_label);
|
| +
|
| + mEditText = (ImeEditText) dialogView.findViewById(R.id.ime_edit_text);
|
| + mEditText.initialize(mDialog);
|
| + mEditText.setText(existingText);
|
| + setEditorOptions(mEditText, inputType);
|
| + mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
| @Override
|
| public boolean onEditorAction(TextView tv, int actionId, KeyEvent event) {
|
| switch (actionId) {
|
| @@ -122,8 +138,8 @@ public class ImeHelperDialog {
|
| case EditorInfo.IME_ACTION_DONE:
|
| case EditorInfo.IME_ACTION_SEARCH:
|
| case EditorInfo.IME_ACTION_GO:
|
| - onImeTextEntered(tv.getText().toString(), true);
|
| - mAlertDialog.dismiss();
|
| + confirmPanel.startAnimation();
|
| + onImeTextEntered(mEditText.getText().toString(), true);
|
| return true;
|
| default:
|
| return false;
|
| @@ -131,9 +147,8 @@ public class ImeHelperDialog {
|
| }
|
| });
|
|
|
| - editText.requestFocus();
|
| -
|
| - mAlertDialog.show();
|
| + mDialog.show();
|
| + mEditText.requestFocus();
|
| }
|
|
|
| /**
|
| @@ -148,36 +163,36 @@ public class ImeHelperDialog {
|
| switch (inputTypeEngine) {
|
| case TextInputType.TEXT:
|
| inputType = InputType.TYPE_CLASS_TEXT;
|
| - imeOptions = EditorInfo.IME_ACTION_GO;
|
| + imeOptions |= EditorInfo.IME_ACTION_GO;
|
| break;
|
| case TextInputType.PASSWORD:
|
| inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
| - imeOptions = EditorInfo.IME_ACTION_GO;
|
| + imeOptions |= EditorInfo.IME_ACTION_GO;
|
| break;
|
| case TextInputType.SEARCH:
|
| - imeOptions = EditorInfo.IME_ACTION_SEARCH;
|
| + imeOptions |= EditorInfo.IME_ACTION_SEARCH;
|
| break;
|
| case TextInputType.EMAIL:
|
| inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
| - imeOptions = EditorInfo.IME_ACTION_GO;
|
| + imeOptions |= EditorInfo.IME_ACTION_GO;
|
| break;
|
| case TextInputType.NUMBER:
|
| inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL
|
| | InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
| - imeOptions = EditorInfo.IME_ACTION_NEXT;
|
| + imeOptions |= EditorInfo.IME_ACTION_NEXT;
|
| break;
|
| case TextInputType.TELEPHONE:
|
| inputType = InputType.TYPE_CLASS_PHONE;
|
| - imeOptions = EditorInfo.IME_ACTION_NEXT;
|
| + imeOptions |= EditorInfo.IME_ACTION_NEXT;
|
| break;
|
| case TextInputType.URL:
|
| inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
|
| - imeOptions = EditorInfo.IME_ACTION_GO;
|
| + imeOptions |= EditorInfo.IME_ACTION_GO;
|
| break;
|
| case TextInputType.TEXT_AREA:
|
| case TextInputType.CONTENT_EDITABLE:
|
| - inputType = InputType.TYPE_TEXT_FLAG_MULTI_LINE;
|
| - imeOptions = EditorInfo.IME_ACTION_NONE;
|
| + inputType |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
|
| + imeOptions |= EditorInfo.IME_ACTION_NONE;
|
| break;
|
| default:
|
| inputType = InputType.TYPE_CLASS_TEXT;
|
|
|