1 /*
2  * Copyright (C) 2019 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 androidx.constraintlayout.core.state.helpers;
18 
19 import androidx.constraintlayout.core.state.ConstraintReference;
20 import androidx.constraintlayout.core.state.HelperReference;
21 import androidx.constraintlayout.core.state.State;
22 
23 public class AlignHorizontallyReference extends HelperReference {
24 
25     private float mBias = 0.5f;
26 
AlignHorizontallyReference(State state)27     public AlignHorizontallyReference(State state) {
28         super(state, State.Helper.ALIGN_VERTICALLY);
29     }
30 
31     // @TODO: add description
32     @Override
apply()33     public void apply() {
34         for (Object key : mReferences) {
35             ConstraintReference reference = mHelperState.constraints(key);
36             reference.clearHorizontal();
37             if (mStartToStart != null) {
38                 reference.startToStart(mStartToStart);
39             } else if (mStartToEnd != null) {
40                 reference.startToEnd(mStartToEnd);
41             } else {
42                 reference.startToStart(State.PARENT);
43             }
44             if (mEndToStart != null) {
45                 reference.endToStart(mEndToStart);
46             } else if (mEndToEnd != null) {
47                 reference.endToEnd(mEndToEnd);
48             } else {
49                 reference.endToEnd(State.PARENT);
50             }
51             if (mBias != 0.5f) {
52                 reference.horizontalBias(mBias);
53             }
54         }
55     }
56 
57 }
58