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 AlignVerticallyReference extends HelperReference { 24 25 private float mBias = 0.5f; 26 AlignVerticallyReference(State state)27 public AlignVerticallyReference(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.clearVertical(); 37 if (mTopToTop != null) { 38 reference.topToTop(mTopToTop); 39 } else if (mTopToBottom != null) { 40 reference.topToBottom(mTopToBottom); 41 } else { 42 reference.topToTop(State.PARENT); 43 } 44 if (mBottomToTop != null) { 45 reference.bottomToTop(mBottomToTop); 46 } else if (mBottomToBottom != null) { 47 reference.bottomToBottom(mBottomToBottom); 48 } else { 49 reference.bottomToBottom(State.PARENT); 50 } 51 if (mBias != 0.5f) { 52 reference.verticalBias(mBias); 53 } 54 } 55 } 56 57 } 58