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