Commit 33a21a54 authored by Marcin Wiącek's avatar Marcin Wiącek Committed by Commit Bot

Reland "Migrate PanelState from enum to @IntDef + remove one Map"

This is a reland of d9d05e18 (https://chromium-review.googlesource.com/c/chromium/src/+/1142764) with fix created by donnd@google.com for bug described inside https://chromium-review.googlesource.com/c/chromium/src/+/1488575

Original change's description:

> Migrate PanelState from enum to @IntDef + remove one Map
>
> @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 PanelState enum in the form common with other Chrome @IntDef:
>
> 1. with @IntDef first, @Retention second
>    and related @interface third
> 2. with values inside @interface
> 3. with NUM_ENTRIES declaring number of entries
> 4. with comment about numbering from 0 without gaps
> 5. with @Retention(RetentionPolicy.SOURCE)
> 6. without "static final" in the @interface
>
> There is additionally removed one unnecessary Map.
>
> BUG=919666
>
> Change-Id: I8149a0800bd5c0bb205028d230edadc83016ebb9
> Reviewed-on: https://chromium-review.googlesource.com/c/1142764
> Reviewed-by: Andrew Grieve <agrieve@chromium.org>
> Reviewed-by: Donn Denman <donnd@chromium.org>
> Reviewed-by: David Trainor <dtrainor@chromium.org>
> Commit-Queue: Andrew Grieve <agrieve@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#635196}

TBR=agrieve@chromium.org,dtrainor@chromium.org

Bug: 919666, 935923

Change-Id: I6bceed612d667d47a9a7205c057d6b04b16c3bb0
Reviewed-on: https://chromium-review.googlesource.com/c/1489732
Commit-Queue: Marcin Wiącek <marcin@mwiacek.com>
Reviewed-by: default avatarDonn Denman <donnd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635774}
parent 0df7fc76
......@@ -52,13 +52,19 @@ public class OverlayPanel extends OverlayPanelAnimation implements ActivityState
private static final long HIDE_PROGRESS_BAR_DELAY_MS = 1000 / 60 * 4;
/** State of the Overlay Panel. */
public static enum PanelState {
@IntDef({PanelState.UNDEFINED, PanelState.CLOSED, PanelState.PEEKED, PanelState.EXPANDED,
PanelState.MAXIMIZED})
@Retention(RetentionPolicy.SOURCE)
public @interface PanelState {
// Values can't have gaps and should be numerated from 0.
// Values CLOSED - MAXIMIZED are sorted and show next states.
// TODO(pedrosimonetti): consider removing the UNDEFINED state
UNDEFINED,
CLOSED,
PEEKED,
EXPANDED,
MAXIMIZED
int UNDEFINED = 0;
int CLOSED = 1;
int PEEKED = 2;
int EXPANDED = 3;
int MAXIMIZED = 4;
int NUM_ENTRIES = 5;
}
/**
......
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.compositor.bottombar;
import android.animation.Animator;
import android.content.Context;
import android.support.annotation.Nullable;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.compositor.animation.CompositorAnimationHandler;
......@@ -36,7 +37,7 @@ public abstract class OverlayPanelAnimation extends OverlayPanelBase {
private static final float INITIAL_ANIMATION_VELOCITY_DP_PER_SECOND = 1750f;
/** The PanelState to which the Panel is being animated. */
private PanelState mAnimatingState;
private @Nullable @PanelState Integer mAnimatingState;
/** The StateChangeReason for which the Panel is being animated. */
private @StateChangeReason int mAnimatingStateReason;
......@@ -139,9 +140,9 @@ public abstract class OverlayPanelAnimation extends OverlayPanelBase {
// before the panel is notified of the size change, resulting in the panel's
// ContentView being laid out incorrectly.
if (isPanelResizeSupported) {
if (mAnimatingState != PanelState.UNDEFINED) {
// If the size changes when an animation is happening, then we need to restart the
// animation, because the size of the Panel might have changed as well.
if (mAnimatingState == null || mAnimatingState != PanelState.UNDEFINED) {
// If the size changes when an animation is happening, then we need to restart
// the animation, because the size of the Panel might have changed as well.
animatePanelToState(mAnimatingState, mAnimatingStateReason);
} else {
updatePanelForSizeChange();
......@@ -176,7 +177,8 @@ public abstract class OverlayPanelAnimation extends OverlayPanelBase {
* @param state The state to animate to.
* @param reason The reason for the change of panel state.
*/
private void animatePanelToState(PanelState state, @StateChangeReason int reason) {
private void animatePanelToState(
@Nullable @PanelState Integer state, @StateChangeReason int reason) {
animatePanelToState(state, reason, BASE_ANIMATION_DURATION_MS);
}
......@@ -188,7 +190,7 @@ public abstract class OverlayPanelAnimation extends OverlayPanelBase {
* @param duration The animation duration in milliseconds.
*/
protected void animatePanelToState(
PanelState state, @StateChangeReason int reason, long duration) {
@Nullable @PanelState Integer state, @StateChangeReason int reason, long duration) {
mAnimatingState = state;
mAnimatingStateReason = reason;
......@@ -202,7 +204,7 @@ public abstract class OverlayPanelAnimation extends OverlayPanelBase {
* @param state The state to resize to.
* @param reason The reason for the change of panel state.
*/
protected void resizePanelToState(PanelState state, @StateChangeReason int reason) {
protected void resizePanelToState(@PanelState int state, @StateChangeReason int reason) {
cancelHeightAnimation();
final float height = getPanelHeightFromState(state);
......@@ -222,7 +224,7 @@ public abstract class OverlayPanelAnimation extends OverlayPanelBase {
// Calculate the nearest state from the current position, and then calculate the duration
// of the animation that will start with a desired initial velocity and move the desired
// amount of dps (displacement).
final PanelState nearestState = findNearestPanelStateFromHeight(getHeight(), 0.0f);
final @PanelState int nearestState = findNearestPanelStateFromHeight(getHeight(), 0.0f);
final float displacement = getPanelHeightFromState(nearestState) - getHeight();
final long duration = calculateAnimationDuration(
INITIAL_ANIMATION_VELOCITY_DP_PER_SECOND, displacement);
......@@ -236,7 +238,8 @@ public abstract class OverlayPanelAnimation extends OverlayPanelBase {
* @param velocity The velocity of the gesture in dps per second.
*/
protected void animateToProjectedState(float velocity) {
PanelState projectedState = getProjectedState(velocity);
@PanelState
int projectedState = getProjectedState(velocity);
final float displacement = getPanelHeightFromState(projectedState) - getHeight();
final long duration = calculateAnimationDuration(velocity, displacement);
......@@ -248,13 +251,14 @@ public abstract class OverlayPanelAnimation extends OverlayPanelBase {
* @param velocity The given velocity.
* @return The projected state the Panel will be if the given velocity is applied.
*/
protected PanelState getProjectedState(float velocity) {
protected @PanelState int getProjectedState(float velocity) {
final float kickY = calculateAnimationDisplacement(velocity, BASE_ANIMATION_DURATION_MS);
final float projectedHeight = getHeight() - kickY;
// Calculate the projected state the Panel will be at the end of the fling movement and the
// duration of the animation given the current velocity and the projected displacement.
PanelState projectedState = findNearestPanelStateFromHeight(projectedHeight, velocity);
@PanelState
int projectedState = findNearestPanelStateFromHeight(projectedHeight, velocity);
return projectedState;
}
......@@ -369,7 +373,7 @@ public abstract class OverlayPanelAnimation extends OverlayPanelBase {
// be checked.
if (mAnimatingState != null && mAnimatingState != PanelState.UNDEFINED
&& MathUtils.areFloatsEqual(
getHeight(), getPanelHeightFromState(mAnimatingState))) {
getHeight(), getPanelHeightFromState(mAnimatingState))) {
setPanelState(mAnimatingState, mAnimatingStateReason);
}
......
......@@ -18,10 +18,6 @@ import org.chromium.chrome.browser.util.MathUtils;
import org.chromium.ui.base.LocalizationUtils;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Base abstract class for the Overlay Panel.
*/
......@@ -116,20 +112,7 @@ abstract class OverlayPanelBase {
protected final Context mContext;
/** The current state of the Overlay Panel. */
private PanelState mPanelState = PanelState.UNDEFINED;
/**
* Valid previous states for the Panel.
*/
protected static final Map<PanelState, PanelState> PREVIOUS_STATES;
static {
Map<PanelState, PanelState> states = new HashMap<>();
// Pairs are of the form <Current, Previous>.
states.put(PanelState.PEEKED, PanelState.CLOSED);
states.put(PanelState.EXPANDED, PanelState.PEEKED);
states.put(PanelState.MAXIMIZED, PanelState.EXPANDED);
PREVIOUS_STATES = Collections.unmodifiableMap(states);
}
private @PanelState int mPanelState = PanelState.UNDEFINED;
// ============================================================================================
// Constructor
......@@ -567,7 +550,7 @@ abstract class OverlayPanelBase {
/**
* @return The panel's state.
*/
public PanelState getPanelState() {
public @PanelState int getPanelState() {
return mPanelState;
}
......@@ -576,7 +559,7 @@ abstract class OverlayPanelBase {
* @param state The panel state to transition to.
* @param reason The reason for a change in the panel's state.
*/
protected void setPanelState(PanelState state, @StateChangeReason int reason) {
protected void setPanelState(@PanelState int state, @StateChangeReason int reason) {
if (state == PanelState.CLOSED) {
mHeight = 0;
onClosed(reason);
......@@ -596,7 +579,7 @@ abstract class OverlayPanelBase {
* @param state A given state.
* @return Whether the panel supports a given state.
*/
protected boolean isSupportedState(PanelState state) {
protected boolean isSupportedState(@PanelState int state) {
return true;
}
......@@ -606,7 +589,7 @@ abstract class OverlayPanelBase {
* @param state The given state.
* @return Whether the state is valid.
*/
private boolean isValidUiState(PanelState state) {
private boolean isValidUiState(@PanelState int state) {
// TODO(pedrosimonetti): consider removing the UNDEFINED state
// which would allow removing this method.
return isSupportedState(state) && state != PanelState.UNDEFINED;
......@@ -615,7 +598,7 @@ abstract class OverlayPanelBase {
/**
* @return The maximum state supported by the panel.
*/
private PanelState getMaximumSupportedState() {
private @PanelState int getMaximumSupportedState() {
if (isSupportedState(PanelState.MAXIMIZED)) {
return PanelState.MAXIMIZED;
} else if (isSupportedState(PanelState.EXPANDED)) {
......@@ -626,12 +609,19 @@ abstract class OverlayPanelBase {
}
/**
* @return The {@code PanelState} that is before the |state| in the order of states.
*/
private PanelState getPreviousPanelState(PanelState state) {
PanelState prevState = PREVIOUS_STATES.get(state);
if (!isSupportedState(PanelState.EXPANDED)) {
prevState = PREVIOUS_STATES.get(prevState);
* Gets the panel's state that is before the given {@code PanelState} in the order of states.
* @param state The given state.
* @return The previous state.
*/
private @PanelState int getPreviousPanelState(@PanelState int state) {
@Nullable
@PanelState
Integer prevState =
state >= PanelState.PEEKED && state <= PanelState.MAXIMIZED ? state - 1 : null;
if (prevState != null && !isSupportedState(PanelState.EXPANDED)) {
prevState = prevState >= PanelState.PEEKED && prevState <= PanelState.MAXIMIZED
? prevState - 1
: null;
}
return prevState != null ? prevState : PanelState.UNDEFINED;
}
......@@ -646,8 +636,10 @@ abstract class OverlayPanelBase {
* @param state The state whose height will be calculated.
* @return The height of the Overlay Panel in dps for a given |state|.
*/
public float getPanelHeightFromState(@Nullable PanelState state) {
if (state == PanelState.PEEKED) {
public float getPanelHeightFromState(@Nullable @PanelState Integer state) {
if (state == null) {
return 0;
} else if (state == PanelState.PEEKED) {
return getPeekedHeight();
} else if (state == PanelState.EXPANDED) {
return getExpandedHeight();
......@@ -712,14 +704,17 @@ abstract class OverlayPanelBase {
* @param velocity The velocity of the swipe if applicable. The swipe is upward if less than 0.
* @return The nearest panel state.
*/
protected PanelState findNearestPanelStateFromHeight(float desiredPanelHeight, float velocity) {
protected @PanelState int findNearestPanelStateFromHeight(
float desiredPanelHeight, float velocity) {
// If the panel was flung hard enough to make the desired height negative, it's closed.
if (desiredPanelHeight < 0) return PanelState.CLOSED;
// First, find the two states that the desired panel height is between.
PanelState nextState = PanelState.values()[0];
PanelState prevState = nextState;
for (PanelState state : PanelState.values()) {
@PanelState
int nextState = PanelState.UNDEFINED;
@PanelState
int prevState = nextState;
for (@PanelState int state = 0; state < PanelState.NUM_ENTRIES; state++) {
if (!isValidUiState(state)) continue;
prevState = nextState;
nextState = state;
......@@ -769,7 +764,7 @@ abstract class OverlayPanelBase {
* @param state The Panel state.
* @return Whether the Panel height matches the one from the given state.
*/
protected boolean doesPanelHeightMatchState(PanelState state) {
protected boolean doesPanelHeightMatchState(@PanelState int state) {
return state == getPanelState()
&& MathUtils.areFloatsEqual(getHeight(), getPanelHeightFromState(state));
}
......@@ -784,8 +779,10 @@ abstract class OverlayPanelBase {
* @param height The Overlay Panel height.
*/
private void updatePanelForHeight(float height) {
PanelState endState = findLargestPanelStateFromHeight(height);
PanelState startState = getPreviousPanelState(endState);
@PanelState
int endState = findLargestPanelStateFromHeight(height);
@PanelState
int startState = getPreviousPanelState(endState);
float percentage = getStateCompletion(height, startState, endState);
updatePanelSize(height);
......@@ -825,12 +822,13 @@ abstract class OverlayPanelBase {
* @param panelHeight The height to compare to.
* @return The panel state which is being transitioned to/from.
*/
private PanelState findLargestPanelStateFromHeight(float panelHeight) {
PanelState stateFound = PanelState.CLOSED;
private @PanelState int findLargestPanelStateFromHeight(float panelHeight) {
@PanelState
int stateFound = PanelState.CLOSED;
// Iterate over all states and find the largest one which is being
// transitioned to/from.
for (PanelState state : PanelState.values()) {
for (@PanelState int state = 0; state < PanelState.NUM_ENTRIES; state++) {
if (!isValidUiState(state)) continue;
if (panelHeight <= getPanelHeightFromState(state)) {
stateFound = state;
......@@ -851,7 +849,8 @@ abstract class OverlayPanelBase {
* @param endState The final state of the Panel.
* @return The completion percentage.
*/
private float getStateCompletion(float height, PanelState startState, PanelState endState) {
private float getStateCompletion(
float height, @PanelState int startState, @PanelState int endState) {
float startSize = getPanelHeightFromState(startState);
float endSize = getPanelHeightFromState(endState);
// NOTE(pedrosimonetti): Handle special case from PanelState.UNDEFINED
......
......@@ -170,8 +170,9 @@ public class ContextualSearchPanel extends OverlayPanel {
// ============================================================================================
@Override
public void setPanelState(PanelState toState, @StateChangeReason int reason) {
PanelState fromState = getPanelState();
public void setPanelState(@PanelState int toState, @StateChangeReason int reason) {
@PanelState
int fromState = getPanelState();
mPanelMetrics.onPanelStateChanged(
fromState, toState, reason, Profile.getLastUsedProfile().getOriginalProfile());
......@@ -193,7 +194,7 @@ public class ContextualSearchPanel extends OverlayPanel {
}
@Override
protected boolean isSupportedState(PanelState state) {
protected boolean isSupportedState(@PanelState int state) {
return canDisplayContentInPanel() || state != PanelState.MAXIMIZED;
}
......@@ -207,8 +208,9 @@ public class ContextualSearchPanel extends OverlayPanel {
}
@Override
protected PanelState getProjectedState(float velocity) {
PanelState projectedState = super.getProjectedState(velocity);
protected @PanelState int getProjectedState(float velocity) {
@PanelState
int projectedState = super.getProjectedState(velocity);
// Prevent the fling gesture from moving the Panel from PEEKED to MAXIMIZED. This is to
// make sure the Promo will be visible, considering that the EXPANDED state is the only
......@@ -522,7 +524,7 @@ public class ContextualSearchPanel extends OverlayPanel {
}
@Override
public PanelState getPanelState() {
public @PanelState int getPanelState() {
// NOTE(pedrosimonetti): exposing superclass method to the interface.
return super.getPanelState();
}
......
......@@ -68,7 +68,7 @@ public class ContextualSearchPanelMetrics {
* @param reason The reason for the state change.
* @param profile The current {@link Profile}.
*/
public void onPanelStateChanged(PanelState fromState, PanelState toState,
public void onPanelStateChanged(@PanelState int fromState, @PanelState int toState,
@StateChangeReason int reason, Profile profile) {
// Note: the logging within this function includes the promo, unless specifically
// excluded.
......@@ -368,7 +368,7 @@ public class ContextualSearchPanelMetrics {
* @return Whether a new contextual search is starting.
*/
private boolean isStartingNewContextualSearch(
PanelState toState, @StateChangeReason int reason) {
@PanelState int toState, @StateChangeReason int reason) {
return toState == PanelState.PEEKED
&& (reason == StateChangeReason.TEXT_SELECT_TAP
|| reason == StateChangeReason.TEXT_SELECT_LONG_PRESS);
......@@ -381,8 +381,8 @@ public class ContextualSearchPanelMetrics {
* @param isStartingSearch Whether a new contextual search is starting.
* @return Whether a contextual search is ending.
*/
private boolean isEndingContextualSearch(PanelState fromState, PanelState toState,
boolean isStartingSearch) {
private boolean isEndingContextualSearch(
@PanelState int fromState, @PanelState int toState, boolean isStartingSearch) {
return isOngoingContextualSearch(fromState)
&& (toState == PanelState.CLOSED || isStartingSearch);
}
......@@ -391,8 +391,7 @@ public class ContextualSearchPanelMetrics {
* @param fromState The state the panel is transitioning from.
* @return Whether there is an ongoing contextual search.
*/
private boolean isOngoingContextualSearch(PanelState fromState) {
private boolean isOngoingContextualSearch(@PanelState int fromState) {
return fromState != PanelState.UNDEFINED && fromState != PanelState.CLOSED;
}
}
......@@ -109,7 +109,7 @@ public class EphemeralTabPanel extends OverlayPanel {
}
@Override
public void setPanelState(PanelState toState, @StateChangeReason int reason) {
public void setPanelState(@PanelState int toState, @StateChangeReason int reason) {
super.setPanelState(toState, reason);
if (toState == PanelState.CLOSED) {
RecordHistogram.recordBooleanHistogram("EphemeralTab.Ctr", mWasPanelOpened);
......@@ -175,7 +175,7 @@ public class EphemeralTabPanel extends OverlayPanel {
}
@Override
protected boolean isSupportedState(PanelState state) {
protected boolean isSupportedState(@PanelState int state) {
return state != PanelState.EXPANDED;
}
......
......@@ -469,7 +469,8 @@ public class ContextualSearchManager
// If the user is jumping from one unseen search to another search, remove the last search
// from history.
PanelState state = mSearchPanel.getPanelState();
@PanelState
int state = mSearchPanel.getPanelState();
if (!mWereSearchResultsSeen && mLoadedSearchUrlTimeMs != 0L
&& state != PanelState.UNDEFINED && state != PanelState.CLOSED) {
removeLastSearchVisit();
......
......@@ -339,14 +339,14 @@ public class ContextualSearchUma {
* Key used in maps from {state, reason} to state entry (exit) logging code.
*/
static class StateChangeKey {
final PanelState mState;
final @PanelState int mState;
final @StateChangeReason int mReason;
final int mHashCode;
StateChangeKey(PanelState state, @StateChangeReason int reason) {
StateChangeKey(@PanelState int state, @StateChangeReason int reason) {
mState = state;
mReason = reason;
mHashCode = 31 * state.hashCode() + reason;
mHashCode = 31 * state + reason;
}
@Override
......@@ -354,7 +354,7 @@ public class ContextualSearchUma {
if (!(obj instanceof StateChangeKey)) return false;
if (obj == this) return true;
StateChangeKey other = (StateChangeKey) obj;
return mState.equals(other.mState) && mReason == other.mReason;
return mState == other.mState && mReason == other.mReason;
}
@Override
......@@ -1152,28 +1152,28 @@ public class ContextualSearchUma {
* @param reason The reason for the state transition.
*/
public static void logFirstStateEntry(
PanelState fromState, PanelState toState, @StateChangeReason int reason) {
@PanelState int fromState, @PanelState int toState, @StateChangeReason int reason) {
int code;
switch (toState) {
case CLOSED:
case PanelState.CLOSED:
code = getStateChangeCode(
fromState, reason, ENTER_CLOSED_STATE_CHANGE_CODES, EnterClosedFrom.OTHER);
RecordHistogram.recordEnumeratedHistogram(
"Search.ContextualSearchEnterClosed", code, EnterClosedFrom.NUM_ENTRIES);
break;
case PEEKED:
case PanelState.PEEKED:
code = getStateChangeCode(
fromState, reason, ENTER_PEEKED_STATE_CHANGE_CODES, EnterPeekedFrom.OTHER);
RecordHistogram.recordEnumeratedHistogram(
"Search.ContextualSearchEnterPeeked", code, EnterPeekedFrom.NUM_ENTRIES);
break;
case EXPANDED:
case PanelState.EXPANDED:
code = getStateChangeCode(fromState, reason, ENTER_EXPANDED_STATE_CHANGE_CODES,
EnterExpandedFrom.OTHER);
RecordHistogram.recordEnumeratedHistogram("Search.ContextualSearchEnterExpanded",
code, EnterExpandedFrom.NUM_ENTRIES);
break;
case MAXIMIZED:
case PanelState.MAXIMIZED:
code = getStateChangeCode(fromState, reason, ENTER_MAXIMIZED_STATE_CHANGE_CODES,
EnterMaximizedFrom.OTHER);
RecordHistogram.recordEnumeratedHistogram("Search.ContextualSearchEnterMaximized",
......@@ -1189,9 +1189,10 @@ public class ContextualSearchUma {
* @param toState The state to transition to.
* @param reason The reason for the state transition.
*/
public static void logPanelStateUserAction(PanelState toState, @StateChangeReason int reason) {
public static void logPanelStateUserAction(
@PanelState int toState, @StateChangeReason int reason) {
switch (toState) {
case CLOSED:
case PanelState.CLOSED:
if (reason == StateChangeReason.BACK_PRESS) {
RecordUserAction.record("ContextualSearch.BackPressClose");
} else if (reason == StateChangeReason.CLOSE_BUTTON) {
......@@ -1212,7 +1213,7 @@ public class ContextualSearchUma {
RecordUserAction.record("ContextualSearch.UncommonClose");
}
break;
case PEEKED:
case PanelState.PEEKED:
if (reason == StateChangeReason.TEXT_SELECT_TAP) {
RecordUserAction.record("ContextualSearch.TapPeek");
} else if (reason == StateChangeReason.SWIPE || reason == StateChangeReason.FLING) {
......@@ -1221,14 +1222,14 @@ public class ContextualSearchUma {
RecordUserAction.record("ContextualSearch.LongpressPeek");
}
break;
case EXPANDED:
case PanelState.EXPANDED:
if (reason == StateChangeReason.SWIPE || reason == StateChangeReason.FLING) {
RecordUserAction.record("ContextualSearch.SwipeOrFlingExpand");
} else if (reason == StateChangeReason.SEARCH_BAR_TAP) {
RecordUserAction.record("ContextualSearch.SearchBarTapExpand");
}
break;
case MAXIMIZED:
case PanelState.MAXIMIZED:
if (reason == StateChangeReason.SWIPE || reason == StateChangeReason.FLING) {
RecordUserAction.record("ContextualSearch.SwipeOrFlingMaximize");
} else if (reason == StateChangeReason.SERP_NAVIGATION) {
......@@ -1247,29 +1248,29 @@ public class ContextualSearchUma {
* @param reason The reason for the state transition.
*/
public static void logFirstStateExit(
PanelState fromState, PanelState toState, @StateChangeReason int reason) {
@PanelState int fromState, @PanelState int toState, @StateChangeReason int reason) {
int code;
switch (fromState) {
case UNDEFINED:
case CLOSED:
case PanelState.UNDEFINED:
case PanelState.CLOSED:
code = getStateChangeCode(
toState, reason, EXIT_CLOSED_TO_STATE_CHANGE_CODES, ExitClosedTo.OTHER);
RecordHistogram.recordEnumeratedHistogram(
"Search.ContextualSearchExitClosed", code, ExitClosedTo.NUM_ENTRIES);
break;
case PEEKED:
case PanelState.PEEKED:
code = getStateChangeCode(
toState, reason, EXIT_PEEKED_TO_STATE_CHANGE_CODES, ExitPeekedTo.OTHER);
RecordHistogram.recordEnumeratedHistogram(
"Search.ContextualSearchExitPeeked", code, ExitPeekedTo.NUM_ENTRIES);
break;
case EXPANDED:
case PanelState.EXPANDED:
code = getStateChangeCode(
toState, reason, EXIT_EXPANDED_TO_STATE_CHANGE_CODES, ExitExpandedTo.OTHER);
RecordHistogram.recordEnumeratedHistogram(
"Search.ContextualSearchExitExpanded", code, ExitExpandedTo.NUM_ENTRIES);
break;
case MAXIMIZED:
case PanelState.MAXIMIZED:
code = getStateChangeCode(toState, reason, EXIT_MAXIMIZED_TO_STATE_CHANGE_CODES,
ExitMaximizedTo.OTHER);
RecordHistogram.recordEnumeratedHistogram(
......@@ -1543,7 +1544,7 @@ public class ContextualSearchUma {
* @param defaultCode The code to return if the given values are not found in the map.
* @return The code to write into an enum histogram, based on the given map.
*/
private static int getStateChangeCode(PanelState state, @StateChangeReason int reason,
private static int getStateChangeCode(@PanelState int state, @StateChangeReason int reason,
Map<StateChangeKey, Integer> stateChangeCodes, int defaultCode) {
Integer code = stateChangeCodes.get(new StateChangeKey(state, reason));
return code != null ? code : defaultCode;
......
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.compositor.bottombar;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.test.InstrumentationRegistry;
import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
......@@ -50,7 +51,8 @@ public class OverlayPanelBaseTest {
* Expose protected super method as public.
*/
@Override
public PanelState findNearestPanelStateFromHeight(float desiredHeight, float velocity) {
public @PanelState int findNearestPanelStateFromHeight(
float desiredHeight, float velocity) {
return super.findNearestPanelStateFromHeight(desiredHeight, velocity);
}
......@@ -58,13 +60,13 @@ public class OverlayPanelBaseTest {
* Override to return arbitrary test heights.
*/
@Override
public float getPanelHeightFromState(PanelState state) {
public float getPanelHeightFromState(@Nullable @PanelState Integer state) {
switch (state) {
case PEEKED:
case PanelState.PEEKED:
return MOCK_PEEKED_HEIGHT;
case EXPANDED:
case PanelState.EXPANDED:
return MOCK_EXPANDED_HEIGHT;
case MAXIMIZED:
case PanelState.MAXIMIZED:
return MOCK_MAXIMIZED_HEIGHT;
default:
return 0.0f;
......@@ -87,7 +89,7 @@ public class OverlayPanelBaseTest {
}
@Override
protected boolean isSupportedState(PanelState state) {
protected boolean isSupportedState(@PanelState int state) {
return state != PanelState.EXPANDED;
}
}
......@@ -118,8 +120,9 @@ public class OverlayPanelBaseTest {
final float maxToPeekBound = (1.0f - threshold) * height + MOCK_PEEKED_HEIGHT;
// Between PEEKING and MAXIMIZED past the threshold in the up direction.
PanelState nextState = mNoExpandPanel.findNearestPanelStateFromHeight(
peekToMaxBound + 1, UPWARD_VELOCITY);
@PanelState
int nextState =
mNoExpandPanel.findNearestPanelStateFromHeight(peekToMaxBound + 1, UPWARD_VELOCITY);
Assert.assertTrue(nextState == PanelState.MAXIMIZED);
// Between PEEKING and MAXIMIZED before the threshold in the up direction.
......@@ -164,8 +167,9 @@ public class OverlayPanelBaseTest {
final float maxToExpBound = (1.0f - threshold) * expToMaxHeight + MOCK_EXPANDED_HEIGHT;
// Between PEEKING and EXPANDED past the threshold in the up direction.
PanelState nextState = mExpandPanel.findNearestPanelStateFromHeight(
peekToExpBound + 1, UPWARD_VELOCITY);
@PanelState
int nextState =
mExpandPanel.findNearestPanelStateFromHeight(peekToExpBound + 1, UPWARD_VELOCITY);
Assert.assertTrue(nextState == PanelState.EXPANDED);
// Between PEEKING and EXPANDED before the threshold in the up direction.
......@@ -214,8 +218,8 @@ public class OverlayPanelBaseTest {
public void testNegativeHeightClosesPanel() {
final float belowPeek = MOCK_PEEKED_HEIGHT - 1000;
PanelState nextState =
mExpandPanel.findNearestPanelStateFromHeight(belowPeek, DOWNWARD_VELOCITY);
@PanelState
int nextState = mExpandPanel.findNearestPanelStateFromHeight(belowPeek, DOWNWARD_VELOCITY);
Assert.assertTrue(nextState == PanelState.CLOSED);
nextState = mNoExpandPanel.findNearestPanelStateFromHeight(belowPeek, DOWNWARD_VELOCITY);
......@@ -239,8 +243,8 @@ public class OverlayPanelBaseTest {
public void testLargeDesiredHeightIsMaximized() {
final float aboveMax = MOCK_MAXIMIZED_HEIGHT + 1000;
PanelState nextState =
mExpandPanel.findNearestPanelStateFromHeight(aboveMax, UPWARD_VELOCITY);
@PanelState
int nextState = mExpandPanel.findNearestPanelStateFromHeight(aboveMax, UPWARD_VELOCITY);
Assert.assertTrue(nextState == PanelState.MAXIMIZED);
nextState = mNoExpandPanel.findNearestPanelStateFromHeight(aboveMax, UPWARD_VELOCITY);
......
......@@ -697,7 +697,8 @@ public class ContextualSearchManagerTest {
if (mPanel == null) {
success = true;
} else {
PanelState panelState = mPanel.getPanelState();
@PanelState
int panelState = mPanel.getPanelState();
success = panelState == PanelState.CLOSED || panelState == PanelState.UNDEFINED;
}
Assert.assertTrue(success);
......@@ -818,7 +819,7 @@ public class ContextualSearchManagerTest {
* Waits for the Search Panel to enter the given {@code PanelState} and assert.
* @param state The {@link PanelState} to wait for.
*/
private void waitForPanelToEnterState(final PanelState state) {
private void waitForPanelToEnterState(final @PanelState int state) {
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
......@@ -842,7 +843,7 @@ public class ContextualSearchManagerTest {
* should not change the panel state.
* @throws InterruptedException
*/
private void assertPanelStillInState(final PanelState initialState)
private void assertPanelStillInState(final @PanelState int initialState)
throws InterruptedException {
boolean didChangeState = false;
long startTime = SystemClock.uptimeMillis();
......@@ -1617,7 +1618,8 @@ public class ContextualSearchManagerTest {
CriteriaHelper.pollInstrumentationThread(new Criteria(){
@Override
public boolean isSatisfied() {
PanelState panelState = mPanel.getPanelState();
@PanelState
int panelState = mPanel.getPanelState();
return panelState != PanelState.PEEKED;
}
});
......@@ -1716,7 +1718,8 @@ public class ContextualSearchManagerTest {
@SmallTest
@Feature({"ContextualSearch"})
public void testTapOnRoleIgnored() throws InterruptedException, TimeoutException {
PanelState initialState = mPanel.getPanelState();
@PanelState
int initialState = mPanel.getPanelState();
clickNode("role");
assertPanelStillInState(initialState);
}
......@@ -1729,7 +1732,8 @@ public class ContextualSearchManagerTest {
@SmallTest
@Feature({"ContextualSearch"})
public void testTapOnARIAIgnored() throws InterruptedException, TimeoutException {
PanelState initialState = mPanel.getPanelState();
@PanelState
int initialState = mPanel.getPanelState();
clickNode("aria");
assertPanelStillInState(initialState);
}
......@@ -1741,7 +1745,8 @@ public class ContextualSearchManagerTest {
@SmallTest
@Feature({"ContextualSearch"})
public void testTapOnFocusableIgnored() throws InterruptedException, TimeoutException {
PanelState initialState = mPanel.getPanelState();
@PanelState
int initialState = mPanel.getPanelState();
clickNode("focusable");
assertPanelStillInState(initialState);
}
......
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