1 /* 2 * Copyright (C) 2009 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 17 package com.cooliris.media; 18 19 import java.util.ArrayList; 20 21 import com.cooliris.app.App; 22 23 public final class GridLayoutInterface extends LayoutInterface { 24 public GridLayoutInterface(int numRows) { 25 mNumRows = numRows; 26 mSpacingX = (int) (20 * App.PIXEL_DENSITY); 27 mSpacingY = (int) (40 * App.PIXEL_DENSITY); 28 } 29 30 public float getSpacingForBreak() { 31 return mSpacingX / 2; 32 } 33 34 public int getNextSlotIndexForBreak(int breakSlotIndex) { 35 int numRows = mNumRows; 36 int mod = breakSlotIndex % numRows; 37 int add = (numRows - mod); 38 if (add >= numRows) 39 add -= numRows; 40 return breakSlotIndex + add; 41 } 42 43 public void getPositionForSlotIndex(int slotIndex, int itemWidth, int itemHeight, Vector3f outPosition) { 44 int numRows = mNumRows; 45 int resultSlotIndex = slotIndex; 46 outPosition.x = (resultSlotIndex / numRows) * (itemWidth + mSpacingX); 47 outPosition.y = (resultSlotIndex % numRows) * (itemHeight + mSpacingY); 48 int maxY = (numRows - 1) * (itemHeight + mSpacingY); 49 outPosition.y -= (maxY >> 1); 50 outPosition.z = 0; 51 } 52 53 public int mNumRows; 54 public int mSpacingX; 55 public int mSpacingY; 56 } 57