19106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn/* 29106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * Copyright (C) 2014 The Android Open Source Project 39106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * 49106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 59106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * in compliance with the License. You may obtain a copy of the License at 69106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * 79106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * http://www.apache.org/licenses/LICENSE-2.0 89106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * 99106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * Unless required by applicable law or agreed to in writing, software distributed under the License 109106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 119106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * or implied. See the License for the specific language governing permissions and limitations under 129106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * the License. 139106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn */ 149106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 159106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbournpackage android.support.v17.leanback.widget; 169106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 179106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbournimport static android.support.v7.widget.RecyclerView.HORIZONTAL; 189106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbournimport static android.support.v7.widget.RecyclerView.VERTICAL; 19a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbournimport static android.support.v17.leanback.widget.BaseGridView.ITEM_ALIGN_OFFSET_PERCENT_DISABLED; 209106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 219106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbournimport android.graphics.Rect; 22c26ebee190513b93c6f30620dac3bfc9038cb621Dake Guimport android.support.v17.leanback.widget.GridLayoutManager.LayoutParams; 239106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbournimport android.view.View; 249106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbournimport android.view.ViewGroup; 259106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 269106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn/** 279106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * Defines alignment position on two directions of an item view. Typically item 289106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * view alignment is at the center of the view. The class allows defining 299106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * alignment at left/right or fixed offset/percentage position; it also allows 309106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn * using descendant view by id match. 319106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn */ 329106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbournclass ItemAlignment { 339106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 3408c56822b71ab0aa0b9bb03e5fd45e28f6e358b8Dake Gu final static class Axis extends ItemAlignmentFacet.ItemAlignmentDef { 359106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn private int mOrientation; 369106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 379106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn Axis(int orientation) { 389106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn mOrientation = orientation; 399106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn } 409106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 41e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu /** 42e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu * get alignment position relative to optical left/top of itemView. 43e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu */ 44c26ebee190513b93c6f30620dac3bfc9038cb621Dake Gu public int getAlignmentPosition(View itemView) { 4508c56822b71ab0aa0b9bb03e5fd45e28f6e358b8Dake Gu return ItemAlignmentFacetHelper.getAlignmentPosition(itemView, this, mOrientation); 469106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn } 479106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn } 489106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 499106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn private int mOrientation = HORIZONTAL; 509106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 519106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn final public Axis vertical = new Axis(VERTICAL); 529106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 539106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn final public Axis horizontal = new Axis(HORIZONTAL); 549106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 559106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn private Axis mMainAxis = horizontal; 569106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 579106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn private Axis mSecondAxis = vertical; 589106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 599106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn final public Axis mainAxis() { 609106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn return mMainAxis; 619106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn } 629106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 639106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn final public Axis secondAxis() { 649106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn return mSecondAxis; 659106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn } 669106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 679106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn final public void setOrientation(int orientation) { 689106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn mOrientation = orientation; 699106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn if (mOrientation == HORIZONTAL) { 709106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn mMainAxis = horizontal; 719106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn mSecondAxis = vertical; 729106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn } else { 739106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn mMainAxis = vertical; 749106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn mSecondAxis = horizontal; 759106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn } 769106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn } 779106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 789106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn final public int getOrientation() { 799106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn return mOrientation; 809106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn } 819106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 829106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn 839106804a84e5e8733e0b9313f749fa1f726e5d11Tim Kilbourn} 84