Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Steve McKay | f68210e | 2015-11-03 15:23:16 -0800 | [diff] [blame] | 17 | package com.android.documentsui.dirlist; |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 18 | |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 19 | import static com.android.documentsui.dirlist.MultiSelectManager.GridModel.NOT_SET; |
| 20 | |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 21 | import android.graphics.Point; |
| 22 | import android.graphics.Rect; |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 23 | import android.support.v7.widget.RecyclerView.AdapterDataObserver; |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 24 | import android.support.v7.widget.RecyclerView.OnScrollListener; |
Ben Kwa | c21888e | 2015-09-30 14:14:16 -0700 | [diff] [blame] | 25 | import android.test.AndroidTestCase; |
Steve McKay | bfd8705 | 2015-11-12 10:54:31 +0900 | [diff] [blame] | 26 | import android.test.suitebuilder.annotation.SmallTest; |
Ben Kwa | a017bc1 | 2015-10-07 14:15:12 -0700 | [diff] [blame] | 27 | import android.view.View; |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 28 | |
Steve McKay | f68210e | 2015-11-03 15:23:16 -0800 | [diff] [blame] | 29 | import com.android.documentsui.dirlist.MultiSelectManager.GridModel; |
Steve McKay | 3755016 | 2015-09-08 17:15:25 -0700 | [diff] [blame] | 30 | |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 31 | import java.util.List; |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 32 | import java.util.Set; |
| 33 | |
Steve McKay | bfd8705 | 2015-11-12 10:54:31 +0900 | [diff] [blame] | 34 | @SmallTest |
Ben Kwa | c21888e | 2015-09-30 14:14:16 -0700 | [diff] [blame] | 35 | public class MultiSelectManager_GridModelTest extends AndroidTestCase { |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 36 | |
| 37 | private static final int VIEW_PADDING_PX = 5; |
| 38 | private static final int CHILD_VIEW_EDGE_PX = 100; |
| 39 | private static final int VIEWPORT_HEIGHT = 500; |
| 40 | |
Steve McKay | 3755016 | 2015-09-08 17:15:25 -0700 | [diff] [blame] | 41 | private static GridModel model; |
Ben Kwa | a017bc1 | 2015-10-07 14:15:12 -0700 | [diff] [blame] | 42 | private static TestEnvironment env; |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 43 | private static Set<String> lastSelection; |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 44 | private static int viewWidth; |
| 45 | |
| 46 | private static void setUp(int numChildren, int numColumns) { |
Ben Kwa | a017bc1 | 2015-10-07 14:15:12 -0700 | [diff] [blame] | 47 | env = new TestEnvironment(numChildren, numColumns); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 48 | viewWidth = VIEW_PADDING_PX + numColumns * (VIEW_PADDING_PX + CHILD_VIEW_EDGE_PX); |
Ben Kwa | a017bc1 | 2015-10-07 14:15:12 -0700 | [diff] [blame] | 49 | model = new GridModel(env); |
Steve McKay | 3755016 | 2015-09-08 17:15:25 -0700 | [diff] [blame] | 50 | model.addOnSelectionChangedListener( |
| 51 | new GridModel.OnSelectionChangedListener() { |
| 52 | @Override |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 53 | public void onSelectionChanged(Set<String> updatedSelection) { |
Steve McKay | 3755016 | 2015-09-08 17:15:25 -0700 | [diff] [blame] | 54 | lastSelection = updatedSelection; |
| 55 | } |
| 56 | }); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Ben Kwa | c21888e | 2015-09-30 14:14:16 -0700 | [diff] [blame] | 59 | @Override |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 60 | public void tearDown() { |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 61 | model = null; |
Ben Kwa | a017bc1 | 2015-10-07 14:15:12 -0700 | [diff] [blame] | 62 | env = null; |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 63 | lastSelection = null; |
| 64 | } |
| 65 | |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 66 | public void testSelectionLeftOfItems() { |
| 67 | setUp(20, 5); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 68 | model.startSelection(new Point(0, 10)); |
| 69 | model.resizeSelection(new Point(1, 11)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 70 | assertSelected(); |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 71 | assertEquals(NOT_SET, model.getPositionNearestOrigin()); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 74 | public void testSelectionRightOfItems() { |
| 75 | setUp(20, 4); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 76 | model.startSelection(new Point(viewWidth - 1, 10)); |
| 77 | model.resizeSelection(new Point(viewWidth - 2, 11)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 78 | assertSelected(); |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 79 | assertEquals(NOT_SET, model.getPositionNearestOrigin()); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 82 | public void testSelectionAboveItems() { |
| 83 | setUp(20, 4); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 84 | model.startSelection(new Point(10, 0)); |
| 85 | model.resizeSelection(new Point(11, 1)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 86 | assertSelected(); |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 87 | assertEquals(NOT_SET, model.getPositionNearestOrigin()); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 90 | public void testSelectionBelowItems() { |
| 91 | setUp(5, 4); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 92 | model.startSelection(new Point(10, VIEWPORT_HEIGHT - 1)); |
| 93 | model.resizeSelection(new Point(11, VIEWPORT_HEIGHT - 2)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 94 | assertSelected(); |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 95 | assertEquals(NOT_SET, model.getPositionNearestOrigin()); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 98 | public void testVerticalSelectionBetweenItems() { |
| 99 | setUp(20, 4); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 100 | model.startSelection(new Point(106, 0)); |
| 101 | model.resizeSelection(new Point(107, 200)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 102 | assertSelected(); |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 103 | assertEquals(NOT_SET, model.getPositionNearestOrigin()); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 106 | public void testHorizontalSelectionBetweenItems() { |
| 107 | setUp(20, 4); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 108 | model.startSelection(new Point(0, 105)); |
| 109 | model.resizeSelection(new Point(200, 106)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 110 | assertSelected(); |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 111 | assertEquals(NOT_SET, model.getPositionNearestOrigin()); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 114 | public void testGrowingAndShrinkingSelection() { |
| 115 | setUp(20, 4); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 116 | model.startSelection(new Point(0, 0)); |
| 117 | model.resizeSelection(new Point(5, 5)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 118 | assertSelected(0); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 119 | model.resizeSelection(new Point(109, 109)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 120 | assertSelected(0); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 121 | model.resizeSelection(new Point(110, 109)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 122 | assertSelected(0, 1); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 123 | model.resizeSelection(new Point(110, 110)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 124 | assertSelected(0, 1, 4, 5); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 125 | model.resizeSelection(new Point(214, 214)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 126 | assertSelected(0, 1, 4, 5); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 127 | model.resizeSelection(new Point(215, 214)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 128 | assertSelected(0, 1, 2, 4, 5, 6); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 129 | model.resizeSelection(new Point(214, 214)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 130 | assertSelected(0, 1, 4, 5); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 131 | model.resizeSelection(new Point(110, 110)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 132 | assertSelected(0, 1, 4, 5); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 133 | model.resizeSelection(new Point(110, 109)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 134 | assertSelected(0, 1); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 135 | model.resizeSelection(new Point(109, 109)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 136 | assertSelected(0); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 137 | model.resizeSelection(new Point(5, 5)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 138 | assertSelected(0); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 139 | model.resizeSelection(new Point(0, 0)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 140 | assertSelected(); |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 141 | assertEquals(NOT_SET, model.getPositionNearestOrigin()); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 144 | public void testSelectionMovingAroundOrigin() { |
| 145 | setUp(16, 4); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 146 | model.startSelection(new Point(210, 210)); |
| 147 | model.resizeSelection(new Point(viewWidth - 1, 0)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 148 | assertSelected(2, 3, 6, 7); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 149 | model.resizeSelection(new Point(0, 0)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 150 | assertSelected(0, 1, 4, 5); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 151 | model.resizeSelection(new Point(0, 420)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 152 | assertSelected(8, 9, 12, 13); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 153 | model.resizeSelection(new Point(viewWidth - 1, 420)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 154 | assertSelected(10, 11, 14, 15); |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 155 | assertEquals(10, model.getPositionNearestOrigin()); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 158 | public void testScrollingBandSelect() { |
| 159 | setUp(40, 4); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 160 | model.startSelection(new Point(0, 0)); |
| 161 | model.resizeSelection(new Point(100, VIEWPORT_HEIGHT - 1)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 162 | assertSelected(0, 4, 8, 12, 16); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 163 | scroll(CHILD_VIEW_EDGE_PX); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 164 | assertSelected(0, 4, 8, 12, 16, 20); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 165 | model.resizeSelection(new Point(200, VIEWPORT_HEIGHT - 1)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 166 | assertSelected(0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 167 | scroll(CHILD_VIEW_EDGE_PX); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 168 | assertSelected(0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 169 | scroll(-2 * CHILD_VIEW_EDGE_PX); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 170 | assertSelected(0, 1, 4, 5, 8, 9, 12, 13, 16, 17); |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 171 | model.resizeSelection(new Point(100, VIEWPORT_HEIGHT - 1)); |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 172 | assertSelected(0, 4, 8, 12, 16); |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 173 | assertEquals(0, model.getPositionNearestOrigin()); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 176 | private static void assertSelected(int... selectedPositions) { |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 177 | assertEquals(selectedPositions.length, lastSelection.size()); |
| 178 | for (int position : selectedPositions) { |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 179 | assertTrue(lastSelection.contains(Integer.toString(position))); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
| 183 | private static void scroll(int dy) { |
Ben Kwa | a017bc1 | 2015-10-07 14:15:12 -0700 | [diff] [blame] | 184 | assertTrue(env.verticalOffset + VIEWPORT_HEIGHT + dy <= env.getTotalHeight()); |
| 185 | env.verticalOffset += dy; |
Kyle Horimoto | 62a7fd0 | 2015-08-18 13:25:29 -0700 | [diff] [blame] | 186 | model.onScrolled(null, 0, dy); |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Ben Kwa | a017bc1 | 2015-10-07 14:15:12 -0700 | [diff] [blame] | 189 | private static final class TestEnvironment implements MultiSelectManager.SelectionEnvironment { |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 190 | |
| 191 | public int horizontalOffset = 0; |
| 192 | public int verticalOffset = 0; |
| 193 | private final int mNumColumns; |
| 194 | private final int mNumRows; |
| 195 | private final int mNumChildren; |
| 196 | |
Ben Kwa | a017bc1 | 2015-10-07 14:15:12 -0700 | [diff] [blame] | 197 | public TestEnvironment(int numChildren, int numColumns) { |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 198 | mNumChildren = numChildren; |
| 199 | mNumColumns = numColumns; |
| 200 | mNumRows = (int) Math.ceil((double) numChildren / mNumColumns); |
| 201 | } |
| 202 | |
| 203 | private int getTotalHeight() { |
| 204 | return CHILD_VIEW_EDGE_PX * mNumRows + VIEW_PADDING_PX * (mNumRows + 1); |
| 205 | } |
| 206 | |
| 207 | private int getFirstVisibleRowIndex() { |
| 208 | return verticalOffset / (CHILD_VIEW_EDGE_PX + VIEW_PADDING_PX); |
| 209 | } |
| 210 | |
| 211 | private int getLastVisibleRowIndex() { |
| 212 | int lastVisibleRowUncapped = |
| 213 | (VIEWPORT_HEIGHT + verticalOffset - 1) / (CHILD_VIEW_EDGE_PX + VIEW_PADDING_PX); |
| 214 | return Math.min(lastVisibleRowUncapped, mNumRows - 1); |
| 215 | } |
| 216 | |
| 217 | private int getNumItemsInRow(int index) { |
| 218 | assertTrue(index >= 0 && index < mNumRows); |
| 219 | if (index == mNumRows - 1 && mNumChildren % mNumColumns != 0) { |
| 220 | return mNumChildren % mNumColumns; |
| 221 | } |
| 222 | |
| 223 | return mNumColumns; |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public void addOnScrollListener(OnScrollListener listener) {} |
| 228 | |
| 229 | @Override |
| 230 | public void removeOnScrollListener(OnScrollListener listener) {} |
| 231 | |
| 232 | @Override |
| 233 | public Point createAbsolutePoint(Point relativePoint) { |
| 234 | return new Point( |
| 235 | relativePoint.x + horizontalOffset, relativePoint.y + verticalOffset); |
| 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public int getVisibleChildCount() { |
| 240 | int childCount = 0; |
| 241 | for (int i = getFirstVisibleRowIndex(); i <= getLastVisibleRowIndex(); i++) { |
| 242 | childCount += getNumItemsInRow(i); |
| 243 | } |
| 244 | return childCount; |
| 245 | } |
| 246 | |
| 247 | @Override |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 248 | public int getAdapterPositionAt(int index) { |
| 249 | return index + mNumColumns * (getFirstVisibleRowIndex()); |
| 250 | } |
| 251 | |
| 252 | @Override |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 253 | public Rect getAbsoluteRectForChildViewAt(int index) { |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 254 | int adapterPosition = (getFirstVisibleRowIndex() * mNumColumns) + index; |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 255 | int rowIndex = adapterPosition / mNumColumns; |
| 256 | int columnIndex = adapterPosition % mNumColumns; |
| 257 | |
| 258 | Rect rect = new Rect(); |
| 259 | rect.top = VIEW_PADDING_PX + rowIndex * (CHILD_VIEW_EDGE_PX + VIEW_PADDING_PX); |
| 260 | rect.bottom = rect.top + CHILD_VIEW_EDGE_PX - 1; |
| 261 | rect.left = VIEW_PADDING_PX + columnIndex * (CHILD_VIEW_EDGE_PX + VIEW_PADDING_PX); |
| 262 | rect.right = rect.left + CHILD_VIEW_EDGE_PX - 1; |
| 263 | return rect; |
| 264 | } |
| 265 | |
| 266 | @Override |
Steve McKay | 3755016 | 2015-09-08 17:15:25 -0700 | [diff] [blame] | 267 | public int getChildCount() { |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 268 | return mNumChildren; |
| 269 | } |
| 270 | |
| 271 | @Override |
Steve McKay | 3755016 | 2015-09-08 17:15:25 -0700 | [diff] [blame] | 272 | public int getColumnCount() { |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 273 | return mNumColumns; |
| 274 | } |
| 275 | |
| 276 | @Override |
Steve McKay | 3755016 | 2015-09-08 17:15:25 -0700 | [diff] [blame] | 277 | public int getRowCount() { |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 278 | return mNumRows; |
| 279 | } |
Steve McKay | 3755016 | 2015-09-08 17:15:25 -0700 | [diff] [blame] | 280 | |
| 281 | @Override |
| 282 | public void showBand(Rect rect) { |
| 283 | throw new UnsupportedOperationException(); |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void hideBand() { |
| 288 | throw new UnsupportedOperationException(); |
| 289 | } |
| 290 | |
| 291 | @Override |
| 292 | public void scrollBy(int dy) { |
| 293 | throw new UnsupportedOperationException(); |
| 294 | } |
| 295 | |
| 296 | @Override |
| 297 | public int getHeight() { |
| 298 | throw new UnsupportedOperationException(); |
| 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public void invalidateView() { |
| 303 | throw new UnsupportedOperationException(); |
| 304 | } |
| 305 | |
| 306 | @Override |
| 307 | public void runAtNextFrame(Runnable r) { |
| 308 | throw new UnsupportedOperationException(); |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public void removeCallback(Runnable r) { |
| 313 | throw new UnsupportedOperationException(); |
| 314 | } |
Ben Kwa | a017bc1 | 2015-10-07 14:15:12 -0700 | [diff] [blame] | 315 | |
| 316 | @Override |
| 317 | public int getAdapterPositionForChildView(View view) { |
| 318 | throw new UnsupportedOperationException(); |
| 319 | } |
| 320 | |
| 321 | @Override |
| 322 | public void focusItem(int i) { |
| 323 | throw new UnsupportedOperationException(); |
| 324 | } |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 325 | |
| 326 | @Override |
| 327 | public String getModelIdFromAdapterPosition(int position) { |
| 328 | return Integer.toString(position); |
| 329 | } |
| 330 | |
| 331 | @Override |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 332 | public int getItemCount() { |
| 333 | return mNumChildren; |
| 334 | } |
| 335 | |
| 336 | @Override |
Ben Kwa | 936a7fc | 2015-12-10 15:21:18 -0800 | [diff] [blame] | 337 | public List<String> getModelIds() { |
| 338 | return null; |
| 339 | } |
| 340 | |
| 341 | @Override |
Ben Kwa | 6280de0 | 2015-12-16 19:42:08 -0800 | [diff] [blame^] | 342 | public void notifyItemChanged(String id) { |
Ben Kwa | d72a1da | 2015-12-01 19:56:57 -0800 | [diff] [blame] | 343 | throw new UnsupportedOperationException(); |
| 344 | } |
| 345 | |
| 346 | @Override |
| 347 | public void registerDataObserver(AdapterDataObserver observer) { |
| 348 | throw new UnsupportedOperationException(); |
| 349 | } |
Kyle Horimoto | 1ed2c92 | 2015-08-06 10:29:37 -0700 | [diff] [blame] | 350 | } |
| 351 | } |