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;
19
20import android.view.View;
21
22/**
23 * Defines alignment position on two directions of an item view. Typically item
24 * view alignment is at the center of the view. The class allows defining
25 * alignment at left/right or fixed offset/percentage position; it also allows
26 * using descendant view by id match.
27 */
28class ItemAlignment {
29
30    final static class Axis extends ItemAlignmentFacet.ItemAlignmentDef {
31        private int mOrientation;
32
33        Axis(int orientation) {
34            mOrientation = orientation;
35        }
36
37        /**
38         * get alignment position relative to optical left/top of itemView.
39         */
40        public int getAlignmentPosition(View itemView) {
41            return ItemAlignmentFacetHelper.getAlignmentPosition(itemView, this, mOrientation);
42        }
43    }
44
45    private int mOrientation = HORIZONTAL;
46
47    final public Axis vertical = new Axis(VERTICAL);
48
49    final public Axis horizontal = new Axis(HORIZONTAL);
50
51    private Axis mMainAxis = horizontal;
52
53    private Axis mSecondAxis = vertical;
54
55    final public Axis mainAxis() {
56        return mMainAxis;
57    }
58
59    final public Axis secondAxis() {
60        return mSecondAxis;
61    }
62
63    final public void setOrientation(int orientation) {
64        mOrientation = orientation;
65        if (mOrientation == HORIZONTAL) {
66            mMainAxis = horizontal;
67            mSecondAxis = vertical;
68        } else {
69            mMainAxis = vertical;
70            mSecondAxis = horizontal;
71        }
72    }
73
74    final public int getOrientation() {
75        return mOrientation;
76    }
77
78
79}
80