Revert "[ChipGroup] Fix ChipGroup.getCheckedChipIds() returns wrong state"

This reverts commit 0356d7c391c4aa64e54a5aa398d58def673d0114.
This commit is contained in:
haodong 2022-05-25 13:04:44 -07:00
parent 299c8e1e82
commit f91a1eba99
55 changed files with 58 additions and 636 deletions

View File

@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

View File

@ -16,7 +16,6 @@
package com.google.android.material.chip;
import android.widget.CompoundButton.OnCheckedChangeListener;
import com.google.android.material.R;
import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
@ -55,7 +54,6 @@ import android.view.ViewOutlineProvider;
import android.view.ViewParent;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.CompoundButton;
import androidx.annotation.AnimatorRes;
import androidx.annotation.BoolRes;
import androidx.annotation.CallSuper;
@ -153,7 +151,6 @@ public class Chip extends AppCompatCheckBox
@Nullable private RippleDrawable ripple;
@Nullable private OnClickListener onCloseIconClickListener;
@Nullable private CompoundButton.OnCheckedChangeListener onCheckedChangeListener;
@Nullable private MaterialCheckable.OnCheckedChangeListener<Chip> onCheckedChangeListenerInternal;
private boolean deferredCheckedValue;
private boolean closeIconPressed;
@ -254,19 +251,6 @@ public class Chip extends AppCompatCheckBox
setMinHeight(minTouchTargetSize);
}
lastLayoutDirection = ViewCompat.getLayoutDirection(this);
super.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (onCheckedChangeListenerInternal != null) {
onCheckedChangeListenerInternal.onCheckedChanged(Chip.this, isChecked);
}
if (onCheckedChangeListener != null) {
onCheckedChangeListener.onCheckedChanged(buttonView, isChecked);
}
}
});
}
@Override
@ -723,15 +707,15 @@ public class Chip extends AppCompatCheckBox
// Defer the setChecked() call until after initialization.
deferredCheckedValue = checked;
} else if (chipDrawable.isCheckable()) {
boolean wasChecked = isChecked();
super.setChecked(checked);
}
}
@Override
public void setOnCheckedChangeListener(
@Nullable CompoundButton.OnCheckedChangeListener listener) {
// Do not call super here - the wrapped listener set in the constructor will call the listener.
onCheckedChangeListener = listener;
if (wasChecked != checked) {
if (onCheckedChangeListenerInternal != null) {
onCheckedChangeListenerInternal.onCheckedChanged(this, checked);
}
}
}
}
/** Register a callback to be invoked when the close icon is clicked. */

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.appbar;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.badge;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.badge;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.bottomnavigation;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.bottomsheet;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.button;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.button;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static android.view.View.GONE;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

View File

@ -16,7 +16,7 @@
package com.google.android.material.checkbox;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -15,9 +15,8 @@
*/
package com.google.android.material.chip;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@ -25,7 +24,6 @@ import static org.junit.Assert.assertTrue;
import android.content.Context;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.CompoundButton;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionInfoCompat;
@ -198,29 +196,6 @@ public class ChipGroupTest {
assertThat(checkedIds).contains(second.getId());
}
@Test
public void multipleSelection_chipListener() {
chipgroup.setSingleSelection(false);
Chip first = (Chip) chipgroup.getChildAt(0);
first.setOnCheckedChangeListener(this::onChipCheckedStateChanged);
Chip second = (Chip) chipgroup.getChildAt(1);
second.setOnCheckedChangeListener(this::onChipCheckedStateChanged);
first.performClick();
getInstrumentation().waitForIdleSync();
assertThat(checkedChangeCallCount).isEqualTo(1);
assertThat(checkedIds).containsExactly(first.getId());
second.performClick();
getInstrumentation().waitForIdleSync();
assertThat(checkedChangeCallCount).isEqualTo(2);
assertThat(checkedIds).containsExactly(first.getId(), second.getId());
}
@Test
public void multiSelection_withSelectionRequired_unSelectsIfTwo() {
chipgroup.setSingleSelection(false);
@ -285,22 +260,4 @@ public class ChipGroupTest {
assertEquals(1, itemInfo.getRowIndex());
assertTrue(itemInfo.isSelected());
}
@Test
public void getChipAccessibilityClassName_multipleChecked_buttonName() {
Chip chip = (Chip) chipgroup.getChildAt(0);
assertEquals("android.widget.Button", chip.getAccessibilityClassName().toString());
}
@Test
public void getChipAccessibilityClassName_singleChecked_radioButtonName() {
chipgroup.setSingleSelection(true);
Chip chip = (Chip) chipgroup.getChildAt(0);
assertEquals("android.widget.RadioButton", chip.getAccessibilityClassName().toString());
}
private void onChipCheckedStateChanged(CompoundButton chip, boolean checked) {
checkedChangeCallCount++;
checkedIds = chipgroup.getCheckedChipIds();
}
}

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.chip;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.android.material.internal.ViewUtils.dpToPx;
import static com.google.common.truth.Truth.assertThat;

View File

@ -1,279 +0,0 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.material.color;
import com.google.android.material.test.R;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.common.truth.Truth.assertThat;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import androidx.appcompat.view.ContextThemeWrapper;
import com.google.android.material.color.DynamicColors.Precondition;
import com.google.android.material.resources.MaterialAttributes;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.ParameterizedRobolectricTestRunner;
import org.robolectric.ParameterizedRobolectricTestRunner.Parameter;
import org.robolectric.ParameterizedRobolectricTestRunner.Parameters;
import org.robolectric.Robolectric;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowContextThemeWrapper;
import org.robolectric.util.ReflectionHelpers;
/** Tests the logic of {@link com.google.android.material.color.DynamicColors} utility class. */
@RunWith(ParameterizedRobolectricTestRunner.class)
public class DynamicColorsTest {
@Parameter(0)
public String testName;
@Parameter(1)
public int baseTheme;
private final MockApplication mockApplication = new MockApplication();
private Activity mockActivity;
@Parameters(name = "{0}")
public static ImmutableList<Object[]> getTestData() {
return ImmutableList.<Object[]>builder()
.add(new Object[] {"Test dynamic colors with Light Theme", R.style.Theme_Material3_Light})
.build();
}
@Before
public void prepareTestActivity() {
setDynamicColorAvailability(true);
setSdkVersion(VERSION_CODES.S);
mockActivity = Robolectric.buildActivity(Activity.class).get();
mockActivity.setTheme(baseTheme);
}
@Test
public void testApplyOnApplicationWithDefaultTheme() {
DynamicColors.applyToActivitiesIfAvailable(mockApplication);
mockApplication.capturedCallbacks.onActivityPreCreated(mockActivity, new Bundle());
// TODO(b/230848477): Update tests to make sure dynamic colors theme overlay is indeed applied.
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testApplyOnApplicationWithCustomTheme() {
final int mockThemeOverlay = 0xABCDABCD;
DynamicColors.applyToActivitiesIfAvailable(mockApplication, mockThemeOverlay);
mockApplication.capturedCallbacks.onActivityPreCreated(mockActivity, new Bundle());
// TODO(b/230848477): Update tests to make sure dynamic colors theme overlay is indeed applied.
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testApplyOnApplicationWithPreconditionFalse() {
final MockPrecondition mockPrecondition = new MockPrecondition();
DynamicColors.applyToActivitiesIfAvailable(mockApplication, mockPrecondition);
mockApplication.capturedCallbacks.onActivityPreCreated(mockActivity, new Bundle());
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testApplyOnApplicationWithPreconditionTrue() {
final MockPrecondition mockPrecondition = new MockPrecondition();
mockPrecondition.shouldApplyDynamicColors = true;
DynamicColors.applyToActivitiesIfAvailable(mockApplication, mockPrecondition);
mockApplication.capturedCallbacks.onActivityPreCreated(mockActivity, new Bundle());
// TODO(b/230848477): Update tests to make sure dynamic colors theme overlay is indeed applied.
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testApplyOnApplicationWithCustomThemeAndPrecondition() {
final int mockThemeOverlay = 0xABCDABCD;
final MockPrecondition mockPrecondition = new MockPrecondition();
mockPrecondition.shouldApplyDynamicColors = true;
DynamicColors.applyToActivitiesIfAvailable(
mockApplication, mockThemeOverlay, mockPrecondition);
mockApplication.capturedCallbacks.onActivityPreCreated(mockActivity, new Bundle());
// TODO(b/230848477): Update tests to make sure dynamic colors theme overlay is indeed applied.
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testApplyOnApplicationWithNoDynamicColorAvailable() {
setDynamicColorAvailability(false);
final int mockThemeOverlay = 0xABCDABCD;
final MockPrecondition mockPrecondition = new MockPrecondition();
mockPrecondition.shouldApplyDynamicColors = true;
DynamicColors.applyToActivitiesIfAvailable(
mockApplication, mockThemeOverlay, mockPrecondition);
mockApplication.capturedCallbacks.onActivityPreCreated(mockActivity, new Bundle());
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testApplyOnApplicationWithLowSdkVersion() {
setSdkVersion(VERSION_CODES.Q);
final int mockThemeOverlay = 0xABCDABCD;
final MockPrecondition mockPrecondition = new MockPrecondition();
mockPrecondition.shouldApplyDynamicColors = true;
DynamicColors.applyToActivitiesIfAvailable(
mockApplication, mockThemeOverlay, mockPrecondition);
mockApplication.capturedCallbacks.onActivityPreCreated(mockActivity, new Bundle());
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testApplyOnActivityWithDefaultTheme() {
DynamicColors.applyIfAvailable(mockActivity);
// TODO(b/230848477): Update tests to make sure dynamic colors theme overlay is indeed applied.
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testApplyOnActivityWithCustomTheme() {
final int mockThemeOverlay = 0xABCDABCD;
DynamicColors.applyIfAvailable(mockActivity, mockThemeOverlay);
// TODO(b/230848477): Update tests to make sure dynamic colors theme overlay is indeed applied.
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testApplyOnActivityWithPreconditionFalse() {
final MockPrecondition mockPrecondition = new MockPrecondition();
DynamicColors.applyIfAvailable(mockActivity, mockPrecondition);
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testApplyOnActivityWithPreconditionTrue() {
final MockPrecondition mockPrecondition = new MockPrecondition();
mockPrecondition.shouldApplyDynamicColors = true;
DynamicColors.applyIfAvailable(mockActivity, mockPrecondition);
// TODO(b/230848477): Update tests to make sure dynamic colors theme overlay is indeed applied.
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testApplyOnActivityWithNoDynamicColorAvailable() {
setDynamicColorAvailability(false);
final int mockThemeOverlay = 0xABCDABCD;
DynamicColors.applyIfAvailable(mockActivity, mockThemeOverlay);
assertThat(getThemeResId(mockActivity)).isEqualTo(baseTheme);
}
@Test
public void testIsDynamicColorAvailable() {
setDynamicColorAvailability(true);
setSdkVersion(VERSION_CODES.S);
assertThat(DynamicColors.isDynamicColorAvailable()).isTrue();
}
@Test
public void testIsDynamicColorAvailableWithNoDynamicColorAvailable() {
setDynamicColorAvailability(false);
assertThat(DynamicColors.isDynamicColorAvailable()).isFalse();
}
@Test
public void testIsDynamicColorAvailableWithLowSdkVersion() {
setSdkVersion(VERSION_CODES.Q);
assertThat(DynamicColors.isDynamicColorAvailable()).isFalse();
}
@Test
public void testWrapContextWithDefaultTheme() {
Context context = DynamicColors.wrapContextIfAvailable(mockActivity);
assertThat(getThemeResId(context))
.isEqualTo(resolveAttribute(baseTheme, R.attr.dynamicColorThemeOverlay));
}
@Test
public void testWrapContextWithCustomTheme() {
final int mockThemeOverlay = 0xABCDABCD;
Context context = DynamicColors.wrapContextIfAvailable(mockActivity, mockThemeOverlay);
assertThat(getThemeResId(context)).isEqualTo(mockThemeOverlay);
}
@Test
public void testWrapContextWithNoDynamicColorAvailable() {
setDynamicColorAvailability(false);
final int mockThemeOverlay = 0xABCDABCD;
Context context = DynamicColors.wrapContextIfAvailable(mockActivity, mockThemeOverlay);
assertThat(getThemeResId(context)).isEqualTo(baseTheme);
}
private void setDynamicColorAvailability(boolean available) {
ReflectionHelpers.setStaticField(
Build.class, "MANUFACTURER", available ? "Google" : "Unsupported OEM");
}
private void setSdkVersion(int sdkVersion) {
ReflectionHelpers.setStaticField(
Build.VERSION.class, "SDK_INT", sdkVersion);
}
@SuppressWarnings("RestrictTo")
private static int resolveAttribute(int theme, int attribute) {
return MaterialAttributes.resolveOrThrow(
new ContextThemeWrapper(getApplicationContext(), theme),
attribute,
"missing in theme");
}
private static int getThemeResId(Context activity) {
ShadowContextThemeWrapper shadowContextThemeWrapper = Shadow.extract(activity);
return shadowContextThemeWrapper.callGetThemeResId();
}
private static class MockApplication extends Application {
private ActivityLifecycleCallbacks capturedCallbacks;
@Override
public void registerActivityLifecycleCallbacks(ActivityLifecycleCallbacks callback) {
capturedCallbacks = callback;
}
}
private static class MockPrecondition implements Precondition {
private boolean shouldApplyDynamicColors;
@Override
public boolean shouldApplyDynamicColors(Activity activity, int theme) {
return shouldApplyDynamicColors;
}
}
}

View File

@ -16,7 +16,7 @@
package com.google.android.material.color;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.datepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static org.junit.Assert.assertEquals;

View File

@ -16,7 +16,7 @@
package com.google.android.material.datepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.datepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.datepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.datepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.datepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.datepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static org.junit.Assert.assertEquals;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.datepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.datepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.datepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static org.junit.Assert.assertEquals;

View File

@ -16,7 +16,7 @@
package com.google.android.material.divider;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.elevation;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.floatingactionbutton;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.floatingactionbutton;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static com.google.android.material.floatingactionbutton.FloatingActionButton.SIZE_MINI;

View File

@ -16,7 +16,7 @@
package com.google.android.material.internal;
import com.google.android.material.test.R;
import com.google.android.material.R;
import android.app.Activity;
import android.content.ContextWrapper;

View File

@ -16,7 +16,7 @@
package com.google.android.material.internal;
import com.google.android.material.test.R;
import com.google.android.material.R;
import android.os.Bundle;
import android.os.Parcel;

View File

@ -16,7 +16,7 @@
package com.google.android.material.internal;
import com.google.android.material.test.R;
import com.google.android.material.R;
import android.os.Parcel;
import org.junit.Assert;

View File

@ -16,7 +16,7 @@
package com.google.android.material.internal;
import com.google.android.material.test.R;
import com.google.android.material.R;
import android.os.Parcel;
import org.junit.Assert;

View File

@ -1,150 +0,0 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.material.motion;
import com.google.android.material.test.R;
import static com.google.common.truth.Truth.assertThat;
import android.animation.TimeInterpolator;
import android.os.Build.VERSION_CODES;
import androidx.appcompat.app.AppCompatActivity;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.PathInterpolator;
import androidx.annotation.RequiresApi;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.internal.DoNotInstrument;
@RunWith(RobolectricTestRunner.class)
@Config(sdk = VERSION_CODES.LOLLIPOP)
@DoNotInstrument
@RequiresApi(api = VERSION_CODES.LOLLIPOP)
public class MotionUtilsTest {
private ActivityController<AppCompatActivity> activityController;
@Rule public final ExpectedException thrown = ExpectedException.none();
@Test
public void testResolvesThemeInterpolator() {
assertThemeInterpolatorIsInstanceOf(
R.style.Theme_Material3_DayNight,
R.attr.motionEasingStandardInterpolator,
LinearInterpolator.class);
}
@Test
public void testCustomInterpolator_resolvesThemeInterpolator() {
assertThemeInterpolatorIsInstanceOf(
R.style.Theme_Material3_DayNight_CustomInterpolator,
R.attr.motionEasingStandardInterpolator,
LinearInterpolator.class);
}
@Test
public void testCustomAnimInterpolator_resolvesThemeInterpolator() {
assertThemeInterpolatorIsInstanceOf(
R.style.Theme_Material3_DayNight_CustomAnimInterpolator,
R.attr.motionEasingStandardInterpolator,
LinearInterpolator.class);
}
@Test
public void testResolvesLegacyInterpolator() {
assertThemeInterpolatorIsInstanceOf(
R.style.Theme_Material3_DayNight, R.attr.motionEasingStandard, PathInterpolator.class);
}
@Test
public void testMaterialComponentsTheme_resolveUnavailableInterpolatorReturnsDefault() {
createActivityAndSetTheme(R.style.Theme_MaterialComponents_DayNight);
DefaultDummyInterpolator defaultInterpolator = new DefaultDummyInterpolator();
TimeInterpolator standardInterpolator =
MotionUtils.resolveThemeInterpolator(
activityController.get().getApplicationContext(),
R.attr.motionEasingStandardInterpolator,
defaultInterpolator);
assertThat(standardInterpolator).isEqualTo(defaultInterpolator);
}
@Test
public void testMaterialComponentsTheme_resolvesLegacyInterpolator() {
assertThemeInterpolatorIsInstanceOf(
R.style.Theme_MaterialComponents_DayNight,
R.attr.motionEasingStandard,
PathInterpolator.class);
}
@Test
public void testMaterialComponentsThemeIncorrectLegacyAttrType_shouldThrowException() {
createActivityAndSetTheme(
R.style.Theme_MaterialComponents_DayNight_IncorrectLegacyEasingAttrType);
// ThrowingRunnable used by assertThrows is not available until gradle 4.13
thrown.expect(IllegalArgumentException.class);
MotionUtils.resolveThemeInterpolator(
activityController.get().getApplicationContext(),
R.attr.motionEasingStandard,
new DefaultDummyInterpolator());
}
@Test
public void testMaterialComponentsThemeIncorrectLegacyFormatting_shouldThrowException() {
createActivityAndSetTheme(
R.style.Theme_MaterialComponents_DayNight_IncorrectLegacyEasingFormat);
// ThrowingRunnable used by assertThrows is not available until gradle 4.13
thrown.expect(IllegalArgumentException.class);
MotionUtils.resolveThemeInterpolator(
activityController.get().getApplicationContext(),
R.attr.motionEasingStandard,
new DefaultDummyInterpolator());
}
private void createActivityAndSetTheme(int themeId) {
ApplicationProvider.getApplicationContext().setTheme(themeId);
activityController = Robolectric.buildActivity(AppCompatActivity.class).create();
}
private void assertThemeInterpolatorIsInstanceOf(int theme, int attrId, Class<?> expectedClass) {
createActivityAndSetTheme(theme);
DefaultDummyInterpolator defaultInterpolator = new DefaultDummyInterpolator();
TimeInterpolator themeInterpolator =
MotionUtils.resolveThemeInterpolator(
activityController.get().getApplicationContext(), attrId, defaultInterpolator);
assertThat(themeInterpolator).isNotEqualTo(defaultInterpolator);
// Robolectric's shadow of Android's AnimationUtils always returns a LinearInterpolator.
assertThat(themeInterpolator).isInstanceOf(expectedClass);
}
private static class DefaultDummyInterpolator implements Interpolator {
@Override
public float getInterpolation(float input) {
return 0;
}
}
}

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.navigation;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static android.os.Build.VERSION_CODES.O;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.radiobutton;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.resources;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static android.content.Context.WINDOW_SERVICE;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.resources;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static org.junit.Assert.assertEquals;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.shape;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.shape;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.slider;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static android.os.Looper.getMainLooper;
import static com.google.android.material.slider.BaseSlider.UNIT_PX;

View File

@ -15,7 +15,7 @@
*/
package com.google.android.material.slider;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static org.robolectric.annotation.LooperMode.Mode.LEGACY;

View File

@ -16,7 +16,7 @@
package com.google.android.material.slider;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.android.material.slider.SliderHelper.dragSliderBetweenValues;
import static com.google.android.material.slider.SliderHelper.touchSliderAtValue;

View File

@ -16,7 +16,7 @@
package com.google.android.material.slider;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.android.material.slider.SliderHelper.clickDpadCenter;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.slider;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.android.material.slider.SliderHelper.touchSliderAtValue;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.slider;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.slider;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.android.material.slider.SliderHelper.calculateXPositionFromValue;
import static com.google.android.material.slider.SliderHelper.dragSliderBetweenValues;

View File

@ -16,7 +16,7 @@
package com.google.android.material.snackbar;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static android.os.Build.VERSION_CODES.JELLY_BEAN;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.textfield;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

View File

@ -1,90 +0,0 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.material.textfield;
import com.google.android.material.test.R;
import static com.google.android.material.textfield.TextInputLayout.END_ICON_CUSTOM;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public final class TextInputLayoutAccessibilityTest {
private TextInputLayout textInputLayout;
private final OnClickListener onClickListener =
new OnClickListener() {
@Override
public void onClick(View v) {
/* Do something */
}
};
@Before
public void themeApplicationContext() {
ApplicationProvider.getApplicationContext()
.setTheme(R.style.Theme_Material3_DayNight_NoActionBar);
AppCompatActivity activity = Robolectric.buildActivity(AppCompatActivity.class).setup().get();
View inflated = activity.getLayoutInflater().inflate(R.layout.test_text_input_layout, null);
((ViewGroup) activity.findViewById(android.R.id.content)).addView(inflated);
textInputLayout = inflated.findViewById(R.id.text_input_layout);
}
@Test
public void testPasswordEndIcon_importantForA11y() {
textInputLayout.setEndIconMode(TextInputLayout.END_ICON_PASSWORD_TOGGLE);
assertThat(textInputLayout.getEndIconView().isImportantForAccessibility(), is(true));
}
@Test
public void testClearTextEndIcon_importantForA11y() {
textInputLayout.setEndIconMode(TextInputLayout.END_ICON_CLEAR_TEXT);
assertThat(textInputLayout.getEndIconView().isImportantForAccessibility(), is(true));
}
@Test
public void testClickableCustomEndIcon_importantForA11y() {
textInputLayout.setEndIconMode(END_ICON_CUSTOM);
textInputLayout.setEndIconDrawable(new ColorDrawable(Color.GREEN));
textInputLayout.setEndIconOnClickListener(onClickListener);
assertThat(textInputLayout.getEndIconView().isImportantForAccessibility(), is(true));
}
@Test
public void testNonClickableCustomEndIcon_notImportantForA11y() {
textInputLayout.setEndIconMode(END_ICON_CUSTOM);
textInputLayout.setEndIconDrawable(new ColorDrawable(Color.GREEN));
assertThat(textInputLayout.getEndIconView().isImportantForAccessibility(), is(false));
}
}

View File

@ -16,7 +16,7 @@
package com.google.android.material.textview;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.theme;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.theme;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;

View File

@ -16,7 +16,7 @@
package com.google.android.material.timepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static android.os.Looper.getMainLooper;
import static com.google.common.truth.Truth.assertThat;

View File

@ -16,7 +16,7 @@
package com.google.android.material.timepicker;
import com.google.android.material.test.R;
import com.google.android.material.R;
import static android.os.Looper.getMainLooper;
import static com.google.common.truth.Truth.assertThat;