Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Property;
import android.view.View;
import android.view.animation.PathInterpolator;
import androidx.interpolator.view.animation.FastOutLinearInInterpolator;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
import androidx.appcompat.app.AppCompatActivity;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
import com.google.android.material.testapp.animation.R;
Expand Down Expand Up @@ -96,11 +91,7 @@ public void validateSetOfObjectAnimatorAlphaMotionTiming() {

assertEquals(3, alpha.getDelay());
assertEquals(5, alpha.getDuration());
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
assertThat(alpha.getInterpolator(), instanceOf(PathInterpolator.class));
} else {
assertThat(alpha.getInterpolator(), instanceOf(FastOutLinearInInterpolator.class));
}
assertThat(alpha.getInterpolator(), instanceOf(PathInterpolator.class));
assertEquals(7, alpha.getRepeatCount());
assertEquals(ValueAnimator.RESTART, alpha.getRepeatMode());
}
Expand All @@ -111,8 +102,8 @@ public void validateSetOfObjectAnimatorAlphaMotionValues() {
MotionSpec.createFromResource(
activityTestRule.getActivity(), R.animator.valid_set_of_object_animator_motion_spec);
View view = new View(activityTestRule.getActivity());
Animator alphaAnimator = spec.getAnimator("alpha", view, View.ALPHA);
PropertyValuesHolder propertyValuesHolder = ((ObjectAnimator) alphaAnimator).getValues()[0];
ObjectAnimator alphaAnimator = spec.getAnimator("alpha", view, View.ALPHA);
PropertyValuesHolder propertyValuesHolder = alphaAnimator.getValues()[0];
assertTrue(fromAndToValuesMatch(propertyValuesHolder, "0.2", "0.8"));
}

Expand All @@ -125,11 +116,7 @@ public void validateSetOfObjectAnimatorTranslationMotionTiming() {

assertEquals(11, translation.getDelay());
assertEquals(13, translation.getDuration());
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
assertThat(translation.getInterpolator(), instanceOf(PathInterpolator.class));
} else {
assertThat(translation.getInterpolator(), instanceOf(FastOutSlowInInterpolator.class));
}
assertThat(translation.getInterpolator(), instanceOf(PathInterpolator.class));
assertEquals(17, translation.getRepeatCount());
assertEquals(ValueAnimator.REVERSE, translation.getRepeatMode());
}
Expand All @@ -140,9 +127,8 @@ public void validateSetOfObjectAnimatorTranslationMotionValues() {
MotionSpec.createFromResource(
activityTestRule.getActivity(), R.animator.valid_set_of_object_animator_motion_spec);
View view = new View(activityTestRule.getActivity());
Animator translationAnimator = spec.getAnimator("translation", view, View.TRANSLATION_X);
PropertyValuesHolder propertyValuesHolder =
((ObjectAnimator) translationAnimator).getValues()[0];
ObjectAnimator translationAnimator = spec.getAnimator("translation", view, View.TRANSLATION_X);
PropertyValuesHolder propertyValuesHolder = translationAnimator.getValues()[0];
assertTrue(fromAndToValuesMatch(propertyValuesHolder, "0", "101"));
}

Expand All @@ -152,9 +138,8 @@ public void validateSetOfObjectAnimatorEmptyMotionValues() {
MotionSpec.createFromResource(
activityTestRule.getActivity(), R.animator.valid_set_of_object_animator_motion_spec);
View view = new View(activityTestRule.getActivity());
Animator translationAnimator = spec.getAnimator("foo", view, View.TRANSLATION_X);
PropertyValuesHolder propertyValuesHolder =
((ObjectAnimator) translationAnimator).getValues()[0];
ObjectAnimator translationAnimator = spec.getAnimator("foo", view, View.TRANSLATION_X);
PropertyValuesHolder propertyValuesHolder = translationAnimator.getValues()[0];
assertTrue(fromAndToValuesMatch(propertyValuesHolder, "0.0", "0.0"));
}

Expand All @@ -164,16 +149,16 @@ public void getAnimatorForNonViewTarget() {
MotionSpec.createFromResource(
activityTestRule.getActivity(), R.animator.valid_set_of_object_animator_motion_spec);
ColorDrawable drawable = new ColorDrawable();
Animator alphaAnimator = spec.getAnimator("alpha", drawable, ALPHA);
PropertyValuesHolder propertyValuesHolder = ((ObjectAnimator) alphaAnimator).getValues()[0];
ObjectAnimator alphaAnimator = spec.getAnimator("alpha", drawable, ALPHA);
PropertyValuesHolder propertyValuesHolder = alphaAnimator.getValues()[0];
assertTrue(fromAndToValuesMatch(propertyValuesHolder, "0.2", "0.8"));
}

