diff options
author | 2025-03-17 18:28:34 -0700 | |
---|---|---|
committer | 2025-03-17 18:28:34 -0700 | |
commit | d1c4052fe39a6abc1477d31b663243d23e468495 (patch) | |
tree | c5ba2a15a995a744d3a687b913a6132c7fe600c3 | |
parent | 0c4bfe79a79fa43a65fec4243cbdec534fed8e14 (diff) | |
parent | ff7dd896e30199ff0b380dade26d46108036ee8b (diff) |
Merge "[DocsUI] Click search chip should reset scroll view" into main
-rw-r--r-- | src/com/android/documentsui/queries/SearchChipViewManager.java | 2 | ||||
-rw-r--r-- | tests/unit/com/android/documentsui/queries/SearchChipViewManagerTest.java | 35 |
2 files changed, 36 insertions, 1 deletions
diff --git a/src/com/android/documentsui/queries/SearchChipViewManager.java b/src/com/android/documentsui/queries/SearchChipViewManager.java index c2403dd03..bf3d1e865 100644 --- a/src/com/android/documentsui/queries/SearchChipViewManager.java +++ b/src/com/android/documentsui/queries/SearchChipViewManager.java @@ -521,7 +521,7 @@ public class SearchChipViewManager { } // Let the first checked chip can be shown. - View parent = (View) mChipGroup.getParent(); + View parent = (View) mChipGroup.getParent().getParent(); if (parent instanceof HorizontalScrollView) { final int scrollToX = isRtl ? parent.getWidth() : 0; ((HorizontalScrollView) parent).smoothScrollTo(scrollToX, 0); diff --git a/tests/unit/com/android/documentsui/queries/SearchChipViewManagerTest.java b/tests/unit/com/android/documentsui/queries/SearchChipViewManagerTest.java index 6d20447dd..02e24a329 100644 --- a/tests/unit/com/android/documentsui/queries/SearchChipViewManagerTest.java +++ b/tests/unit/com/android/documentsui/queries/SearchChipViewManagerTest.java @@ -18,6 +18,7 @@ package com.android.documentsui.queries; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.spy; @@ -35,6 +36,9 @@ import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.provider.DocumentsContract; import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; +import android.widget.FrameLayout; +import android.widget.HorizontalScrollView; import android.widget.LinearLayout; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -235,6 +239,37 @@ public final class SearchChipViewManagerTest { assertThat(View.VISIBLE).isEqualTo(mirror.getVisibility()); } + @Test + public void testChipChecked_resetScroll() { + // Mock chip group's parent chain according to search_chip_row.xml. + FrameLayout parent = spy(new FrameLayout(mContext)); + HorizontalScrollView grandparent = spy(new HorizontalScrollView(mContext)); + parent.addView(mChipGroup); + grandparent.addView(parent); + // Verify that getParent().getParent() returns the HorizontalScrollView mock. + ViewParent result = mChipGroup.getParent().getParent(); + assertEquals(grandparent, result); + + mSearchChipViewManager.initChipSets( + new String[] {"image/*", "audio/*", "video/*", "text/*"}); + mSearchChipViewManager.updateChips(new String[] {"*/*"}); + + // Manually set HorizontalScrollView's scrollX to something larger than 0. + grandparent.scrollTo(100, 0); + assertTrue(grandparent.getScaleX() > 0); + + assertEquals(6, mChipGroup.getChildCount()); + Chip lastChip = (Chip) mChipGroup.getChildAt(5); + + // chip.setChecked will trigger reorder animation, which needs to be run inside + // the looper thread. + InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { + // Check last chip will move it to the first child and reset scroll view. + lastChip.setChecked(true); + assertEquals(0, grandparent.getScrollX()); + }); + } + private static Set<SearchChipData> getFakeSearchChipDataList() { final Set<SearchChipData> chipDataList = new HashSet<>(); chipDataList.add(new SearchChipData(CHIP_TYPE, 0 /* titleRes */, TEST_MIME_TYPES)); |