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