0

Use CharSequence for message on ModalDialogView

This allows us to display links and other char styles on the
default ModalDialogView. This will make it easier for us to
migrate some infobars to modal dialogs, as those infobars shows text
with links today.

BUG=1240233

Change-Id: Ice785ca7cc314e24154838cd1e7cbcf289c8d5e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3092930
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Kamila Hasanbega <hkamila@chromium.org>
Reviewed-by: Theresa  <twellington@chromium.org>
Reviewed-by: Pavel Yatsuk <pavely@chromium.org>
Reviewed-by: Filip Gorski <fgorski@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#913092}
This commit is contained in:
Min Qin
2021-08-18 18:59:58 +00:00
committed by Chromium LUCI CQ
parent 7df9e5eacc
commit 042dcb2bc3
11 changed files with 37 additions and 19 deletions
chrome
android
features
autofill_assistant
java
src
org
chromium
chrome
browser
autofill_assistant
java
browser
safe_browsing
android
java
src
org
chromium
chrome
browser
ui
android
omnibox
java
src
org
chromium
chrome
browser
omnibox
components
browser_ui
modaldialog
android
java
src
org
chromium
components
permissions
android
java
src
org
chromium
components
ui/android/java/src/org/chromium/ui/modaldialog
weblayer/browser/java/org/chromium/weblayer_private

@ -456,8 +456,8 @@ class AssistantDetailsAdapter extends RecyclerView.Adapter<AssistantDetailsAdapt
if (!clickthroughData.getDescription().isEmpty()) {
builder.with(ModalDialogProperties.MESSAGE, clickthroughData.getDescription());
} else {
builder.with(ModalDialogProperties.MESSAGE, resources,
R.string.autofill_assistant_view_original_image_desc);
builder.with(ModalDialogProperties.MESSAGE,
resources.getString(R.string.autofill_assistant_view_original_image_desc));
}
if (!clickthroughData.getPositiveText().isEmpty()) {

@ -424,7 +424,8 @@ public class ActivityTabWebContentsDelegateAndroid extends TabWebContentsDelegat
.with(ModalDialogProperties.CONTROLLER, dialogController)
.with(ModalDialogProperties.TITLE, resources,
R.string.http_post_warning_title)
.with(ModalDialogProperties.MESSAGE, resources, R.string.http_post_warning)
.with(ModalDialogProperties.MESSAGE,
resources.getString(R.string.http_post_warning))
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, resources,
R.string.http_post_warning_resend)
.with(ModalDialogProperties.NEGATIVE_BUTTON_TEXT, resources,

@ -45,13 +45,13 @@ public class UsageStatsConsentDialog {
if (mIsRevocation) {
builder.with(ModalDialogProperties.TITLE, resources,
R.string.usage_stats_revocation_prompt)
.with(ModalDialogProperties.MESSAGE, resources,
R.string.usage_stats_revocation_explanation)
.with(ModalDialogProperties.MESSAGE,
resources.getString(R.string.usage_stats_revocation_explanation))
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, resources, R.string.remove);
} else {
builder.with(ModalDialogProperties.TITLE, resources, R.string.usage_stats_consent_title)
.with(ModalDialogProperties.MESSAGE, resources,
R.string.usage_stats_consent_prompt)
.with(ModalDialogProperties.MESSAGE,
resources.getString(R.string.usage_stats_consent_prompt))
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, resources, R.string.show);
}

@ -101,8 +101,8 @@ public class WebApkIconNameUpdateDialog implements ModalDialogProperties.Control
new PropertyModel.Builder(ModalDialogProperties.ALL_KEYS)
.with(ModalDialogProperties.CONTROLLER, this)
.with(ModalDialogProperties.TITLE, resources, titleId)
.with(ModalDialogProperties.MESSAGE, resources,
R.string.webapp_update_explanation)
.with(ModalDialogProperties.MESSAGE,
resources.getString(R.string.webapp_update_explanation))
.with(ModalDialogProperties.CUSTOM_VIEW, dialogCustomView)
.with(ModalDialogProperties.PRIMARY_BUTTON_FILLED, true)
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, resources, R.string.ok)

@ -43,8 +43,9 @@ public class NoProtectionConfirmationDialog {
.with(ModalDialogProperties.CONTROLLER, makeController())
.with(ModalDialogProperties.TITLE, resources,
R.string.safe_browsing_no_protection_confirmation_dialog_title)
.with(ModalDialogProperties.MESSAGE, resources,
R.string.safe_browsing_no_protection_confirmation_dialog_message)
.with(ModalDialogProperties.MESSAGE,
resources.getString(
R.string.safe_browsing_no_protection_confirmation_dialog_message))
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, resources,
R.string.safe_browsing_no_protection_confirmation_dialog_confirm)
.with(ModalDialogProperties.PRIMARY_BUTTON_FILLED, true)

