1 /* 2 * Copyright (C) 2016 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.widget; 18 19 import android.annotation.SuppressLint; 20 import android.content.Context; 21 import android.content.res.Resources; 22 import android.content.res.TypedArray; 23 import android.content.res.XmlResourceParser; 24 import android.graphics.Color; 25 import android.os.Build; 26 import android.os.Build.VERSION_CODES; 27 import android.util.AttributeSet; 28 import android.util.Log; 29 import android.util.SparseArray; 30 import android.util.SparseIntArray; 31 import android.util.TypedValue; 32 import android.util.Xml; 33 import android.view.LayoutInflater; 34 import android.view.View; 35 36 import androidx.constraintlayout.core.motion.utils.Easing; 37 import androidx.constraintlayout.core.widgets.ConstraintWidget; 38 import androidx.constraintlayout.core.widgets.HelperWidget; 39 import androidx.constraintlayout.motion.widget.Debug; 40 import androidx.constraintlayout.motion.widget.MotionLayout; 41 import androidx.constraintlayout.motion.widget.MotionScene; 42 import androidx.constraintlayout.widget.ConstraintAttribute.AttributeType; 43 import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams; 44 45 import org.xmlpull.v1.XmlPullParser; 46 import org.xmlpull.v1.XmlPullParserException; 47 48 import java.io.IOException; 49 import java.io.Writer; 50 import java.lang.reflect.Field; 51 import java.lang.reflect.Modifier; 52 import java.util.ArrayList; 53 import java.util.Arrays; 54 import java.util.HashMap; 55 import java.util.HashSet; 56 import java.util.Locale; 57 import java.util.Set; 58 59 /** 60 * Defines a set of constraints to be used with {@link ConstraintLayout}. 61 * 62 * <p>{@code ConstraintSet} enables you create and save constraints and apply 63 * them to an existing {@code ConstraintLayout}. For details about constraint 64 * behaviour, see {@link ConstraintLayout}.</p> 65 * 66 * <p>{@code ConstraintsSet} can be created in various ways:</p> 67 * <ul> 68 * <li>Manually — 69 * {@code c = new ConstraintSet(); c.connect(...);}</li> 70 * <li>From an {@code R.layout.*} object — 71 * {@code c.clone(context, R.layout.layout1);}</li> 72 * <li>From a {@code ConstraintLayout} — 73 * {@code c.clone(constraintLayout);}</li> 74 * </ul> 75 * 76 * <p>Example code:</p> 77 * <pre>import android.content.Context; 78 * import android.os.Bundle; 79 * import android.support.constraint.ConstraintLayout; 80 * import android.support.constraint.ConstraintSet; 81 * import android.support.transition.TransitionManager; 82 * import android.support.v7.app.AppCompatActivity; 83 * import android.view.View; 84 * 85 * public class MainActivity extends AppCompatActivity { 86 * ConstraintSet mConstraintSet1 = new ConstraintSet(); // Create a ConstraintSet. 87 * ConstraintSet mConstraintSet2 = new ConstraintSet(); // Create a ConstraintSet. 88 * ConstraintLayout mConstraintLayout; // Cache the ConstraintLayout. 89 * boolean mOld = true; 90 * 91 * 92 * protected void onCreate(Bundle savedInstanceState) { 93 * super.onCreate(savedInstanceState); 94 * Context context = this; 95 * mConstraintSet2.clone(context, R.layout.state2); // Get constraints from layout. 96 * setContentView(R.layout.state1); 97 * mConstraintLayout = (ConstraintLayout) findViewById(R.id.activity_main); 98 * mConstraintSet1.clone(mConstraintLayout); // Get constraints from ConstraintSet. 99 * } 100 * 101 * public void foo(View view) { 102 * TransitionManager.beginDelayedTransition(mConstraintLayout); 103 * if (mOld = !mOld) { 104 * mConstraintSet1.applyTo(mConstraintLayout); // Set new constraints. 105 * } else { 106 * mConstraintSet2.applyTo(mConstraintLayout); // Set new constraints. 107 * } 108 * } 109 * }</pre> 110 */ 111 public class ConstraintSet { 112 private static final String TAG = "ConstraintSet"; 113 private static final String ERROR_MESSAGE = "XML parser error must be within a Constraint "; 114 115 private static final int INTERNAL_MATCH_PARENT = -1; 116 private static final int INTERNAL_WRAP_CONTENT = -2; 117 private static final int INTERNAL_MATCH_CONSTRAINT = -3; 118 private static final int INTERNAL_WRAP_CONTENT_CONSTRAINED = -4; 119 120 private boolean mValidate; 121 public String mIdString; 122 public String derivedState = ""; 123 private String [] mMatchLabels = new String[0]; 124 public static final int ROTATE_NONE = 0; 125 public static final int ROTATE_PORTRATE_OF_RIGHT = 1; 126 public static final int ROTATE_PORTRATE_OF_LEFT = 2; 127 public static final int ROTATE_RIGHT_OF_PORTRATE = 3; 128 public static final int ROTATE_LEFT_OF_PORTRATE = 4; 129 public int mRotate = 0; 130 private HashMap<String, ConstraintAttribute> mSavedAttributes = new HashMap<>(); 131 132 /** 133 * require that all views have IDs to function 134 */ 135 private boolean mForceId = true; 136 /** 137 * Used to indicate a parameter is cleared or not set 138 */ 139 public static final int UNSET = LayoutParams.UNSET; 140 141 /** 142 * Dimension will be controlled by constraints 143 */ 144 public static final int MATCH_CONSTRAINT = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT; 145 146 /** 147 * Dimension will set by the view's content 148 */ 149 public static final int WRAP_CONTENT = ConstraintLayout.LayoutParams.WRAP_CONTENT; 150 151 /** 152 * How to calculate the size of a view in 0 dp by using its wrap_content size 153 */ 154 public static final int MATCH_CONSTRAINT_WRAP = 155 ConstraintLayout.LayoutParams.MATCH_CONSTRAINT_WRAP; 156 157 /** 158 * Calculate the size of a view in 0 dp by reducing the constrains gaps as much as possible 159 */ 160 public static final int MATCH_CONSTRAINT_SPREAD = 161 ConstraintLayout.LayoutParams.MATCH_CONSTRAINT_SPREAD; 162 163 public static final int MATCH_CONSTRAINT_PERCENT = 164 ConstraintLayout.LayoutParams.MATCH_CONSTRAINT_PERCENT; 165 166 /** 167 * References the id of the parent. 168 * Used in: 169 * <ul> 170 * <li>{@link #connect(int, int, int, int, int)}</li> 171 * <li>{@link #center(int, int, int, int, int, int, int, float)}</li> 172 * </ul> 173 */ 174 public static final int PARENT_ID = ConstraintLayout.LayoutParams.PARENT_ID; 175 176 /** 177 * The horizontal orientation. 178 */ 179 public static final int HORIZONTAL = ConstraintLayout.LayoutParams.HORIZONTAL; 180 181 /** 182 * The vertical orientation. 183 */ 184 public static final int VERTICAL = ConstraintLayout.LayoutParams.VERTICAL; 185 186 /** 187 * Used to create a horizontal create guidelines. 188 */ 189 public static final int HORIZONTAL_GUIDELINE = 0; 190 191 /** 192 * Used to create a vertical create guidelines. 193 * see {@link #create(int, int)} 194 */ 195 public static final int VERTICAL_GUIDELINE = 1; 196 197 /** 198 * This view is visible. 199 * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code 200 * android:visibility}. 201 */ 202 public static final int VISIBLE = View.VISIBLE; 203 204 /** 205 * This view is invisible, but it still takes up space for layout purposes. 206 * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code 207 * android:visibility}. 208 */ 209 public static final int INVISIBLE = View.INVISIBLE; 210 211 /** 212 * This view is gone, and will not take any space for layout 213 * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code 214 * android:visibility}. 215 */ 216 public static final int GONE = View.GONE; 217 218 /** 219 * The left side of a view. 220 */ 221 public static final int LEFT = ConstraintLayout.LayoutParams.LEFT; 222 223 /** 224 * The right side of a view. 225 */ 226 public static final int RIGHT = ConstraintLayout.LayoutParams.RIGHT; 227 228 /** 229 * The top of a view. 230 */ 231 public static final int TOP = ConstraintLayout.LayoutParams.TOP; 232 233 /** 234 * The bottom side of a view. 235 */ 236 public static final int BOTTOM = ConstraintLayout.LayoutParams.BOTTOM; 237 238 /** 239 * The baseline of the text in a view. 240 */ 241 public static final int BASELINE = ConstraintLayout.LayoutParams.BASELINE; 242 243 /** 244 * The left side of a view in left to right languages. 245 * In right to left languages it corresponds to the right side of the view 246 */ 247 public static final int START = ConstraintLayout.LayoutParams.START; 248 249 /** 250 * The right side of a view in left to right languages. 251 * In right to left languages it corresponds to the left side of the view 252 */ 253 public static final int END = ConstraintLayout.LayoutParams.END; 254 255 /** 256 * Circle reference from a view. 257 */ 258 public static final int CIRCLE_REFERENCE = ConstraintLayout.LayoutParams.CIRCLE; 259 260 /** 261 * Chain spread style 262 */ 263 public static final int CHAIN_SPREAD = ConstraintLayout.LayoutParams.CHAIN_SPREAD; 264 265 /** 266 * Chain spread inside style 267 */ 268 public static final int CHAIN_SPREAD_INSIDE = ConstraintLayout.LayoutParams.CHAIN_SPREAD_INSIDE; 269 270 public static final int VISIBILITY_MODE_NORMAL = 0; 271 public static final int VISIBILITY_MODE_IGNORE = 1; 272 /** 273 * Chain packed style 274 */ 275 public static final int CHAIN_PACKED = ConstraintLayout.LayoutParams.CHAIN_PACKED; 276 277 private static final boolean DEBUG = false; 278 private static final int[] VISIBILITY_FLAGS = new int[]{VISIBLE, INVISIBLE, GONE}; 279 private static final int BARRIER_TYPE = 1; 280 281 private HashMap<Integer, Constraint> mConstraints = new HashMap<Integer, Constraint>(); 282 283 private static SparseIntArray sMapToConstant = new SparseIntArray(); 284 private static SparseIntArray sOverrideMapToConstant = new SparseIntArray(); 285 private static final int BASELINE_TO_BASELINE = 1; 286 private static final int BOTTOM_MARGIN = 2; 287 private static final int BOTTOM_TO_BOTTOM = 3; 288 private static final int BOTTOM_TO_TOP = 4; 289 private static final int DIMENSION_RATIO = 5; 290 private static final int EDITOR_ABSOLUTE_X = 6; 291 private static final int EDITOR_ABSOLUTE_Y = 7; 292 private static final int END_MARGIN = 8; 293 private static final int END_TO_END = 9; 294 private static final int END_TO_START = 10; 295 private static final int GONE_BOTTOM_MARGIN = 11; 296 private static final int GONE_END_MARGIN = 12; 297 private static final int GONE_LEFT_MARGIN = 13; 298 private static final int GONE_RIGHT_MARGIN = 14; 299 private static final int GONE_START_MARGIN = 15; 300 private static final int GONE_TOP_MARGIN = 16; 301 private static final int GUIDE_BEGIN = 17; 302 private static final int GUIDE_END = 18; 303 private static final int GUIDE_PERCENT = 19; 304 private static final int HORIZONTAL_BIAS = 20; 305 private static final int LAYOUT_HEIGHT = 21; 306 private static final int LAYOUT_VISIBILITY = 22; 307 private static final int LAYOUT_WIDTH = 23; 308 private static final int LEFT_MARGIN = 24; 309 private static final int LEFT_TO_LEFT = 25; 310 private static final int LEFT_TO_RIGHT = 26; 311 private static final int ORIENTATION = 27; 312 private static final int RIGHT_MARGIN = 28; 313 private static final int RIGHT_TO_LEFT = 29; 314 private static final int RIGHT_TO_RIGHT = 30; 315 private static final int START_MARGIN = 31; 316 private static final int START_TO_END = 32; 317 private static final int START_TO_START = 33; 318 private static final int TOP_MARGIN = 34; 319 private static final int TOP_TO_BOTTOM = 35; 320 private static final int TOP_TO_TOP = 36; 321 private static final int VERTICAL_BIAS = 37; 322 private static final int VIEW_ID = 38; 323 private static final int HORIZONTAL_WEIGHT = 39; 324 private static final int VERTICAL_WEIGHT = 40; 325 private static final int HORIZONTAL_STYLE = 41; 326 private static final int VERTICAL_STYLE = 42; 327 private static final int ALPHA = 43; 328 private static final int ELEVATION = 44; 329 private static final int ROTATION_X = 45; 330 private static final int ROTATION_Y = 46; 331 private static final int SCALE_X = 47; 332 private static final int SCALE_Y = 48; 333 private static final int TRANSFORM_PIVOT_X = 49; 334 private static final int TRANSFORM_PIVOT_Y = 50; 335 private static final int TRANSLATION_X = 51; 336 private static final int TRANSLATION_Y = 52; 337 private static final int TRANSLATION_Z = 53; 338 private static final int WIDTH_DEFAULT = 54; 339 private static final int HEIGHT_DEFAULT = 55; 340 private static final int WIDTH_MAX = 56; 341 private static final int HEIGHT_MAX = 57; 342 private static final int WIDTH_MIN = 58; 343 private static final int HEIGHT_MIN = 59; 344 private static final int ROTATION = 60; 345 private static final int CIRCLE = 61; 346 private static final int CIRCLE_RADIUS = 62; 347 private static final int CIRCLE_ANGLE = 63; 348 private static final int ANIMATE_RELATIVE_TO = 64; 349 private static final int TRANSITION_EASING = 65; 350 private static final int DRAW_PATH = 66; 351 private static final int TRANSITION_PATH_ROTATE = 67; 352 private static final int PROGRESS = 68; 353 private static final int WIDTH_PERCENT = 69; 354 private static final int HEIGHT_PERCENT = 70; 355 private static final int CHAIN_USE_RTL = 71; 356 private static final int BARRIER_DIRECTION = 72; 357 private static final int BARRIER_MARGIN = 73; 358 private static final int CONSTRAINT_REFERENCED_IDS = 74; 359 private static final int BARRIER_ALLOWS_GONE_WIDGETS = 75; 360 private static final int PATH_MOTION_ARC = 76; 361 private static final int CONSTRAINT_TAG = 77; 362 private static final int VISIBILITY_MODE = 78; 363 private static final int MOTION_STAGGER = 79; 364 private static final int CONSTRAINED_WIDTH = 80; 365 private static final int CONSTRAINED_HEIGHT = 81; 366 private static final int ANIMATE_CIRCLE_ANGLE_TO = 82; 367 private static final int TRANSFORM_PIVOT_TARGET = 83; 368 private static final int QUANTIZE_MOTION_STEPS = 84; 369 private static final int QUANTIZE_MOTION_PHASE = 85; 370 private static final int QUANTIZE_MOTION_INTERPOLATOR = 86; 371 private static final int UNUSED = 87; 372 private static final int QUANTIZE_MOTION_INTERPOLATOR_TYPE = 88; 373 private static final int QUANTIZE_MOTION_INTERPOLATOR_ID = 89; 374 private static final int QUANTIZE_MOTION_INTERPOLATOR_STR = 90; 375 private static final int BASELINE_TO_TOP = 91; 376 private static final int BASELINE_TO_BOTTOM = 92; 377 private static final int BASELINE_MARGIN = 93; 378 private static final int GONE_BASELINE_MARGIN = 94; 379 private static final int LAYOUT_CONSTRAINT_WIDTH = 95; 380 private static final int LAYOUT_CONSTRAINT_HEIGHT = 96; 381 private static final int LAYOUT_WRAP_BEHAVIOR = 97; 382 private static final int MOTION_TARGET = 98; 383 private static final int GUIDELINE_USE_RTL = 99; 384 385 private static final String KEY_WEIGHT = "weight"; 386 private static final String KEY_RATIO = "ratio"; 387 private static final String KEY_PERCENT_PARENT = "parent"; 388 389 390 static { sMapToConstant.append(R.styleable.Constraint_layout_constraintLeft_toLeftOf, LEFT_TO_LEFT)391 sMapToConstant.append(R.styleable.Constraint_layout_constraintLeft_toLeftOf, LEFT_TO_LEFT); sMapToConstant.append(R.styleable.Constraint_layout_constraintLeft_toRightOf, LEFT_TO_RIGHT)392 sMapToConstant.append(R.styleable.Constraint_layout_constraintLeft_toRightOf, 393 LEFT_TO_RIGHT); sMapToConstant.append(R.styleable.Constraint_layout_constraintRight_toLeftOf, RIGHT_TO_LEFT)394 sMapToConstant.append(R.styleable.Constraint_layout_constraintRight_toLeftOf, 395 RIGHT_TO_LEFT); sMapToConstant.append( R.styleable.Constraint_layout_constraintRight_toRightOf, RIGHT_TO_RIGHT)396 sMapToConstant.append( 397 R.styleable.Constraint_layout_constraintRight_toRightOf, RIGHT_TO_RIGHT); sMapToConstant.append(R.styleable.Constraint_layout_constraintTop_toTopOf, TOP_TO_TOP)398 sMapToConstant.append(R.styleable.Constraint_layout_constraintTop_toTopOf, TOP_TO_TOP); sMapToConstant.append(R.styleable.Constraint_layout_constraintTop_toBottomOf, TOP_TO_BOTTOM)399 sMapToConstant.append(R.styleable.Constraint_layout_constraintTop_toBottomOf, 400 TOP_TO_BOTTOM); sMapToConstant.append(R.styleable.Constraint_layout_constraintBottom_toTopOf, BOTTOM_TO_TOP)401 sMapToConstant.append(R.styleable.Constraint_layout_constraintBottom_toTopOf, 402 BOTTOM_TO_TOP); sMapToConstant.append( R.styleable.Constraint_layout_constraintBottom_toBottomOf, BOTTOM_TO_BOTTOM)403 sMapToConstant.append( 404 R.styleable.Constraint_layout_constraintBottom_toBottomOf, BOTTOM_TO_BOTTOM); sMapToConstant.append( R.styleable.Constraint_layout_constraintBaseline_toBaselineOf, BASELINE_TO_BASELINE)405 sMapToConstant.append( 406 R.styleable.Constraint_layout_constraintBaseline_toBaselineOf, 407 BASELINE_TO_BASELINE); sMapToConstant.append( R.styleable.Constraint_layout_constraintBaseline_toTopOf, BASELINE_TO_TOP)408 sMapToConstant.append( 409 R.styleable.Constraint_layout_constraintBaseline_toTopOf, BASELINE_TO_TOP); sMapToConstant.append( R.styleable.Constraint_layout_constraintBaseline_toBottomOf, BASELINE_TO_BOTTOM)410 sMapToConstant.append( 411 R.styleable.Constraint_layout_constraintBaseline_toBottomOf, BASELINE_TO_BOTTOM); 412 sMapToConstant.append(R.styleable.Constraint_layout_editor_absoluteX, EDITOR_ABSOLUTE_X)413 sMapToConstant.append(R.styleable.Constraint_layout_editor_absoluteX, EDITOR_ABSOLUTE_X); sMapToConstant.append(R.styleable.Constraint_layout_editor_absoluteY, EDITOR_ABSOLUTE_Y)414 sMapToConstant.append(R.styleable.Constraint_layout_editor_absoluteY, EDITOR_ABSOLUTE_Y); sMapToConstant.append(R.styleable.Constraint_layout_constraintGuide_begin, GUIDE_BEGIN)415 sMapToConstant.append(R.styleable.Constraint_layout_constraintGuide_begin, GUIDE_BEGIN); sMapToConstant.append(R.styleable.Constraint_layout_constraintGuide_end, GUIDE_END)416 sMapToConstant.append(R.styleable.Constraint_layout_constraintGuide_end, GUIDE_END); sMapToConstant.append(R.styleable.Constraint_layout_constraintGuide_percent, GUIDE_PERCENT)417 sMapToConstant.append(R.styleable.Constraint_layout_constraintGuide_percent, GUIDE_PERCENT); sMapToConstant.append(R.styleable.Constraint_guidelineUseRtl, GUIDELINE_USE_RTL)418 sMapToConstant.append(R.styleable.Constraint_guidelineUseRtl, GUIDELINE_USE_RTL); 419 sMapToConstant.append(R.styleable.Constraint_android_orientation, ORIENTATION)420 sMapToConstant.append(R.styleable.Constraint_android_orientation, ORIENTATION); sMapToConstant.append(R.styleable.Constraint_layout_constraintStart_toEndOf, START_TO_END)421 sMapToConstant.append(R.styleable.Constraint_layout_constraintStart_toEndOf, START_TO_END); sMapToConstant.append( R.styleable.Constraint_layout_constraintStart_toStartOf, START_TO_START)422 sMapToConstant.append( 423 R.styleable.Constraint_layout_constraintStart_toStartOf, START_TO_START); sMapToConstant.append(R.styleable.Constraint_layout_constraintEnd_toStartOf, END_TO_START)424 sMapToConstant.append(R.styleable.Constraint_layout_constraintEnd_toStartOf, END_TO_START); sMapToConstant.append(R.styleable.Constraint_layout_constraintEnd_toEndOf, END_TO_END)425 sMapToConstant.append(R.styleable.Constraint_layout_constraintEnd_toEndOf, END_TO_END); sMapToConstant.append(R.styleable.Constraint_layout_goneMarginLeft, GONE_LEFT_MARGIN)426 sMapToConstant.append(R.styleable.Constraint_layout_goneMarginLeft, GONE_LEFT_MARGIN); sMapToConstant.append(R.styleable.Constraint_layout_goneMarginTop, GONE_TOP_MARGIN)427 sMapToConstant.append(R.styleable.Constraint_layout_goneMarginTop, GONE_TOP_MARGIN); sMapToConstant.append(R.styleable.Constraint_layout_goneMarginRight, GONE_RIGHT_MARGIN)428 sMapToConstant.append(R.styleable.Constraint_layout_goneMarginRight, GONE_RIGHT_MARGIN); sMapToConstant.append(R.styleable.Constraint_layout_goneMarginBottom, GONE_BOTTOM_MARGIN)429 sMapToConstant.append(R.styleable.Constraint_layout_goneMarginBottom, GONE_BOTTOM_MARGIN); sMapToConstant.append(R.styleable.Constraint_layout_goneMarginStart, GONE_START_MARGIN)430 sMapToConstant.append(R.styleable.Constraint_layout_goneMarginStart, GONE_START_MARGIN); sMapToConstant.append(R.styleable.Constraint_layout_goneMarginEnd, GONE_END_MARGIN)431 sMapToConstant.append(R.styleable.Constraint_layout_goneMarginEnd, GONE_END_MARGIN); sMapToConstant.append( R.styleable.Constraint_layout_constraintVertical_weight, VERTICAL_WEIGHT)432 sMapToConstant.append( 433 R.styleable.Constraint_layout_constraintVertical_weight, VERTICAL_WEIGHT); sMapToConstant.append( R.styleable.Constraint_layout_constraintHorizontal_weight, HORIZONTAL_WEIGHT)434 sMapToConstant.append( 435 R.styleable.Constraint_layout_constraintHorizontal_weight, HORIZONTAL_WEIGHT); sMapToConstant.append( R.styleable.Constraint_layout_constraintHorizontal_chainStyle, HORIZONTAL_STYLE)436 sMapToConstant.append( 437 R.styleable.Constraint_layout_constraintHorizontal_chainStyle, HORIZONTAL_STYLE); sMapToConstant.append( R.styleable.Constraint_layout_constraintVertical_chainStyle, VERTICAL_STYLE)438 sMapToConstant.append( 439 R.styleable.Constraint_layout_constraintVertical_chainStyle, VERTICAL_STYLE); 440 sMapToConstant.append( R.styleable.Constraint_layout_constraintHorizontal_bias, HORIZONTAL_BIAS)441 sMapToConstant.append( 442 R.styleable.Constraint_layout_constraintHorizontal_bias, HORIZONTAL_BIAS); sMapToConstant.append( R.styleable.Constraint_layout_constraintVertical_bias, VERTICAL_BIAS)443 sMapToConstant.append( 444 R.styleable.Constraint_layout_constraintVertical_bias, VERTICAL_BIAS); sMapToConstant.append( R.styleable.Constraint_layout_constraintDimensionRatio, DIMENSION_RATIO)445 sMapToConstant.append( 446 R.styleable.Constraint_layout_constraintDimensionRatio, DIMENSION_RATIO); sMapToConstant.append(R.styleable.Constraint_layout_constraintLeft_creator, UNUSED)447 sMapToConstant.append(R.styleable.Constraint_layout_constraintLeft_creator, UNUSED); sMapToConstant.append(R.styleable.Constraint_layout_constraintTop_creator, UNUSED)448 sMapToConstant.append(R.styleable.Constraint_layout_constraintTop_creator, UNUSED); sMapToConstant.append(R.styleable.Constraint_layout_constraintRight_creator, UNUSED)449 sMapToConstant.append(R.styleable.Constraint_layout_constraintRight_creator, UNUSED); sMapToConstant.append(R.styleable.Constraint_layout_constraintBottom_creator, UNUSED)450 sMapToConstant.append(R.styleable.Constraint_layout_constraintBottom_creator, UNUSED); sMapToConstant.append(R.styleable.Constraint_layout_constraintBaseline_creator, UNUSED)451 sMapToConstant.append(R.styleable.Constraint_layout_constraintBaseline_creator, UNUSED); sMapToConstant.append(R.styleable.Constraint_android_layout_marginLeft, LEFT_MARGIN)452 sMapToConstant.append(R.styleable.Constraint_android_layout_marginLeft, LEFT_MARGIN); sMapToConstant.append(R.styleable.Constraint_android_layout_marginRight, RIGHT_MARGIN)453 sMapToConstant.append(R.styleable.Constraint_android_layout_marginRight, RIGHT_MARGIN); sMapToConstant.append(R.styleable.Constraint_android_layout_marginStart, START_MARGIN)454 sMapToConstant.append(R.styleable.Constraint_android_layout_marginStart, START_MARGIN); sMapToConstant.append(R.styleable.Constraint_android_layout_marginEnd, END_MARGIN)455 sMapToConstant.append(R.styleable.Constraint_android_layout_marginEnd, END_MARGIN); sMapToConstant.append(R.styleable.Constraint_android_layout_marginTop, TOP_MARGIN)456 sMapToConstant.append(R.styleable.Constraint_android_layout_marginTop, TOP_MARGIN); sMapToConstant.append(R.styleable.Constraint_android_layout_marginBottom, BOTTOM_MARGIN)457 sMapToConstant.append(R.styleable.Constraint_android_layout_marginBottom, BOTTOM_MARGIN); sMapToConstant.append(R.styleable.Constraint_android_layout_width, LAYOUT_WIDTH)458 sMapToConstant.append(R.styleable.Constraint_android_layout_width, LAYOUT_WIDTH); sMapToConstant.append( R.styleable.Constraint_android_layout_height, LAYOUT_HEIGHT)459 sMapToConstant.append( 460 R.styleable.Constraint_android_layout_height, LAYOUT_HEIGHT); sMapToConstant.append( R.styleable.Constraint_layout_constraintWidth, LAYOUT_CONSTRAINT_WIDTH)461 sMapToConstant.append( 462 R.styleable.Constraint_layout_constraintWidth, LAYOUT_CONSTRAINT_WIDTH); sMapToConstant.append( R.styleable.Constraint_layout_constraintHeight, LAYOUT_CONSTRAINT_HEIGHT)463 sMapToConstant.append( 464 R.styleable.Constraint_layout_constraintHeight, LAYOUT_CONSTRAINT_HEIGHT); sMapToConstant.append(R.styleable.Constraint_android_visibility, LAYOUT_VISIBILITY)465 sMapToConstant.append(R.styleable.Constraint_android_visibility, LAYOUT_VISIBILITY); sMapToConstant.append(R.styleable.Constraint_android_alpha, ALPHA)466 sMapToConstant.append(R.styleable.Constraint_android_alpha, ALPHA); sMapToConstant.append(R.styleable.Constraint_android_elevation, ELEVATION)467 sMapToConstant.append(R.styleable.Constraint_android_elevation, ELEVATION); sMapToConstant.append(R.styleable.Constraint_android_rotationX, ROTATION_X)468 sMapToConstant.append(R.styleable.Constraint_android_rotationX, ROTATION_X); sMapToConstant.append(R.styleable.Constraint_android_rotationY, ROTATION_Y)469 sMapToConstant.append(R.styleable.Constraint_android_rotationY, ROTATION_Y); sMapToConstant.append(R.styleable.Constraint_android_rotation, ROTATION)470 sMapToConstant.append(R.styleable.Constraint_android_rotation, ROTATION); sMapToConstant.append(R.styleable.Constraint_android_scaleX, SCALE_X)471 sMapToConstant.append(R.styleable.Constraint_android_scaleX, SCALE_X); sMapToConstant.append(R.styleable.Constraint_android_scaleY, SCALE_Y)472 sMapToConstant.append(R.styleable.Constraint_android_scaleY, SCALE_Y); sMapToConstant.append(R.styleable.Constraint_android_transformPivotX, TRANSFORM_PIVOT_X)473 sMapToConstant.append(R.styleable.Constraint_android_transformPivotX, TRANSFORM_PIVOT_X); sMapToConstant.append(R.styleable.Constraint_android_transformPivotY, TRANSFORM_PIVOT_Y)474 sMapToConstant.append(R.styleable.Constraint_android_transformPivotY, TRANSFORM_PIVOT_Y); sMapToConstant.append(R.styleable.Constraint_android_translationX, TRANSLATION_X)475 sMapToConstant.append(R.styleable.Constraint_android_translationX, TRANSLATION_X); sMapToConstant.append(R.styleable.Constraint_android_translationY, TRANSLATION_Y)476 sMapToConstant.append(R.styleable.Constraint_android_translationY, TRANSLATION_Y); sMapToConstant.append(R.styleable.Constraint_android_translationZ, TRANSLATION_Z)477 sMapToConstant.append(R.styleable.Constraint_android_translationZ, TRANSLATION_Z); sMapToConstant.append(R.styleable.Constraint_layout_constraintWidth_default, WIDTH_DEFAULT)478 sMapToConstant.append(R.styleable.Constraint_layout_constraintWidth_default, WIDTH_DEFAULT); sMapToConstant.append( R.styleable.Constraint_layout_constraintHeight_default, HEIGHT_DEFAULT)479 sMapToConstant.append( 480 R.styleable.Constraint_layout_constraintHeight_default, HEIGHT_DEFAULT); sMapToConstant.append(R.styleable.Constraint_layout_constraintWidth_max, WIDTH_MAX)481 sMapToConstant.append(R.styleable.Constraint_layout_constraintWidth_max, WIDTH_MAX); sMapToConstant.append(R.styleable.Constraint_layout_constraintHeight_max, HEIGHT_MAX)482 sMapToConstant.append(R.styleable.Constraint_layout_constraintHeight_max, HEIGHT_MAX); sMapToConstant.append(R.styleable.Constraint_layout_constraintWidth_min, WIDTH_MIN)483 sMapToConstant.append(R.styleable.Constraint_layout_constraintWidth_min, WIDTH_MIN); sMapToConstant.append(R.styleable.Constraint_layout_constraintHeight_min, HEIGHT_MIN)484 sMapToConstant.append(R.styleable.Constraint_layout_constraintHeight_min, HEIGHT_MIN); sMapToConstant.append(R.styleable.Constraint_layout_constraintCircle, CIRCLE)485 sMapToConstant.append(R.styleable.Constraint_layout_constraintCircle, CIRCLE); sMapToConstant.append(R.styleable.Constraint_layout_constraintCircleRadius, CIRCLE_RADIUS)486 sMapToConstant.append(R.styleable.Constraint_layout_constraintCircleRadius, CIRCLE_RADIUS); sMapToConstant.append(R.styleable.Constraint_layout_constraintCircleAngle, CIRCLE_ANGLE)487 sMapToConstant.append(R.styleable.Constraint_layout_constraintCircleAngle, CIRCLE_ANGLE); sMapToConstant.append(R.styleable.Constraint_animateRelativeTo, ANIMATE_RELATIVE_TO)488 sMapToConstant.append(R.styleable.Constraint_animateRelativeTo, ANIMATE_RELATIVE_TO); sMapToConstant.append(R.styleable.Constraint_transitionEasing, TRANSITION_EASING)489 sMapToConstant.append(R.styleable.Constraint_transitionEasing, TRANSITION_EASING); sMapToConstant.append(R.styleable.Constraint_drawPath, DRAW_PATH)490 sMapToConstant.append(R.styleable.Constraint_drawPath, DRAW_PATH); sMapToConstant.append(R.styleable.Constraint_transitionPathRotate, TRANSITION_PATH_ROTATE)491 sMapToConstant.append(R.styleable.Constraint_transitionPathRotate, TRANSITION_PATH_ROTATE); sMapToConstant.append(R.styleable.Constraint_motionStagger, MOTION_STAGGER)492 sMapToConstant.append(R.styleable.Constraint_motionStagger, MOTION_STAGGER); sMapToConstant.append(R.styleable.Constraint_android_id, VIEW_ID)493 sMapToConstant.append(R.styleable.Constraint_android_id, VIEW_ID); sMapToConstant.append(R.styleable.Constraint_motionProgress, PROGRESS)494 sMapToConstant.append(R.styleable.Constraint_motionProgress, PROGRESS); sMapToConstant.append( R.styleable.Constraint_layout_constraintWidth_percent, WIDTH_PERCENT)495 sMapToConstant.append( 496 R.styleable.Constraint_layout_constraintWidth_percent, WIDTH_PERCENT); sMapToConstant.append( R.styleable.Constraint_layout_constraintHeight_percent, HEIGHT_PERCENT)497 sMapToConstant.append( 498 R.styleable.Constraint_layout_constraintHeight_percent, HEIGHT_PERCENT); sMapToConstant.append( R.styleable.Constraint_layout_wrapBehaviorInParent, LAYOUT_WRAP_BEHAVIOR)499 sMapToConstant.append( 500 R.styleable.Constraint_layout_wrapBehaviorInParent, LAYOUT_WRAP_BEHAVIOR); 501 sMapToConstant.append(R.styleable.Constraint_chainUseRtl, CHAIN_USE_RTL)502 sMapToConstant.append(R.styleable.Constraint_chainUseRtl, CHAIN_USE_RTL); sMapToConstant.append(R.styleable.Constraint_barrierDirection, BARRIER_DIRECTION)503 sMapToConstant.append(R.styleable.Constraint_barrierDirection, BARRIER_DIRECTION); sMapToConstant.append(R.styleable.Constraint_barrierMargin, BARRIER_MARGIN)504 sMapToConstant.append(R.styleable.Constraint_barrierMargin, BARRIER_MARGIN); sMapToConstant.append( R.styleable.Constraint_constraint_referenced_ids, CONSTRAINT_REFERENCED_IDS)505 sMapToConstant.append( 506 R.styleable.Constraint_constraint_referenced_ids, CONSTRAINT_REFERENCED_IDS); sMapToConstant.append( R.styleable.Constraint_barrierAllowsGoneWidgets, BARRIER_ALLOWS_GONE_WIDGETS)507 sMapToConstant.append( 508 R.styleable.Constraint_barrierAllowsGoneWidgets, BARRIER_ALLOWS_GONE_WIDGETS); sMapToConstant.append(R.styleable.Constraint_pathMotionArc, PATH_MOTION_ARC)509 sMapToConstant.append(R.styleable.Constraint_pathMotionArc, PATH_MOTION_ARC); sMapToConstant.append(R.styleable.Constraint_layout_constraintTag, CONSTRAINT_TAG)510 sMapToConstant.append(R.styleable.Constraint_layout_constraintTag, CONSTRAINT_TAG); sMapToConstant.append(R.styleable.Constraint_visibilityMode, VISIBILITY_MODE)511 sMapToConstant.append(R.styleable.Constraint_visibilityMode, VISIBILITY_MODE); sMapToConstant.append( R.styleable.Constraint_layout_constrainedWidth, CONSTRAINED_WIDTH)512 sMapToConstant.append( 513 R.styleable.Constraint_layout_constrainedWidth, CONSTRAINED_WIDTH); sMapToConstant.append( R.styleable.Constraint_layout_constrainedHeight, CONSTRAINED_HEIGHT)514 sMapToConstant.append( 515 R.styleable.Constraint_layout_constrainedHeight, CONSTRAINED_HEIGHT); sMapToConstant.append( R.styleable.Constraint_polarRelativeTo, ANIMATE_CIRCLE_ANGLE_TO)516 sMapToConstant.append( 517 R.styleable.Constraint_polarRelativeTo, ANIMATE_CIRCLE_ANGLE_TO); sMapToConstant.append( R.styleable.Constraint_transformPivotTarget, TRANSFORM_PIVOT_TARGET)518 sMapToConstant.append( 519 R.styleable.Constraint_transformPivotTarget, TRANSFORM_PIVOT_TARGET); sMapToConstant.append( R.styleable.Constraint_quantizeMotionSteps, QUANTIZE_MOTION_STEPS)520 sMapToConstant.append( 521 R.styleable.Constraint_quantizeMotionSteps, QUANTIZE_MOTION_STEPS); sMapToConstant.append( R.styleable.Constraint_quantizeMotionPhase, QUANTIZE_MOTION_PHASE)522 sMapToConstant.append( 523 R.styleable.Constraint_quantizeMotionPhase, QUANTIZE_MOTION_PHASE); sMapToConstant.append( R.styleable.Constraint_quantizeMotionInterpolator, QUANTIZE_MOTION_INTERPOLATOR)524 sMapToConstant.append( 525 R.styleable.Constraint_quantizeMotionInterpolator, QUANTIZE_MOTION_INTERPOLATOR); 526 527 528 /* 529 The tags not available in constraintOverride 530 Left here to help with documentation and understanding 531 overrideMapToConstant.append( 532 R.styleable.ConstraintOverride_layout_constraintLeft_toLeftOf, LEFT_TO_LEFT); 533 overrideMapToConstant.append( 534 R.styleable.ConstraintOverride_layout_constraintLeft_toRightOf, LEFT_TO_RIGHT); 535 overrideMapToConstant.append( 536 R.styleable.ConstraintOverride_layout_constraintRight_toLeftOf, RIGHT_TO_LEFT); 537 overrideMapToConstant.append( 538 R.styleable.ConstraintOverride_layout_constraintRight_toRightOf, RIGHT_TO_RIGHT); 539 overrideMapToConstant.append( 540 R.styleable.ConstraintOverride_layout_constraintTop_toTopOf, TOP_TO_TOP); 541 overrideMapToConstant.append( 542 R.styleable.ConstraintOverride_layout_constraintTop_toBottomOf, TOP_TO_BOTTOM); 543 overrideMapToConstant.append( 544 R.styleable.ConstraintOverride_layout_constraintBottom_toTopOf, BOTTOM_TO_TOP); 545 overrideMapToConstant.append( 546 R.styleable.ConstraintOverride_layout_constraintBottom_toBottomOf, BOTTOM_TO_BOTTOM); 547 overrideMapToConstant.append( 548 R.styleable.ConstraintOverride_layout_constraintBaseline_toBaselineOf, 549 BASELINE_TO_BASELINE); 550 overrideMapToConstant.append( 551 R.styleable.ConstraintOverride_layout_constraintGuide_begin, GUIDE_BEGIN); 552 overrideMapToConstant.append( 553 R.styleable.ConstraintOverride_layout_constraintGuide_end, GUIDE_END); 554 overrideMapToConstant.append( 555 R.styleable.ConstraintOverride_layout_constraintGuide_percent, GUIDE_PERCENT); 556 overrideMapToConstant.append( 557 R.styleable.ConstraintOverride_layout_constraintStart_toEndOf, START_TO_END); 558 overrideMapToConstant.append( 559 R.styleable.ConstraintOverride_layout_constraintStart_toStartOf, START_TO_START); 560 overrideMapToConstant.append( 561 R.styleable.ConstraintOverride_layout_constraintEnd_toStartOf, END_TO_START); 562 overrideMapToConstant.append( 563 R.styleable.ConstraintOverride_layout_constraintEnd_toEndOf, END_TO_END); 564 */ sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_editor_absoluteY, EDITOR_ABSOLUTE_X)565 sOverrideMapToConstant.append( 566 R.styleable.ConstraintOverride_layout_editor_absoluteY, EDITOR_ABSOLUTE_X); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_editor_absoluteY, EDITOR_ABSOLUTE_Y)567 sOverrideMapToConstant.append( 568 R.styleable.ConstraintOverride_layout_editor_absoluteY, EDITOR_ABSOLUTE_Y); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_android_orientation, ORIENTATION)569 sOverrideMapToConstant.append( 570 R.styleable.ConstraintOverride_android_orientation, ORIENTATION); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_goneMarginLeft, GONE_LEFT_MARGIN)571 sOverrideMapToConstant.append( 572 R.styleable.ConstraintOverride_layout_goneMarginLeft, GONE_LEFT_MARGIN); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_goneMarginTop, GONE_TOP_MARGIN)573 sOverrideMapToConstant.append( 574 R.styleable.ConstraintOverride_layout_goneMarginTop, GONE_TOP_MARGIN); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_goneMarginRight, GONE_RIGHT_MARGIN)575 sOverrideMapToConstant.append( 576 R.styleable.ConstraintOverride_layout_goneMarginRight, GONE_RIGHT_MARGIN); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_goneMarginBottom, GONE_BOTTOM_MARGIN)577 sOverrideMapToConstant.append( 578 R.styleable.ConstraintOverride_layout_goneMarginBottom, GONE_BOTTOM_MARGIN); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_goneMarginStart, GONE_START_MARGIN)579 sOverrideMapToConstant.append( 580 R.styleable.ConstraintOverride_layout_goneMarginStart, GONE_START_MARGIN); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_goneMarginEnd, GONE_END_MARGIN)581 sOverrideMapToConstant.append( 582 R.styleable.ConstraintOverride_layout_goneMarginEnd, GONE_END_MARGIN); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_constraintVertical_weight, VERTICAL_WEIGHT)583 sOverrideMapToConstant.append( 584 R.styleable.ConstraintOverride_layout_constraintVertical_weight, 585 VERTICAL_WEIGHT); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_constraintHorizontal_weight, HORIZONTAL_WEIGHT)586 sOverrideMapToConstant.append( 587 R.styleable.ConstraintOverride_layout_constraintHorizontal_weight, 588 HORIZONTAL_WEIGHT); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_constraintHorizontal_chainStyle, HORIZONTAL_STYLE)589 sOverrideMapToConstant.append( 590 R.styleable.ConstraintOverride_layout_constraintHorizontal_chainStyle, 591 HORIZONTAL_STYLE); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_constraintVertical_chainStyle, VERTICAL_STYLE)592 sOverrideMapToConstant.append( 593 R.styleable.ConstraintOverride_layout_constraintVertical_chainStyle, 594 VERTICAL_STYLE); 595 sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_constraintHorizontal_bias, HORIZONTAL_BIAS)596 sOverrideMapToConstant.append( 597 R.styleable.ConstraintOverride_layout_constraintHorizontal_bias, 598 HORIZONTAL_BIAS); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintVertical_bias, VERTICAL_BIAS)599 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintVertical_bias, 600 VERTICAL_BIAS); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_constraintDimensionRatio, DIMENSION_RATIO)601 sOverrideMapToConstant.append( 602 R.styleable.ConstraintOverride_layout_constraintDimensionRatio, DIMENSION_RATIO); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintLeft_creator, UNUSED)603 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintLeft_creator, 604 UNUSED); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintTop_creator, UNUSED)605 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintTop_creator, 606 UNUSED); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintRight_creator, UNUSED)607 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintRight_creator, 608 UNUSED); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_constraintBottom_creator, UNUSED)609 sOverrideMapToConstant.append( 610 R.styleable.ConstraintOverride_layout_constraintBottom_creator, UNUSED); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_constraintBaseline_creator, UNUSED)611 sOverrideMapToConstant.append( 612 R.styleable.ConstraintOverride_layout_constraintBaseline_creator, 613 UNUSED); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginLeft, LEFT_MARGIN)614 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginLeft, 615 LEFT_MARGIN); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginRight, RIGHT_MARGIN)616 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginRight, 617 RIGHT_MARGIN); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginStart, START_MARGIN)618 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginStart, 619 START_MARGIN); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginEnd, END_MARGIN)620 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginEnd, 621 END_MARGIN); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginTop, TOP_MARGIN)622 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginTop, 623 TOP_MARGIN); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginBottom, BOTTOM_MARGIN)624 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_marginBottom, 625 BOTTOM_MARGIN); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_width, LAYOUT_WIDTH)626 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_width, 627 LAYOUT_WIDTH); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_height, LAYOUT_HEIGHT)628 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_layout_height, 629 LAYOUT_HEIGHT); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintWidth, LAYOUT_CONSTRAINT_WIDTH)630 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintWidth, 631 LAYOUT_CONSTRAINT_WIDTH); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintHeight, LAYOUT_CONSTRAINT_HEIGHT)632 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintHeight, 633 LAYOUT_CONSTRAINT_HEIGHT); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_visibility, LAYOUT_VISIBILITY)634 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_visibility, 635 LAYOUT_VISIBILITY); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_alpha, ALPHA)636 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_alpha, ALPHA); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_elevation, ELEVATION)637 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_elevation, ELEVATION); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_rotationX, ROTATION_X)638 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_rotationX, ROTATION_X); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_rotationY, ROTATION_Y)639 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_rotationY, ROTATION_Y); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_rotation, ROTATION)640 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_rotation, ROTATION); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_scaleX, SCALE_X)641 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_scaleX, SCALE_X); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_scaleY, SCALE_Y)642 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_scaleY, SCALE_Y); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_transformPivotX, TRANSFORM_PIVOT_X)643 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_transformPivotX, 644 TRANSFORM_PIVOT_X); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_transformPivotY, TRANSFORM_PIVOT_Y)645 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_transformPivotY, 646 TRANSFORM_PIVOT_Y); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_translationX, TRANSLATION_X)647 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_translationX, 648 TRANSLATION_X); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_translationY, TRANSLATION_Y)649 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_translationY, 650 TRANSLATION_Y); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_translationZ, TRANSLATION_Z)651 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_translationZ, 652 TRANSLATION_Z); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintWidth_default, WIDTH_DEFAULT)653 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintWidth_default, 654 WIDTH_DEFAULT); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_constraintHeight_default, HEIGHT_DEFAULT)655 sOverrideMapToConstant.append( 656 R.styleable.ConstraintOverride_layout_constraintHeight_default, HEIGHT_DEFAULT); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintWidth_max, WIDTH_MAX)657 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintWidth_max, 658 WIDTH_MAX); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintHeight_max, HEIGHT_MAX)659 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintHeight_max, 660 HEIGHT_MAX); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintWidth_min, WIDTH_MIN)661 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintWidth_min, 662 WIDTH_MIN); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintHeight_min, HEIGHT_MIN)663 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintHeight_min, 664 HEIGHT_MIN); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintCircleRadius, CIRCLE_RADIUS)665 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintCircleRadius, 666 CIRCLE_RADIUS); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintCircleAngle, CIRCLE_ANGLE)667 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintCircleAngle, 668 CIRCLE_ANGLE); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_animateRelativeTo, ANIMATE_RELATIVE_TO)669 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_animateRelativeTo, 670 ANIMATE_RELATIVE_TO); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_transitionEasing, TRANSITION_EASING)671 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_transitionEasing, 672 TRANSITION_EASING); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_drawPath, DRAW_PATH)673 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_drawPath, DRAW_PATH); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_transitionPathRotate, TRANSITION_PATH_ROTATE)674 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_transitionPathRotate, 675 TRANSITION_PATH_ROTATE); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_motionStagger, MOTION_STAGGER)676 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_motionStagger, MOTION_STAGGER); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_id, VIEW_ID)677 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_android_id, VIEW_ID); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_motionTarget, MOTION_TARGET)678 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_motionTarget, MOTION_TARGET); 679 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_motionProgress, PROGRESS)680 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_motionProgress, PROGRESS); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintWidth_percent, WIDTH_PERCENT)681 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintWidth_percent, 682 WIDTH_PERCENT); sOverrideMapToConstant.append( R.styleable.ConstraintOverride_layout_constraintHeight_percent, HEIGHT_PERCENT)683 sOverrideMapToConstant.append( 684 R.styleable.ConstraintOverride_layout_constraintHeight_percent, HEIGHT_PERCENT); 685 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_chainUseRtl, CHAIN_USE_RTL)686 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_chainUseRtl, CHAIN_USE_RTL); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_barrierDirection, BARRIER_DIRECTION)687 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_barrierDirection, 688 BARRIER_DIRECTION); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_barrierMargin, BARRIER_MARGIN)689 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_barrierMargin, 690 BARRIER_MARGIN); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_constraint_referenced_ids, CONSTRAINT_REFERENCED_IDS)691 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_constraint_referenced_ids, 692 CONSTRAINT_REFERENCED_IDS); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_barrierAllowsGoneWidgets, BARRIER_ALLOWS_GONE_WIDGETS)693 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_barrierAllowsGoneWidgets, 694 BARRIER_ALLOWS_GONE_WIDGETS); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_pathMotionArc, PATH_MOTION_ARC)695 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_pathMotionArc, 696 PATH_MOTION_ARC); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintTag, CONSTRAINT_TAG)697 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constraintTag, 698 CONSTRAINT_TAG); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_visibilityMode, VISIBILITY_MODE)699 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_visibilityMode, 700 VISIBILITY_MODE); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constrainedWidth, CONSTRAINED_WIDTH)701 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constrainedWidth, 702 CONSTRAINED_WIDTH); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constrainedHeight, CONSTRAINED_HEIGHT)703 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_constrainedHeight, 704 CONSTRAINED_HEIGHT); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_polarRelativeTo, ANIMATE_CIRCLE_ANGLE_TO)705 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_polarRelativeTo, 706 ANIMATE_CIRCLE_ANGLE_TO); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_transformPivotTarget, TRANSFORM_PIVOT_TARGET)707 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_transformPivotTarget, 708 TRANSFORM_PIVOT_TARGET); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_quantizeMotionSteps, QUANTIZE_MOTION_STEPS)709 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_quantizeMotionSteps, 710 QUANTIZE_MOTION_STEPS); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_quantizeMotionPhase, QUANTIZE_MOTION_PHASE)711 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_quantizeMotionPhase, 712 QUANTIZE_MOTION_PHASE); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_quantizeMotionInterpolator, QUANTIZE_MOTION_INTERPOLATOR)713 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_quantizeMotionInterpolator, 714 QUANTIZE_MOTION_INTERPOLATOR); sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_wrapBehaviorInParent, LAYOUT_WRAP_BEHAVIOR)715 sOverrideMapToConstant.append(R.styleable.ConstraintOverride_layout_wrapBehaviorInParent, 716 LAYOUT_WRAP_BEHAVIOR); 717 718 } 719 getCustomAttributeSet()720 public HashMap<String, ConstraintAttribute> getCustomAttributeSet() { 721 return mSavedAttributes; 722 } 723 724 // @TODO: add description 725 726 /** 727 * 728 * @param mId 729 * @return 730 */ getParameters(int mId)731 public Constraint getParameters(int mId) { 732 return get(mId); 733 } 734 735 /** 736 * This will copy Constraints from the ConstraintSet 737 * 738 * @param set 739 */ readFallback(ConstraintSet set)740 public void readFallback(ConstraintSet set) { 741 742 for (Integer key : set.mConstraints.keySet()) { 743 int id = key; 744 Constraint parent = set.mConstraints.get(key); 745 746 if (!mConstraints.containsKey(id)) { 747 mConstraints.put(id, new Constraint()); 748 } 749 Constraint constraint = mConstraints.get(id); 750 if (constraint == null) { 751 continue; 752 } 753 if (!constraint.layout.mApply) { 754 constraint.layout.copyFrom(parent.layout); 755 } 756 if (!constraint.propertySet.mApply) { 757 constraint.propertySet.copyFrom(parent.propertySet); 758 } 759 if (!constraint.transform.mApply) { 760 constraint.transform.copyFrom(parent.transform); 761 } 762 if (!constraint.motion.mApply) { 763 constraint.motion.copyFrom(parent.motion); 764 } 765 for (String s : parent.mCustomConstraints.keySet()) { 766 if (!constraint.mCustomConstraints.containsKey(s)) { 767 constraint.mCustomConstraints.put(s, parent.mCustomConstraints.get(s)); 768 } 769 } 770 } 771 } 772 773 /** 774 * This will copy Constraints from the ConstraintLayout if it does not have parameters 775 * 776 * @param constraintLayout 777 */ readFallback(ConstraintLayout constraintLayout)778 public void readFallback(ConstraintLayout constraintLayout) { 779 int count = constraintLayout.getChildCount(); 780 for (int i = 0; i < count; i++) { 781 View view = constraintLayout.getChildAt(i); 782 ConstraintLayout.LayoutParams param = 783 (ConstraintLayout.LayoutParams) view.getLayoutParams(); 784 785 int id = view.getId(); 786 if (mForceId && id == -1) { 787 throw new RuntimeException("All children of ConstraintLayout " 788 + "must have ids to use ConstraintSet"); 789 } 790 if (!mConstraints.containsKey(id)) { 791 mConstraints.put(id, new Constraint()); 792 } 793 Constraint constraint = mConstraints.get(id); 794 if (constraint == null) { 795 continue; 796 } 797 if (!constraint.layout.mApply) { 798 constraint.fillFrom(id, param); 799 if (view instanceof ConstraintHelper) { 800 constraint.layout.mReferenceIds = ((ConstraintHelper) view).getReferencedIds(); 801 if (view instanceof Barrier) { 802 Barrier barrier = (Barrier) view; 803 constraint.layout.mBarrierAllowsGoneWidgets = barrier.getAllowsGoneWidget(); 804 constraint.layout.mBarrierDirection = barrier.getType(); 805 constraint.layout.mBarrierMargin = barrier.getMargin(); 806 } 807 } 808 constraint.layout.mApply = true; 809 } 810 if (!constraint.propertySet.mApply) { 811 constraint.propertySet.visibility = view.getVisibility(); 812 constraint.propertySet.alpha = view.getAlpha(); 813 constraint.propertySet.mApply = true; 814 } 815 if (!constraint.transform.mApply) { 816 constraint.transform.mApply = true; 817 constraint.transform.rotation = view.getRotation(); 818 constraint.transform.rotationX = view.getRotationX(); 819 constraint.transform.rotationY = view.getRotationY(); 820 constraint.transform.scaleX = view.getScaleX(); 821 constraint.transform.scaleY = view.getScaleY(); 822 823 float pivotX = view.getPivotX(); // we assume it is not set if set to 0.0 824 float pivotY = view.getPivotY(); // we assume it is not set if set to 0.0 825 826 if (pivotX != 0.0 || pivotY != 0.0) { 827 constraint.transform.transformPivotX = pivotX; 828 constraint.transform.transformPivotY = pivotY; 829 } 830 831 constraint.transform.translationX = view.getTranslationX(); 832 constraint.transform.translationY = view.getTranslationY(); 833 if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { 834 constraint.transform.translationZ = view.getTranslationZ(); 835 if (constraint.transform.applyElevation) { 836 constraint.transform.elevation = view.getElevation(); 837 } 838 } 839 } 840 } 841 842 } 843 844 /** 845 * Get the delta from the ConstraintSet and apply to this 846 * @param cs 847 */ applyDeltaFrom(ConstraintSet cs)848 public void applyDeltaFrom(ConstraintSet cs) { 849 for (Constraint from : cs.mConstraints.values()) { 850 if (from.mDelta == null) { 851 continue; 852 } 853 if (from.mTargetString == null) { 854 Constraint constraint = getConstraint(from.mViewId); 855 from.mDelta.applyDelta(constraint); 856 continue; 857 } 858 for (int key : mConstraints.keySet()) { 859 Constraint potential = getConstraint(key); 860 if (potential.layout.mConstraintTag == null) { 861 continue; 862 } 863 if (from.mTargetString.matches(potential.layout.mConstraintTag)) { 864 from.mDelta.applyDelta(potential); 865 866 @SuppressWarnings("unchecked") 867 HashMap<String, ConstraintAttribute> fromClone = 868 (HashMap<String, ConstraintAttribute>) from.mCustomConstraints.clone(); 869 potential.mCustomConstraints.putAll(fromClone); 870 } 871 } 872 } 873 } 874 875 /** 876 * Parse the constraint dimension attribute 877 * 878 * @param a 879 * @param attr 880 * @param orientation 881 */ parseDimensionConstraints(Object data, TypedArray a, int attr, int orientation)882 static void parseDimensionConstraints(Object data, TypedArray a, int attr, int orientation) { 883 if (data == null) { 884 return; 885 } 886 // data can be of: 887 // 888 // ConstraintLayout.LayoutParams 889 // ConstraintSet.Layout 890 // Constraint.Delta 891 892 TypedValue v = a.peekValue(attr); 893 int type = v.type; 894 int finalValue = 0; 895 boolean finalConstrained = false; 896 switch (type) { 897 case TypedValue.TYPE_DIMENSION: { 898 finalValue = a.getDimensionPixelSize(attr, 0); 899 } 900 break; 901 case TypedValue.TYPE_STRING: { 902 String value = a.getString(attr); 903 parseDimensionConstraintsString(data, value, orientation); 904 return; 905 } 906 default: { 907 int value = a.getInt(attr, 0); 908 switch (value) { 909 case INTERNAL_WRAP_CONTENT: 910 case INTERNAL_MATCH_PARENT: { 911 finalValue = value; 912 } 913 break; 914 case INTERNAL_MATCH_CONSTRAINT: { 915 finalValue = MATCH_CONSTRAINT; 916 } 917 break; 918 case INTERNAL_WRAP_CONTENT_CONSTRAINED: { 919 finalValue = WRAP_CONTENT; 920 finalConstrained = true; 921 } 922 break; 923 } 924 } 925 } 926 927 if (data instanceof ConstraintLayout.LayoutParams) { 928 ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) data; 929 if (orientation == HORIZONTAL) { 930 params.width = finalValue; 931 params.constrainedWidth = finalConstrained; 932 } else { 933 params.height = finalValue; 934 params.constrainedHeight = finalConstrained; 935 } 936 } else if (data instanceof Layout) { 937 Layout params = (Layout) data; 938 if (orientation == HORIZONTAL) { 939 params.mWidth = finalValue; 940 params.constrainedWidth = finalConstrained; 941 } else { 942 params.mHeight = finalValue; 943 params.constrainedHeight = finalConstrained; 944 } 945 } else if (data instanceof Constraint.Delta) { 946 Constraint.Delta params = (Constraint.Delta) data; 947 if (orientation == HORIZONTAL) { 948 params.add(LAYOUT_WIDTH, finalValue); 949 params.add(CONSTRAINED_WIDTH, finalConstrained); 950 } else { 951 params.add(LAYOUT_HEIGHT, finalValue); 952 params.add(CONSTRAINED_HEIGHT, finalConstrained); 953 } 954 } 955 } 956 957 /** 958 * Parse the dimension ratio string 959 * 960 * @param value 961 */ parseDimensionRatioString(ConstraintLayout.LayoutParams params, String value)962 static void parseDimensionRatioString(ConstraintLayout.LayoutParams params, String value) { 963 String dimensionRatio = value; 964 float dimensionRatioValue = Float.NaN; 965 int dimensionRatioSide = UNSET; 966 if (dimensionRatio != null) { 967 int len = dimensionRatio.length(); 968 int commaIndex = dimensionRatio.indexOf(','); 969 if (commaIndex > 0 && commaIndex < len - 1) { 970 String dimension = dimensionRatio.substring(0, commaIndex); 971 if (dimension.equalsIgnoreCase("W")) { 972 dimensionRatioSide = HORIZONTAL; 973 } else if (dimension.equalsIgnoreCase("H")) { 974 dimensionRatioSide = VERTICAL; 975 } 976 commaIndex++; 977 } else { 978 commaIndex = 0; 979 } 980 int colonIndex = dimensionRatio.indexOf(':'); 981 if (colonIndex >= 0 && colonIndex < len - 1) { 982 String nominator = dimensionRatio.substring(commaIndex, colonIndex); 983 String denominator = dimensionRatio.substring(colonIndex + 1); 984 if (nominator.length() > 0 && denominator.length() > 0) { 985 try { 986 float nominatorValue = Float.parseFloat(nominator); 987 float denominatorValue = Float.parseFloat(denominator); 988 if (nominatorValue > 0 && denominatorValue > 0) { 989 if (dimensionRatioSide == VERTICAL) { 990 dimensionRatioValue = Math.abs(denominatorValue / nominatorValue); 991 } else { 992 dimensionRatioValue = Math.abs(nominatorValue / denominatorValue); 993 } 994 } 995 } catch (NumberFormatException e) { 996 // Ignore 997 } 998 } 999 } else { 1000 String r = dimensionRatio.substring(commaIndex); 1001 if (r.length() > 0) { 1002 try { 1003 dimensionRatioValue = Float.parseFloat(r); 1004 } catch (NumberFormatException e) { 1005 // Ignore 1006 } 1007 } 1008 } 1009 } 1010 params.dimensionRatio = dimensionRatio; 1011 params.mDimensionRatioValue = dimensionRatioValue; 1012 params.mDimensionRatioSide = dimensionRatioSide; 1013 } 1014 1015 /** 1016 * Parse the constraints string dimension 1017 * 1018 * @param value 1019 * @param orientation 1020 */ parseDimensionConstraintsString(Object data, String value, int orientation)1021 static void parseDimensionConstraintsString(Object data, String value, int orientation) { 1022 // data can be of: 1023 // 1024 // ConstraintLayout.LayoutParams 1025 // ConstraintSet.Layout 1026 // Constraint.Delta 1027 1028 // String should be of the form 1029 // 1030 // "<Key>=<Value>" 1031 // supported Keys are: 1032 // "weight=<value>" 1033 // "ratio=<value>" 1034 // "parent=<value>" 1035 if (value == null) { 1036 return; 1037 } 1038 1039 int equalIndex = value.indexOf('='); 1040 int len = value.length(); 1041 if (equalIndex > 0 && equalIndex < len - 1) { 1042 String key = value.substring(0, equalIndex); 1043 String val = value.substring(equalIndex + 1); 1044 if (val.length() > 0) { 1045 key = key.trim(); 1046 val = val.trim(); 1047 if (KEY_RATIO.equalsIgnoreCase(key)) { 1048 if (data instanceof ConstraintLayout.LayoutParams) { 1049 ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) data; 1050 if (orientation == HORIZONTAL) { 1051 params.width = MATCH_CONSTRAINT; 1052 } else { 1053 params.height = MATCH_CONSTRAINT; 1054 } 1055 parseDimensionRatioString(params, val); 1056 } else if (data instanceof Layout) { 1057 Layout params = (Layout) data; 1058 params.dimensionRatio = val; 1059 } else if (data instanceof Constraint.Delta) { 1060 Constraint.Delta params = (Constraint.Delta) data; 1061 params.add(DIMENSION_RATIO, val); 1062 } 1063 } else if (KEY_WEIGHT.equalsIgnoreCase(key)) { 1064 try { 1065 float weight = Float.parseFloat(val); 1066 if (data instanceof ConstraintLayout.LayoutParams) { 1067 ConstraintLayout.LayoutParams params = 1068 (ConstraintLayout.LayoutParams) data; 1069 if (orientation == HORIZONTAL) { 1070 params.width = MATCH_CONSTRAINT; 1071 params.horizontalWeight = weight; 1072 } else { 1073 params.height = MATCH_CONSTRAINT; 1074 params.verticalWeight = weight; 1075 } 1076 } else if (data instanceof Layout) { 1077 Layout params = (Layout) data; 1078 if (orientation == HORIZONTAL) { 1079 params.mWidth = MATCH_CONSTRAINT; 1080 params.horizontalWeight = weight; 1081 } else { 1082 params.mHeight = MATCH_CONSTRAINT; 1083 params.verticalWeight = weight; 1084 } 1085 } else if (data instanceof Constraint.Delta) { 1086 Constraint.Delta params = (Constraint.Delta) data; 1087 if (orientation == HORIZONTAL) { 1088 params.add(LAYOUT_WIDTH, MATCH_CONSTRAINT); 1089 params.add(HORIZONTAL_WEIGHT, weight); 1090 } else { 1091 params.add(LAYOUT_HEIGHT, MATCH_CONSTRAINT); 1092 params.add(VERTICAL_WEIGHT, weight); 1093 } 1094 } 1095 } catch (NumberFormatException e) { 1096 // nothing 1097 } 1098 } else if (KEY_PERCENT_PARENT.equalsIgnoreCase(key)) { 1099 try { 1100 float percent = Math.min(1, Float.parseFloat(val)); 1101 percent = Math.max(0, percent); 1102 if (data instanceof ConstraintLayout.LayoutParams) { 1103 ConstraintLayout.LayoutParams params = 1104 (ConstraintLayout.LayoutParams) data; 1105 if (orientation == HORIZONTAL) { 1106 params.width = MATCH_CONSTRAINT; 1107 params.matchConstraintPercentWidth = percent; 1108 params.matchConstraintDefaultWidth = MATCH_CONSTRAINT_PERCENT; 1109 } else { 1110 params.height = MATCH_CONSTRAINT; 1111 params.matchConstraintPercentHeight = percent; 1112 params.matchConstraintDefaultHeight = MATCH_CONSTRAINT_PERCENT; 1113 } 1114 } else if (data instanceof Layout) { 1115 Layout params = (Layout) data; 1116 if (orientation == HORIZONTAL) { 1117 params.mWidth = MATCH_CONSTRAINT; 1118 params.widthPercent = percent; 1119 params.widthDefault = MATCH_CONSTRAINT_PERCENT; 1120 } else { 1121 params.mHeight = MATCH_CONSTRAINT; 1122 params.heightPercent = percent; 1123 params.heightDefault = MATCH_CONSTRAINT_PERCENT; 1124 } 1125 } else if (data instanceof Constraint.Delta) { 1126 Constraint.Delta params = (Constraint.Delta) data; 1127 if (orientation == HORIZONTAL) { 1128 params.add(LAYOUT_WIDTH, MATCH_CONSTRAINT); 1129 params.add(WIDTH_DEFAULT, MATCH_CONSTRAINT_PERCENT); 1130 } else { 1131 params.add(LAYOUT_HEIGHT, MATCH_CONSTRAINT); 1132 params.add(HEIGHT_DEFAULT, MATCH_CONSTRAINT_PERCENT); 1133 } 1134 } 1135 } catch (NumberFormatException e) { 1136 // nothing 1137 } 1138 } 1139 } 1140 } 1141 } 1142 1143 1144 /** 1145 * Get the types associated with this ConstraintSet 1146 * The types mechanism allows you to tag the constraint set 1147 * with a series of string to define properties of a ConstraintSet 1148 * 1149 * @return an array of type strings 1150 */ getStateLabels()1151 public String[] getStateLabels() { 1152 return Arrays.copyOf(mMatchLabels, mMatchLabels.length); 1153 } 1154 1155 /** 1156 * Set the types associated with this ConstraintSet 1157 * The types mechanism allows you to tag the constraint set 1158 * with a series of string to define properties of a ConstraintSet 1159 * @param types a comer separated array of strings. 1160 */ setStateLabels(String types)1161 public void setStateLabels(String types) { 1162 mMatchLabels = types.split(","); 1163 for (int i = 0; i < mMatchLabels.length; i++) { 1164 mMatchLabels[i] = mMatchLabels[i].trim(); 1165 } 1166 } 1167 /** 1168 * Set the types associated with this ConstraintSet 1169 * The types mechanism allows you to tag the constraint set 1170 * with a series of string to define properties of a ConstraintSet 1171 * @param types a comer separated array of strings. 1172 */ setStateLabelsList(String... types)1173 public void setStateLabelsList(String... types) { 1174 mMatchLabels = types; 1175 for (int i = 0; i < mMatchLabels.length; i++) { 1176 mMatchLabels[i] = mMatchLabels[i].trim(); 1177 } 1178 } 1179 1180 /** 1181 * Test if the list of strings matches labels defined on this constraintSet 1182 * @param types list of types 1183 * @return true if all types are in the labels 1184 */ matchesLabels(String...types)1185 public boolean matchesLabels(String...types) { 1186 for (String type : types) { 1187 boolean match = false; 1188 for (String matchType : mMatchLabels) { 1189 if (matchType.equals(type)) { 1190 match = true; 1191 break; 1192 } 1193 } 1194 if (!match) { 1195 return false; 1196 } 1197 1198 } 1199 return true; 1200 } 1201 1202 /** 1203 * 1204 */ 1205 public static class Layout { 1206 public boolean mIsGuideline = false; 1207 public boolean mApply = false; 1208 public boolean mOverride = false; 1209 public int mWidth; 1210 public int mHeight; 1211 public static final int UNSET = ConstraintSet.UNSET; 1212 public static final int UNSET_GONE_MARGIN = Integer.MIN_VALUE; 1213 public int guideBegin = UNSET; 1214 public int guideEnd = UNSET; 1215 public float guidePercent = UNSET; 1216 public boolean guidelineUseRtl = true; 1217 public int leftToLeft = UNSET; 1218 public int leftToRight = UNSET; 1219 public int rightToLeft = UNSET; 1220 public int rightToRight = UNSET; 1221 public int topToTop = UNSET; 1222 public int topToBottom = UNSET; 1223 public int bottomToTop = UNSET; 1224 public int bottomToBottom = UNSET; 1225 public int baselineToBaseline = UNSET; 1226 public int baselineToTop = UNSET; 1227 public int baselineToBottom = UNSET; 1228 public int startToEnd = UNSET; 1229 public int startToStart = UNSET; 1230 public int endToStart = UNSET; 1231 public int endToEnd = UNSET; 1232 public float horizontalBias = 0.5f; 1233 public float verticalBias = 0.5f; 1234 public String dimensionRatio = null; 1235 public int circleConstraint = UNSET; 1236 public int circleRadius = 0; 1237 public float circleAngle = 0; 1238 public int editorAbsoluteX = UNSET; 1239 public int editorAbsoluteY = UNSET; 1240 public int orientation = UNSET; 1241 public int leftMargin = 0; 1242 public int rightMargin = 0; 1243 public int topMargin = 0; 1244 public int bottomMargin = 0; 1245 public int endMargin = 0; 1246 public int startMargin = 0; 1247 public int baselineMargin = 0; 1248 public int goneLeftMargin = UNSET_GONE_MARGIN; 1249 public int goneTopMargin = UNSET_GONE_MARGIN; 1250 public int goneRightMargin = UNSET_GONE_MARGIN; 1251 public int goneBottomMargin = UNSET_GONE_MARGIN; 1252 public int goneEndMargin = UNSET_GONE_MARGIN; 1253 public int goneStartMargin = UNSET_GONE_MARGIN; 1254 public int goneBaselineMargin = UNSET_GONE_MARGIN; 1255 public float verticalWeight = UNSET; 1256 public float horizontalWeight = UNSET; 1257 public int horizontalChainStyle = CHAIN_SPREAD; 1258 public int verticalChainStyle = CHAIN_SPREAD; 1259 public int widthDefault = ConstraintWidget.MATCH_CONSTRAINT_SPREAD; 1260 public int heightDefault = ConstraintWidget.MATCH_CONSTRAINT_SPREAD; 1261 public int widthMax = 0; 1262 public int heightMax = 0; 1263 public int widthMin = 0; 1264 public int heightMin = 0; 1265 public float widthPercent = 1; 1266 public float heightPercent = 1; 1267 public int mBarrierDirection = UNSET; 1268 public int mBarrierMargin = 0; 1269 public int mHelperType = UNSET; 1270 public int[] mReferenceIds; 1271 public String mReferenceIdString; 1272 public String mConstraintTag; 1273 public boolean constrainedWidth = false; 1274 public boolean constrainedHeight = false; 1275 // TODO public boolean mChainUseRtl = false; 1276 public boolean mBarrierAllowsGoneWidgets = true; 1277 public int mWrapBehavior = ConstraintWidget.WRAP_BEHAVIOR_INCLUDED; 1278 1279 /** 1280 * Copy from Layout 1281 * @param src 1282 */ copyFrom(Layout src)1283 public void copyFrom(Layout src) { 1284 mIsGuideline = src.mIsGuideline; 1285 mWidth = src.mWidth; 1286 mApply = src.mApply; 1287 mHeight = src.mHeight; 1288 guideBegin = src.guideBegin; 1289 guideEnd = src.guideEnd; 1290 guidePercent = src.guidePercent; 1291 guidelineUseRtl = src.guidelineUseRtl; 1292 leftToLeft = src.leftToLeft; 1293 leftToRight = src.leftToRight; 1294 rightToLeft = src.rightToLeft; 1295 rightToRight = src.rightToRight; 1296 topToTop = src.topToTop; 1297 topToBottom = src.topToBottom; 1298 bottomToTop = src.bottomToTop; 1299 bottomToBottom = src.bottomToBottom; 1300 baselineToBaseline = src.baselineToBaseline; 1301 baselineToTop = src.baselineToTop; 1302 baselineToBottom = src.baselineToBottom; 1303 startToEnd = src.startToEnd; 1304 startToStart = src.startToStart; 1305 endToStart = src.endToStart; 1306 endToEnd = src.endToEnd; 1307 horizontalBias = src.horizontalBias; 1308 verticalBias = src.verticalBias; 1309 dimensionRatio = src.dimensionRatio; 1310 circleConstraint = src.circleConstraint; 1311 circleRadius = src.circleRadius; 1312 circleAngle = src.circleAngle; 1313 editorAbsoluteX = src.editorAbsoluteX; 1314 editorAbsoluteY = src.editorAbsoluteY; 1315 orientation = src.orientation; 1316 leftMargin = src.leftMargin; 1317 rightMargin = src.rightMargin; 1318 topMargin = src.topMargin; 1319 bottomMargin = src.bottomMargin; 1320 endMargin = src.endMargin; 1321 startMargin = src.startMargin; 1322 baselineMargin = src.baselineMargin; 1323 goneLeftMargin = src.goneLeftMargin; 1324 goneTopMargin = src.goneTopMargin; 1325 goneRightMargin = src.goneRightMargin; 1326 goneBottomMargin = src.goneBottomMargin; 1327 goneEndMargin = src.goneEndMargin; 1328 goneStartMargin = src.goneStartMargin; 1329 goneBaselineMargin = src.goneBaselineMargin; 1330 verticalWeight = src.verticalWeight; 1331 horizontalWeight = src.horizontalWeight; 1332 horizontalChainStyle = src.horizontalChainStyle; 1333 verticalChainStyle = src.verticalChainStyle; 1334 widthDefault = src.widthDefault; 1335 heightDefault = src.heightDefault; 1336 widthMax = src.widthMax; 1337 heightMax = src.heightMax; 1338 widthMin = src.widthMin; 1339 heightMin = src.heightMin; 1340 widthPercent = src.widthPercent; 1341 heightPercent = src.heightPercent; 1342 mBarrierDirection = src.mBarrierDirection; 1343 mBarrierMargin = src.mBarrierMargin; 1344 mHelperType = src.mHelperType; 1345 mConstraintTag = src.mConstraintTag; 1346 1347 if (src.mReferenceIds != null && src.mReferenceIdString == null) { 1348 mReferenceIds = Arrays.copyOf(src.mReferenceIds, src.mReferenceIds.length); 1349 } else { 1350 mReferenceIds = null; 1351 } 1352 mReferenceIdString = src.mReferenceIdString; 1353 constrainedWidth = src.constrainedWidth; 1354 constrainedHeight = src.constrainedHeight; 1355 // TODO mChainUseRtl = t.mChainUseRtl; 1356 mBarrierAllowsGoneWidgets = src.mBarrierAllowsGoneWidgets; 1357 mWrapBehavior = src.mWrapBehavior; 1358 } 1359 1360 private static SparseIntArray sMapToConstant = new SparseIntArray(); 1361 private static final int BASELINE_TO_BASELINE = 1; 1362 private static final int BOTTOM_MARGIN = 2; 1363 private static final int BOTTOM_TO_BOTTOM = 3; 1364 private static final int BOTTOM_TO_TOP = 4; 1365 private static final int DIMENSION_RATIO = 5; 1366 private static final int EDITOR_ABSOLUTE_X = 6; 1367 private static final int EDITOR_ABSOLUTE_Y = 7; 1368 private static final int END_MARGIN = 8; 1369 private static final int END_TO_END = 9; 1370 private static final int END_TO_START = 10; 1371 private static final int GONE_BOTTOM_MARGIN = 11; 1372 private static final int GONE_END_MARGIN = 12; 1373 private static final int GONE_LEFT_MARGIN = 13; 1374 private static final int GONE_RIGHT_MARGIN = 14; 1375 private static final int GONE_START_MARGIN = 15; 1376 private static final int GONE_TOP_MARGIN = 16; 1377 private static final int GUIDE_BEGIN = 17; 1378 private static final int GUIDE_END = 18; 1379 private static final int GUIDE_PERCENT = 19; 1380 private static final int HORIZONTAL_BIAS = 20; 1381 private static final int LAYOUT_HEIGHT = 21; 1382 private static final int LAYOUT_WIDTH = 22; 1383 private static final int LEFT_MARGIN = 23; 1384 private static final int LEFT_TO_LEFT = 24; 1385 private static final int LEFT_TO_RIGHT = 25; 1386 private static final int ORIENTATION = 26; 1387 private static final int RIGHT_MARGIN = 27; 1388 private static final int RIGHT_TO_LEFT = 28; 1389 private static final int RIGHT_TO_RIGHT = 29; 1390 private static final int START_MARGIN = 30; 1391 private static final int START_TO_END = 31; 1392 private static final int START_TO_START = 32; 1393 private static final int TOP_MARGIN = 33; 1394 private static final int TOP_TO_BOTTOM = 34; 1395 private static final int TOP_TO_TOP = 35; 1396 private static final int VERTICAL_BIAS = 36; 1397 private static final int HORIZONTAL_WEIGHT = 37; 1398 private static final int VERTICAL_WEIGHT = 38; 1399 private static final int HORIZONTAL_STYLE = 39; 1400 private static final int VERTICAL_STYLE = 40; 1401 private static final int LAYOUT_CONSTRAINT_WIDTH = 41; 1402 private static final int LAYOUT_CONSTRAINT_HEIGHT = 42; 1403 1404 private static final int CIRCLE = 61; 1405 private static final int CIRCLE_RADIUS = 62; 1406 private static final int CIRCLE_ANGLE = 63; 1407 private static final int WIDTH_PERCENT = 69; 1408 private static final int HEIGHT_PERCENT = 70; 1409 private static final int CHAIN_USE_RTL = 71; 1410 private static final int BARRIER_DIRECTION = 72; 1411 private static final int BARRIER_MARGIN = 73; 1412 private static final int CONSTRAINT_REFERENCED_IDS = 74; 1413 private static final int BARRIER_ALLOWS_GONE_WIDGETS = 75; 1414 1415 private static final int LAYOUT_WRAP_BEHAVIOR = 76; 1416 private static final int BASELINE_TO_TOP = 77; 1417 private static final int BASELINE_TO_BOTTOM = 78; 1418 private static final int GONE_BASELINE_MARGIN = 79; 1419 private static final int BASELINE_MARGIN = 80; 1420 private static final int WIDTH_DEFAULT = 81; 1421 private static final int HEIGHT_DEFAULT = 82; 1422 private static final int HEIGHT_MAX = 83; 1423 private static final int WIDTH_MAX = 84; 1424 private static final int HEIGHT_MIN = 85; 1425 private static final int WIDTH_MIN = 86; 1426 private static final int CONSTRAINED_WIDTH = 87; 1427 private static final int CONSTRAINED_HEIGHT = 88; 1428 private static final int CONSTRAINT_TAG = 89; 1429 private static final int GUIDE_USE_RTL = 90; 1430 1431 private static final int UNUSED = 91; 1432 1433 static { sMapToConstant.append(R.styleable.Layout_layout_constraintLeft_toLeftOf, LEFT_TO_LEFT)1434 sMapToConstant.append(R.styleable.Layout_layout_constraintLeft_toLeftOf, LEFT_TO_LEFT); sMapToConstant.append(R.styleable.Layout_layout_constraintLeft_toRightOf, LEFT_TO_RIGHT)1435 sMapToConstant.append(R.styleable.Layout_layout_constraintLeft_toRightOf, 1436 LEFT_TO_RIGHT); sMapToConstant.append(R.styleable.Layout_layout_constraintRight_toLeftOf, RIGHT_TO_LEFT)1437 sMapToConstant.append(R.styleable.Layout_layout_constraintRight_toLeftOf, 1438 RIGHT_TO_LEFT); sMapToConstant.append(R.styleable.Layout_layout_constraintRight_toRightOf, RIGHT_TO_RIGHT)1439 sMapToConstant.append(R.styleable.Layout_layout_constraintRight_toRightOf, 1440 RIGHT_TO_RIGHT); sMapToConstant.append(R.styleable.Layout_layout_constraintTop_toTopOf, TOP_TO_TOP)1441 sMapToConstant.append(R.styleable.Layout_layout_constraintTop_toTopOf, TOP_TO_TOP); sMapToConstant.append(R.styleable.Layout_layout_constraintTop_toBottomOf, TOP_TO_BOTTOM)1442 sMapToConstant.append(R.styleable.Layout_layout_constraintTop_toBottomOf, 1443 TOP_TO_BOTTOM); sMapToConstant.append(R.styleable.Layout_layout_constraintBottom_toTopOf, BOTTOM_TO_TOP)1444 sMapToConstant.append(R.styleable.Layout_layout_constraintBottom_toTopOf, 1445 BOTTOM_TO_TOP); sMapToConstant.append(R.styleable.Layout_layout_constraintBottom_toBottomOf, BOTTOM_TO_BOTTOM)1446 sMapToConstant.append(R.styleable.Layout_layout_constraintBottom_toBottomOf, 1447 BOTTOM_TO_BOTTOM); sMapToConstant.append(R.styleable.Layout_layout_constraintBaseline_toBaselineOf, BASELINE_TO_BASELINE)1448 sMapToConstant.append(R.styleable.Layout_layout_constraintBaseline_toBaselineOf, 1449 BASELINE_TO_BASELINE); 1450 sMapToConstant.append(R.styleable.Layout_layout_editor_absoluteX, EDITOR_ABSOLUTE_X)1451 sMapToConstant.append(R.styleable.Layout_layout_editor_absoluteX, EDITOR_ABSOLUTE_X); sMapToConstant.append(R.styleable.Layout_layout_editor_absoluteY, EDITOR_ABSOLUTE_Y)1452 sMapToConstant.append(R.styleable.Layout_layout_editor_absoluteY, EDITOR_ABSOLUTE_Y); sMapToConstant.append(R.styleable.Layout_layout_constraintGuide_begin, GUIDE_BEGIN)1453 sMapToConstant.append(R.styleable.Layout_layout_constraintGuide_begin, GUIDE_BEGIN); sMapToConstant.append(R.styleable.Layout_layout_constraintGuide_end, GUIDE_END)1454 sMapToConstant.append(R.styleable.Layout_layout_constraintGuide_end, GUIDE_END); sMapToConstant.append(R.styleable.Layout_layout_constraintGuide_percent, GUIDE_PERCENT)1455 sMapToConstant.append(R.styleable.Layout_layout_constraintGuide_percent, GUIDE_PERCENT); sMapToConstant.append(R.styleable.Layout_guidelineUseRtl, GUIDE_USE_RTL)1456 sMapToConstant.append(R.styleable.Layout_guidelineUseRtl, GUIDE_USE_RTL); sMapToConstant.append(R.styleable.Layout_android_orientation, ORIENTATION)1457 sMapToConstant.append(R.styleable.Layout_android_orientation, ORIENTATION); sMapToConstant.append(R.styleable.Layout_layout_constraintStart_toEndOf, START_TO_END)1458 sMapToConstant.append(R.styleable.Layout_layout_constraintStart_toEndOf, START_TO_END); sMapToConstant.append(R.styleable.Layout_layout_constraintStart_toStartOf, START_TO_START)1459 sMapToConstant.append(R.styleable.Layout_layout_constraintStart_toStartOf, 1460 START_TO_START); sMapToConstant.append(R.styleable.Layout_layout_constraintEnd_toStartOf, END_TO_START)1461 sMapToConstant.append(R.styleable.Layout_layout_constraintEnd_toStartOf, END_TO_START); sMapToConstant.append(R.styleable.Layout_layout_constraintEnd_toEndOf, END_TO_END)1462 sMapToConstant.append(R.styleable.Layout_layout_constraintEnd_toEndOf, END_TO_END); sMapToConstant.append(R.styleable.Layout_layout_goneMarginLeft, GONE_LEFT_MARGIN)1463 sMapToConstant.append(R.styleable.Layout_layout_goneMarginLeft, GONE_LEFT_MARGIN); sMapToConstant.append(R.styleable.Layout_layout_goneMarginTop, GONE_TOP_MARGIN)1464 sMapToConstant.append(R.styleable.Layout_layout_goneMarginTop, GONE_TOP_MARGIN); sMapToConstant.append(R.styleable.Layout_layout_goneMarginRight, GONE_RIGHT_MARGIN)1465 sMapToConstant.append(R.styleable.Layout_layout_goneMarginRight, GONE_RIGHT_MARGIN); sMapToConstant.append(R.styleable.Layout_layout_goneMarginBottom, GONE_BOTTOM_MARGIN)1466 sMapToConstant.append(R.styleable.Layout_layout_goneMarginBottom, GONE_BOTTOM_MARGIN); sMapToConstant.append(R.styleable.Layout_layout_goneMarginStart, GONE_START_MARGIN)1467 sMapToConstant.append(R.styleable.Layout_layout_goneMarginStart, GONE_START_MARGIN); sMapToConstant.append(R.styleable.Layout_layout_goneMarginEnd, GONE_END_MARGIN)1468 sMapToConstant.append(R.styleable.Layout_layout_goneMarginEnd, GONE_END_MARGIN); sMapToConstant.append(R.styleable.Layout_layout_constraintVertical_weight, VERTICAL_WEIGHT)1469 sMapToConstant.append(R.styleable.Layout_layout_constraintVertical_weight, 1470 VERTICAL_WEIGHT); sMapToConstant.append(R.styleable.Layout_layout_constraintHorizontal_weight, HORIZONTAL_WEIGHT)1471 sMapToConstant.append(R.styleable.Layout_layout_constraintHorizontal_weight, 1472 HORIZONTAL_WEIGHT); sMapToConstant.append(R.styleable.Layout_layout_constraintHorizontal_chainStyle, HORIZONTAL_STYLE)1473 sMapToConstant.append(R.styleable.Layout_layout_constraintHorizontal_chainStyle, 1474 HORIZONTAL_STYLE); sMapToConstant.append(R.styleable.Layout_layout_constraintVertical_chainStyle, VERTICAL_STYLE)1475 sMapToConstant.append(R.styleable.Layout_layout_constraintVertical_chainStyle, 1476 VERTICAL_STYLE); 1477 sMapToConstant.append(R.styleable.Layout_layout_constraintHorizontal_bias, HORIZONTAL_BIAS)1478 sMapToConstant.append(R.styleable.Layout_layout_constraintHorizontal_bias, 1479 HORIZONTAL_BIAS); sMapToConstant.append(R.styleable.Layout_layout_constraintVertical_bias, VERTICAL_BIAS)1480 sMapToConstant.append(R.styleable.Layout_layout_constraintVertical_bias, 1481 VERTICAL_BIAS); sMapToConstant.append(R.styleable.Layout_layout_constraintDimensionRatio, DIMENSION_RATIO)1482 sMapToConstant.append(R.styleable.Layout_layout_constraintDimensionRatio, 1483 DIMENSION_RATIO); sMapToConstant.append(R.styleable.Layout_layout_constraintLeft_creator, UNUSED)1484 sMapToConstant.append(R.styleable.Layout_layout_constraintLeft_creator, UNUSED); sMapToConstant.append(R.styleable.Layout_layout_constraintTop_creator, UNUSED)1485 sMapToConstant.append(R.styleable.Layout_layout_constraintTop_creator, UNUSED); sMapToConstant.append(R.styleable.Layout_layout_constraintRight_creator, UNUSED)1486 sMapToConstant.append(R.styleable.Layout_layout_constraintRight_creator, UNUSED); sMapToConstant.append(R.styleable.Layout_layout_constraintBottom_creator, UNUSED)1487 sMapToConstant.append(R.styleable.Layout_layout_constraintBottom_creator, UNUSED); sMapToConstant.append(R.styleable.Layout_layout_constraintBaseline_creator, UNUSED)1488 sMapToConstant.append(R.styleable.Layout_layout_constraintBaseline_creator, UNUSED); sMapToConstant.append(R.styleable.Layout_android_layout_marginLeft, LEFT_MARGIN)1489 sMapToConstant.append(R.styleable.Layout_android_layout_marginLeft, LEFT_MARGIN); sMapToConstant.append(R.styleable.Layout_android_layout_marginRight, RIGHT_MARGIN)1490 sMapToConstant.append(R.styleable.Layout_android_layout_marginRight, RIGHT_MARGIN); sMapToConstant.append(R.styleable.Layout_android_layout_marginStart, START_MARGIN)1491 sMapToConstant.append(R.styleable.Layout_android_layout_marginStart, START_MARGIN); sMapToConstant.append(R.styleable.Layout_android_layout_marginEnd, END_MARGIN)1492 sMapToConstant.append(R.styleable.Layout_android_layout_marginEnd, END_MARGIN); sMapToConstant.append(R.styleable.Layout_android_layout_marginTop, TOP_MARGIN)1493 sMapToConstant.append(R.styleable.Layout_android_layout_marginTop, TOP_MARGIN); sMapToConstant.append(R.styleable.Layout_android_layout_marginBottom, BOTTOM_MARGIN)1494 sMapToConstant.append(R.styleable.Layout_android_layout_marginBottom, BOTTOM_MARGIN); sMapToConstant.append(R.styleable.Layout_android_layout_width, LAYOUT_WIDTH)1495 sMapToConstant.append(R.styleable.Layout_android_layout_width, LAYOUT_WIDTH); sMapToConstant.append(R.styleable.Layout_android_layout_height, LAYOUT_HEIGHT)1496 sMapToConstant.append(R.styleable.Layout_android_layout_height, LAYOUT_HEIGHT); sMapToConstant.append(R.styleable.Layout_layout_constraintWidth, LAYOUT_CONSTRAINT_WIDTH)1497 sMapToConstant.append(R.styleable.Layout_layout_constraintWidth, 1498 LAYOUT_CONSTRAINT_WIDTH); sMapToConstant.append(R.styleable.Layout_layout_constraintHeight, LAYOUT_CONSTRAINT_HEIGHT)1499 sMapToConstant.append(R.styleable.Layout_layout_constraintHeight, 1500 LAYOUT_CONSTRAINT_HEIGHT); sMapToConstant.append(R.styleable.Layout_layout_constrainedWidth, CONSTRAINED_WIDTH)1501 sMapToConstant.append(R.styleable.Layout_layout_constrainedWidth, 1502 CONSTRAINED_WIDTH); sMapToConstant.append(R.styleable.Layout_layout_constrainedHeight, CONSTRAINED_HEIGHT)1503 sMapToConstant.append(R.styleable.Layout_layout_constrainedHeight, 1504 CONSTRAINED_HEIGHT); sMapToConstant.append(R.styleable.Layout_layout_wrapBehaviorInParent, LAYOUT_WRAP_BEHAVIOR)1505 sMapToConstant.append(R.styleable.Layout_layout_wrapBehaviorInParent, 1506 LAYOUT_WRAP_BEHAVIOR); 1507 sMapToConstant.append(R.styleable.Layout_layout_constraintCircle, CIRCLE)1508 sMapToConstant.append(R.styleable.Layout_layout_constraintCircle, CIRCLE); sMapToConstant.append(R.styleable.Layout_layout_constraintCircleRadius, CIRCLE_RADIUS)1509 sMapToConstant.append(R.styleable.Layout_layout_constraintCircleRadius, CIRCLE_RADIUS); sMapToConstant.append(R.styleable.Layout_layout_constraintCircleAngle, CIRCLE_ANGLE)1510 sMapToConstant.append(R.styleable.Layout_layout_constraintCircleAngle, CIRCLE_ANGLE); sMapToConstant.append(R.styleable.Layout_layout_constraintWidth_percent, WIDTH_PERCENT)1511 sMapToConstant.append(R.styleable.Layout_layout_constraintWidth_percent, WIDTH_PERCENT); sMapToConstant.append(R.styleable.Layout_layout_constraintHeight_percent, HEIGHT_PERCENT)1512 sMapToConstant.append(R.styleable.Layout_layout_constraintHeight_percent, 1513 HEIGHT_PERCENT); 1514 sMapToConstant.append(R.styleable.Layout_chainUseRtl, CHAIN_USE_RTL)1515 sMapToConstant.append(R.styleable.Layout_chainUseRtl, CHAIN_USE_RTL); sMapToConstant.append(R.styleable.Layout_barrierDirection, BARRIER_DIRECTION)1516 sMapToConstant.append(R.styleable.Layout_barrierDirection, BARRIER_DIRECTION); sMapToConstant.append(R.styleable.Layout_barrierMargin, BARRIER_MARGIN)1517 sMapToConstant.append(R.styleable.Layout_barrierMargin, BARRIER_MARGIN); sMapToConstant.append(R.styleable.Layout_constraint_referenced_ids, CONSTRAINT_REFERENCED_IDS)1518 sMapToConstant.append(R.styleable.Layout_constraint_referenced_ids, 1519 CONSTRAINT_REFERENCED_IDS); sMapToConstant.append(R.styleable.Layout_barrierAllowsGoneWidgets, BARRIER_ALLOWS_GONE_WIDGETS)1520 sMapToConstant.append(R.styleable.Layout_barrierAllowsGoneWidgets, 1521 BARRIER_ALLOWS_GONE_WIDGETS); sMapToConstant.append(R.styleable.Layout_layout_constraintWidth_max, WIDTH_MAX)1522 sMapToConstant.append(R.styleable.Layout_layout_constraintWidth_max, 1523 WIDTH_MAX); sMapToConstant.append(R.styleable.Layout_layout_constraintWidth_min, WIDTH_MIN)1524 sMapToConstant.append(R.styleable.Layout_layout_constraintWidth_min, 1525 WIDTH_MIN); sMapToConstant.append(R.styleable.Layout_layout_constraintWidth_max, HEIGHT_MAX)1526 sMapToConstant.append(R.styleable.Layout_layout_constraintWidth_max, 1527 HEIGHT_MAX); sMapToConstant.append(R.styleable.Layout_layout_constraintHeight_min, HEIGHT_MIN)1528 sMapToConstant.append(R.styleable.Layout_layout_constraintHeight_min, 1529 HEIGHT_MIN); 1530 sMapToConstant.append(R.styleable.Layout_layout_constraintWidth, CONSTRAINED_WIDTH)1531 sMapToConstant.append(R.styleable.Layout_layout_constraintWidth, CONSTRAINED_WIDTH); sMapToConstant.append(R.styleable.Layout_layout_constraintHeight, CONSTRAINED_HEIGHT)1532 sMapToConstant.append(R.styleable.Layout_layout_constraintHeight, CONSTRAINED_HEIGHT); sMapToConstant.append(R.styleable.ConstraintLayout_Layout_layout_constraintTag, CONSTRAINT_TAG)1533 sMapToConstant.append(R.styleable.ConstraintLayout_Layout_layout_constraintTag, 1534 CONSTRAINT_TAG); sMapToConstant.append(R.styleable.Layout_guidelineUseRtl, GUIDE_USE_RTL)1535 sMapToConstant.append(R.styleable.Layout_guidelineUseRtl, GUIDE_USE_RTL); 1536 1537 } 1538 fillFromAttributeList(Context context, AttributeSet attrs)1539 void fillFromAttributeList(Context context, AttributeSet attrs) { 1540 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Layout); 1541 mApply = true; 1542 final int count = a.getIndexCount(); 1543 for (int i = 0; i < count; i++) { 1544 int attr = a.getIndex(i); 1545 1546 switch (sMapToConstant.get(attr)) { 1547 case LEFT_TO_LEFT: 1548 leftToLeft = lookupID(a, attr, leftToLeft); 1549 break; 1550 case LEFT_TO_RIGHT: 1551 leftToRight = lookupID(a, attr, leftToRight); 1552 break; 1553 case RIGHT_TO_LEFT: 1554 rightToLeft = lookupID(a, attr, rightToLeft); 1555 break; 1556 case RIGHT_TO_RIGHT: 1557 rightToRight = lookupID(a, attr, rightToRight); 1558 break; 1559 case TOP_TO_TOP: 1560 topToTop = lookupID(a, attr, topToTop); 1561 break; 1562 case TOP_TO_BOTTOM: 1563 topToBottom = lookupID(a, attr, topToBottom); 1564 break; 1565 case BOTTOM_TO_TOP: 1566 bottomToTop = lookupID(a, attr, bottomToTop); 1567 break; 1568 case BOTTOM_TO_BOTTOM: 1569 bottomToBottom = lookupID(a, attr, bottomToBottom); 1570 break; 1571 case BASELINE_TO_BASELINE: 1572 baselineToBaseline = lookupID(a, attr, baselineToBaseline); 1573 break; 1574 case BASELINE_TO_TOP: 1575 baselineToTop = lookupID(a, attr, baselineToTop); 1576 break; 1577 case BASELINE_TO_BOTTOM: 1578 baselineToBottom = lookupID(a, attr, baselineToBottom); 1579 break; 1580 case EDITOR_ABSOLUTE_X: 1581 editorAbsoluteX = a.getDimensionPixelOffset(attr, editorAbsoluteX); 1582 break; 1583 case EDITOR_ABSOLUTE_Y: 1584 editorAbsoluteY = a.getDimensionPixelOffset(attr, editorAbsoluteY); 1585 break; 1586 case GUIDE_BEGIN: 1587 guideBegin = a.getDimensionPixelOffset(attr, guideBegin); 1588 break; 1589 case GUIDE_END: 1590 guideEnd = a.getDimensionPixelOffset(attr, guideEnd); 1591 break; 1592 case GUIDE_PERCENT: 1593 guidePercent = a.getFloat(attr, guidePercent); 1594 break; 1595 case GUIDE_USE_RTL: 1596 guidelineUseRtl = a.getBoolean(attr, guidelineUseRtl); 1597 break; 1598 1599 case ORIENTATION: 1600 orientation = a.getInt(attr, orientation); 1601 break; 1602 case START_TO_END: 1603 startToEnd = lookupID(a, attr, startToEnd); 1604 break; 1605 case START_TO_START: 1606 startToStart = lookupID(a, attr, startToStart); 1607 break; 1608 case END_TO_START: 1609 endToStart = lookupID(a, attr, endToStart); 1610 break; 1611 case END_TO_END: 1612 endToEnd = lookupID(a, attr, endToEnd); 1613 break; 1614 case CIRCLE: 1615 circleConstraint = lookupID(a, attr, circleConstraint); 1616 break; 1617 case CIRCLE_RADIUS: 1618 circleRadius = a.getDimensionPixelSize(attr, circleRadius); 1619 break; 1620 case CIRCLE_ANGLE: 1621 circleAngle = a.getFloat(attr, circleAngle); 1622 break; 1623 case GONE_LEFT_MARGIN: 1624 goneLeftMargin = a.getDimensionPixelSize(attr, goneLeftMargin); 1625 break; 1626 case GONE_TOP_MARGIN: 1627 goneTopMargin = a.getDimensionPixelSize(attr, goneTopMargin); 1628 break; 1629 case GONE_RIGHT_MARGIN: 1630 goneRightMargin = a.getDimensionPixelSize(attr, goneRightMargin); 1631 break; 1632 case GONE_BOTTOM_MARGIN: 1633 goneBottomMargin = a.getDimensionPixelSize(attr, goneBottomMargin); 1634 break; 1635 case GONE_START_MARGIN: 1636 goneStartMargin = a.getDimensionPixelSize(attr, goneStartMargin); 1637 break; 1638 case GONE_END_MARGIN: 1639 goneEndMargin = a.getDimensionPixelSize(attr, goneEndMargin); 1640 break; 1641 case GONE_BASELINE_MARGIN: 1642 goneBaselineMargin = a.getDimensionPixelSize(attr, goneBaselineMargin); 1643 break; 1644 case HORIZONTAL_BIAS: 1645 horizontalBias = a.getFloat(attr, horizontalBias); 1646 break; 1647 case VERTICAL_BIAS: 1648 verticalBias = a.getFloat(attr, verticalBias); 1649 break; 1650 case LEFT_MARGIN: 1651 leftMargin = a.getDimensionPixelSize(attr, leftMargin); 1652 break; 1653 case RIGHT_MARGIN: 1654 rightMargin = a.getDimensionPixelSize(attr, rightMargin); 1655 break; 1656 case START_MARGIN: 1657 startMargin = a.getDimensionPixelSize(attr, startMargin); 1658 break; 1659 case END_MARGIN: 1660 endMargin = a.getDimensionPixelSize(attr, endMargin); 1661 break; 1662 case TOP_MARGIN: 1663 topMargin = a.getDimensionPixelSize(attr, topMargin); 1664 break; 1665 case BOTTOM_MARGIN: 1666 bottomMargin = a.getDimensionPixelSize(attr, bottomMargin); 1667 break; 1668 case BASELINE_MARGIN: 1669 baselineMargin = a.getDimensionPixelSize(attr, baselineMargin); 1670 break; 1671 case LAYOUT_WIDTH: 1672 mWidth = a.getLayoutDimension(attr, mWidth); 1673 break; 1674 case LAYOUT_HEIGHT: 1675 mHeight = a.getLayoutDimension(attr, mHeight); 1676 break; 1677 case LAYOUT_CONSTRAINT_WIDTH: 1678 ConstraintSet.parseDimensionConstraints(this, a, attr, HORIZONTAL); 1679 break; 1680 case LAYOUT_CONSTRAINT_HEIGHT: 1681 ConstraintSet.parseDimensionConstraints(this, a, attr, VERTICAL); 1682 break; 1683 case WIDTH_DEFAULT: 1684 widthDefault = a.getInt(attr, widthDefault); 1685 break; 1686 case HEIGHT_DEFAULT: 1687 heightDefault = a.getInt(attr, heightDefault); 1688 break; 1689 case VERTICAL_WEIGHT: 1690 verticalWeight = a.getFloat(attr, verticalWeight); 1691 break; 1692 case HORIZONTAL_WEIGHT: 1693 horizontalWeight = a.getFloat(attr, horizontalWeight); 1694 break; 1695 case VERTICAL_STYLE: 1696 verticalChainStyle = a.getInt(attr, verticalChainStyle); 1697 break; 1698 case HORIZONTAL_STYLE: 1699 horizontalChainStyle = a.getInt(attr, horizontalChainStyle); 1700 break; 1701 case DIMENSION_RATIO: 1702 dimensionRatio = a.getString(attr); 1703 break; 1704 case HEIGHT_MAX: 1705 heightMax = a.getDimensionPixelSize(attr, heightMax); 1706 break; 1707 case WIDTH_MAX: 1708 widthMax = a.getDimensionPixelSize(attr, widthMax); 1709 break; 1710 case HEIGHT_MIN: 1711 heightMin = a.getDimensionPixelSize(attr, heightMin); 1712 break; 1713 case WIDTH_MIN: 1714 widthMin = a.getDimensionPixelSize(attr, widthMin); 1715 break; 1716 case WIDTH_PERCENT: 1717 widthPercent = a.getFloat(attr, 1); 1718 break; 1719 case HEIGHT_PERCENT: 1720 heightPercent = a.getFloat(attr, 1); 1721 break; 1722 case CONSTRAINED_WIDTH: 1723 constrainedWidth = a.getBoolean(attr, constrainedWidth); 1724 break; 1725 case CONSTRAINED_HEIGHT: 1726 constrainedHeight = a.getBoolean(attr, constrainedHeight); 1727 break; 1728 case CHAIN_USE_RTL: 1729 Log.e(TAG, "CURRENTLY UNSUPPORTED"); // TODO add support or remove 1730 // TODO add support or remove c.mChainUseRtl 1731 // = a.getBoolean(attr,c.mChainUseRtl); 1732 break; 1733 case BARRIER_DIRECTION: 1734 mBarrierDirection = a.getInt(attr, mBarrierDirection); 1735 break; 1736 case LAYOUT_WRAP_BEHAVIOR: 1737 mWrapBehavior = a.getInt(attr, mWrapBehavior); 1738 break; 1739 case BARRIER_MARGIN: 1740 mBarrierMargin = a.getDimensionPixelSize(attr, mBarrierMargin); 1741 break; 1742 case CONSTRAINT_REFERENCED_IDS: 1743 mReferenceIdString = a.getString(attr); 1744 break; 1745 case BARRIER_ALLOWS_GONE_WIDGETS: 1746 mBarrierAllowsGoneWidgets = a.getBoolean(attr, mBarrierAllowsGoneWidgets); 1747 break; 1748 case CONSTRAINT_TAG: 1749 mConstraintTag = a.getString(attr); 1750 break; 1751 case UNUSED: 1752 Log.w(TAG, 1753 "unused attribute 0x" + Integer.toHexString(attr) 1754 + " " + sMapToConstant.get(attr)); 1755 break; 1756 default: 1757 Log.w(TAG, 1758 "Unknown attribute 0x" + Integer.toHexString(attr) 1759 + " " + sMapToConstant.get(attr)); 1760 1761 } 1762 } 1763 a.recycle(); 1764 } 1765 1766 /** 1767 * Print the content to a string 1768 * @param scene 1769 * @param stringBuilder 1770 */ dump(MotionScene scene, StringBuilder stringBuilder)1771 public void dump(MotionScene scene, StringBuilder stringBuilder) { 1772 Field[] fields = this.getClass().getDeclaredFields(); 1773 stringBuilder.append("\n"); 1774 for (int i = 0; i < fields.length; i++) { 1775 Field field = fields[i]; 1776 String name = field.getName(); 1777 if (Modifier.isStatic(field.getModifiers())) { 1778 continue; 1779 } 1780 1781 try { 1782 Object value = field.get(this); 1783 Class<?> type = field.getType(); 1784 if (type == Integer.TYPE) { 1785 Integer iValue = (Integer) value; 1786 if (iValue != UNSET) { 1787 String stringId = scene.lookUpConstraintName(iValue); 1788 stringBuilder.append(" "); 1789 stringBuilder.append(name); 1790 stringBuilder.append(" = \""); 1791 stringBuilder.append((stringId == null) ? iValue : stringId); 1792 stringBuilder.append("\"\n"); 1793 } 1794 } else if (type == Float.TYPE) { 1795 Float fValue = (Float) value; 1796 if (fValue != UNSET) { 1797 stringBuilder.append(" "); 1798 stringBuilder.append(name); 1799 stringBuilder.append(" = \""); 1800 stringBuilder.append(fValue); 1801 stringBuilder.append("\"\n"); 1802 } 1803 } 1804 } catch (IllegalAccessException e) { 1805 Log.e(TAG, "Error accessing ConstraintSet field", e); 1806 } 1807 } 1808 } 1809 } 1810 1811 /** 1812 * 1813 */ 1814 public static class Transform { 1815 public boolean mApply = false; 1816 public float rotation = 0; 1817 public float rotationX = 0; 1818 public float rotationY = 0; 1819 public float scaleX = 1; 1820 public float scaleY = 1; 1821 public float transformPivotX = Float.NaN; 1822 public float transformPivotY = Float.NaN; 1823 public int transformPivotTarget = UNSET; 1824 public float translationX = 0; 1825 public float translationY = 0; 1826 public float translationZ = 0; 1827 public boolean applyElevation = false; 1828 public float elevation = 0; 1829 1830 /** 1831 * Copy Transform from src 1832 * @param src 1833 */ copyFrom(Transform src)1834 public void copyFrom(Transform src) { 1835 mApply = src.mApply; 1836 rotation = src.rotation; 1837 rotationX = src.rotationX; 1838 rotationY = src.rotationY; 1839 scaleX = src.scaleX; 1840 scaleY = src.scaleY; 1841 transformPivotX = src.transformPivotX; 1842 transformPivotY = src.transformPivotY; 1843 transformPivotTarget = src.transformPivotTarget; 1844 translationX = src.translationX; 1845 translationY = src.translationY; 1846 translationZ = src.translationZ; 1847 applyElevation = src.applyElevation; 1848 elevation = src.elevation; 1849 } 1850 1851 private static SparseIntArray sMapToConstant = new SparseIntArray(); 1852 private static final int ROTATION = 1; 1853 private static final int ROTATION_X = 2; 1854 private static final int ROTATION_Y = 3; 1855 private static final int SCALE_X = 4; 1856 private static final int SCALE_Y = 5; 1857 private static final int TRANSFORM_PIVOT_X = 6; 1858 private static final int TRANSFORM_PIVOT_Y = 7; 1859 private static final int TRANSLATION_X = 8; 1860 private static final int TRANSLATION_Y = 9; 1861 private static final int TRANSLATION_Z = 10; 1862 private static final int ELEVATION = 11; 1863 private static final int TRANSFORM_PIVOT_TARGET = 12; 1864 1865 1866 static { sMapToConstant.append(R.styleable.Transform_android_rotation, ROTATION)1867 sMapToConstant.append(R.styleable.Transform_android_rotation, ROTATION); sMapToConstant.append(R.styleable.Transform_android_rotationX, ROTATION_X)1868 sMapToConstant.append(R.styleable.Transform_android_rotationX, ROTATION_X); sMapToConstant.append(R.styleable.Transform_android_rotationY, ROTATION_Y)1869 sMapToConstant.append(R.styleable.Transform_android_rotationY, ROTATION_Y); sMapToConstant.append(R.styleable.Transform_android_scaleX, SCALE_X)1870 sMapToConstant.append(R.styleable.Transform_android_scaleX, SCALE_X); sMapToConstant.append(R.styleable.Transform_android_scaleY, SCALE_Y)1871 sMapToConstant.append(R.styleable.Transform_android_scaleY, SCALE_Y); sMapToConstant.append(R.styleable.Transform_android_transformPivotX, TRANSFORM_PIVOT_X)1872 sMapToConstant.append(R.styleable.Transform_android_transformPivotX, TRANSFORM_PIVOT_X); sMapToConstant.append(R.styleable.Transform_android_transformPivotY, TRANSFORM_PIVOT_Y)1873 sMapToConstant.append(R.styleable.Transform_android_transformPivotY, TRANSFORM_PIVOT_Y); sMapToConstant.append(R.styleable.Transform_android_translationX, TRANSLATION_X)1874 sMapToConstant.append(R.styleable.Transform_android_translationX, TRANSLATION_X); sMapToConstant.append(R.styleable.Transform_android_translationY, TRANSLATION_Y)1875 sMapToConstant.append(R.styleable.Transform_android_translationY, TRANSLATION_Y); sMapToConstant.append(R.styleable.Transform_android_translationZ, TRANSLATION_Z)1876 sMapToConstant.append(R.styleable.Transform_android_translationZ, TRANSLATION_Z); sMapToConstant.append(R.styleable.Transform_android_elevation, ELEVATION)1877 sMapToConstant.append(R.styleable.Transform_android_elevation, ELEVATION); sMapToConstant.append(R.styleable.Transform_transformPivotTarget, TRANSFORM_PIVOT_TARGET)1878 sMapToConstant.append(R.styleable.Transform_transformPivotTarget, 1879 TRANSFORM_PIVOT_TARGET); 1880 1881 } 1882 fillFromAttributeList(Context context, AttributeSet attrs)1883 void fillFromAttributeList(Context context, AttributeSet attrs) { 1884 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Transform); 1885 mApply = true; 1886 final int count = a.getIndexCount(); 1887 for (int i = 0; i < count; i++) { 1888 int attr = a.getIndex(i); 1889 1890 switch (sMapToConstant.get(attr)) { 1891 case ROTATION: 1892 rotation = a.getFloat(attr, rotation); 1893 break; 1894 case ROTATION_X: 1895 rotationX = a.getFloat(attr, rotationX); 1896 break; 1897 case ROTATION_Y: 1898 rotationY = a.getFloat(attr, rotationY); 1899 break; 1900 case SCALE_X: 1901 scaleX = a.getFloat(attr, scaleX); 1902 break; 1903 case SCALE_Y: 1904 scaleY = a.getFloat(attr, scaleY); 1905 break; 1906 case TRANSFORM_PIVOT_X: 1907 transformPivotX = a.getDimension(attr, transformPivotX); 1908 break; 1909 case TRANSFORM_PIVOT_Y: 1910 transformPivotY = a.getDimension(attr, transformPivotY); 1911 break; 1912 case TRANSFORM_PIVOT_TARGET: 1913 transformPivotTarget = lookupID(a, attr, transformPivotTarget); 1914 break; 1915 case TRANSLATION_X: 1916 translationX = a.getDimension(attr, translationX); 1917 break; 1918 case TRANSLATION_Y: 1919 translationY = a.getDimension(attr, translationY); 1920 break; 1921 case TRANSLATION_Z: 1922 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 1923 translationZ = a.getDimension(attr, translationZ); 1924 } 1925 break; 1926 case ELEVATION: 1927 if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { 1928 applyElevation = true; 1929 elevation = a.getDimension(attr, elevation); 1930 } 1931 break; 1932 } 1933 } 1934 a.recycle(); 1935 } 1936 } 1937 1938 /** 1939 * 1940 */ 1941 public static class PropertySet { 1942 public boolean mApply = false; 1943 public int visibility = View.VISIBLE; 1944 public int mVisibilityMode = VISIBILITY_MODE_NORMAL; 1945 public float alpha = 1; 1946 public float mProgress = Float.NaN; 1947 1948 // @TODO: add description 1949 1950 /** 1951 * 1952 * @param src 1953 */ copyFrom(PropertySet src)1954 public void copyFrom(PropertySet src) { 1955 mApply = src.mApply; 1956 visibility = src.visibility; 1957 alpha = src.alpha; 1958 mProgress = src.mProgress; 1959 mVisibilityMode = src.mVisibilityMode; 1960 } 1961 fillFromAttributeList(Context context, AttributeSet attrs)1962 void fillFromAttributeList(Context context, AttributeSet attrs) { 1963 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PropertySet); 1964 mApply = true; 1965 final int count = a.getIndexCount(); 1966 for (int i = 0; i < count; i++) { 1967 int attr = a.getIndex(i); 1968 1969 if (attr == R.styleable.PropertySet_android_alpha) { 1970 alpha = a.getFloat(attr, alpha); 1971 } else if (attr == R.styleable.PropertySet_android_visibility) { 1972 visibility = a.getInt(attr, visibility); 1973 visibility = VISIBILITY_FLAGS[visibility]; 1974 } else if (attr == R.styleable.PropertySet_visibilityMode) { 1975 mVisibilityMode = a.getInt(attr, mVisibilityMode); 1976 } else if (attr == R.styleable.PropertySet_motionProgress) { 1977 mProgress = a.getFloat(attr, mProgress); 1978 } 1979 } 1980 a.recycle(); 1981 } 1982 } 1983 1984 /** 1985 * 1986 */ 1987 public static class Motion { 1988 public boolean mApply = false; 1989 public int mAnimateRelativeTo = Layout.UNSET; 1990 public int mAnimateCircleAngleTo = 0; 1991 public String mTransitionEasing = null; 1992 public int mPathMotionArc = Layout.UNSET; 1993 public int mDrawPath = 0; 1994 public float mMotionStagger = Float.NaN; 1995 public int mPolarRelativeTo = Layout.UNSET; 1996 public float mPathRotate = Float.NaN; 1997 public float mQuantizeMotionPhase = Float.NaN; 1998 public int mQuantizeMotionSteps = Layout.UNSET; 1999 public String mQuantizeInterpolatorString = null; 2000 public int mQuantizeInterpolatorType = INTERPOLATOR_UNDEFINED; // undefined 2001 public int mQuantizeInterpolatorID = -1; 2002 private static final int INTERPOLATOR_REFERENCE_ID = -2; 2003 private static final int SPLINE_STRING = -1; 2004 private static final int INTERPOLATOR_UNDEFINED = -3; 2005 2006 // @TODO: add description 2007 2008 /** 2009 * 2010 * @param src 2011 */ copyFrom(Motion src)2012 public void copyFrom(Motion src) { 2013 mApply = src.mApply; 2014 mAnimateRelativeTo = src.mAnimateRelativeTo; 2015 mTransitionEasing = src.mTransitionEasing; 2016 mPathMotionArc = src.mPathMotionArc; 2017 mDrawPath = src.mDrawPath; 2018 mPathRotate = src.mPathRotate; 2019 mMotionStagger = src.mMotionStagger; 2020 mPolarRelativeTo = src.mPolarRelativeTo; 2021 } 2022 2023 private static SparseIntArray sMapToConstant = new SparseIntArray(); 2024 private static final int TRANSITION_PATH_ROTATE = 1; 2025 private static final int PATH_MOTION_ARC = 2; 2026 private static final int TRANSITION_EASING = 3; 2027 private static final int MOTION_DRAW_PATH = 4; 2028 private static final int ANIMATE_RELATIVE_TO = 5; 2029 private static final int ANIMATE_CIRCLE_ANGLE_TO = 6; 2030 private static final int MOTION_STAGGER = 7; 2031 private static final int QUANTIZE_MOTION_STEPS = 8; 2032 private static final int QUANTIZE_MOTION_PHASE = 9; 2033 private static final int QUANTIZE_MOTION_INTERPOLATOR = 10; 2034 2035 2036 static { sMapToConstant.append(R.styleable.Motion_motionPathRotate, TRANSITION_PATH_ROTATE)2037 sMapToConstant.append(R.styleable.Motion_motionPathRotate, TRANSITION_PATH_ROTATE); sMapToConstant.append(R.styleable.Motion_pathMotionArc, PATH_MOTION_ARC)2038 sMapToConstant.append(R.styleable.Motion_pathMotionArc, PATH_MOTION_ARC); sMapToConstant.append(R.styleable.Motion_transitionEasing, TRANSITION_EASING)2039 sMapToConstant.append(R.styleable.Motion_transitionEasing, TRANSITION_EASING); sMapToConstant.append(R.styleable.Motion_drawPath, MOTION_DRAW_PATH)2040 sMapToConstant.append(R.styleable.Motion_drawPath, MOTION_DRAW_PATH); sMapToConstant.append(R.styleable.Motion_animateRelativeTo, ANIMATE_RELATIVE_TO)2041 sMapToConstant.append(R.styleable.Motion_animateRelativeTo, ANIMATE_RELATIVE_TO); sMapToConstant.append(R.styleable.Motion_animateCircleAngleTo, ANIMATE_CIRCLE_ANGLE_TO)2042 sMapToConstant.append(R.styleable.Motion_animateCircleAngleTo, ANIMATE_CIRCLE_ANGLE_TO); sMapToConstant.append(R.styleable.Motion_motionStagger, MOTION_STAGGER)2043 sMapToConstant.append(R.styleable.Motion_motionStagger, MOTION_STAGGER); sMapToConstant.append(R.styleable.Motion_quantizeMotionSteps, QUANTIZE_MOTION_STEPS)2044 sMapToConstant.append(R.styleable.Motion_quantizeMotionSteps, QUANTIZE_MOTION_STEPS); sMapToConstant.append(R.styleable.Motion_quantizeMotionPhase, QUANTIZE_MOTION_PHASE)2045 sMapToConstant.append(R.styleable.Motion_quantizeMotionPhase, QUANTIZE_MOTION_PHASE); sMapToConstant.append(R.styleable.Motion_quantizeMotionInterpolator, QUANTIZE_MOTION_INTERPOLATOR)2046