Commit ac69b787 authored by Marcin Wiacek's avatar Marcin Wiacek Committed by Commit Bot

Move existing @IntDef elements inside existing LocationBarButtonType

@IntDef/@StringDef annotation are preferred way for declaring
set of String/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 writing "static final" values, enum
and some classes in one common @IntDef/@StringDef form:

1. with @IntDef/@StringDef first, @Retention second
   and related @interface third
2. with values inside @interface
3. with NUM_ENTRIES declaring number of entries if necessary
4. with comment about numbering from 0 without gaps when necessary
5. with @Retention(RetentionPolicy.SOURCE)
6. without "static final" in the @interface

Change-Id: Ifa37fd39666c206bf727f97fbf1f5c2e2a277ac0
Reviewed-on: https://chromium-review.googlesource.com/1147522Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Commit-Queue: Marcin Wiącek <marcin@mwiacek.com>
Cr-Commit-Position: refs/heads/master@{#578377}
parent 026709ee
...@@ -367,15 +367,17 @@ public class LocationBarLayout extends FrameLayout ...@@ -367,15 +367,17 @@ public class LocationBarLayout extends FrameLayout
} }
/** Specifies which button should be shown in location bar, if any. */ /** Specifies which button should be shown in location bar, if any. */
@IntDef({LocationBarButtonType.NONE, LocationBarButtonType.SECURITY_ICON,
LocationBarButtonType.NAVIGATION_ICON})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({BUTTON_TYPE_NONE, BUTTON_TYPE_SECURITY_ICON, BUTTON_TYPE_NAVIGATION_ICON}) public @interface LocationBarButtonType {
public @interface LocationBarButtonType {} /** No button should be shown. */
/** No button should be shown. */ int NONE = 0;
public static final int BUTTON_TYPE_NONE = 0; /** Security button should be shown (includes offline icon). */
/** Security button should be shown (includes offline icon). */ int SECURITY_ICON = 1;
public static final int BUTTON_TYPE_SECURITY_ICON = 1; /** Navigation button should be shown. */
/** Navigation button should be shown. */ int NAVIGATION_ICON = 2;
public static final int BUTTON_TYPE_NAVIGATION_ICON = 2; }
public LocationBarLayout(Context context, AttributeSet attrs) { public LocationBarLayout(Context context, AttributeSet attrs) {
this(context, attrs, R.layout.location_bar); this(context, attrs, R.layout.location_bar);
...@@ -436,7 +438,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -436,7 +438,7 @@ public class LocationBarLayout extends FrameLayout
mUrlBar.setCursorVisible(false); mUrlBar.setCursorVisible(false);
mLocationBarButtonType = BUTTON_TYPE_NONE; mLocationBarButtonType = LocationBarButtonType.NONE;
mNavigationButton.setVisibility(INVISIBLE); mNavigationButton.setVisibility(INVISIBLE);
mSecurityButton.setVisibility(INVISIBLE); mSecurityButton.setVisibility(INVISIBLE);
...@@ -640,11 +642,11 @@ public class LocationBarLayout extends FrameLayout ...@@ -640,11 +642,11 @@ public class LocationBarLayout extends FrameLayout
// not have an icon visible to the user when the URL is focused, BUTTON_TYPE_NONE is not // not have an icon visible to the user when the URL is focused, BUTTON_TYPE_NONE is not
// returned as it will trigger an undesired jump during the animation as it attempts to // returned as it will trigger an undesired jump during the animation as it attempts to
// hide the icon. // hide the icon.
if (mUrlHasFocus && mIsTablet) return BUTTON_TYPE_NAVIGATION_ICON; if (mUrlHasFocus && mIsTablet) return LocationBarButtonType.NAVIGATION_ICON;
return mToolbarDataProvider.getSecurityIconResource(mIsTablet) != 0 return mToolbarDataProvider.getSecurityIconResource(mIsTablet) != 0
? BUTTON_TYPE_SECURITY_ICON ? LocationBarButtonType.SECURITY_ICON
: BUTTON_TYPE_NONE; : LocationBarButtonType.NONE;
} }
private void changeLocationBarIcon() { private void changeLocationBarIcon() {
...@@ -656,15 +658,15 @@ public class LocationBarLayout extends FrameLayout ...@@ -656,15 +658,15 @@ public class LocationBarLayout extends FrameLayout
View viewToBeShown = null; View viewToBeShown = null;
switch (mLocationBarButtonType) { switch (mLocationBarButtonType) {
case BUTTON_TYPE_SECURITY_ICON: case LocationBarButtonType.SECURITY_ICON:
viewToBeShown = mSecurityButton; viewToBeShown = mSecurityButton;
mLocationBarIconActiveAnimator = mSecurityButtonShowAnimator; mLocationBarIconActiveAnimator = mSecurityButtonShowAnimator;
break; break;
case BUTTON_TYPE_NAVIGATION_ICON: case LocationBarButtonType.NAVIGATION_ICON:
viewToBeShown = mNavigationButton; viewToBeShown = mNavigationButton;
mLocationBarIconActiveAnimator = mNavigationIconShowAnimator; mLocationBarIconActiveAnimator = mNavigationIconShowAnimator;
break; break;
case BUTTON_TYPE_NONE: case LocationBarButtonType.NONE:
default: default:
mLocationBarIconActiveAnimator = null; mLocationBarIconActiveAnimator = null;
return; return;
...@@ -1065,7 +1067,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -1065,7 +1067,7 @@ public class LocationBarLayout extends FrameLayout
*/ */
@VisibleForTesting @VisibleForTesting
public boolean isSecurityButtonShown() { public boolean isSecurityButtonShown() {
return mLocationBarButtonType == BUTTON_TYPE_SECURITY_ICON; return mLocationBarButtonType == LocationBarButtonType.SECURITY_ICON;
} }
/** /**
...@@ -1141,7 +1143,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -1141,7 +1143,7 @@ public class LocationBarLayout extends FrameLayout
@LocationBarButtonType @LocationBarButtonType
int buttonToShow = getLocationBarButtonToShow(); int buttonToShow = getLocationBarButtonToShow();
findViewById(R.id.location_bar_icon) findViewById(R.id.location_bar_icon)
.setVisibility(buttonToShow != BUTTON_TYPE_NONE ? VISIBLE : GONE); .setVisibility(buttonToShow != LocationBarButtonType.NONE ? VISIBLE : GONE);
} }
/** /**
......
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