1 /* 2 * Copyright 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 import androidx.constraintlayout.core.widgets.Barrier; 23 import androidx.constraintlayout.core.widgets.HelperWidget; 24 25 public class BarrierReference extends HelperReference { 26 27 private State.Direction mDirection; 28 private int mMargin; 29 private Barrier mBarrierWidget; 30 BarrierReference(State state)31 public BarrierReference(State state) { 32 super(state, State.Helper.BARRIER); 33 } 34 setBarrierDirection(State.Direction barrierDirection)35 public void setBarrierDirection(State.Direction barrierDirection) { 36 mDirection = barrierDirection; 37 } 38 39 @Override margin(Object marginValue)40 public ConstraintReference margin(Object marginValue) { 41 margin(mHelperState.convertDimension(marginValue)); 42 return this; 43 } 44 45 // @TODO: add description 46 @Override margin(int value)47 public ConstraintReference margin(int value) { 48 mMargin = value; 49 return this; 50 } 51 52 @Override getHelperWidget()53 public HelperWidget getHelperWidget() { 54 if (mBarrierWidget == null) { 55 mBarrierWidget = new Barrier(); 56 } 57 return mBarrierWidget; 58 } 59 60 // @TODO: add description 61 @Override apply()62 public void apply() { 63 getHelperWidget(); 64 int direction = Barrier.LEFT; 65 switch (mDirection) { 66 case LEFT: 67 case START: { 68 // TODO: handle RTL 69 } 70 break; 71 case RIGHT: 72 case END: { 73 // TODO: handle RTL 74 direction = Barrier.RIGHT; 75 } 76 break; 77 case TOP: { 78 direction = Barrier.TOP; 79 } 80 break; 81 case BOTTOM: { 82 direction = Barrier.BOTTOM; 83 } 84 } 85 mBarrierWidget.setBarrierType(direction); 86 mBarrierWidget.setMargin(mMargin); 87 } 88 } 89