@ -540,7 +540,7 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener,
new PropertyModel.Builder(ModalDialogProperties.ALL_KEYS)
.with(ModalDialogProperties.CONTROLLER, dialogController)
.with(ModalDialogProperties.TITLE, suggestion.getDisplayText())
.with(ModalDialogProperties.MESSAGE, resources, dialogMessageId)
.with(ModalDialogProperties.MESSAGE, resources.getString(dialogMessageId))
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, resources, R.string.ok)
.with(ModalDialogProperties.NEGATIVE_BUTTON_TEXT, resources,
R.string.cancel)

@ -8,6 +8,7 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
@ -89,6 +90,7 @@ public class ModalDialogView extends BoundedLinearLayout implements View.OnClick
mPositiveButton.setOnClickListener(this);
mNegativeButton.setOnClickListener(this);
mMessageView.setMovementMethod(LinkMovementMethod.getInstance());
updateContentVisibility();
updateButtonVisibility();
@ -247,7 +249,7 @@ public class ModalDialogView extends BoundedLinearLayout implements View.OnClick
}
/** @param message The message in the dialog content. */
void setMessage(String message) {
void setMessage(CharSequence message) {
mMessageView.setText(message);
updateContentVisibility();
}

@ -21,6 +21,9 @@ import static org.hamcrest.Matchers.not;
import android.app.Activity;
import android.content.res.Resources;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
@ -199,8 +202,8 @@ public class ModalDialogViewTest {
@Feature({"ModalDialog"})
public void testMessage() {
// Verify that the message set from builder is displayed.
PropertyModel model = createModel(
mModelBuilder.with(ModalDialogProperties.MESSAGE, sResources, R.string.more));
String msg = sResources.getString(R.string.more);
PropertyModel model = createModel(mModelBuilder.with(ModalDialogProperties.MESSAGE, msg));
onView(withId(R.id.title_container)).check(matches(not(isDisplayed())));
onView(withId(R.id.scrollable_title_container)).check(matches(not(isDisplayed())));
onView(withId(R.id.modal_dialog_scroll_view)).check(matches(isDisplayed()));
@ -212,6 +215,15 @@ public class ModalDialogViewTest {
onView(withId(R.id.scrollable_title_container)).check(matches(not(isDisplayed())));
onView(withId(R.id.modal_dialog_scroll_view)).check(matches(not(isDisplayed())));
onView(withId(R.id.message)).check(matches(not(isDisplayed())));
// Use CharSequence for the message.
SpannableStringBuilder sb = new SpannableStringBuilder(msg);
sb.setSpan(new ForegroundColorSpan(0xffff0000), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TestThreadUtils.runOnUiThreadBlocking(() -> model.set(ModalDialogProperties.MESSAGE, sb));
onView(withId(R.id.title_container)).check(matches(not(isDisplayed())));
onView(withId(R.id.scrollable_title_container)).check(matches(not(isDisplayed())));
onView(withId(R.id.modal_dialog_scroll_view)).check(matches(isDisplayed()));
onView(withId(R.id.message)).check(matches(allOf(isDisplayed(), withText(R.string.more))));
}
@Test

@ -232,8 +232,9 @@ public class PermissionDialogController
.with(ModalDialogProperties.TITLE,
context.getString(R.string.overlay_detected_dialog_title,
BuildInfo.getInstance().hostPackageLabel))
.with(ModalDialogProperties.MESSAGE, context.getResources(),
R.string.overlay_detected_dialog_message)
.with(ModalDialogProperties.MESSAGE,
context.getResources().getString(
R.string.overlay_detected_dialog_message))
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, context.getResources(),
R.string.cancel)
.with(ModalDialogProperties.NEGATIVE_BUTTON_TEXT, context.getResources(),

@ -71,7 +71,7 @@ public class ModalDialogProperties {
new WritableObjectPropertyKey<>();
/** The message of the dialog. */
public static final WritableObjectPropertyKey<String> MESSAGE =
public static final WritableObjectPropertyKey<CharSequence> MESSAGE =
new WritableObjectPropertyKey<>();
/** The customized content view of the dialog. */

@ -512,7 +512,8 @@ public final class BrowserViewController
.with(ModalDialogProperties.CONTROLLER, dialogController)
.with(ModalDialogProperties.TITLE, resources,
R.string.http_post_warning_title)
.with(ModalDialogProperties.MESSAGE, resources, R.string.http_post_warning)
.with(ModalDialogProperties.MESSAGE,
resources.getString(R.string.http_post_warning))
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, resources,
R.string.http_post_warning_resend)
.with(ModalDialogProperties.NEGATIVE_BUTTON_TEXT, resources,