Commit 15f3437d authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

Add TextBubble String Constructor

Adds a generic constructor to widget.TextBubble to accept a String so
that formattable string resources can be used in TextBubbles.

This CL is 2 of 4 to move the DataSaver "Chrome saved you XX data" from
a snackbar to an IPH.

Bug: 878337
Change-Id: I35b04641bcd680fa4eaa527f265b4c7f33f6ddd1
Reviewed-on: https://chromium-review.googlesource.com/c/1492472
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636886}
parent f5211bfb
...@@ -76,13 +76,11 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -76,13 +76,11 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
private long mAutoDismissTimeoutMs; private long mAutoDismissTimeoutMs;
// Content specific variables. // Content specific variables.
/** The resource id for the string to show in the bubble. */ /** The string to show in the bubble. */
@StringRes private final String mString;
private final int mStringId;
/** The resource id for the accessibility string associated with the bubble. */ /** The accessibility string associated with the bubble. */
@StringRes private final String mAccessibilityString;
private final int mAccessibilityStringId;
/** The content view shown in the popup window. */ /** The content view shown in the popup window. */
protected View mContentView; protected View mContentView;
...@@ -158,10 +156,25 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -158,10 +156,25 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
public TextBubble(Context context, View rootView, @StringRes int stringId, public TextBubble(Context context, View rootView, @StringRes int stringId,
@StringRes int accessibilityStringId, boolean showArrow, @StringRes int accessibilityStringId, boolean showArrow,
RectProvider anchorRectProvider) { RectProvider anchorRectProvider) {
this(context, rootView, context.getString(stringId),
context.getString(accessibilityStringId), showArrow, anchorRectProvider);
}
/**
* Constructs a {@link TextBubble} instance.
* @param context Context to draw resources from.
* @param rootView The {@link View} to use for size calculations and for display.
* @param contentString The string for the text that should be shown.
* @param accessibilityString The string shown in the bubble when accessibility is enabled.
* @param showArrow Whether the bubble should have an arrow.
* @param anchorRectProvider The {@link RectProvider} used to anchor the text bubble.
*/
public TextBubble(Context context, View rootView, String contentString,
String accessibilityString, boolean showArrow, RectProvider anchorRectProvider) {
mContext = context; mContext = context;
mRootView = rootView.getRootView(); mRootView = rootView.getRootView();
mStringId = stringId; mString = contentString;
mAccessibilityStringId = accessibilityStringId; mAccessibilityString = accessibilityString;
mDrawable = new ArrowBubbleDrawable(context); mDrawable = new ArrowBubbleDrawable(context);
mDrawable.setShowArrow(showArrow); mDrawable.setShowArrow(showArrow);
...@@ -321,8 +334,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -321,8 +334,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param view The {@link TextView} to set text on. * @param view The {@link TextView} to set text on.
*/ */
protected void setText(TextView view) { protected void setText(TextView view) {
view.setText( view.setText(AccessibilityUtil.isAccessibilityEnabled() ? mAccessibilityString : mString);
AccessibilityUtil.isAccessibilityEnabled() ? mAccessibilityStringId : mStringId);
} }
/** /**
...@@ -343,7 +355,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -343,7 +355,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
view = mRootView; view = mRootView;
} }
if (view == null) return; if (view == null) return;
view.announceForAccessibility(mContext.getString(mAccessibilityStringId)); view.announceForAccessibility(mAccessibilityString);
} }
}); });
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment