Skip to content

Commit f91a1eb

Browse files
committed
Revert "[ChipGroup] Fix ChipGroup.getCheckedChipIds() returns wrong state"
This reverts commit 0356d7c.
1 parent 299c8e1 commit f91a1eb

File tree

55 files changed

+58
-636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+58
-636
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:7.1.3'
8+
classpath 'com.android.tools.build:gradle:4.0.0'
99
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
1010
}
1111
}

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

lib/java/com/google/android/material/chip/Chip.java

+7-23
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.android.material.chip;
1818

19-
import android.widget.CompoundButton.OnCheckedChangeListener;
2019
import com.google.android.material.R;
2120

2221
import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
@@ -55,7 +54,6 @@
5554
import android.view.ViewParent;
5655
import android.view.accessibility.AccessibilityEvent;
5756
import android.view.accessibility.AccessibilityNodeInfo;
58-
import android.widget.CompoundButton;
5957
import androidx.annotation.AnimatorRes;
6058
import androidx.annotation.BoolRes;
6159
import androidx.annotation.CallSuper;
@@ -153,7 +151,6 @@ public class Chip extends AppCompatCheckBox
153151
@Nullable private RippleDrawable ripple;
154152

155153
@Nullable private OnClickListener onCloseIconClickListener;
156-
@Nullable private CompoundButton.OnCheckedChangeListener onCheckedChangeListener;
157154
@Nullable private MaterialCheckable.OnCheckedChangeListener<Chip> onCheckedChangeListenerInternal;
158155
private boolean deferredCheckedValue;
159156
private boolean closeIconPressed;
@@ -254,19 +251,6 @@ public Chip(Context context, AttributeSet attrs, int defStyleAttr) {
254251
setMinHeight(minTouchTargetSize);
255252
}
256253
lastLayoutDirection = ViewCompat.getLayoutDirection(this);
257-
258-
super.setOnCheckedChangeListener(
259-
new CompoundButton.OnCheckedChangeListener() {
260-
@Override
261-
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
262-
if (onCheckedChangeListenerInternal != null) {
263-
onCheckedChangeListenerInternal.onCheckedChanged(Chip.this, isChecked);
264-
}
265-
if (onCheckedChangeListener != null) {
266-
onCheckedChangeListener.onCheckedChanged(buttonView, isChecked);
267-
}
268-
}
269-
});
270254
}
271255

272256
@Override
@@ -723,15 +707,15 @@ public void setChecked(boolean checked) {
723707
// Defer the setChecked() call until after initialization.
724708
deferredCheckedValue = checked;
725709
} else if (chipDrawable.isCheckable()) {
710+
boolean wasChecked = isChecked();
726711
super.setChecked(checked);
727-
}
728-
}
729712

730-
@Override
731-
public void setOnCheckedChangeListener(
732-
@Nullable CompoundButton.OnCheckedChangeListener listener) {
733-
// Do not call super here - the wrapped listener set in the constructor will call the listener.
734-
onCheckedChangeListener = listener;
713+
if (wasChecked != checked) {
714+
if (onCheckedChangeListenerInternal != null) {
715+
onCheckedChangeListenerInternal.onCheckedChanged(this, checked);
716+
}
717+
}
718+
}
735719
}
736720

737721
/** Register a callback to be invoked when the close icon is clicked. */

lib/javatests/com/google/android/material/appbar/MaterialToolbarTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.google.android.material.appbar;
1717

18-
import com.google.android.material.test.R;
18+
import com.google.android.material.R;
1919

2020
import static com.google.common.truth.Truth.assertThat;
2121

lib/javatests/com/google/android/material/badge/BadgeDrawableTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.google.android.material.badge;
1717

18-
import com.google.android.material.test.R;
18+
import com.google.android.material.R;
1919

2020
import static com.google.common.truth.Truth.assertThat;
2121

lib/javatests/com/google/android/material/badge/BadgeUtilsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.google.android.material.badge;
1717

18-
import com.google.android.material.test.R;
18+
import com.google.android.material.R;
1919

2020
import static com.google.common.truth.Truth.assertThat;
2121

lib/javatests/com/google/android/material/bottomnavigation/BottomNavigationViewTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.google.android.material.bottomnavigation;
1717

18-
import com.google.android.material.test.R;
18+
import com.google.android.material.R;
1919

2020
import static com.google.common.truth.Truth.assertThat;
2121

lib/javatests/com/google/android/material/bottomsheet/BottomSheetBehaviorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.google.android.material.bottomsheet;
1717

18-
import com.google.android.material.test.R;
18+
import com.google.android.material.R;
1919

2020
import static com.google.common.truth.Truth.assertThat;
2121

lib/javatests/com/google/android/material/button/MaterialButtonTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.google.android.material.button;
1717

18-
import com.google.android.material.test.R;
18+
import com.google.android.material.R;
1919

2020
import static com.google.common.truth.Truth.assertThat;
2121

lib/javatests/com/google/android/material/button/MaterialButtonToggleGroupTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.android.material.button;
1818

19-
import com.google.android.material.test.R;
19+
import com.google.android.material.R;
2020

2121
import static android.view.View.GONE;
2222
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

lib/javatests/com/google/android/material/checkbox/MaterialCheckBoxTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.android.material.checkbox;
1818

19-
import com.google.android.material.test.R;
19+
import com.google.android.material.R;
2020

2121
import static com.google.common.truth.Truth.assertThat;
2222

lib/javatests/com/google/android/material/chip/ChipGroupTest.java

+1-44
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@
1515
*/
1616
package com.google.android.material.chip;
1717

18-
import com.google.android.material.test.R;
18+
import com.google.android.material.R;
1919

20-
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
2120
import static com.google.common.truth.Truth.assertThat;
2221
import static org.junit.Assert.assertEquals;
2322
import static org.junit.Assert.assertTrue;
2423

2524
import android.content.Context;
2625
import androidx.appcompat.app.AppCompatActivity;
2726
import android.view.View;
28-
import android.widget.CompoundButton;
2927
import androidx.core.view.ViewCompat;
3028
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
3129
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionInfoCompat;
@@ -198,29 +196,6 @@ public void onCheckedChanged(ChipGroup group, List<Integer> checkedIds) {
198196
assertThat(checkedIds).contains(second.getId());
199197
}
200198

201-
@Test
202-
public void multipleSelection_chipListener() {
203-
chipgroup.setSingleSelection(false);
204-
205-
Chip first = (Chip) chipgroup.getChildAt(0);
206-
first.setOnCheckedChangeListener(this::onChipCheckedStateChanged);
207-
208-
Chip second = (Chip) chipgroup.getChildAt(1);
209-
second.setOnCheckedChangeListener(this::onChipCheckedStateChanged);
210-
211-
first.performClick();
212-
getInstrumentation().waitForIdleSync();
213-
214-
assertThat(checkedChangeCallCount).isEqualTo(1);
215-
assertThat(checkedIds).containsExactly(first.getId());
216-
217-
second.performClick();
218-
getInstrumentation().waitForIdleSync();
219-
220-
assertThat(checkedChangeCallCount).isEqualTo(2);
221-
assertThat(checkedIds).containsExactly(first.getId(), second.getId());
222-
}
223-
224199
@Test
225200
public void multiSelection_withSelectionRequired_unSelectsIfTwo() {
226201
chipgroup.setSingleSelection(false);
@@ -285,22 +260,4 @@ public void isNotSingleLine_initializesAccessibilityNodeInfo() {
285260
assertEquals(1, itemInfo.getRowIndex());
286261
assertTrue(itemInfo.isSelected());
287262
}
288-
289-
@Test
290-
public void getChipAccessibilityClassName_multipleChecked_buttonName() {
291-
Chip chip = (Chip) chipgroup.getChildAt(0);
292-
assertEquals("android.widget.Button", chip.getAccessibilityClassName().toString());
293-
}
294-
295-
@Test
296-
public void getChipAccessibilityClassName_singleChecked_radioButtonName() {
297-
chipgroup.setSingleSelection(true);
298-
Chip chip = (Chip) chipgroup.getChildAt(0);
299-
assertEquals("android.widget.RadioButton", chip.getAccessibilityClassName().toString());
300-
}
301-
302-
private void onChipCheckedStateChanged(CompoundButton chip, boolean checked) {
303-
checkedChangeCallCount++;
304-
checkedIds = chipgroup.getCheckedChipIds();
305-
}
306263
}

lib/javatests/com/google/android/material/chip/ChipTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.google.android.material.chip;
1717

18-
import com.google.android.material.test.R;
18+
import com.google.android.material.R;
1919

2020
import static com.google.android.material.internal.ViewUtils.dpToPx;
2121
import static com.google.common.truth.Truth.assertThat;

0 commit comments

Comments
 (0)