Commit d7df279b authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Added min width/height to ui framework.

Bug: b/145043394
Change-Id: I58214e0073f255662c6efca3f3f1e47f1c8b94ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124711Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#754836}
parent 1343d831
...@@ -64,7 +64,7 @@ public class AssistantViewFactory { ...@@ -64,7 +64,7 @@ public class AssistantViewFactory {
@CalledByNative @CalledByNative
public static void setViewLayoutParams(View view, Context context, int width, int height, public static void setViewLayoutParams(View view, Context context, int width, int height,
float weight, int marginStart, int marginTop, int marginEnd, int marginBottom, float weight, int marginStart, int marginTop, int marginEnd, int marginBottom,
int layoutGravity) { int layoutGravity, int minimumWidth, int minimumHeight) {
if (width > 0) { if (width > 0) {
width = AssistantDimension.getPixelSizeDp(context, width); width = AssistantDimension.getPixelSizeDp(context, width);
} }
...@@ -80,6 +80,8 @@ public class AssistantViewFactory { ...@@ -80,6 +80,8 @@ public class AssistantViewFactory {
layoutParams.bottomMargin = AssistantDimension.getPixelSizeDp(context, marginBottom); layoutParams.bottomMargin = AssistantDimension.getPixelSizeDp(context, marginBottom);
layoutParams.gravity = layoutGravity; layoutParams.gravity = layoutGravity;
view.setLayoutParams(layoutParams); view.setLayoutParams(layoutParams);
view.setMinimumWidth(AssistantDimension.getPixelSizeDp(context, minimumWidth));
view.setMinimumHeight(AssistantDimension.getPixelSizeDp(context, minimumHeight));
} }
/** Creates a {@code android.widget.LinearLayout} widget. */ /** Creates a {@code android.widget.LinearLayout} widget. */
......
...@@ -34,6 +34,7 @@ import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUi ...@@ -34,6 +34,7 @@ import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUi
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.isImportantForAccessibility; import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.isImportantForAccessibility;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.startAutofillAssistant; import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.startAutofillAssistant;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.waitUntilViewMatchesCondition; import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.waitUntilViewMatchesCondition;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.withMinimumSize;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
...@@ -49,6 +50,7 @@ import org.chromium.base.test.util.CommandLineFlags; ...@@ -49,6 +50,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisableIf; import org.chromium.base.test.util.DisableIf;
import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.autofill_assistant.R; import org.chromium.chrome.autofill_assistant.R;
import org.chromium.chrome.browser.autofill_assistant.generic_ui.AssistantDimension;
import org.chromium.chrome.browser.autofill_assistant.proto.ActionProto; import org.chromium.chrome.browser.autofill_assistant.proto.ActionProto;
import org.chromium.chrome.browser.autofill_assistant.proto.BooleanAndProto; import org.chromium.chrome.browser.autofill_assistant.proto.BooleanAndProto;
import org.chromium.chrome.browser.autofill_assistant.proto.BooleanList; import org.chromium.chrome.browser.autofill_assistant.proto.BooleanList;
...@@ -1089,6 +1091,9 @@ public class AutofillAssistantGenericUiTest { ...@@ -1089,6 +1091,9 @@ public class AutofillAssistantGenericUiTest {
.setRootView( .setRootView(
ViewProto.newBuilder() ViewProto.newBuilder()
.setIdentifier("text_view") .setIdentifier("text_view")
.setLayoutParams(
ViewLayoutParamsProto.newBuilder().setMinimumHeight(
48))
.setTextView(TextViewProto.newBuilder().setModelIdentifier( .setTextView(TextViewProto.newBuilder().setModelIdentifier(
"date_string"))) "date_string")))
.setInteractions( .setInteractions(
...@@ -1115,6 +1120,10 @@ public class AutofillAssistantGenericUiTest { ...@@ -1115,6 +1120,10 @@ public class AutofillAssistantGenericUiTest {
startAutofillAssistant(mTestRule.getActivity(), testService); startAutofillAssistant(mTestRule.getActivity(), testService);
waitUntilViewMatchesCondition(withText("date not set"), isCompletelyDisplayed()); waitUntilViewMatchesCondition(withText("date not set"), isCompletelyDisplayed());
onView(withText("date not set"))
.check(matches(withMinimumSize(0,
AssistantDimension.getPixelSizeDp(
InstrumentationRegistry.getContext(), 48))));
onView(withText("date not set")).perform(click()); onView(withText("date not set")).perform(click());
onView(withClassName(equalTo(DatePicker.class.getName()))) onView(withClassName(equalTo(DatePicker.class.getName())))
......
...@@ -112,7 +112,7 @@ class AutofillAssistantUiTestUtil { ...@@ -112,7 +112,7 @@ class AutofillAssistantUiTestUtil {
} }
/** Checks that a text view has a specific maximum number of lines to display. */ /** Checks that a text view has a specific maximum number of lines to display. */
public static TypeSafeMatcher<View> isTextMaxLines(int maxLines) { static TypeSafeMatcher<View> isTextMaxLines(int maxLines) {
return new TypeSafeMatcher<View>() { return new TypeSafeMatcher<View>() {
@Override @Override
protected boolean matchesSafely(View item) { protected boolean matchesSafely(View item) {
...@@ -134,7 +134,7 @@ class AutofillAssistantUiTestUtil { ...@@ -134,7 +134,7 @@ class AutofillAssistantUiTestUtil {
* explicitly set the text style, *NOT* for text spans! @see {@link #hasTypefaceSpan(int, int, * explicitly set the text style, *NOT* for text spans! @see {@link #hasTypefaceSpan(int, int,
* int)} * int)}
*/ */
public static TypeSafeMatcher<View> hasTypefaceStyle(/*@Typeface.Style*/ int style) { static TypeSafeMatcher<View> hasTypefaceStyle(/*@Typeface.Style*/ int style) {
return new TypeSafeMatcher<View>() { return new TypeSafeMatcher<View>() {
@Override @Override
protected boolean matchesSafely(View item) { protected boolean matchesSafely(View item) {
...@@ -162,7 +162,7 @@ class AutofillAssistantUiTestUtil { ...@@ -162,7 +162,7 @@ class AutofillAssistantUiTestUtil {
* @param style The style to check for * @param style The style to check for
* @return A matcher that returns true if the view satisfies the condition. * @return A matcher that returns true if the view satisfies the condition.
*/ */
public static TypeSafeMatcher<View> hasTypefaceSpan( static TypeSafeMatcher<View> hasTypefaceSpan(
int start, int end, /*@Typeface.Style*/ int style) { int start, int end, /*@Typeface.Style*/ int style) {
return new TypeSafeMatcher<View>() { return new TypeSafeMatcher<View>() {
@Override @Override
...@@ -195,7 +195,7 @@ class AutofillAssistantUiTestUtil { ...@@ -195,7 +195,7 @@ class AutofillAssistantUiTestUtil {
}; };
} }
public static Matcher<View> isImportantForAccessibility(int mode) { static Matcher<View> isImportantForAccessibility(int mode) {
return new TypeSafeMatcher<View>() { return new TypeSafeMatcher<View>() {
@Override @Override
protected boolean matchesSafely(View item) { protected boolean matchesSafely(View item) {
...@@ -209,7 +209,7 @@ class AutofillAssistantUiTestUtil { ...@@ -209,7 +209,7 @@ class AutofillAssistantUiTestUtil {
}; };
} }
public static Matcher<View> hasTintColor(final int colorResId) { static Matcher<View> hasTintColor(final int colorResId) {
return new BoundedMatcher<View, ImageView>(ImageView.class) { return new BoundedMatcher<View, ImageView>(ImageView.class) {
private Context mContext; private Context mContext;
...@@ -242,7 +242,7 @@ class AutofillAssistantUiTestUtil { ...@@ -242,7 +242,7 @@ class AutofillAssistantUiTestUtil {
}; };
} }
public static Matcher<View> isNextAfterSibling(final Matcher<View> siblingMatcher) { static Matcher<View> isNextAfterSibling(final Matcher<View> siblingMatcher) {
Preconditions.checkNotNull(siblingMatcher); Preconditions.checkNotNull(siblingMatcher);
return new TypeSafeMatcher<View>() { return new TypeSafeMatcher<View>() {
@Override @Override
...@@ -271,7 +271,7 @@ class AutofillAssistantUiTestUtil { ...@@ -271,7 +271,7 @@ class AutofillAssistantUiTestUtil {
}; };
} }
public static Matcher<View> withParentIndex(int parentIndex) { static Matcher<View> withParentIndex(int parentIndex) {
return new TypeSafeMatcher<View>() { return new TypeSafeMatcher<View>() {
@Override @Override
public void describeTo(Description description) { public void describeTo(Description description) {
...@@ -291,7 +291,24 @@ class AutofillAssistantUiTestUtil { ...@@ -291,7 +291,24 @@ class AutofillAssistantUiTestUtil {
}; };
} }
public static ViewAction openTextLink(String textLink) { static Matcher<View> withMinimumSize(int minWidthInPixels, int minHeightInPixels) {
return new TypeSafeMatcher<View>() {
@Override
protected boolean matchesSafely(View view) {
return view.getWidth() >= minWidthInPixels && view.getHeight() >= minHeightInPixels
&& view.getMinimumWidth() == minWidthInPixels
&& view.getMinimumHeight() == minHeightInPixels;
}
@Override
public void describeTo(Description description) {
description.appendText(
"Width >= " + minWidthInPixels + " and height >= " + minHeightInPixels);
}
};
}
static ViewAction openTextLink(String textLink) {
return new ViewAction() { return new ViewAction() {
@Override @Override
public Matcher<View> getConstraints() { public Matcher<View> getConstraints() {
......
...@@ -261,7 +261,9 @@ base::android::ScopedJavaGlobalRef<jobject> CreateJavaView( ...@@ -261,7 +261,9 @@ base::android::ScopedJavaGlobalRef<jobject> CreateJavaView(
proto.layout_params().margin_start(), proto.layout_params().margin_start(),
proto.layout_params().margin_top(), proto.layout_params().margin_end(), proto.layout_params().margin_top(), proto.layout_params().margin_end(),
proto.layout_params().margin_bottom(), proto.layout_params().margin_bottom(),
proto.layout_params().layout_gravity()); proto.layout_params().layout_gravity(),
proto.layout_params().minimum_width(),
proto.layout_params().minimum_height());
} }
if (proto.view_case() == ViewProto::kViewContainer) { if (proto.view_case() == ViewProto::kViewContainer) {
......
...@@ -139,6 +139,12 @@ message ViewLayoutParamsProto { ...@@ -139,6 +139,12 @@ message ViewLayoutParamsProto {
// A bit-wise OR of the desired |Gravity| values. // A bit-wise OR of the desired |Gravity| values.
optional int32 layout_gravity = 7; optional int32 layout_gravity = 7;
// The minimum width of the view, in dp.
optional int32 minimum_width = 9;
// The minimum height of the view, in dp.
optional int32 minimum_height = 10;
} }
message ViewContainerProto { message ViewContainerProto {
......
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