Merge "Converting FastBitmapDrawable to kotlin" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
2f9d81a9d7
+39
-53
@@ -65,10 +65,9 @@ public class FastBitmapDrawableTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FastBitmapDrawable.setFlagHoverEnabled(true);
|
||||
when(mFastBitmapDrawable.isVisible()).thenReturn(true);
|
||||
mFastBitmapDrawable.mIsPressed = false;
|
||||
mFastBitmapDrawable.mIsHovered = false;
|
||||
mFastBitmapDrawable.isPressed = false;
|
||||
mFastBitmapDrawable.isHovered = false;
|
||||
mFastBitmapDrawable.resetScale();
|
||||
}
|
||||
|
||||
@@ -80,7 +79,7 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
// No scale changes without state change.
|
||||
assertFalse("State change handled.", isHandled);
|
||||
assertNull("Scale animation not null.", mFastBitmapDrawable.mScaleAnimation);
|
||||
assertNull("Scale animation not null.", mFastBitmapDrawable.scaleAnimation);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,13 +90,13 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
// Animate to state pressed.
|
||||
assertTrue("State change not handled.", isHandled);
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.mScaleAnimation.getDuration(),
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.scaleAnimation.getDuration(),
|
||||
CLICK_FEEDBACK_DURATION);
|
||||
mFastBitmapDrawable.mScaleAnimation.end();
|
||||
mFastBitmapDrawable.scaleAnimation.end();
|
||||
assertEquals("End value not correct.",
|
||||
(float) SCALE.get(mFastBitmapDrawable), PRESSED_SCALE, EPSILON);
|
||||
assertTrue("Wrong interpolator used.",
|
||||
mFastBitmapDrawable.mScaleAnimation.getInterpolator()
|
||||
mFastBitmapDrawable.scaleAnimation.getInterpolator()
|
||||
instanceof AccelerateInterpolator);
|
||||
}
|
||||
|
||||
@@ -109,26 +108,13 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
// Animate to state hovered.
|
||||
assertTrue("State change not handled.", isHandled);
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.mScaleAnimation.getDuration(),
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.scaleAnimation.getDuration(),
|
||||
HOVER_FEEDBACK_DURATION);
|
||||
mFastBitmapDrawable.mScaleAnimation.end();
|
||||
mFastBitmapDrawable.scaleAnimation.end();
|
||||
assertEquals("End value not correct.",
|
||||
(float) SCALE.get(mFastBitmapDrawable), HOVERED_SCALE, EPSILON);
|
||||
assertTrue("Wrong interpolator used.",
|
||||
mFastBitmapDrawable.mScaleAnimation.getInterpolator() instanceof PathInterpolator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnStateChange_stateHoveredFlagDisabled() {
|
||||
FastBitmapDrawable.setFlagHoverEnabled(false);
|
||||
int[] state = new int[]{android.R.attr.state_hovered};
|
||||
|
||||
boolean isHandled = mFastBitmapDrawable.onStateChange(state);
|
||||
|
||||
// No state change with flag disabled.
|
||||
assertFalse("Hover state change handled with flag disabled.", isHandled);
|
||||
assertNull("Animation should not run with hover flag disabled.",
|
||||
mFastBitmapDrawable.mScaleAnimation);
|
||||
mFastBitmapDrawable.scaleAnimation.getInterpolator() instanceof PathInterpolator);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,13 +125,13 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
// Animate to pressed state only.
|
||||
assertTrue("State change not handled.", isHandled);
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.mScaleAnimation.getDuration(),
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.scaleAnimation.getDuration(),
|
||||
CLICK_FEEDBACK_DURATION);
|
||||
mFastBitmapDrawable.mScaleAnimation.end();
|
||||
mFastBitmapDrawable.scaleAnimation.end();
|
||||
assertEquals("End value not correct.",
|
||||
(float) SCALE.get(mFastBitmapDrawable), PRESSED_SCALE, EPSILON);
|
||||
assertTrue("Wrong interpolator used.",
|
||||
mFastBitmapDrawable.mScaleAnimation.getInterpolator()
|
||||
mFastBitmapDrawable.scaleAnimation.getInterpolator()
|
||||
instanceof AccelerateInterpolator);
|
||||
}
|
||||
|
||||
@@ -157,20 +143,20 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
// Animate to pressed state only.
|
||||
assertTrue("State change not handled.", isHandled);
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.mScaleAnimation.getDuration(),
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.scaleAnimation.getDuration(),
|
||||
CLICK_FEEDBACK_DURATION);
|
||||
mFastBitmapDrawable.mScaleAnimation.end();
|
||||
mFastBitmapDrawable.scaleAnimation.end();
|
||||
assertEquals("End value not correct.",
|
||||
(float) SCALE.get(mFastBitmapDrawable), PRESSED_SCALE, EPSILON);
|
||||
assertTrue("Wrong interpolator used.",
|
||||
mFastBitmapDrawable.mScaleAnimation.getInterpolator()
|
||||
mFastBitmapDrawable.scaleAnimation.getInterpolator()
|
||||
instanceof AccelerateInterpolator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnStateChange_stateHoveredAndPressedToPressed() {
|
||||
mFastBitmapDrawable.mIsPressed = true;
|
||||
mFastBitmapDrawable.mIsHovered = true;
|
||||
mFastBitmapDrawable.isPressed = true;
|
||||
mFastBitmapDrawable.isHovered = true;
|
||||
SCALE.setValue(mFastBitmapDrawable, PRESSED_SCALE);
|
||||
int[] state = new int[]{android.R.attr.state_pressed};
|
||||
|
||||
@@ -184,8 +170,8 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
@Test
|
||||
public void testOnStateChange_stateHoveredAndPressedToHovered() {
|
||||
mFastBitmapDrawable.mIsPressed = true;
|
||||
mFastBitmapDrawable.mIsHovered = true;
|
||||
mFastBitmapDrawable.isPressed = true;
|
||||
mFastBitmapDrawable.isHovered = true;
|
||||
SCALE.setValue(mFastBitmapDrawable, PRESSED_SCALE);
|
||||
int[] state = new int[]{android.R.attr.state_hovered};
|
||||
|
||||
@@ -199,7 +185,7 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
@Test
|
||||
public void testOnStateChange_stateHoveredToPressed() {
|
||||
mFastBitmapDrawable.mIsHovered = true;
|
||||
mFastBitmapDrawable.isHovered = true;
|
||||
SCALE.setValue(mFastBitmapDrawable, HOVERED_SCALE);
|
||||
int[] state = new int[]{android.R.attr.state_pressed};
|
||||
|
||||
@@ -213,7 +199,7 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
@Test
|
||||
public void testOnStateChange_statePressedToHovered() {
|
||||
mFastBitmapDrawable.mIsPressed = true;
|
||||
mFastBitmapDrawable.isPressed = true;
|
||||
SCALE.setValue(mFastBitmapDrawable, PRESSED_SCALE);
|
||||
int[] state = new int[]{android.R.attr.state_hovered};
|
||||
|
||||
@@ -227,7 +213,7 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
@Test
|
||||
public void testOnStateChange_stateDefaultFromPressed() {
|
||||
mFastBitmapDrawable.mIsPressed = true;
|
||||
mFastBitmapDrawable.isPressed = true;
|
||||
SCALE.setValue(mFastBitmapDrawable, PRESSED_SCALE);
|
||||
int[] state = new int[]{};
|
||||
|
||||
@@ -235,18 +221,18 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
// Animate to default state from pressed state.
|
||||
assertTrue("State change not handled.", isHandled);
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.mScaleAnimation.getDuration(),
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.scaleAnimation.getDuration(),
|
||||
CLICK_FEEDBACK_DURATION);
|
||||
mFastBitmapDrawable.mScaleAnimation.end();
|
||||
mFastBitmapDrawable.scaleAnimation.end();
|
||||
assertEquals("End value not correct.", (float) SCALE.get(mFastBitmapDrawable), 1f, EPSILON);
|
||||
assertTrue("Wrong interpolator used.",
|
||||
mFastBitmapDrawable.mScaleAnimation.getInterpolator()
|
||||
mFastBitmapDrawable.scaleAnimation.getInterpolator()
|
||||
instanceof DecelerateInterpolator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnStateChange_stateDefaultFromHovered() {
|
||||
mFastBitmapDrawable.mIsHovered = true;
|
||||
mFastBitmapDrawable.isHovered = true;
|
||||
SCALE.setValue(mFastBitmapDrawable, HOVERED_SCALE);
|
||||
int[] state = new int[]{};
|
||||
|
||||
@@ -254,12 +240,12 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
// Animate to default state from hovered state.
|
||||
assertTrue("State change not handled.", isHandled);
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.mScaleAnimation.getDuration(),
|
||||
assertEquals("Duration not correct.", mFastBitmapDrawable.scaleAnimation.getDuration(),
|
||||
HOVER_FEEDBACK_DURATION);
|
||||
mFastBitmapDrawable.mScaleAnimation.end();
|
||||
mFastBitmapDrawable.scaleAnimation.end();
|
||||
assertEquals("End value not correct.", (float) SCALE.get(mFastBitmapDrawable), 1f, EPSILON);
|
||||
assertTrue("Wrong interpolator used.",
|
||||
mFastBitmapDrawable.mScaleAnimation.getInterpolator() instanceof PathInterpolator);
|
||||
mFastBitmapDrawable.scaleAnimation.getInterpolator() instanceof PathInterpolator);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -272,12 +258,12 @@ public class FastBitmapDrawableTest {
|
||||
// Animate to hovered state from midway to pressed state.
|
||||
assertTrue("State change not handled.", isHandled);
|
||||
assertEquals("Duration not correct.",
|
||||
mFastBitmapDrawable.mScaleAnimation.getDuration(), HOVER_FEEDBACK_DURATION);
|
||||
mFastBitmapDrawable.mScaleAnimation.end();
|
||||
mFastBitmapDrawable.scaleAnimation.getDuration(), HOVER_FEEDBACK_DURATION);
|
||||
mFastBitmapDrawable.scaleAnimation.end();
|
||||
assertEquals("End value not correct.",
|
||||
(float) SCALE.get(mFastBitmapDrawable), HOVERED_SCALE, EPSILON);
|
||||
assertTrue("Wrong interpolator used.",
|
||||
mFastBitmapDrawable.mScaleAnimation.getInterpolator() instanceof PathInterpolator);
|
||||
mFastBitmapDrawable.scaleAnimation.getInterpolator() instanceof PathInterpolator);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -290,19 +276,19 @@ public class FastBitmapDrawableTest {
|
||||
// Animate to pressed state from midway to hovered state.
|
||||
assertTrue("State change not handled.", isHandled);
|
||||
assertEquals("Duration not correct.",
|
||||
mFastBitmapDrawable.mScaleAnimation.getDuration(), CLICK_FEEDBACK_DURATION);
|
||||
mFastBitmapDrawable.mScaleAnimation.end();
|
||||
mFastBitmapDrawable.scaleAnimation.getDuration(), CLICK_FEEDBACK_DURATION);
|
||||
mFastBitmapDrawable.scaleAnimation.end();
|
||||
assertEquals("End value not correct.",
|
||||
(float) SCALE.get(mFastBitmapDrawable), PRESSED_SCALE, EPSILON);
|
||||
assertTrue("Wrong interpolator used.",
|
||||
mFastBitmapDrawable.mScaleAnimation.getInterpolator()
|
||||
mFastBitmapDrawable.scaleAnimation.getInterpolator()
|
||||
instanceof AccelerateInterpolator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnStateChange_stateDefaultFromPressedNotVisible() {
|
||||
when(mFastBitmapDrawable.isVisible()).thenReturn(false);
|
||||
mFastBitmapDrawable.mIsPressed = true;
|
||||
mFastBitmapDrawable.isPressed = true;
|
||||
SCALE.setValue(mFastBitmapDrawable, PRESSED_SCALE);
|
||||
clearInvocations(mFastBitmapDrawable);
|
||||
int[] state = new int[]{};
|
||||
@@ -311,7 +297,7 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
// No animations when state was pressed but drawable no longer visible. Set values directly.
|
||||
assertTrue("State change not handled.", isHandled);
|
||||
assertNull("Scale animation not null.", mFastBitmapDrawable.mScaleAnimation);
|
||||
assertNull("Scale animation not null.", mFastBitmapDrawable.scaleAnimation);
|
||||
assertEquals("End value not correct.", (float) SCALE.get(mFastBitmapDrawable), 1f, EPSILON);
|
||||
verify(mFastBitmapDrawable).invalidateSelf();
|
||||
}
|
||||
@@ -319,7 +305,7 @@ public class FastBitmapDrawableTest {
|
||||
@Test
|
||||
public void testOnStateChange_stateDefaultFromHoveredNotVisible() {
|
||||
when(mFastBitmapDrawable.isVisible()).thenReturn(false);
|
||||
mFastBitmapDrawable.mIsHovered = true;
|
||||
mFastBitmapDrawable.isHovered = true;
|
||||
SCALE.setValue(mFastBitmapDrawable, HOVERED_SCALE);
|
||||
clearInvocations(mFastBitmapDrawable);
|
||||
int[] state = new int[]{};
|
||||
@@ -328,7 +314,7 @@ public class FastBitmapDrawableTest {
|
||||
|
||||
// No animations when state was hovered but drawable no longer visible. Set values directly.
|
||||
assertTrue("State change not handled.", isHandled);
|
||||
assertNull("Scale animation not null.", mFastBitmapDrawable.mScaleAnimation);
|
||||
assertNull("Scale animation not null.", mFastBitmapDrawable.scaleAnimation);
|
||||
assertEquals("End value not correct.", (float) SCALE.get(mFastBitmapDrawable), 1f, EPSILON);
|
||||
verify(mFastBitmapDrawable).invalidateSelf();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user