private static final Property<Object, Integer> ALPHA =
new Property<Object, Integer>(Integer.class, "alpha") {
@Override
public void set(Object object, Integer value) {
((ColorDrawable) object).setAlpha(value.intValue());
((ColorDrawable) object).setAlpha(value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@
import static org.junit.Assert.assertEquals;

import android.graphics.Color;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.SystemClock;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
Expand All @@ -42,6 +38,8 @@
import androidx.annotation.IntRange;
import androidx.annotation.LayoutRes;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.google.android.material.internal.BaseDynamicCoordinatorLayoutTest;
Expand All @@ -60,8 +58,6 @@ public abstract class AppBarLayoutBaseTest extends BaseDynamicCoordinatorLayoutT

protected Toolbar mToolbar;

protected TextView mTextView;

protected float mDefaultElevationValue;

protected static void performVerticalSwipeUpGesture(
Expand Down Expand Up @@ -106,9 +102,7 @@ protected void configureContent(@LayoutRes final int layoutResId, @StringRes fin
}

protected void assertAppBarElevation(float expectedValue) {
if (Build.VERSION.SDK_INT >= 21) {
assertEquals(expectedValue, ViewCompat.getElevation(mAppBar), 0.05f);
}
assertEquals(expectedValue, ViewCompat.getElevation(mAppBar), 0.05f);
}

protected void assertScrimAlpha(@IntRange(from = 0, to = 255) int alpha) {
Expand All @@ -131,27 +125,21 @@ protected boolean matchesSafely(View view) {
}

protected void assertAccessibilityHasScrollForwardAction(boolean hasScrollForward) {
if (VERSION.SDK_INT >= 21) {
AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain();
ViewCompat.onInitializeAccessibilityNodeInfo(mCoordinatorLayout, info);
assertThat(
AccessibilityUtils.hasAction(
info,
AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SCROLL_FORWARD))
.isEqualTo(hasScrollForward);
}
AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain();
ViewCompat.onInitializeAccessibilityNodeInfo(mCoordinatorLayout, info);
assertThat(
AccessibilityUtils.hasAction(
info, AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SCROLL_FORWARD))
.isEqualTo(hasScrollForward);
}

protected void assertAccessibilityHasScrollBackwardAction(boolean hasScrollBackward) {
if (VERSION.SDK_INT >= 21) {
AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain();
ViewCompat.onInitializeAccessibilityNodeInfo(mCoordinatorLayout, info);
assertThat(
AccessibilityUtils.hasAction(
info,
AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SCROLL_BACKWARD))
.isEqualTo(hasScrollBackward);
}
AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain();
ViewCompat.onInitializeAccessibilityNodeInfo(mCoordinatorLayout, info);
assertThat(
AccessibilityUtils.hasAction(
info, AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SCROLL_BACKWARD))
.isEqualTo(hasScrollBackward);
}

protected void assertAccessibilityScrollable(boolean isScrollable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void perform(UiController uiController, View view) {
}
int duration = ViewConfiguration.getPressedStateDuration();
if (duration > 0) {
uiController.loopMainThreadForAtLeast((long) duration);
uiController.loopMainThreadForAtLeast(duration);
}
} finally {
downEvent.recycle();
Expand Down Expand Up @@ -483,30 +483,30 @@ private void testSkipCollapsed_smallSwipe(int expectedState, float swipeViewHeig
@MediumTest
public void testSkipCollapsed_smallSwipe_remainsExpanded() throws Throwable {
testSkipCollapsed_smallSwipe(
BottomSheetBehavior.STATE_EXPANDED, /* swipeViewHeightPercentage = */ 0.5f);
BottomSheetBehavior.STATE_EXPANDED, /* swipeViewHeightPercentage= */ 0.5f);
}

@Test
@MediumTest
public void testSkipCollapsedFullyExpanded_smallSwipe_remainsExpanded() throws Throwable {
getBehavior().setFitToContents(false);
testSkipCollapsed_smallSwipe(
BottomSheetBehavior.STATE_HALF_EXPANDED, /* swipeViewHeightPercentage = */ 0.5f);
BottomSheetBehavior.STATE_HALF_EXPANDED, /* swipeViewHeightPercentage= */ 0.5f);
}

@Test
@MediumTest
public void testSkipCollapsed_smallSwipePastThreshold_getsHidden() throws Throwable {
testSkipCollapsed_smallSwipe(
BottomSheetBehavior.STATE_HIDDEN, /* swipeViewHeightPercentage = */ 0.75f);
BottomSheetBehavior.STATE_HIDDEN, /* swipeViewHeightPercentage= */ 0.75f);
}

@Test
@MediumTest
public void testSkipCollapsedFullyExpanded_smallSwipePastThreshold_getsHidden() throws Throwable {
getBehavior().setFitToContents(false);
testSkipCollapsed_smallSwipe(
BottomSheetBehavior.STATE_HIDDEN, /* swipeViewHeightPercentage = */ 0.75f);
BottomSheetBehavior.STATE_HIDDEN, /* swipeViewHeightPercentage= */ 0.75f);
}

@Test
Expand Down Expand Up @@ -969,7 +969,7 @@ public void testFindScrollingChildEnabled() {
disabledParent.addView(enabledChild);

View scrollingChild = getBehavior().findScrollingChild(disabledParent);
assertThat(scrollingChild, is((View) enabledChild));
assertThat(scrollingChild, is(enabledChild));
}

@Test
Expand Down Expand Up @@ -999,8 +999,7 @@ private void checkSetState(final int state, Matcher<View> matcher) throws Throwa
}
}

private void checkSlideOffset(final int state, float slideOffset)
throws Throwable {
private void checkSlideOffset(final int state, float slideOffset) throws Throwable {
registerIdlingResourceCallback();
try {
activityTestRule.runOnUiThread(() -> getBehavior().setState(state));
Expand Down Expand Up @@ -1052,15 +1051,12 @@ private static void assertAccessibilityActions(
state == BottomSheetBehavior.STATE_EXPANDED
|| state == BottomSheetBehavior.STATE_HALF_EXPANDED;
boolean hasDismissAction = state != BottomSheetBehavior.STATE_HIDDEN && behavior.isHideable();
assertThat(
hasCustomAccessibilityAction(behavior.expandActionIds),
equalTo(hasExpandAction));
assertThat(hasCustomAccessibilityAction(behavior.expandActionIds), equalTo(hasExpandAction));
assertThat(
hasCustomAccessibilityAction(behavior.expandHalfwayActionIds),
equalTo(hasHalfExpandAction));
assertThat(
hasCustomAccessibilityAction(behavior.collapseActionIds),
equalTo(hasCollapseAction));
hasCustomAccessibilityAction(behavior.collapseActionIds), equalTo(hasCollapseAction));
assertThat(
AccessibilityUtils.hasAction(bottomSheet, AccessibilityNodeInfoCompat.ACTION_DISMISS),
equalTo(hasDismissAction));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void testSetUp() {
public void testTouchCoordinatorLayout() {
final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
down = false;
Espresso.onView(sameInstance((View) activity.mCoordinatorLayout))
Espresso.onView(sameInstance(activity.mCoordinatorLayout))
.perform(ViewActions.click()) // Click outside the bottom sheet
.check(
(view, e) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

import android.content.DialogInterface;
import android.os.Bundle;
import androidx.appcompat.widget.AppCompatTextView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.test.espresso.Espresso;
import androidx.test.filters.MediumTest;
import androidx.test.rule.ActivityTestRule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import android.content.Context;
import android.content.DialogInterface;
import android.os.SystemClock;
import androidx.appcompat.widget.AppCompatTextView;
import android.view.View;
import android.widget.FrameLayout;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.UiController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;

import androidx.fragment.app.FragmentManager;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.arch.core.executor.testing.InstantTaskExecutorRule;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.fragment.app.FragmentManager;
import androidx.test.espresso.IdlingRegistry;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
import static org.hamcrest.core.IsEqual.equalTo;

import android.app.Activity;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.util.Pair;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.test.espresso.ViewInteraction;
import androidx.test.espresso.action.CoordinatesProvider;
import androidx.test.espresso.action.GeneralLocation;
Expand Down Expand Up @@ -171,7 +171,7 @@ public static void clickDay(Month month, int day) {
onView(
allOf(
isDescendantOfA(withTagValue(equalTo(MaterialCalendar.MONTHS_VIEW_GROUP_TAG))),
withTagValue(IsEqual.<Object>equalTo(month)),
withTagValue(IsEqual.equalTo(month)),
withText(String.valueOf(day))))
.perform(click());
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package com.google.android.material.datepicker;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.OnScrollListener;
import androidx.annotation.NonNull;
import androidx.test.espresso.IdlingResource;

public class RecyclerIdlingResource implements IdlingResource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ public void testClickableTouchAndDragOffView() {
@Test
@MediumTest
public void testOnClickListener() {
final View.OnClickListener listener = mock(View.OnClickListener.class);
final View view = activityTestRule.getActivity().findViewById(R.id.fab_standard);
view.setOnClickListener(listener);
final View.OnClickListener listener = mock(View.OnClickListener.class);
final View view = activityTestRule.getActivity().findViewById(R.id.fab_standard);
view.setOnClickListener(listener);

// Click on the fab
onView(withId(R.id.fab_standard)).perform(click());
// Click on the fab
onView(withId(R.id.fab_standard)).perform(click());

// And verify that the listener was invoked once
verify(listener, times(1)).onClick(view);
// And verify that the listener was invoked once
verify(listener, times(1)).onClick(view);
}

@Test
Expand Down
Loading