diff options
author | butnariu@chromium.org <butnariu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-01 16:11:36 +0000 |
---|---|---|
committer | butnariu@chromium.org <butnariu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-01 16:11:36 +0000 |
commit | ef25718ab493c764bacc8b028aaafa1f2ac0667b (patch) | |
tree | 602a4a1f1fb92ced63ecd14acf877c07ee08b098 /chrome/android | |
parent | 79edb22ffdc18ae4b5f9db084114275182b2738e (diff) | |
download | chromium_src-ef25718ab493c764bacc8b028aaafa1f2ac0667b.zip chromium_src-ef25718ab493c764bacc8b028aaafa1f2ac0667b.tar.gz chromium_src-ef25718ab493c764bacc8b028aaafa1f2ac0667b.tar.bz2 |
Display problems for Javascript modal dialogs on Android were caused by using setMessage in the AlertDialog.Builder, while at the same time setting the AlertDialog layout inside a ScrollView element. Removed setMessage and made the modal dialog layout a linear one, containing a scroll view for the text, followed by the edit text field and the checkbox.
ScrollView has heigh of 0dp and weight of 1 so that the ScrollView can expand exactly as much as necessary in order to wrap the TextView content and not fill the whole AlertDialog. For more information regarding this layout choice see the Layout Weight paragraph from: http://developer.android.com/guide/topics/ui/layout/linear.html/
Fix for BUG=313232
Review URL: https://codereview.chromium.org/65163002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/android')
-rw-r--r-- | chrome/android/java/res/layout/js_modal_dialog.xml | 51 | ||||
-rw-r--r-- | chrome/android/java/src/org/chromium/chrome/browser/JavascriptAppModalDialog.java | 16 |
2 files changed, 44 insertions, 23 deletions
diff --git a/chrome/android/java/res/layout/js_modal_dialog.xml b/chrome/android/java/res/layout/js_modal_dialog.xml index 9df1b9c..52ce78f 100644 --- a/chrome/android/java/res/layout/js_modal_dialog.xml +++ b/chrome/android/java/res/layout/js_modal_dialog.xml @@ -13,30 +13,43 @@ TODO(benm): Move this into the framework once we are integrated with the Android tree. --> -<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" - android:layout_height="match_parent"> - <LinearLayout - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical" - android:padding="5dp"> + android:layout_height="match_parent" + android:orientation="vertical" + android:padding="5dp"> - <EditText android:id="@+id/js_modal_dialog_prompt" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:singleLine="true" - android:visibility="gone" - android:contentDescription="@string/accessibility_js_modal_dialog_prompt" - /> + <ScrollView android:id="@+id/js_modal_dialog_scroll_view" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:layout_marginStart="10dp" + android:layout_marginTop="5dp" + android:layout_marginBottom="5dp"> - <CheckBox android:id="@+id/suppress_js_modal_dialogs" - android:textAppearance="?android:attr/textAppearanceSmall" + <TextView android:id="@+id/js_modal_dialog_message" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/suppress_js_modal_dialogs" android:layout_gravity="start" + android:textAppearance="?android:attr/textAppearanceMedium" /> - </LinearLayout> -</ScrollView> + </ScrollView> + + <EditText android:id="@+id/js_modal_dialog_prompt" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:singleLine="true" + android:visibility="gone" + android:contentDescription="@string/accessibility_js_modal_dialog_prompt" + /> + + <CheckBox android:id="@+id/suppress_js_modal_dialogs" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="start" + android:textAppearance="?android:attr/textAppearanceSmall" + android:text="@string/suppress_js_modal_dialogs" + /> + +</LinearLayout> diff --git a/chrome/android/java/src/org/chromium/chrome/browser/JavascriptAppModalDialog.java b/chrome/android/java/src/org/chromium/chrome/browser/JavascriptAppModalDialog.java index a25f7f2..2c1813f 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/JavascriptAppModalDialog.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/JavascriptAppModalDialog.java @@ -7,6 +7,7 @@ package org.chromium.chrome.browser; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -30,7 +31,7 @@ public class JavascriptAppModalDialog implements DialogInterface.OnClickListener private long mNativeDialogPointer; private AlertDialog mDialog; private CheckBox mSuppressCheckBox; - private TextView mPrompTextView; + private TextView mPromptTextView; private JavascriptAppModalDialog(String title, String message, boolean shouldShowSuppressCheckBox) { @@ -78,14 +79,13 @@ public class JavascriptAppModalDialog implements DialogInterface.OnClickListener ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.js_modal_dialog, null); mSuppressCheckBox = (CheckBox) layout.findViewById(R.id.suppress_js_modal_dialogs); - mPrompTextView = (TextView) layout.findViewById(R.id.js_modal_dialog_prompt); + mPromptTextView = (TextView) layout.findViewById(R.id.js_modal_dialog_prompt); prepare(layout); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context) .setView(layout) .setTitle(mTitle) - .setMessage(mMessage) .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { @@ -159,7 +159,7 @@ public class JavascriptAppModalDialog implements DialogInterface.OnClickListener } public void onPositiveButtonClicked() { - confirm(mPrompTextView.getText().toString(), mSuppressCheckBox.isChecked()); + confirm(mPromptTextView.getText().toString(), mSuppressCheckBox.isChecked()); mDialog.dismiss(); } @@ -172,6 +172,14 @@ public class JavascriptAppModalDialog implements DialogInterface.OnClickListener // Display the checkbox for suppressing dialogs if necessary. layout.findViewById(R.id.suppress_js_modal_dialogs).setVisibility( mShouldShowSuppressCheckBox ? View.VISIBLE : View.GONE); + + // If the message is null or empty do not display the message text view. + // Hide parent scroll view instead of text view in order to prevent ui discrepancies. + if (TextUtils.isEmpty(mMessage)) { + layout.findViewById(R.id.js_modal_dialog_scroll_view).setVisibility(View.GONE); + } else { + ((TextView) layout.findViewById(R.id.js_modal_dialog_message)).setText(mMessage); + } } public void confirm(String promptResult, boolean suppressDialogs) { |