Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Louis Pullen-Freilich | 4dc4dac | 2020-07-22 14:39:14 +0100 | [diff] [blame^] | 17 | package androidx.compose.ui.graphics.vector.compat |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 18 | |
| 19 | import android.content.res.Resources |
| 20 | import android.util.AttributeSet |
Nader Jawad | d02c097 | 2019-08-27 15:01:07 -0700 | [diff] [blame] | 21 | import androidx.core.content.res.ComplexColorCompat |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 22 | import androidx.core.content.res.TypedArrayUtils |
Louis Pullen-Freilich | 4dc4dac | 2020-07-22 14:39:14 +0100 | [diff] [blame^] | 23 | import androidx.compose.ui.graphics.Brush |
| 24 | import androidx.compose.ui.graphics.Color |
| 25 | import androidx.compose.ui.graphics.ShaderBrush |
| 26 | import androidx.compose.ui.graphics.SolidColor |
| 27 | import androidx.compose.ui.graphics.StrokeCap |
| 28 | import androidx.compose.ui.graphics.StrokeJoin |
| 29 | import androidx.compose.ui.graphics.vector.DefaultPivotX |
| 30 | import androidx.compose.ui.graphics.vector.DefaultPivotY |
| 31 | import androidx.compose.ui.graphics.vector.DefaultRotation |
| 32 | import androidx.compose.ui.graphics.vector.DefaultScaleX |
| 33 | import androidx.compose.ui.graphics.vector.DefaultScaleY |
| 34 | import androidx.compose.ui.graphics.vector.DefaultTranslationX |
| 35 | import androidx.compose.ui.graphics.vector.DefaultTranslationY |
| 36 | import androidx.compose.ui.graphics.vector.EmptyPath |
| 37 | import androidx.compose.ui.graphics.vector.PathNode |
| 38 | import androidx.compose.ui.graphics.vector.VectorAssetBuilder |
| 39 | import androidx.compose.ui.graphics.vector.addPathNodes |
Yuichi Araki | 543845e | 2020-06-25 19:37:40 +0900 | [diff] [blame] | 40 | import androidx.ui.unit.dp |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 41 | import org.xmlpull.v1.XmlPullParser |
| 42 | import org.xmlpull.v1.XmlPullParserException |
| 43 | |
Louis Pullen-Freilich | 78e7cd7 | 2020-01-09 14:54:01 +0000 | [diff] [blame] | 44 | private const val LINECAP_BUTT = 0 |
| 45 | private const val LINECAP_ROUND = 1 |
| 46 | private const val LINECAP_SQUARE = 2 |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 47 | |
Louis Pullen-Freilich | 78e7cd7 | 2020-01-09 14:54:01 +0000 | [diff] [blame] | 48 | private const val LINEJOIN_MITER = 0 |
| 49 | private const val LINEJOIN_ROUND = 1 |
| 50 | private const val LINEJOIN_BEVEL = 2 |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 51 | |
| 52 | private val FILL_TYPE_WINDING = 0 |
| 53 | |
Louis Pullen-Freilich | 78e7cd7 | 2020-01-09 14:54:01 +0000 | [diff] [blame] | 54 | private const val SHAPE_CLIP_PATH = "clip-path" |
| 55 | private const val SHAPE_GROUP = "group" |
| 56 | private const val SHAPE_PATH = "path" |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 57 | |
| 58 | private fun getStrokeLineCap(id: Int, defValue: StrokeCap = StrokeCap.butt): StrokeCap = |
| 59 | when (id) { |
| 60 | LINECAP_BUTT -> StrokeCap.butt |
| 61 | LINECAP_ROUND -> StrokeCap.round |
| 62 | LINECAP_SQUARE -> StrokeCap.square |
| 63 | else -> defValue |
| 64 | } |
| 65 | |
| 66 | private fun getStrokeLineJoin(id: Int, defValue: StrokeJoin = StrokeJoin.miter): StrokeJoin = |
| 67 | when (id) { |
| 68 | LINEJOIN_MITER -> StrokeJoin.miter |
| 69 | LINEJOIN_ROUND -> StrokeJoin.round |
| 70 | LINEJOIN_BEVEL -> StrokeJoin.bevel |
| 71 | else -> defValue |
| 72 | } |
| 73 | |
| 74 | internal fun XmlPullParser.isAtEnd(): Boolean = |
| 75 | eventType == XmlPullParser.END_DOCUMENT || |
| 76 | (depth < 1 && eventType == XmlPullParser.END_TAG) |
| 77 | |
Yuichi Araki | 543845e | 2020-06-25 19:37:40 +0900 | [diff] [blame] | 78 | /** |
| 79 | * @param nestedGroups The number of additionally nested VectorGroups to represent clip paths. |
| 80 | * @return The number of nested VectorGroups that are not `<group>` in XML, but represented as |
| 81 | * VectorGroup in the [builder]. These are also popped when this function sees `</group>`. |
| 82 | */ |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 83 | internal fun XmlPullParser.parseCurrentVectorNode( |
| 84 | res: Resources, |
| 85 | attrs: AttributeSet, |
| 86 | theme: Resources.Theme? = null, |
Yuichi Araki | 543845e | 2020-06-25 19:37:40 +0900 | [diff] [blame] | 87 | builder: VectorAssetBuilder, |
| 88 | nestedGroups: Int |
| 89 | ): Int { |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 90 | when (eventType) { |
| 91 | XmlPullParser.START_TAG -> { |
| 92 | when (name) { |
| 93 | SHAPE_PATH -> { |
| 94 | parsePath(res, theme, attrs, builder) |
| 95 | } |
| 96 | SHAPE_CLIP_PATH -> { |
Yuichi Araki | 543845e | 2020-06-25 19:37:40 +0900 | [diff] [blame] | 97 | parseClipPath(res, theme, attrs, builder) |
| 98 | return nestedGroups + 1 |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 99 | } |
| 100 | SHAPE_GROUP -> { |
| 101 | parseGroup(res, theme, attrs, builder) |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | XmlPullParser.END_TAG -> { |
| 106 | if (SHAPE_GROUP == name) { |
Yuichi Araki | 543845e | 2020-06-25 19:37:40 +0900 | [diff] [blame] | 107 | repeat(nestedGroups + 1) { |
| 108 | builder.popGroup() |
| 109 | } |
| 110 | return 0 |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | } |
Yuichi Araki | 543845e | 2020-06-25 19:37:40 +0900 | [diff] [blame] | 114 | return nestedGroups |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Helper method to seek to the first tag within the VectorDrawable xml asset |
| 119 | */ |
| 120 | @Throws(XmlPullParserException::class) |
| 121 | internal fun XmlPullParser.seekToStartTag(): XmlPullParser { |
| 122 | var type = next() |
| 123 | while (type != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { |
| 124 | // Empty loop |
| 125 | type = next() |
| 126 | } |
| 127 | if (type != XmlPullParser.START_TAG) { |
| 128 | throw XmlPullParserException("No start tag found") |
| 129 | } |
| 130 | return this |
| 131 | } |
| 132 | |
| 133 | @SuppressWarnings("RestrictedApi") |
| 134 | internal fun XmlPullParser.createVectorImageBuilder( |
| 135 | res: Resources, |
| 136 | theme: Resources.Theme?, |
| 137 | attrs: AttributeSet |
| 138 | ): VectorAssetBuilder { |
| 139 | val vectorAttrs = TypedArrayUtils.obtainAttributes( |
| 140 | res, |
| 141 | theme, |
| 142 | attrs, |
| 143 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_TYPE_ARRAY |
| 144 | ) |
| 145 | |
| 146 | // TODO (njawad) handle mirroring here |
| 147 | // state.mAutoMirrored = TypedArrayUtils.getNamedBoolean(a, parser, "autoMirrored", |
| 148 | // AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_AUTO_MIRRORED, state.mAutoMirrored) |
| 149 | |
| 150 | val viewportWidth = TypedArrayUtils.getNamedFloat( |
| 151 | vectorAttrs, |
| 152 | this, |
| 153 | "viewportWidth", |
| 154 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_VIEWPORT_WIDTH, |
| 155 | 0.0f |
| 156 | ) |
| 157 | |
| 158 | val viewportHeight = TypedArrayUtils.getNamedFloat( |
| 159 | vectorAttrs, |
| 160 | this, |
| 161 | "viewportHeight", |
| 162 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_VIEWPORT_HEIGHT, |
| 163 | 0.0f |
| 164 | ) |
| 165 | |
| 166 | if (viewportWidth <= 0) { |
| 167 | throw XmlPullParserException( |
Louis Pullen-Freilich | 0d2d0ed | 2019-12-13 18:41:46 +0000 | [diff] [blame] | 168 | vectorAttrs.positionDescription + "<VectorGraphic> tag requires viewportWidth > 0" |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 169 | ) |
| 170 | } else if (viewportHeight <= 0) { |
| 171 | throw XmlPullParserException( |
Louis Pullen-Freilich | 0d2d0ed | 2019-12-13 18:41:46 +0000 | [diff] [blame] | 172 | vectorAttrs.positionDescription + "<VectorGraphic> tag requires viewportHeight > 0" |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 173 | ) |
| 174 | } |
| 175 | |
| 176 | val defaultWidth = vectorAttrs.getDimension( |
| 177 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_WIDTH, 0.0f |
| 178 | ) |
| 179 | val defaultHeight = vectorAttrs.getDimension( |
| 180 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_HEIGHT, 0.0f |
| 181 | ) |
| 182 | |
Louis Pullen-Freilich | 0d2d0ed | 2019-12-13 18:41:46 +0000 | [diff] [blame] | 183 | val defaultWidthDp = (defaultWidth / res.displayMetrics.density).dp |
| 184 | val defaultHeightDp = (defaultHeight / res.displayMetrics.density).dp |
| 185 | |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 186 | vectorAttrs.recycle() |
| 187 | |
| 188 | return VectorAssetBuilder( |
Louis Pullen-Freilich | 0d2d0ed | 2019-12-13 18:41:46 +0000 | [diff] [blame] | 189 | defaultWidth = defaultWidthDp, |
| 190 | defaultHeight = defaultHeightDp, |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 191 | viewportWidth = viewportWidth, |
| 192 | viewportHeight = viewportHeight |
| 193 | ) |
| 194 | } |
| 195 | |
| 196 | @Throws(IllegalArgumentException::class) |
| 197 | @SuppressWarnings("RestrictedApi") |
| 198 | internal fun XmlPullParser.parsePath( |
| 199 | res: Resources, |
| 200 | theme: Resources.Theme?, |
| 201 | attrs: AttributeSet, |
| 202 | builder: VectorAssetBuilder |
| 203 | ) { |
| 204 | val a = TypedArrayUtils.obtainAttributes( |
| 205 | res, |
| 206 | theme, |
| 207 | attrs, |
| 208 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH |
| 209 | ) |
| 210 | |
| 211 | val hasPathData = TypedArrayUtils.hasAttribute(this, "pathData") |
| 212 | if (!hasPathData) { |
| 213 | // If there is no pathData in the VPath tag, then this is an empty VPath, |
| 214 | // nothing need to be drawn. |
| 215 | throw IllegalArgumentException("No path data available") |
| 216 | } |
| 217 | |
| 218 | val name: String = a.getString(AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_NAME) ?: "" |
| 219 | |
| 220 | val pathStr = a.getString(AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_PATH_DATA) |
| 221 | |
Nader Jawad | 4ef199b | 2019-10-22 18:37:01 -0700 | [diff] [blame] | 222 | val pathData: List<PathNode> = addPathNodes(pathStr) |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 223 | |
| 224 | val fillColor = TypedArrayUtils.getNamedComplexColor( |
| 225 | a, |
| 226 | this, |
| 227 | theme, |
| 228 | "fillColor", |
| 229 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_FILL_COLOR, 0 |
| 230 | ) |
| 231 | val fillAlpha = TypedArrayUtils.getNamedFloat( |
| 232 | a, |
| 233 | this, |
| 234 | "fillAlpha", |
| 235 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_FILL_ALPHA, 1.0f |
| 236 | ) |
| 237 | val lineCap = TypedArrayUtils.getNamedInt( |
| 238 | a, |
| 239 | this, |
| 240 | "strokeLineCap", |
| 241 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_STROKE_LINE_CAP, -1 |
| 242 | ) |
| 243 | val strokeLineCap = getStrokeLineCap(lineCap, StrokeCap.butt) |
| 244 | val lineJoin = TypedArrayUtils.getNamedInt( |
| 245 | a, |
| 246 | this, |
| 247 | "strokeLineJoin", |
| 248 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_STROKE_LINE_JOIN, -1 |
| 249 | ) |
Nader Jawad | 02a9d4e | 2019-08-27 10:49:47 -0700 | [diff] [blame] | 250 | val strokeLineJoin = |
| 251 | getStrokeLineJoin(lineJoin, StrokeJoin.bevel) |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 252 | val strokeMiterLimit = TypedArrayUtils.getNamedFloat( |
| 253 | a, |
| 254 | this, |
| 255 | "strokeMiterLimit", |
| 256 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_STROKE_MITER_LIMIT, |
| 257 | 1.0f |
| 258 | ) |
| 259 | val strokeColor = TypedArrayUtils.getNamedComplexColor( |
| 260 | a, |
| 261 | this, |
| 262 | theme, |
| 263 | "strokeColor", |
| 264 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_STROKE_COLOR, 0 |
| 265 | ) |
| 266 | val strokeAlpha = TypedArrayUtils.getNamedFloat( |
| 267 | a, |
| 268 | this, |
| 269 | "strokeAlpha", |
| 270 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_STROKE_ALPHA, 1.0f |
| 271 | ) |
| 272 | val strokeLineWidth = TypedArrayUtils.getNamedFloat( |
| 273 | a, |
| 274 | this, |
| 275 | "strokeWidth", |
| 276 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_STROKE_WIDTH, 1.0f |
| 277 | ) |
| 278 | |
| 279 | // TODO (njawad) handle trim paths + fill rule |
| 280 | // val trimPathEnd = TypedArrayUtils.getNamedFloat( |
| 281 | // a, this, "trimPathEnd", |
| 282 | // AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_TRIM_PATH_END, 1.0f |
| 283 | // ) |
| 284 | // val trimPathOffset = TypedArrayUtils.getNamedFloat( |
| 285 | // a, this, "trimPathOffset", |
| 286 | // AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_TRIM_PATH_OFFSET, |
| 287 | // 0.0f |
| 288 | // ) |
| 289 | // val trimPathStart = TypedArrayUtils.getNamedFloat( |
| 290 | // a, this, "trimPathStart", |
| 291 | // AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_TRIM_PATH_START, |
| 292 | // 0.0f |
| 293 | // ) |
| 294 | // val fillRule = TypedArrayUtils.getNamedInt( |
| 295 | // a, this, "fillType", |
| 296 | // AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_PATH_TRIM_PATH_FILLTYPE, |
| 297 | // FILL_TYPE_WINDING |
| 298 | // ) |
| 299 | |
| 300 | a.recycle() |
| 301 | |
Nader Jawad | d02c097 | 2019-08-27 15:01:07 -0700 | [diff] [blame] | 302 | val fillBrush = obtainBrushFromComplexColor(fillColor) |
| 303 | val strokeBrush = obtainBrushFromComplexColor(strokeColor) |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 304 | |
| 305 | builder.addPath( |
| 306 | pathData, |
| 307 | name, |
| 308 | fillBrush, |
| 309 | fillAlpha, |
| 310 | strokeBrush, |
| 311 | strokeAlpha, |
| 312 | strokeLineWidth, |
| 313 | strokeLineCap, |
| 314 | strokeLineJoin, |
| 315 | strokeMiterLimit) |
| 316 | } |
| 317 | |
| 318 | @SuppressWarnings("RestrictedApi") |
Nader Jawad | d02c097 | 2019-08-27 15:01:07 -0700 | [diff] [blame] | 319 | private fun obtainBrushFromComplexColor(complexColor: ComplexColorCompat): Brush? = |
Aurimas Liutikas | 7a828d3 | 2019-10-07 17:16:05 -0700 | [diff] [blame] | 320 | if (complexColor.willDraw()) { |
| 321 | val shader = complexColor.shader |
| 322 | if (shader != null) { |
Nader Jawad | d4dceed | 2020-06-26 17:18:55 -0700 | [diff] [blame] | 323 | ShaderBrush(shader) |
Aurimas Liutikas | 7a828d3 | 2019-10-07 17:16:05 -0700 | [diff] [blame] | 324 | } else { |
| 325 | SolidColor(Color(complexColor.color)) |
| 326 | } |
| 327 | } else { |
| 328 | null |
| 329 | } |
Nader Jawad | d02c097 | 2019-08-27 15:01:07 -0700 | [diff] [blame] | 330 | |
Yuichi Araki | 543845e | 2020-06-25 19:37:40 +0900 | [diff] [blame] | 331 | internal fun XmlPullParser.parseClipPath( |
| 332 | res: Resources, |
| 333 | theme: Resources.Theme?, |
| 334 | attrs: AttributeSet, |
| 335 | builder: VectorAssetBuilder |
| 336 | ) { |
Louis Pullen-Freilich | 7e6ecdb | 2020-07-09 15:14:37 +0100 | [diff] [blame] | 337 | val a = theme?.obtainStyledAttributes( |
Yuichi Araki | 543845e | 2020-06-25 19:37:40 +0900 | [diff] [blame] | 338 | attrs, |
Louis Pullen-Freilich | 7e6ecdb | 2020-07-09 15:14:37 +0100 | [diff] [blame] | 339 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_CLIP_PATH, |
| 340 | 0, |
| 341 | 0 |
| 342 | ) ?: res.obtainAttributes(attrs, AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_CLIP_PATH) |
| 343 | |
Yuichi Araki | 543845e | 2020-06-25 19:37:40 +0900 | [diff] [blame] | 344 | val name: String = a.getString( |
| 345 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_CLIP_PATH_NAME |
| 346 | ) ?: "" |
| 347 | val pathData = addPathNodes(a.getString( |
| 348 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_CLIP_PATH_PATH_DATA |
| 349 | )) |
| 350 | a.recycle() |
| 351 | |
| 352 | // <clip-path> is parsed out as an additional VectorGroup. |
| 353 | // This allows us to replicate the behavior of VectorDrawable where <clip-path> only affects |
| 354 | // <path> that comes after it in <group>. |
| 355 | builder.pushGroup( |
| 356 | name = name, |
| 357 | clipPathData = pathData |
| 358 | ) |
| 359 | } |
| 360 | |
Nader Jawad | d02c097 | 2019-08-27 15:01:07 -0700 | [diff] [blame] | 361 | @SuppressWarnings("RestrictedApi") |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 362 | internal fun XmlPullParser.parseGroup( |
| 363 | res: Resources, |
| 364 | theme: Resources.Theme?, |
| 365 | attrs: AttributeSet, |
| 366 | builder: VectorAssetBuilder |
| 367 | ) { |
| 368 | val a = TypedArrayUtils.obtainAttributes( |
| 369 | res, |
| 370 | theme, |
| 371 | attrs, |
| 372 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_GROUP |
| 373 | ) |
| 374 | |
| 375 | // Account for any configuration changes. |
| 376 | // mChangingConfigurations |= Utils.getChangingConfigurations(a); |
| 377 | |
| 378 | // Extract the theme attributes, if any. |
| 379 | // mThemeAttrs = null // TODO TINT THEME Not supported yet a.extractThemeAttrs(); |
| 380 | |
| 381 | // This is added in API 11 |
| 382 | val rotate = TypedArrayUtils.getNamedFloat( |
| 383 | a, |
| 384 | this, |
| 385 | "rotation", |
| 386 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_GROUP_ROTATION, |
| 387 | DefaultRotation |
| 388 | ) |
| 389 | |
| 390 | val pivotX = a.getFloat( |
| 391 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_GROUP_PIVOT_X, |
| 392 | DefaultPivotX |
| 393 | ) |
| 394 | val pivotY = a.getFloat( |
| 395 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_GROUP_PIVOT_Y, |
| 396 | DefaultPivotY |
| 397 | ) |
| 398 | |
| 399 | // This is added in API 11 |
| 400 | val scaleX = TypedArrayUtils.getNamedFloat( |
| 401 | a, |
| 402 | this, |
| 403 | "scaleX", |
| 404 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_GROUP_SCALE_X, |
| 405 | DefaultScaleX |
| 406 | ) |
| 407 | |
| 408 | // This is added in API 11 |
| 409 | val scaleY = TypedArrayUtils.getNamedFloat( |
| 410 | a, |
| 411 | this, |
| 412 | "scaleY", |
| 413 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_GROUP_SCALE_Y, |
| 414 | DefaultScaleY |
| 415 | ) |
| 416 | |
| 417 | val translateX = TypedArrayUtils.getNamedFloat( |
| 418 | a, |
| 419 | this, |
Yuichi Araki | 16a7489 | 2020-06-17 14:06:44 +0900 | [diff] [blame] | 420 | "translateX", |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 421 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_GROUP_TRANSLATE_X, |
| 422 | DefaultTranslationX |
| 423 | ) |
| 424 | val translateY = TypedArrayUtils.getNamedFloat( |
| 425 | a, |
| 426 | this, |
Yuichi Araki | 16a7489 | 2020-06-17 14:06:44 +0900 | [diff] [blame] | 427 | "translateY", |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 428 | AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_GROUP_TRANSLATE_Y, |
| 429 | DefaultTranslationY |
| 430 | ) |
| 431 | |
| 432 | val name: String = |
| 433 | a.getString(AndroidVectorResources.STYLEABLE_VECTOR_DRAWABLE_GROUP_NAME) ?: "" |
| 434 | |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 435 | a.recycle() |
| 436 | |
| 437 | builder.pushGroup( |
| 438 | name, |
| 439 | rotate, |
Louis Pullen-Freilich | 78e7cd7 | 2020-01-09 14:54:01 +0000 | [diff] [blame] | 440 | pivotX, |
| 441 | pivotY, |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 442 | scaleX, |
| 443 | scaleY, |
| 444 | translateX, |
| 445 | translateY, |
Yuichi Araki | 543845e | 2020-06-25 19:37:40 +0900 | [diff] [blame] | 446 | EmptyPath |
Nader Jawad | b1030d4 | 2019-05-07 15:33:13 -0700 | [diff] [blame] | 447 | ) |
| 448 | } |