Commit 1e84bc3d authored by Marcin Wiacek's avatar Marcin Wiacek Committed by Commit Bot

Migrate ChipStyle to @IntDef

@IntDef annotation are preferred way for declaring set of int values.

1. they need less space in APK than enum, see
https://developer.android.com/topic/performance/reduce-apk-size#remove-enums
2. they give more control over allowed values than "static final" values

Main goal of patch is replacing ChipStyle enum to the style common with other @IntDef:

1. with @IntDef first, @Retention second
   and related @interface third
2. with values inside @interface
3. with @Retention(RetentionPolicy.SOURCE)
4. without "static final" in the @interface

Change-Id: I19e43717e9ddf46efc3978d25ed2f2d698a204d8
Reviewed-on: https://chromium-review.googlesource.com/c/1338620
Commit-Queue: Marcin Wiącek <marcin@mwiacek.com>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609115}
parent 282a4597
...@@ -17,6 +17,7 @@ import android.graphics.drawable.Drawable; ...@@ -17,6 +17,7 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.media.ThumbnailUtils; import android.media.ThumbnailUtils;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable; import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory; import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
...@@ -52,6 +53,8 @@ import org.chromium.chrome.browser.snackbar.SnackbarManager; ...@@ -52,6 +53,8 @@ import org.chromium.chrome.browser.snackbar.SnackbarManager;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.payments.mojom.PaymentOptions; import org.chromium.payments.mojom.PaymentOptions;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -211,7 +214,13 @@ class AutofillAssistantUiDelegate { ...@@ -211,7 +214,13 @@ class AutofillAssistantUiDelegate {
// Names borrowed from : // Names borrowed from :
// - https://guidelines.googleplex.com/googlematerial/components/chips.html // - https://guidelines.googleplex.com/googlematerial/components/chips.html
// - https://guidelines.googleplex.com/googlematerial/components/buttons.html // - https://guidelines.googleplex.com/googlematerial/components/buttons.html
private enum ChipStyle { CHIP_ASSISTIVE, BUTTON_FILLED, BUTTON_HAIRLINE } @IntDef({ChipStyle.CHIP_ASSISTIVE, ChipStyle.BUTTON_FILLED, ChipStyle.BUTTON_HAIRLINE})
@Retention(RetentionPolicy.SOURCE)
private @interface ChipStyle {
int CHIP_ASSISTIVE = 0;
int BUTTON_FILLED = 1;
int BUTTON_HAIRLINE = 2;
}
/** /**
* Constructs an assistant UI delegate. * Constructs an assistant UI delegate.
...@@ -294,12 +303,13 @@ class AutofillAssistantUiDelegate { ...@@ -294,12 +303,13 @@ class AutofillAssistantUiDelegate {
} }
boolean alignRight = hasHighlightedScript(scriptHandles); boolean alignRight = hasHighlightedScript(scriptHandles);
ChipStyle nonHighlightStyle = @ChipStyle
alignRight ? ChipStyle.BUTTON_HAIRLINE : ChipStyle.CHIP_ASSISTIVE; int nonHighlightStyle = alignRight ? ChipStyle.BUTTON_HAIRLINE : ChipStyle.CHIP_ASSISTIVE;
ArrayList<View> childViews = new ArrayList<>(); ArrayList<View> childViews = new ArrayList<>();
for (int i = 0; i < scriptHandles.size(); i++) { for (int i = 0; i < scriptHandles.size(); i++) {
ScriptHandle scriptHandle = scriptHandles.get(i); ScriptHandle scriptHandle = scriptHandles.get(i);
ChipStyle chipStyle = @ChipStyle
int chipStyle =
scriptHandle.isHighlight() ? ChipStyle.BUTTON_FILLED : nonHighlightStyle; scriptHandle.isHighlight() ? ChipStyle.BUTTON_FILLED : nonHighlightStyle;
TextView chipView = createChipView(scriptHandle.getName(), chipStyle); TextView chipView = createChipView(scriptHandle.getName(), chipStyle);
chipView.setOnClickListener((unusedView) -> { chipView.setOnClickListener((unusedView) -> {
...@@ -371,16 +381,16 @@ class AutofillAssistantUiDelegate { ...@@ -371,16 +381,16 @@ class AutofillAssistantUiDelegate {
() -> mCarouselScroll.fullScroll(alignRight ? View.FOCUS_RIGHT : View.FOCUS_LEFT)); () -> mCarouselScroll.fullScroll(alignRight ? View.FOCUS_RIGHT : View.FOCUS_LEFT));
} }
private TextView createChipView(String text, ChipStyle style) { private TextView createChipView(String text, @ChipStyle int style) {
int resId = -1; int resId = -1;
switch (style) { switch (style) {
case CHIP_ASSISTIVE: case ChipStyle.CHIP_ASSISTIVE:
resId = R.layout.autofill_assistant_chip_assistive; resId = R.layout.autofill_assistant_chip_assistive;
break; break;
case BUTTON_FILLED: case ChipStyle.BUTTON_FILLED:
resId = R.layout.autofill_assistant_button_filled; resId = R.layout.autofill_assistant_button_filled;
break; break;
case BUTTON_HAIRLINE: case ChipStyle.BUTTON_HAIRLINE:
resId = R.layout.autofill_assistant_button_hairline; resId = R.layout.autofill_assistant_button_hairline;
break; break;
} }
......
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