1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14
15package android.support.v17.leanback.widget;
16
17import static android.support.v7.widget.RecyclerView.HORIZONTAL;
18import static android.support.v7.widget.RecyclerView.VERTICAL;
19import static android.support.v17.leanback.widget.BaseGridView.ITEM_ALIGN_OFFSET_PERCENT_DISABLED;
20
21import android.graphics.Rect;
22import android.support.v17.leanback.widget.GridLayoutManager.LayoutParams;
23import android.view.View;
24import android.view.ViewGroup;
25
26/**
27 * Defines alignment position on two directions of an item view. Typically item
28 * view alignment is at the center of the view. The class allows defining
29 * alignment at left/right or fixed offset/percentage position; it also allows
30 * using descendant view by id match.
31 */
32class ItemAlignment {
33
34    final static class Axis extends ItemAlignmentFacet.ItemAlignmentDef {
35        private int mOrientation;
36
37        Axis(int orientation) {
38            mOrientation = orientation;
39        }
40
41        /**
42         * get alignment position relative to optical left/top of itemView.
43         */
44        public int getAlignmentPosition(View itemView) {
45            return ItemAlignmentFacetHelper.getAlignmentPosition(itemView, this, mOrientation);
46        }
47    }
48
49    private int mOrientation = HORIZONTAL;
50
51    final public Axis vertical = new Axis(VERTICAL);
52
53    final public Axis horizontal = new Axis(HORIZONTAL);
54
55    private Axis mMainAxis = horizontal;
56
57    private Axis mSecondAxis = vertical;
58
59    final public Axis mainAxis() {
60        return mMainAxis;
61    }
62
63    final public Axis secondAxis() {
64        return mSecondAxis;
65    }
66
67    final public void setOrientation(int orientation) {
68        mOrientation = orientation;
69        if (mOrientation == HORIZONTAL) {
70            mMainAxis = horizontal;
71            mSecondAxis = vertical;
72        } else {
73            mMainAxis = vertical;
74            mSecondAxis = horizontal;
75        }
76    }
77
78    final public int getOrientation() {
79        return mOrientation;
80    }
81
82
83}
84