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 */ 16package android.support.v17.leanback.widget; 17 18import java.io.PrintWriter; 19import java.io.StringWriter; 20 21public abstract class GridTest { 22 23 static class Provider implements Grid.Provider { 24 25 int[] mItems; 26 int mCount; 27 int[] mEdges; 28 29 Provider(int[] items) { 30 mItems = items; 31 mCount = items.length; 32 mEdges = new int[mCount]; 33 } 34 35 @Override 36 public int getMinIndex() { 37 return 0; 38 } 39 40 @Override 41 public int getCount() { 42 return mCount; 43 } 44 45 @Override 46 public int createItem(int index, boolean append, Object[] item, boolean disappearingItem) { 47 return mItems[index]; 48 } 49 50 @Override 51 public void addItem(Object item, int index, int length, int rowIndex, int edge) { 52 if (edge == Integer.MAX_VALUE || edge == Integer.MIN_VALUE) { 53 // initialize edge for first item added 54 edge = 0; 55 } 56 mEdges[index] = edge; 57 } 58 59 @Override 60 public void removeItem(int index) { 61 } 62 63 @Override 64 public int getEdge(int index) { 65 return mEdges[index]; 66 } 67 68 @Override 69 public int getSize(int index) { 70 return mItems[index]; 71 } 72 73 void scroll(int distance) { 74 for (int i= 0; i < mEdges.length; i++) { 75 mEdges[i] -= distance; 76 } 77 } 78 } 79 80 Provider mProvider; 81 82 static String dump(Grid grid) { 83 StringWriter w = new StringWriter(); 84 grid.debugPrint(new PrintWriter(w)); 85 return w.toString(); 86 } 87} 88