VectorDrawable.java revision fd3c4744f265c5277e6e2641a18d5ec3dff19f6b
1abb7d134c02ac60091108c491dafb00877093170John Hoford/*
2abb7d134c02ac60091108c491dafb00877093170John Hoford * Copyright (C) 2014 The Android Open Source Project
3abb7d134c02ac60091108c491dafb00877093170John Hoford *
4abb7d134c02ac60091108c491dafb00877093170John Hoford * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5abb7d134c02ac60091108c491dafb00877093170John Hoford * in compliance with the License. You may obtain a copy of the License at
6abb7d134c02ac60091108c491dafb00877093170John Hoford *
7abb7d134c02ac60091108c491dafb00877093170John Hoford * http://www.apache.org/licenses/LICENSE-2.0
8abb7d134c02ac60091108c491dafb00877093170John Hoford *
9abb7d134c02ac60091108c491dafb00877093170John Hoford * Unless required by applicable law or agreed to in writing, software distributed under the License
10abb7d134c02ac60091108c491dafb00877093170John Hoford * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11abb7d134c02ac60091108c491dafb00877093170John Hoford * or implied. See the License for the specific language governing permissions and limitations under
12abb7d134c02ac60091108c491dafb00877093170John Hoford * the License.
13abb7d134c02ac60091108c491dafb00877093170John Hoford */
14abb7d134c02ac60091108c491dafb00877093170John Hoford
15abb7d134c02ac60091108c491dafb00877093170John Hofordpackage android.graphics.drawable;
16abb7d134c02ac60091108c491dafb00877093170John Hoford
17b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viveretteimport android.content.res.ColorStateList;
18abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.content.res.Resources;
19abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.content.res.Resources.Theme;
204b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viveretteimport android.content.res.TypedArray;
21482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghuiimport android.graphics.Bitmap;
22abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.graphics.Canvas;
232af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghuiimport android.graphics.Color;
24abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.graphics.ColorFilter;
25abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.graphics.Matrix;
26abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.graphics.Paint;
27abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.graphics.Path;
28abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.graphics.PathMeasure;
29abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.graphics.PixelFormat;
30b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viveretteimport android.graphics.PorterDuffColorFilter;
31abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.graphics.Rect;
32abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.graphics.Region;
33b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viveretteimport android.graphics.PorterDuff.Mode;
34e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghuiimport android.util.ArrayMap;
35abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.util.AttributeSet;
36738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghuiimport android.util.LayoutDirection;
37abb7d134c02ac60091108c491dafb00877093170John Hofordimport android.util.Log;
38cf4832f69c8786b098ce18c24319021f8cd6733aztenghuiimport android.util.PathParser;
394b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viveretteimport android.util.Xml;
40abb7d134c02ac60091108c491dafb00877093170John Hoford
41abb7d134c02ac60091108c491dafb00877093170John Hofordimport com.android.internal.R;
42abb7d134c02ac60091108c491dafb00877093170John Hoford
43abb7d134c02ac60091108c491dafb00877093170John Hofordimport org.xmlpull.v1.XmlPullParser;
44abb7d134c02ac60091108c491dafb00877093170John Hofordimport org.xmlpull.v1.XmlPullParserException;
454b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viveretteimport org.xmlpull.v1.XmlPullParserFactory;
46abb7d134c02ac60091108c491dafb00877093170John Hoford
47abb7d134c02ac60091108c491dafb00877093170John Hofordimport java.io.IOException;
48abb7d134c02ac60091108c491dafb00877093170John Hofordimport java.util.ArrayList;
494d24caf1dec2babf273b18c99638fe2a0635ced4ztenghuiimport java.util.Stack;
504b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette
51abb7d134c02ac60091108c491dafb00877093170John Hoford/**
526beeb75723cec42603b47664bce794a2b97d7bacChet Haase * This lets you create a drawable based on an XML vector graphic. It can be
53d20974bd51852c71114b6e0e4ffdc3613a4d90aaAlan Viverette * defined in an XML file with the <code>&lt;vector></code> element.
54abb7d134c02ac60091108c491dafb00877093170John Hoford * <p/>
5546e546c28fd52b4dedf0a0fbd313db589cb9048bztenghui * The vector drawable has the following elements:
56abb7d134c02ac60091108c491dafb00877093170John Hoford * <p/>
57177dffd869ff1f5bdf816faead01a7dc4980bf75ztenghui * <dt><code>&lt;vector></code></dt>
58a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dl>
59a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Used to defined a vector drawable
60a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dl>
61a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:width</code></dt>
62a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Used to defined the intrinsic width of the drawable.
63a95c8abb366d9c39450513335f550b56da13b30aztenghui * This support all the dimension units, normally specified with dp.</dd>
64a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:height</code></dt>
65a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Used to defined the intrinsic height the drawable.
66a95c8abb366d9c39450513335f550b56da13b30aztenghui * This support all the dimension units, normally specified with dp.</dd>
67a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:viewportWidth</code></dt>
68a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Used to defined the width of the viewport space. Viewport is basically
69a95c8abb366d9c39450513335f550b56da13b30aztenghui * the virtual canvas where the paths are drawn on.</dd>
70a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:viewportHeight</code></dt>
71a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Used to defined the height of the viewport space. Viewport is basically
72a95c8abb366d9c39450513335f550b56da13b30aztenghui * the virtual canvas where the paths are drawn on.</dd>
73a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:tint</code></dt>
74a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The color to apply to the drawable as a tint. By default, no tint is applied.</dd>
75a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:tintMode</code></dt>
76a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The Porter-Duff blending mode for the tint color. The default value is src_in.</dd>
77a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:autoMirrored</code></dt>
78a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Indicates if the drawable needs to be mirrored when its layout direction is
79a95c8abb366d9c39450513335f550b56da13b30aztenghui * RTL (right-to-left).</dd>
80a95c8abb366d9c39450513335f550b56da13b30aztenghui * </dl></dd>
81a95c8abb366d9c39450513335f550b56da13b30aztenghui * </dl>
82a95c8abb366d9c39450513335f550b56da13b30aztenghui *
83a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dl>
846d9c422de5e0a3890dd723cb1b9264d4507053e9ztenghui * <dt><code>&lt;group></code></dt>
85452f6ece7fe2fd1a85fca53f54e90bf041083b21ztenghui * <dd>Defines a group of paths or subgroups, plus transformation information.
86452f6ece7fe2fd1a85fca53f54e90bf041083b21ztenghui * The transformations are defined in the same coordinates as the viewport.
87a95c8abb366d9c39450513335f550b56da13b30aztenghui * And the transformations are applied in the order of scale, rotate then translate.
88a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dl>
89a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:rotation</code></dt>
90a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The degrees of rotation of the group.</dd>
91a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:pivotX</code></dt>
92a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The X coordinate of the pivot for the scale and rotation of the group.
93a95c8abb366d9c39450513335f550b56da13b30aztenghui * This is defined in the viewport space.</dd>
94a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:pivotY</code></dt>
95a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The Y coordinate of the pivot for the scale and rotation of the group.
96a95c8abb366d9c39450513335f550b56da13b30aztenghui * This is defined in the viewport space.</dd>
97a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:scaleX</code></dt>
98a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The amount of scale on the X Coordinate.</dd>
99a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:scaleY</code></dt>
100a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The amount of scale on the Y coordinate.</dd>
101a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:translateX</code></dt>
102a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The amount of translation on the X coordinate.
103a95c8abb366d9c39450513335f550b56da13b30aztenghui * This is defined in the viewport space.</dd>
104a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:translateY</code></dt>
105a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The amount of translation on the Y coordinate.
106a95c8abb366d9c39450513335f550b56da13b30aztenghui * This is defined in the viewport space.</dd>
107f143ae8ffecc46008b9f6a9fa85d77324b5a145bztenghui * <dt><code>android:alpha</code></dt>
108f143ae8ffecc46008b9f6a9fa85d77324b5a145bztenghui * <dd>The amount of transparency.</dd>
109a95c8abb366d9c39450513335f550b56da13b30aztenghui * </dl></dd>
110a95c8abb366d9c39450513335f550b56da13b30aztenghui * </dl>
111a95c8abb366d9c39450513335f550b56da13b30aztenghui *
112a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dl>
113abb7d134c02ac60091108c491dafb00877093170John Hoford * <dt><code>&lt;path></code></dt>
1146d9c422de5e0a3890dd723cb1b9264d4507053e9ztenghui * <dd>Defines paths to be drawn.
115abb7d134c02ac60091108c491dafb00877093170John Hoford * <dl>
116a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:name</code></dt>
117a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Defines the name of the path.</dd>
118a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:pathData</code></dt>
11946e546c28fd52b4dedf0a0fbd313db589cb9048bztenghui * <dd>Defines path string. This is using exactly same format as "d" attribute
120a95c8abb366d9c39450513335f550b56da13b30aztenghui * in the SVG's path data. This is defined in the viewport space.</dd>
121a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:fillColor</code></dt>
122a70b4742a7a0b2edc57cbbbf83d2c6d43ebc300dztenghui * <dd>Defines the color to fill the path (none if not present).</dd>
123a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:strokeColor</code></dt>
124d20974bd51852c71114b6e0e4ffdc3613a4d90aaAlan Viverette * <dd>Defines the color to draw the path outline (none if not present).</dd>
125a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:strokeWidth</code></dt>
126a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The width a path stroke.</dd>
127a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:trimPathStart</code></dt>
128a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The fraction of the path to trim from the start, in the range from 0 to 1.</dd>
129a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:trimPathEnd</code></dt>
130a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>The fraction of the path to trim from the end, in the range from 0 to 1.</dd>
131a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:trimPathOffset</code></dt>
132a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Shift trim region (allows showed region to include the start and end), in the range
133a95c8abb366d9c39450513335f550b56da13b30aztenghui * from 0 to 1.</dd>
134a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:strokeLineCap</code></dt>
135a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Sets the linecap for a stroked path: butt, round, square.</dd>
136a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:strokeLineJoin</code></dt>
137a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Sets the lineJoin for a stroked path: miter,round,bevel.</dd>
138a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:strokeMiterLimit</code></dt>
139a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Sets the Miter limit for a stroked path.</dd>
140a95c8abb366d9c39450513335f550b56da13b30aztenghui * </dl></dd>
141a95c8abb366d9c39450513335f550b56da13b30aztenghui * </dl>
142a95c8abb366d9c39450513335f550b56da13b30aztenghui *
143a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dl>
144a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>&lt;clip-path></code></dt>
145a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Defines path to be the current clip.
146a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dl>
147a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:name</code></dt>
148a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Defines the name of the clip path.</dd>
149a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dt><code>android:pathData</code></dt>
150a95c8abb366d9c39450513335f550b56da13b30aztenghui * <dd>Defines clip path string. This is using exactly same format as "d" attribute
151a95c8abb366d9c39450513335f550b56da13b30aztenghui * in the SVG's path data.</dd>
152a95c8abb366d9c39450513335f550b56da13b30aztenghui * </dl></dd>
153abb7d134c02ac60091108c491dafb00877093170John Hoford * </dl>
154a95c8abb366d9c39450513335f550b56da13b30aztenghui * <li>Here is a simple VectorDrawable in this vectordrawable.xml file.
155a95c8abb366d9c39450513335f550b56da13b30aztenghui * <pre>
156a95c8abb366d9c39450513335f550b56da13b30aztenghui * &lt;vector xmlns:android=&quot;http://schemas.android.com/apk/res/android";
157a95c8abb366d9c39450513335f550b56da13b30aztenghui *     android:height=&quot;64dp&quot;
158a95c8abb366d9c39450513335f550b56da13b30aztenghui *     android:width=&quot;64dp&quot;
159a95c8abb366d9c39450513335f550b56da13b30aztenghui *     android:viewportHeight=&quot;600&quot;
160a95c8abb366d9c39450513335f550b56da13b30aztenghui *     android:viewportWidth=&quot;600&quot; &gt;
161a95c8abb366d9c39450513335f550b56da13b30aztenghui *     &lt;group
162a95c8abb366d9c39450513335f550b56da13b30aztenghui *         android:name=&quot;rotationGroup&quot;
163a95c8abb366d9c39450513335f550b56da13b30aztenghui *         android:pivotX=&quot;300.0&quot;
164a95c8abb366d9c39450513335f550b56da13b30aztenghui *         android:pivotY=&quot;300.0&quot;
165a95c8abb366d9c39450513335f550b56da13b30aztenghui *         android:rotation=&quot;45.0&quot; &gt;
166a95c8abb366d9c39450513335f550b56da13b30aztenghui *         &lt;path
167a95c8abb366d9c39450513335f550b56da13b30aztenghui *             android:name=&quot;v&quot;
168a95c8abb366d9c39450513335f550b56da13b30aztenghui *             android:fillColor=&quot;#000000&quot;
169a95c8abb366d9c39450513335f550b56da13b30aztenghui *             android:pathData=&quot;M300,70 l 0,-70 70,70 0,0 -70,70z&quot; /&gt;
170a95c8abb366d9c39450513335f550b56da13b30aztenghui *     &lt;/group&gt;
171a95c8abb366d9c39450513335f550b56da13b30aztenghui * &lt;/vector&gt;
172a95c8abb366d9c39450513335f550b56da13b30aztenghui * </pre></li>
173abb7d134c02ac60091108c491dafb00877093170John Hoford */
174a95c8abb366d9c39450513335f550b56da13b30aztenghui
175abb7d134c02ac60091108c491dafb00877093170John Hofordpublic class VectorDrawable extends Drawable {
1769453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette    private static final String LOGTAG = VectorDrawable.class.getSimpleName();
1779453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
178a95c8abb366d9c39450513335f550b56da13b30aztenghui    private static final String SHAPE_CLIP_PATH = "clip-path";
1796d9c422de5e0a3890dd723cb1b9264d4507053e9ztenghui    private static final String SHAPE_GROUP = "group";
180abb7d134c02ac60091108c491dafb00877093170John Hoford    private static final String SHAPE_PATH = "path";
181abb7d134c02ac60091108c491dafb00877093170John Hoford    private static final String SHAPE_VECTOR = "vector";
182abb7d134c02ac60091108c491dafb00877093170John Hoford
183abb7d134c02ac60091108c491dafb00877093170John Hoford    private static final int LINECAP_BUTT = 0;
184abb7d134c02ac60091108c491dafb00877093170John Hoford    private static final int LINECAP_ROUND = 1;
185abb7d134c02ac60091108c491dafb00877093170John Hoford    private static final int LINECAP_SQUARE = 2;
1869453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
187abb7d134c02ac60091108c491dafb00877093170John Hoford    private static final int LINEJOIN_MITER = 0;
188abb7d134c02ac60091108c491dafb00877093170John Hoford    private static final int LINEJOIN_ROUND = 1;
189abb7d134c02ac60091108c491dafb00877093170John Hoford    private static final int LINEJOIN_BEVEL = 2;
1909453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
1914d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui    private static final boolean DBG_VECTOR_DRAWABLE = false;
1924d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
19355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui    private VectorDrawableState mVectorState;
194e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
195b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette    private PorterDuffColorFilter mTintFilter;
196b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette
19755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui    private boolean mMutated;
19855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
199482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui    // AnimatedVectorDrawable needs to turn off the cache all the time, otherwise,
200482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui    // caching the bitmap by default is allowed.
201482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui    private boolean mAllowCaching = true;
202482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui
203abb7d134c02ac60091108c491dafb00877093170John Hoford    public VectorDrawable() {
20455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        mVectorState = new VectorDrawableState();
205abb7d134c02ac60091108c491dafb00877093170John Hoford    }
206abb7d134c02ac60091108c491dafb00877093170John Hoford
2079453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette    private VectorDrawable(VectorDrawableState state, Resources res, Theme theme) {
20816c1bd5db8f4f18e1eee8b19006bba5f06a88123ztenghui        if (theme != null && state.canApplyTheme()) {
20916c1bd5db8f4f18e1eee8b19006bba5f06a88123ztenghui            // If we need to apply a theme, implicitly mutate.
21016c1bd5db8f4f18e1eee8b19006bba5f06a88123ztenghui            mVectorState = new VectorDrawableState(state);
2119453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette            applyTheme(theme);
21216c1bd5db8f4f18e1eee8b19006bba5f06a88123ztenghui        } else {
21316c1bd5db8f4f18e1eee8b19006bba5f06a88123ztenghui            mVectorState = state;
2149453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        }
215b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette
216b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
217b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        mVectorState.mVPathRenderer.setColorFilter(mTintFilter);
218abb7d134c02ac60091108c491dafb00877093170John Hoford    }
219abb7d134c02ac60091108c491dafb00877093170John Hoford
22055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui    @Override
22155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui    public Drawable mutate() {
22255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        if (!mMutated && super.mutate() == this) {
22355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mVectorState = new VectorDrawableState(mVectorState);
22455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mMutated = true;
22555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        }
22655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        return this;
22755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui    }
22855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
229e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui    Object getTargetByName(String name) {
23055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        return mVectorState.mVPathRenderer.mVGTargetsMap.get(name);
231e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui    }
232e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
233abb7d134c02ac60091108c491dafb00877093170John Hoford    @Override
234abb7d134c02ac60091108c491dafb00877093170John Hoford    public ConstantState getConstantState() {
23555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        mVectorState.mChangingConfigurations = getChangingConfigurations();
23655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        return mVectorState;
237abb7d134c02ac60091108c491dafb00877093170John Hoford    }
238abb7d134c02ac60091108c491dafb00877093170John Hoford
2394554a6a5137d8e9bdfb623ad84ff344a48b7eb9dAlan Viverette    @Override
240abb7d134c02ac60091108c491dafb00877093170John Hoford    public void draw(Canvas canvas) {
2414b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        final Rect bounds = getBounds();
2421968201b44567262e7b2e382eee3d88990748d89Dan Sandler        if (bounds.width() == 0 || bounds.height() == 0) {
2431968201b44567262e7b2e382eee3d88990748d89Dan Sandler            // too small to draw
2441968201b44567262e7b2e382eee3d88990748d89Dan Sandler            return;
2451968201b44567262e7b2e382eee3d88990748d89Dan Sandler        }
2461968201b44567262e7b2e382eee3d88990748d89Dan Sandler
2470670f029a4e59448aa53b46a98e60dff6404f360ztenghui        final int saveCount = canvas.save();
248738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui        final boolean needMirroring = needMirroring();
249738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui
2504b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        canvas.translate(bounds.left, bounds.top);
251738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui        if (needMirroring) {
252738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui            canvas.translate(bounds.width(), 0);
253738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui            canvas.scale(-1.0f, 1.0f);
254738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui        }
255482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui
256482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        if (!mAllowCaching) {
257482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            mVectorState.mVPathRenderer.draw(canvas, bounds.width(), bounds.height());
258482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        } else {
259482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            Bitmap bitmap = mVectorState.mCachedBitmap;
260482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            if (bitmap == null || !mVectorState.canReuseCache(bounds.width(),
261482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                    bounds.height())) {
262482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(),
263482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                        Bitmap.Config.ARGB_8888);
264482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                Canvas tmpCanvas = new Canvas(bitmap);
265482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                mVectorState.mVPathRenderer.draw(tmpCanvas, bounds.width(), bounds.height());
266482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                mVectorState.mCachedBitmap = bitmap;
267482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui
268482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                mVectorState.updateCacheStates();
269482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            }
27066613415966f2f1a43cdaa76560eb6d53a05f15dztenghui            // The bitmap's size is the same as the bounds.
27166613415966f2f1a43cdaa76560eb6d53a05f15dztenghui            canvas.drawBitmap(bitmap, 0, 0, null);
272482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        }
273738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui
2744b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        canvas.restoreToCount(saveCount);
275abb7d134c02ac60091108c491dafb00877093170John Hoford    }
276abb7d134c02ac60091108c491dafb00877093170John Hoford
277abb7d134c02ac60091108c491dafb00877093170John Hoford    @Override
278e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui    public int getAlpha() {
279e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        return mVectorState.mVPathRenderer.getRootAlpha();
280e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui    }
281e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
282e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui    @Override
283abb7d134c02ac60091108c491dafb00877093170John Hoford    public void setAlpha(int alpha) {
2842af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        if (mVectorState.mVPathRenderer.getRootAlpha() != alpha) {
2852af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui            mVectorState.mVPathRenderer.setRootAlpha(alpha);
286abb7d134c02ac60091108c491dafb00877093170John Hoford            invalidateSelf();
287abb7d134c02ac60091108c491dafb00877093170John Hoford        }
288abb7d134c02ac60091108c491dafb00877093170John Hoford    }
289abb7d134c02ac60091108c491dafb00877093170John Hoford
290abb7d134c02ac60091108c491dafb00877093170John Hoford    @Override
291abb7d134c02ac60091108c491dafb00877093170John Hoford    public void setColorFilter(ColorFilter colorFilter) {
292b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        final VectorDrawableState state = mVectorState;
293b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        if (colorFilter != null) {
294b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette            // Color filter overrides tint.
295b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette            mTintFilter = null;
296b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        } else if (state.mTint != null && state.mTintMode != null) {
297b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette            // Restore the tint filter, if we need one.
298b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette            final int color = state.mTint.getColorForState(getState(), Color.TRANSPARENT);
299b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette            mTintFilter = new PorterDuffColorFilter(color, state.mTintMode);
300b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette            colorFilter = mTintFilter;
301b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        }
302b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette
303b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        state.mVPathRenderer.setColorFilter(colorFilter);
304fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette        invalidateSelf();
305abb7d134c02ac60091108c491dafb00877093170John Hoford    }
306abb7d134c02ac60091108c491dafb00877093170John Hoford
307abb7d134c02ac60091108c491dafb00877093170John Hoford    @Override
308a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette    public void setTintList(ColorStateList tint) {
309b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        final VectorDrawableState state = mVectorState;
310a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette        if (state.mTint != tint) {
311b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette            state.mTint = tint;
312a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette            mTintFilter = updateTintFilter(mTintFilter, tint, state.mTintMode);
313a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette            state.mVPathRenderer.setColorFilter(mTintFilter);
314a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette            invalidateSelf();
315a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette        }
316a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette    }
317b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette
318a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette    @Override
319a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette    public void setTintMode(Mode tintMode) {
320a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette        final VectorDrawableState state = mVectorState;
321a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette        if (state.mTintMode != tintMode) {
322a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette            state.mTintMode = tintMode;
323a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette            mTintFilter = updateTintFilter(mTintFilter, state.mTint, tintMode);
324a426445dfdab43886dd894f2ba8a1d55bfcbb278Alan Viverette            state.mVPathRenderer.setColorFilter(mTintFilter);
325b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette            invalidateSelf();
326b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        }
327b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette    }
328b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette
329b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette    @Override
330b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette    protected boolean onStateChange(int[] stateSet) {
331b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        final VectorDrawableState state = mVectorState;
332b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        if (state.mTint != null && state.mTintMode != null) {
333b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette            mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
334b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette            mVectorState.mVPathRenderer.setColorFilter(mTintFilter);
335b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette            return true;
336b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        }
337b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        return false;
338b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette    }
339b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette
340b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette    @Override
341abb7d134c02ac60091108c491dafb00877093170John Hoford    public int getOpacity() {
342abb7d134c02ac60091108c491dafb00877093170John Hoford        return PixelFormat.TRANSLUCENT;
343abb7d134c02ac60091108c491dafb00877093170John Hoford    }
344abb7d134c02ac60091108c491dafb00877093170John Hoford
345abb7d134c02ac60091108c491dafb00877093170John Hoford    @Override
346abb7d134c02ac60091108c491dafb00877093170John Hoford    public int getIntrinsicWidth() {
347ddbbb8ae8561c9e61becd03faa40997d76ab5a51ztenghui        return (int) mVectorState.mVPathRenderer.mBaseWidth;
348abb7d134c02ac60091108c491dafb00877093170John Hoford    }
349abb7d134c02ac60091108c491dafb00877093170John Hoford
350abb7d134c02ac60091108c491dafb00877093170John Hoford    @Override
351abb7d134c02ac60091108c491dafb00877093170John Hoford    public int getIntrinsicHeight() {
352ddbbb8ae8561c9e61becd03faa40997d76ab5a51ztenghui        return (int) mVectorState.mVPathRenderer.mBaseHeight;
353abb7d134c02ac60091108c491dafb00877093170John Hoford    }
354abb7d134c02ac60091108c491dafb00877093170John Hoford
355abb7d134c02ac60091108c491dafb00877093170John Hoford    @Override
3569453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette    public boolean canApplyTheme() {
3579453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        return super.canApplyTheme() || mVectorState != null && mVectorState.canApplyTheme();
3589453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette    }
3599453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
3609453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette    @Override
3619453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette    public void applyTheme(Theme t) {
3629453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        super.applyTheme(t);
3639453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
3649453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        final VectorDrawableState state = mVectorState;
365ddbbb8ae8561c9e61becd03faa40997d76ab5a51ztenghui        final VPathRenderer path = state.mVPathRenderer;
3669453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        if (path != null && path.canApplyTheme()) {
3679453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette            path.applyTheme(t);
3689453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        }
3699453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette    }
3709453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
371fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount    /**
372fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount     * The size of a pixel when scaled from the intrinsic dimension to the viewport dimension.
373fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount     * This is used to calculate the path animation accuracy.
374fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount     *
375fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount     * @hide
376fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount     */
377fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount    public float getPixelSize() {
378fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount        if (mVectorState == null && mVectorState.mVPathRenderer == null ||
379fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount                mVectorState.mVPathRenderer.mBaseWidth == 0 ||
380fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount                mVectorState.mVPathRenderer.mBaseHeight == 0 ||
381fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount                mVectorState.mVPathRenderer.mViewportHeight == 0 ||
382fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount                mVectorState.mVPathRenderer.mViewportWidth == 0) {
383fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount            return 1; // fall back to 1:1 pixel mapping.
384fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount        }
385fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount        float intrinsicWidth = mVectorState.mVPathRenderer.mBaseWidth;
386fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount        float intrinsicHeight = mVectorState.mVPathRenderer.mBaseHeight;
387fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount        float viewportWidth = mVectorState.mVPathRenderer.mViewportWidth;
388fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount        float viewportHeight = mVectorState.mVPathRenderer.mViewportHeight;
389fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount        float scaleX = viewportWidth / intrinsicWidth;
390fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount        float scaleY = viewportHeight / intrinsicHeight;
391fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount        return Math.min(scaleX, scaleY);
392fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount    }
393fd3c4744f265c5277e6e2641a18d5ec3dff19f6bGeorge Mount
3944b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette    /** @hide */
3954b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette    public static VectorDrawable create(Resources resources, int rid) {
3964b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette        try {
397874bcd82c223ce58c9d76edcf619b3988c672307ztenghui            final XmlPullParser parser = resources.getXml(rid);
398874bcd82c223ce58c9d76edcf619b3988c672307ztenghui            final AttributeSet attrs = Xml.asAttributeSet(parser);
399874bcd82c223ce58c9d76edcf619b3988c672307ztenghui            int type;
400874bcd82c223ce58c9d76edcf619b3988c672307ztenghui            while ((type=parser.next()) != XmlPullParser.START_TAG &&
401874bcd82c223ce58c9d76edcf619b3988c672307ztenghui                    type != XmlPullParser.END_DOCUMENT) {
402874bcd82c223ce58c9d76edcf619b3988c672307ztenghui                // Empty loop
403874bcd82c223ce58c9d76edcf619b3988c672307ztenghui            }
404874bcd82c223ce58c9d76edcf619b3988c672307ztenghui            if (type != XmlPullParser.START_TAG) {
405874bcd82c223ce58c9d76edcf619b3988c672307ztenghui                throw new XmlPullParserException("No start tag found");
406874bcd82c223ce58c9d76edcf619b3988c672307ztenghui            }
4074b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette
4084b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette            final VectorDrawable drawable = new VectorDrawable();
409874bcd82c223ce58c9d76edcf619b3988c672307ztenghui            drawable.inflate(resources, parser, attrs);
4104b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette
4114b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette            return drawable;
4124b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette        } catch (XmlPullParserException e) {
4134b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette            Log.e(LOGTAG, "parser error", e);
4144b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette        } catch (IOException e) {
4154b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette            Log.e(LOGTAG, "parser error", e);
4164b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette        }
4174b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette        return null;
4184b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette    }
4194b1a7c203d5e32c8b2dc7f4f54f28559ca31860aAlan Viverette
4202af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui    private static int applyAlpha(int color, float alpha) {
4212af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        int alphaBytes = Color.alpha(color);
4222af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        color &= 0x00FFFFFF;
4232af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        color |= ((int) (alphaBytes * alpha)) << 24;
4242af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        return color;
4252af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui    }
4262af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui
4279cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette    @Override
4289cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette    public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme)
4299cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette            throws XmlPullParserException, IOException {
430a95c8abb366d9c39450513335f550b56da13b30aztenghui        final VectorDrawableState state = mVectorState;
431a95c8abb366d9c39450513335f550b56da13b30aztenghui        final VPathRenderer pathRenderer = new VPathRenderer();
432a95c8abb366d9c39450513335f550b56da13b30aztenghui        state.mVPathRenderer = pathRenderer;
433a95c8abb366d9c39450513335f550b56da13b30aztenghui
434a95c8abb366d9c39450513335f550b56da13b30aztenghui        TypedArray a = obtainAttributes(res, theme, attrs, R.styleable.VectorDrawable);
4359cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        updateStateFromTypedArray(a);
4369cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        a.recycle();
4379cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette
438a95c8abb366d9c39450513335f550b56da13b30aztenghui        state.mCacheDirty = true;
43955f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        inflateInternal(res, parser, attrs, theme);
4409cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette
4419cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
4429cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        state.mVPathRenderer.setColorFilter(mTintFilter);
4439cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette    }
4449cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette
445a95c8abb366d9c39450513335f550b56da13b30aztenghui    private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
4469cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        final VectorDrawableState state = mVectorState;
447a95c8abb366d9c39450513335f550b56da13b30aztenghui        final VPathRenderer pathRenderer = state.mVPathRenderer;
4489cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette
4498e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette        // Account for any configuration changes.
4508e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette        state.mChangingConfigurations |= a.getChangingConfigurations();
4518e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette
4529cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        // Extract the theme attributes, if any.
4539cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        state.mThemeAttrs = a.extractThemeAttrs();
4549cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette
4559cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        final int tintMode = a.getInt(R.styleable.VectorDrawable_tintMode, -1);
4569cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        if (tintMode != -1) {
4579cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette            state.mTintMode = Drawable.parseTintMode(tintMode, Mode.SRC_IN);
4589cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        }
4599cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette
4609cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_tint);
4619cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        if (tint != null) {
4629cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette            state.mTint = tint;
4639cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        }
464738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui
465738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui        state.mAutoMirrored = a.getBoolean(
466738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui                R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored);
467a95c8abb366d9c39450513335f550b56da13b30aztenghui
468a95c8abb366d9c39450513335f550b56da13b30aztenghui        pathRenderer.mViewportWidth = a.getFloat(
469a95c8abb366d9c39450513335f550b56da13b30aztenghui                R.styleable.VectorDrawable_viewportWidth, pathRenderer.mViewportWidth);
470a95c8abb366d9c39450513335f550b56da13b30aztenghui        pathRenderer.mViewportHeight = a.getFloat(
471a95c8abb366d9c39450513335f550b56da13b30aztenghui                R.styleable.VectorDrawable_viewportHeight, pathRenderer.mViewportHeight);
472a95c8abb366d9c39450513335f550b56da13b30aztenghui
473a95c8abb366d9c39450513335f550b56da13b30aztenghui        if (pathRenderer.mViewportWidth <= 0) {
474a95c8abb366d9c39450513335f550b56da13b30aztenghui            throw new XmlPullParserException(a.getPositionDescription() +
4751c4d8b2173bf4b5bbac94748959752599775628dztenghui                    "<vector> tag requires viewportWidth > 0");
476a95c8abb366d9c39450513335f550b56da13b30aztenghui        } else if (pathRenderer.mViewportHeight <= 0) {
477a95c8abb366d9c39450513335f550b56da13b30aztenghui            throw new XmlPullParserException(a.getPositionDescription() +
4781c4d8b2173bf4b5bbac94748959752599775628dztenghui                    "<vector> tag requires viewportHeight > 0");
479a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
480a95c8abb366d9c39450513335f550b56da13b30aztenghui
481a95c8abb366d9c39450513335f550b56da13b30aztenghui        pathRenderer.mBaseWidth = a.getDimension(
482a95c8abb366d9c39450513335f550b56da13b30aztenghui                R.styleable.VectorDrawable_width, pathRenderer.mBaseWidth);
483a95c8abb366d9c39450513335f550b56da13b30aztenghui        pathRenderer.mBaseHeight = a.getDimension(
484a95c8abb366d9c39450513335f550b56da13b30aztenghui                R.styleable.VectorDrawable_height, pathRenderer.mBaseHeight);
485a95c8abb366d9c39450513335f550b56da13b30aztenghui
486a95c8abb366d9c39450513335f550b56da13b30aztenghui        if (pathRenderer.mBaseWidth <= 0) {
487a95c8abb366d9c39450513335f550b56da13b30aztenghui            throw new XmlPullParserException(a.getPositionDescription() +
4881c4d8b2173bf4b5bbac94748959752599775628dztenghui                    "<vector> tag requires width > 0");
489a95c8abb366d9c39450513335f550b56da13b30aztenghui        } else if (pathRenderer.mBaseHeight <= 0) {
490a95c8abb366d9c39450513335f550b56da13b30aztenghui            throw new XmlPullParserException(a.getPositionDescription() +
4911c4d8b2173bf4b5bbac94748959752599775628dztenghui                    "<vector> tag requires height > 0");
492a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
4939cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette    }
4949cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette
49555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui    private void inflateInternal(Resources res, XmlPullParser parser, AttributeSet attrs,
4968e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette            Theme theme) throws XmlPullParserException, IOException {
4978e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette        final VectorDrawableState state = mVectorState;
498a95c8abb366d9c39450513335f550b56da13b30aztenghui        final VPathRenderer pathRenderer = state.mVPathRenderer;
499abb7d134c02ac60091108c491dafb00877093170John Hoford        boolean noPathTag = true;
5009453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
5014d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        // Use a stack to help to build the group tree.
5024d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        // The top of the stack is always the current group.
5034d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        final Stack<VGroup> groupStack = new Stack<VGroup>();
5044d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        groupStack.push(pathRenderer.mRootGroup);
505abb7d134c02ac60091108c491dafb00877093170John Hoford
506abb7d134c02ac60091108c491dafb00877093170John Hoford        int eventType = parser.getEventType();
507abb7d134c02ac60091108c491dafb00877093170John Hoford        while (eventType != XmlPullParser.END_DOCUMENT) {
508abb7d134c02ac60091108c491dafb00877093170John Hoford            if (eventType == XmlPullParser.START_TAG) {
5099453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette                final String tagName = parser.getName();
5104d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                final VGroup currentGroup = groupStack.peek();
5114d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
512abb7d134c02ac60091108c491dafb00877093170John Hoford                if (SHAPE_PATH.equals(tagName)) {
513a95c8abb366d9c39450513335f550b56da13b30aztenghui                    final VFullPath path = new VFullPath();
5149453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette                    path.inflate(res, attrs, theme);
5158d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    currentGroup.mChildren.add(path);
516e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                    if (path.getPathName() != null) {
51755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui                        pathRenderer.mVGTargetsMap.put(path.getPathName(), path);
518e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                    }
519abb7d134c02ac60091108c491dafb00877093170John Hoford                    noPathTag = false;
5208e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette                    state.mChangingConfigurations |= path.mChangingConfigurations;
521a95c8abb366d9c39450513335f550b56da13b30aztenghui                } else if (SHAPE_CLIP_PATH.equals(tagName)) {
522a95c8abb366d9c39450513335f550b56da13b30aztenghui                    final VClipPath path = new VClipPath();
523a95c8abb366d9c39450513335f550b56da13b30aztenghui                    path.inflate(res, attrs, theme);
524a95c8abb366d9c39450513335f550b56da13b30aztenghui                    currentGroup.mChildren.add(path);
525a95c8abb366d9c39450513335f550b56da13b30aztenghui                    if (path.getPathName() != null) {
526a95c8abb366d9c39450513335f550b56da13b30aztenghui                        pathRenderer.mVGTargetsMap.put(path.getPathName(), path);
527a95c8abb366d9c39450513335f550b56da13b30aztenghui                    }
528a95c8abb366d9c39450513335f550b56da13b30aztenghui                    state.mChangingConfigurations |= path.mChangingConfigurations;
5296d9c422de5e0a3890dd723cb1b9264d4507053e9ztenghui                } else if (SHAPE_GROUP.equals(tagName)) {
5304d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                    VGroup newChildGroup = new VGroup();
5314d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                    newChildGroup.inflate(res, attrs, theme);
5328d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    currentGroup.mChildren.add(newChildGroup);
5334d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                    groupStack.push(newChildGroup);
534e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                    if (newChildGroup.getGroupName() != null) {
53555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui                        pathRenderer.mVGTargetsMap.put(newChildGroup.getGroupName(),
53655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui                                newChildGroup);
537e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                    }
5388e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette                    state.mChangingConfigurations |= newChildGroup.mChangingConfigurations;
539abb7d134c02ac60091108c491dafb00877093170John Hoford                }
5404d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            } else if (eventType == XmlPullParser.END_TAG) {
5414d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                final String tagName = parser.getName();
5424d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                if (SHAPE_GROUP.equals(tagName)) {
5434d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                    groupStack.pop();
5444d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                }
545abb7d134c02ac60091108c491dafb00877093170John Hoford            }
546abb7d134c02ac60091108c491dafb00877093170John Hoford            eventType = parser.next();
547abb7d134c02ac60091108c491dafb00877093170John Hoford        }
5489453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
5494d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        // Print the tree out for debug.
5504d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        if (DBG_VECTOR_DRAWABLE) {
5514d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            printGroupTree(pathRenderer.mRootGroup, 0);
5526d9c422de5e0a3890dd723cb1b9264d4507053e9ztenghui        }
5536d9c422de5e0a3890dd723cb1b9264d4507053e9ztenghui
554a95c8abb366d9c39450513335f550b56da13b30aztenghui        if (noPathTag) {
5559453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette            final StringBuffer tag = new StringBuffer();
5569453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
557a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (tag.length() > 0) {
558a95c8abb366d9c39450513335f550b56da13b30aztenghui                tag.append(" or ");
559abb7d134c02ac60091108c491dafb00877093170John Hoford            }
560a95c8abb366d9c39450513335f550b56da13b30aztenghui            tag.append(SHAPE_PATH);
5619453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
5629453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette            throw new XmlPullParserException("no " + tag + " defined");
563abb7d134c02ac60091108c491dafb00877093170John Hoford        }
564abb7d134c02ac60091108c491dafb00877093170John Hoford    }
565abb7d134c02ac60091108c491dafb00877093170John Hoford
5664d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui    private void printGroupTree(VGroup currentGroup, int level) {
5674d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        String indent = "";
5688d0d24f7a2b1a59060aa18926984491691d3c667ztenghui        for (int i = 0; i < level; i++) {
5694d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            indent += "    ";
5704d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
5714d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        // Print the current node
5728d0d24f7a2b1a59060aa18926984491691d3c667ztenghui        Log.v(LOGTAG, indent + "current group is :" + currentGroup.getGroupName()
5734d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                + " rotation is " + currentGroup.mRotate);
5748d0d24f7a2b1a59060aa18926984491691d3c667ztenghui        Log.v(LOGTAG, indent + "matrix is :" + currentGroup.getLocalMatrix().toString());
5758d0d24f7a2b1a59060aa18926984491691d3c667ztenghui        // Then print all the children groups
5768d0d24f7a2b1a59060aa18926984491691d3c667ztenghui        for (int i = 0; i < currentGroup.mChildren.size(); i++) {
5778d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            Object child = currentGroup.mChildren.get(i);
5788d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            if (child instanceof VGroup) {
5798d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                printGroupTree((VGroup) child, level + 1);
5808d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            }
5814d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
5824d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui    }
5834d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
58455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui    @Override
58555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui    public int getChangingConfigurations() {
58655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        return super.getChangingConfigurations() | mVectorState.mChangingConfigurations;
58755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui    }
58855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
589482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui    void setAllowCaching(boolean allowCaching) {
590482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        mAllowCaching = allowCaching;
591482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui    }
592482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui
593738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui    private boolean needMirroring() {
594738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui        return isAutoMirrored() && getLayoutDirection() == LayoutDirection.RTL;
595738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui    }
596738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui
597738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui    @Override
598738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui    public void setAutoMirrored(boolean mirrored) {
599738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui        if (mVectorState.mAutoMirrored != mirrored) {
600738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui            mVectorState.mAutoMirrored = mirrored;
601738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui            invalidateSelf();
602738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui        }
603738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui    }
604738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui
605738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui    @Override
606738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui    public boolean isAutoMirrored() {
607738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui        return mVectorState.mAutoMirrored;
608738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui    }
609738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui
6105c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette    private static class VectorDrawableState extends ConstantState {
6119cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette        int[] mThemeAttrs;
6125c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        int mChangingConfigurations;
613ddbbb8ae8561c9e61becd03faa40997d76ab5a51ztenghui        VPathRenderer mVPathRenderer;
614b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        ColorStateList mTint;
615b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette        Mode mTintMode;
616738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui        boolean mAutoMirrored;
6175c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette
618482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        Bitmap mCachedBitmap;
619482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        int[] mCachedThemeAttrs;
620482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        ColorStateList mCachedTint;
621482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        Mode mCachedTintMode;
622482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        int mCachedRootAlpha;
623670689af43358568bf2b5916284f1cac5762f428ztenghui        boolean mCachedAutoMirrored;
624670689af43358568bf2b5916284f1cac5762f428ztenghui        boolean mCacheDirty;
625482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui
62655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // Deep copy for mutate() or implicitly mutate.
6275c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        public VectorDrawableState(VectorDrawableState copy) {
6285c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette            if (copy != null) {
6299cd14fc710cf81cc6d1c47d599abe349d3aa87dcAlan Viverette                mThemeAttrs = copy.mThemeAttrs;
6305c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette                mChangingConfigurations = copy.mChangingConfigurations;
631ddbbb8ae8561c9e61becd03faa40997d76ab5a51ztenghui                mVPathRenderer = new VPathRenderer(copy.mVPathRenderer);
632b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette                mTint = copy.mTint;
633b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette                mTintMode = copy.mTintMode;
634738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui                mAutoMirrored = copy.mAutoMirrored;
6355c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette            }
6365c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        }
6375c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette
638482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        public boolean canReuseCache(int width, int height) {
639670689af43358568bf2b5916284f1cac5762f428ztenghui            if (!mCacheDirty
640670689af43358568bf2b5916284f1cac5762f428ztenghui                    && mCachedThemeAttrs == mThemeAttrs
641482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                    && mCachedTint == mTint
642482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                    && mCachedTintMode == mTintMode
643670689af43358568bf2b5916284f1cac5762f428ztenghui                    && mCachedAutoMirrored == mAutoMirrored
644482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                    && width == mCachedBitmap.getWidth()
645482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                    && height == mCachedBitmap.getHeight()
646482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                    && mCachedRootAlpha == mVPathRenderer.getRootAlpha())  {
647482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                return true;
648482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            }
649482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            return false;
650482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        }
651482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui
652482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        public void updateCacheStates() {
653482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            // Use shallow copy here and shallow comparison in canReuseCache(),
654482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            // likely hit cache miss more, but practically not much difference.
655482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            mCachedThemeAttrs = mThemeAttrs;
656482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            mCachedTint = mTint;
657482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            mCachedTintMode = mTintMode;
658482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            mCachedRootAlpha = mVPathRenderer.getRootAlpha();
659670689af43358568bf2b5916284f1cac5762f428ztenghui            mCachedAutoMirrored = mAutoMirrored;
660670689af43358568bf2b5916284f1cac5762f428ztenghui            mCacheDirty = false;
661482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        }
662482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui
66355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        public VectorDrawableState() {
66455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mVPathRenderer = new VPathRenderer();
66555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        }
66655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
6675c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        @Override
6685c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        public Drawable newDrawable() {
6695c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette            return new VectorDrawable(this, null, null);
6705c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        }
6715c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette
6725c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        @Override
6735c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        public Drawable newDrawable(Resources res) {
6745c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette            return new VectorDrawable(this, res, null);
6755c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        }
6765c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette
6775c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        @Override
6785c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        public Drawable newDrawable(Resources res, Theme theme) {
6795c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette            return new VectorDrawable(this, res, theme);
6805c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        }
6815c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette
6825c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        @Override
6835c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        public int getChangingConfigurations() {
6845c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette            return mChangingConfigurations;
6855c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        }
6865c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette    }
6875c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette
688ddbbb8ae8561c9e61becd03faa40997d76ab5a51ztenghui    private static class VPathRenderer {
6894d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        /* Right now the internal data structure is organized as a tree.
6904d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         * Each node can be a group node, or a path.
6914d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         * A group node can have groups or paths as children, but a path node has
6924d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         * no children.
6934d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         * One example can be:
6944d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *                 Root Group
6954d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *                /    |     \
6964d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *           Group    Path    Group
6974d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *          /     \             |
6984d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *         Path   Path         Path
6994d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *
7004d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         */
70155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // Variables that only used temporarily inside the draw() call, so there
70255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // is no need for deep copying.
7034b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        private final Path mPath = new Path();
7044b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        private final Path mRenderPath = new Path();
7054d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        private static final Matrix IDENTITY_MATRIX = new Matrix();
70655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        private final Matrix mFinalPathMatrix = new Matrix();
7074b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette
7084b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        private Paint mStrokePaint;
7094b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        private Paint mFillPaint;
710fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette        private ColorFilter mColorFilter;
711abb7d134c02ac60091108c491dafb00877093170John Hoford        private PathMeasure mPathMeasure;
7124b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette
71355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        /////////////////////////////////////////////////////
71455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // Variables below need to be copied (deep copy if applicable) for mutation.
7158e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette        private int mChangingConfigurations;
71655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        private final VGroup mRootGroup;
717a95c8abb366d9c39450513335f550b56da13b30aztenghui        float mBaseWidth = 0;
718a95c8abb366d9c39450513335f550b56da13b30aztenghui        float mBaseHeight = 0;
719a95c8abb366d9c39450513335f550b56da13b30aztenghui        float mViewportWidth = 0;
720a95c8abb366d9c39450513335f550b56da13b30aztenghui        float mViewportHeight = 0;
7212af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        private int mRootAlpha = 0xFF;
7229453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
72355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        final ArrayMap<String, Object> mVGTargetsMap = new ArrayMap<String, Object>();
724abb7d134c02ac60091108c491dafb00877093170John Hoford
725ddbbb8ae8561c9e61becd03faa40997d76ab5a51ztenghui        public VPathRenderer() {
7264d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            mRootGroup = new VGroup();
727abb7d134c02ac60091108c491dafb00877093170John Hoford        }
7289453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
7292af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        public void setRootAlpha(int alpha) {
7302af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui            mRootAlpha = alpha;
7312af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        }
7322af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui
7332af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        public int getRootAlpha() {
7342af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui            return mRootAlpha;
7352af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        }
7362af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui
737ddbbb8ae8561c9e61becd03faa40997d76ab5a51ztenghui        public VPathRenderer(VPathRenderer copy) {
73855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mRootGroup = new VGroup(copy.mRootGroup, mVGTargetsMap);
739abb7d134c02ac60091108c491dafb00877093170John Hoford            mBaseWidth = copy.mBaseWidth;
740abb7d134c02ac60091108c491dafb00877093170John Hoford            mBaseHeight = copy.mBaseHeight;
7415eb5cde467081d1af628e5463ba55f110265a86fztenghui            mViewportWidth = copy.mViewportWidth;
742abb7d134c02ac60091108c491dafb00877093170John Hoford            mViewportHeight = copy.mViewportHeight;
7438e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette            mChangingConfigurations = copy.mChangingConfigurations;
74455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mRootAlpha = copy.mRootAlpha;
745abb7d134c02ac60091108c491dafb00877093170John Hoford        }
746abb7d134c02ac60091108c491dafb00877093170John Hoford
7479453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        public boolean canApplyTheme() {
7484d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // If one of the paths can apply theme, then return true;
7494d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            return recursiveCanApplyTheme(mRootGroup);
7504d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
7514d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
7524d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        private boolean recursiveCanApplyTheme(VGroup currentGroup) {
7534d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // We can do a tree traverse here, if there is one path return true,
7544d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // then we return true for the whole tree.
7558d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            final ArrayList<Object> children = currentGroup.mChildren;
7568d0d24f7a2b1a59060aa18926984491691d3c667ztenghui
7578d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            for (int i = 0; i < children.size(); i++) {
7588d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                Object child = children.get(i);
7598d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                if (child instanceof VGroup) {
7608d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VGroup childGroup = (VGroup) child;
7618d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (childGroup.canApplyTheme()
7628d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                            || recursiveCanApplyTheme(childGroup)) {
7638d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        return true;
7648d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
7658d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                } else if (child instanceof VPath) {
7668d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VPath childPath = (VPath) child;
7678d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (childPath.canApplyTheme()) {
7688d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        return true;
7698d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
7704d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                }
7714d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            }
7729453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette            return false;
7739453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        }
7749453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
7759453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        public void applyTheme(Theme t) {
7764d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // Apply theme to every path of the tree.
7774d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            recursiveApplyTheme(mRootGroup, t);
7784d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
7794d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
7804d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        private void recursiveApplyTheme(VGroup currentGroup, Theme t) {
7814d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // We can do a tree traverse here, apply theme to all paths which
7824d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // can apply theme.
7838d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            final ArrayList<Object> children = currentGroup.mChildren;
7848d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            for (int i = 0; i < children.size(); i++) {
7858d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                Object child = children.get(i);
7868d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                if (child instanceof VGroup) {
7878d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VGroup childGroup = (VGroup) child;
7888d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (childGroup.canApplyTheme()) {
7898d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        childGroup.applyTheme(t);
7908d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
7918d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    recursiveApplyTheme(childGroup, t);
7928d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                } else if (child instanceof VPath) {
7938d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VPath childPath = (VPath) child;
7948d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (childPath.canApplyTheme()) {
7958d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        childPath.applyTheme(t);
7968d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
7974d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                }
7984d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            }
799abb7d134c02ac60091108c491dafb00877093170John Hoford        }
800abb7d134c02ac60091108c491dafb00877093170John Hoford
801fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette        public void setColorFilter(ColorFilter colorFilter) {
802fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette            mColorFilter = colorFilter;
803fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette
804fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette            if (mFillPaint != null) {
805fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette                mFillPaint.setColorFilter(colorFilter);
806fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette            }
807fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette
808fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette            if (mStrokePaint != null) {
809fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette                mStrokePaint.setColorFilter(colorFilter);
810fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette            }
8116d9c422de5e0a3890dd723cb1b9264d4507053e9ztenghui
812fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette        }
813fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette
8144d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        private void drawGroupTree(VGroup currentGroup, Matrix currentMatrix,
8152af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui                float currentAlpha, Canvas canvas, int w, int h) {
8164d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // Calculate current group's matrix by preConcat the parent's and
8174d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // and the current one on the top of the stack.
8184d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // Basically the Mfinal = Mviewport * M0 * M1 * M2;
8194d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // Mi the local matrix at level i of the group tree.
8204d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            currentGroup.mStackedMatrix.set(currentMatrix);
8214d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
8224d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            currentGroup.mStackedMatrix.preConcat(currentGroup.mLocalMatrix);
8234d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
8242af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui            float stackedAlpha = currentAlpha * currentGroup.mGroupAlpha;
8258d0d24f7a2b1a59060aa18926984491691d3c667ztenghui
8268d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            // Draw the group tree in the same order as the XML file.
8278d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            for (int i = 0; i < currentGroup.mChildren.size(); i++) {
8288d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                Object child = currentGroup.mChildren.get(i);
8298d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                if (child instanceof VGroup) {
8308d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VGroup childGroup = (VGroup) child;
8318d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    drawGroupTree(childGroup, currentGroup.mStackedMatrix,
8328d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                            stackedAlpha, canvas, w, h);
8338d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                } else if (child instanceof VPath) {
8348d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VPath childPath = (VPath) child;
8358d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    drawPath(currentGroup, childPath, stackedAlpha, canvas, w, h);
8368d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                }
837abb7d134c02ac60091108c491dafb00877093170John Hoford            }
8384d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
839abb7d134c02ac60091108c491dafb00877093170John Hoford
8404d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        public void draw(Canvas canvas, int w, int h) {
8414d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // Travese the tree in pre-order to draw.
842a95c8abb366d9c39450513335f550b56da13b30aztenghui            drawGroupTree(mRootGroup, IDENTITY_MATRIX, ((float) mRootAlpha) / 0xFF,
843a95c8abb366d9c39450513335f550b56da13b30aztenghui                    canvas, w, h);
844abb7d134c02ac60091108c491dafb00877093170John Hoford        }
845abb7d134c02ac60091108c491dafb00877093170John Hoford
8468d0d24f7a2b1a59060aa18926984491691d3c667ztenghui        private void drawPath(VGroup vGroup, VPath vPath, float stackedAlpha,
8478d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                Canvas canvas, int w, int h) {
8489d59a76dd0e850558e83ef1a48fefd865fac1336ztenghui            final float scaleX =  w / mViewportWidth;
8499d59a76dd0e850558e83ef1a48fefd865fac1336ztenghui            final float scaleY = h / mViewportHeight;
8509d59a76dd0e850558e83ef1a48fefd865fac1336ztenghui            final float minScale = Math.min(scaleX, scaleY);
851abb7d134c02ac60091108c491dafb00877093170John Hoford
8524d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            mFinalPathMatrix.set(vGroup.mStackedMatrix);
8535a836f74df027bb568da17fbde4e641b6a56d2a9ztenghui            mFinalPathMatrix.postScale(scaleX, scaleY);
854abb7d134c02ac60091108c491dafb00877093170John Hoford
8558d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            vPath.toPath(mPath);
8568d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            final Path path = mPath;
857abb7d134c02ac60091108c491dafb00877093170John Hoford
8588d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            mRenderPath.reset();
8599453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
860a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (vPath.isClipPath()) {
861a95c8abb366d9c39450513335f550b56da13b30aztenghui                mRenderPath.addPath(path, mFinalPathMatrix);
8628d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                canvas.clipPath(mRenderPath, Region.Op.REPLACE);
8638d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            } else {
864a95c8abb366d9c39450513335f550b56da13b30aztenghui                VFullPath fullPath = (VFullPath) vPath;
865a95c8abb366d9c39450513335f550b56da13b30aztenghui                if (fullPath.mTrimPathStart != 0.0f || fullPath.mTrimPathEnd != 1.0f) {
866a95c8abb366d9c39450513335f550b56da13b30aztenghui                    float start = (fullPath.mTrimPathStart + fullPath.mTrimPathOffset) % 1.0f;
867a95c8abb366d9c39450513335f550b56da13b30aztenghui                    float end = (fullPath.mTrimPathEnd + fullPath.mTrimPathOffset) % 1.0f;
868a95c8abb366d9c39450513335f550b56da13b30aztenghui
869a95c8abb366d9c39450513335f550b56da13b30aztenghui                    if (mPathMeasure == null) {
870a95c8abb366d9c39450513335f550b56da13b30aztenghui                        mPathMeasure = new PathMeasure();
871a95c8abb366d9c39450513335f550b56da13b30aztenghui                    }
872a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mPathMeasure.setPath(mPath, false);
873a95c8abb366d9c39450513335f550b56da13b30aztenghui
874a95c8abb366d9c39450513335f550b56da13b30aztenghui                    float len = mPathMeasure.getLength();
875a95c8abb366d9c39450513335f550b56da13b30aztenghui                    start = start * len;
876a95c8abb366d9c39450513335f550b56da13b30aztenghui                    end = end * len;
877a95c8abb366d9c39450513335f550b56da13b30aztenghui                    path.reset();
878a95c8abb366d9c39450513335f550b56da13b30aztenghui                    if (start > end) {
879a95c8abb366d9c39450513335f550b56da13b30aztenghui                        mPathMeasure.getSegment(start, len, path, true);
880a95c8abb366d9c39450513335f550b56da13b30aztenghui                        mPathMeasure.getSegment(0f, end, path, true);
881a95c8abb366d9c39450513335f550b56da13b30aztenghui                    } else {
882a95c8abb366d9c39450513335f550b56da13b30aztenghui                        mPathMeasure.getSegment(start, end, path, true);
883a95c8abb366d9c39450513335f550b56da13b30aztenghui                    }
884a95c8abb366d9c39450513335f550b56da13b30aztenghui                    path.rLineTo(0, 0); // fix bug in measure
885a95c8abb366d9c39450513335f550b56da13b30aztenghui                }
886a95c8abb366d9c39450513335f550b56da13b30aztenghui                mRenderPath.addPath(path, mFinalPathMatrix);
887a95c8abb366d9c39450513335f550b56da13b30aztenghui
888a70b4742a7a0b2edc57cbbbf83d2c6d43ebc300dztenghui                if (fullPath.mFillColor != Color.TRANSPARENT) {
8898d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (mFillPaint == null) {
8908d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mFillPaint = new Paint();
8918d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mFillPaint.setColorFilter(mColorFilter);
8928d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mFillPaint.setStyle(Paint.Style.FILL);
8938d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mFillPaint.setAntiAlias(true);
89463cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui                    }
895a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mFillPaint.setColor(applyAlpha(fullPath.mFillColor, stackedAlpha));
8968d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    canvas.drawPath(mRenderPath, mFillPaint);
8978d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                }
89863cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
899a70b4742a7a0b2edc57cbbbf83d2c6d43ebc300dztenghui                if (fullPath.mStrokeColor != Color.TRANSPARENT) {
9008d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (mStrokePaint == null) {
9018d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mStrokePaint = new Paint();
9028d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mStrokePaint.setColorFilter(mColorFilter);
9038d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mStrokePaint.setStyle(Paint.Style.STROKE);
9048d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mStrokePaint.setAntiAlias(true);
9058d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
9064b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette
9078d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    final Paint strokePaint = mStrokePaint;
908a95c8abb366d9c39450513335f550b56da13b30aztenghui                    if (fullPath.mStrokeLineJoin != null) {
909a95c8abb366d9c39450513335f550b56da13b30aztenghui                        strokePaint.setStrokeJoin(fullPath.mStrokeLineJoin);
9108d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
911abb7d134c02ac60091108c491dafb00877093170John Hoford
912a95c8abb366d9c39450513335f550b56da13b30aztenghui                    if (fullPath.mStrokeLineCap != null) {
913a95c8abb366d9c39450513335f550b56da13b30aztenghui                        strokePaint.setStrokeCap(fullPath.mStrokeLineCap);
9148d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
91563cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
916c4d651ec8a8c190c5df173166357c2fdf47472ceztenghui                    strokePaint.setStrokeMiter(fullPath.mStrokeMiterlimit);
91763cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
918a95c8abb366d9c39450513335f550b56da13b30aztenghui                    strokePaint.setColor(applyAlpha(fullPath.mStrokeColor, stackedAlpha));
919a95c8abb366d9c39450513335f550b56da13b30aztenghui                    strokePaint.setStrokeWidth(fullPath.mStrokeWidth * minScale);
9208d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    canvas.drawPath(mRenderPath, strokePaint);
92163cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui                }
922abb7d134c02ac60091108c491dafb00877093170John Hoford            }
923abb7d134c02ac60091108c491dafb00877093170John Hoford        }
924abb7d134c02ac60091108c491dafb00877093170John Hoford    }
925abb7d134c02ac60091108c491dafb00877093170John Hoford
926a95c8abb366d9c39450513335f550b56da13b30aztenghui    private static class VGroup {
92755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // mStackedMatrix is only used temporarily when drawing, it combines all
92855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // the parents' local matrices with the current one.
92955f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        private final Matrix mStackedMatrix = new Matrix();
93055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
93155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        /////////////////////////////////////////////////////
93255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // Variables below need to be copied (deep copy if applicable) for mutation.
9338d0d24f7a2b1a59060aa18926984491691d3c667ztenghui        final ArrayList<Object> mChildren = new ArrayList<Object>();
934abb7d134c02ac60091108c491dafb00877093170John Hoford
93563cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui        private float mRotate = 0;
93663cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui        private float mPivotX = 0;
93763cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui        private float mPivotY = 0;
938452f6ece7fe2fd1a85fca53f54e90bf041083b21ztenghui        private float mScaleX = 1;
939452f6ece7fe2fd1a85fca53f54e90bf041083b21ztenghui        private float mScaleY = 1;
940452f6ece7fe2fd1a85fca53f54e90bf041083b21ztenghui        private float mTranslateX = 0;
941452f6ece7fe2fd1a85fca53f54e90bf041083b21ztenghui        private float mTranslateY = 0;
9422af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        private float mGroupAlpha = 1;
9434d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
94455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // mLocalMatrix is updated based on the update of transformation information,
94555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // either parsed from the XML or by animation.
9464d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        private final Matrix mLocalMatrix = new Matrix();
9478e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette        private int mChangingConfigurations;
94863cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui        private int[] mThemeAttrs;
949e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        private String mGroupName = null;
950e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
95155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        public VGroup(VGroup copy, ArrayMap<String, Object> targetsMap) {
95255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mRotate = copy.mRotate;
95355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mPivotX = copy.mPivotX;
95455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mPivotY = copy.mPivotY;
95555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mScaleX = copy.mScaleX;
95655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mScaleY = copy.mScaleY;
95755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mTranslateX = copy.mTranslateX;
95855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mTranslateY = copy.mTranslateY;
95955f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mGroupAlpha = copy.mGroupAlpha;
96055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mThemeAttrs = copy.mThemeAttrs;
96155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mGroupName = copy.mGroupName;
96255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mChangingConfigurations = copy.mChangingConfigurations;
96355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            if (mGroupName != null) {
96455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui                targetsMap.put(mGroupName, this);
96555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            }
96655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
96755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mLocalMatrix.set(copy.mLocalMatrix);
96855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
9698d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            final ArrayList<Object> children = copy.mChildren;
9708d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            for (int i = 0; i < children.size(); i++) {
9718d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                Object copyChild = children.get(i);
9728d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                if (copyChild instanceof VGroup) {
9738d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VGroup copyGroup = (VGroup) copyChild;
9748d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    mChildren.add(new VGroup(copyGroup, targetsMap));
975a95c8abb366d9c39450513335f550b56da13b30aztenghui                } else {
976a95c8abb366d9c39450513335f550b56da13b30aztenghui                    VPath newPath = null;
977a95c8abb366d9c39450513335f550b56da13b30aztenghui                    if (copyChild instanceof VFullPath) {
978a95c8abb366d9c39450513335f550b56da13b30aztenghui                        newPath = new VFullPath((VFullPath) copyChild);
979a95c8abb366d9c39450513335f550b56da13b30aztenghui                    } else if (copyChild instanceof VClipPath) {
980a95c8abb366d9c39450513335f550b56da13b30aztenghui                        newPath = new VClipPath((VClipPath) copyChild);
981a95c8abb366d9c39450513335f550b56da13b30aztenghui                    } else {
982a95c8abb366d9c39450513335f550b56da13b30aztenghui                        throw new IllegalStateException("Unknown object in the tree!");
983a95c8abb366d9c39450513335f550b56da13b30aztenghui                    }
9848d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    mChildren.add(newPath);
9858d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (newPath.mPathName != null) {
9868d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        targetsMap.put(newPath.mPathName, newPath);
9878d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
98855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui                }
98955f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            }
99055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        }
99155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
99255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        public VGroup() {
99355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        }
99455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
995a95c8abb366d9c39450513335f550b56da13b30aztenghui        public String getGroupName() {
996a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mGroupName;
997a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
998a95c8abb366d9c39450513335f550b56da13b30aztenghui
999a95c8abb366d9c39450513335f550b56da13b30aztenghui        public Matrix getLocalMatrix() {
1000a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mLocalMatrix;
1001a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1002a95c8abb366d9c39450513335f550b56da13b30aztenghui
1003a95c8abb366d9c39450513335f550b56da13b30aztenghui        public boolean canApplyTheme() {
1004a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mThemeAttrs != null;
1005a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1006a95c8abb366d9c39450513335f550b56da13b30aztenghui
1007a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void inflate(Resources res, AttributeSet attrs, Theme theme) {
1008a95c8abb366d9c39450513335f550b56da13b30aztenghui            final TypedArray a = obtainAttributes(res, theme, attrs,
1009a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawableGroup);
1010a95c8abb366d9c39450513335f550b56da13b30aztenghui            updateStateFromTypedArray(a);
1011a95c8abb366d9c39450513335f550b56da13b30aztenghui            a.recycle();
1012a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1013a95c8abb366d9c39450513335f550b56da13b30aztenghui
1014a95c8abb366d9c39450513335f550b56da13b30aztenghui        private void updateStateFromTypedArray(TypedArray a) {
1015a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Account for any configuration changes.
1016a95c8abb366d9c39450513335f550b56da13b30aztenghui            mChangingConfigurations |= a.getChangingConfigurations();
1017a95c8abb366d9c39450513335f550b56da13b30aztenghui
1018a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Extract the theme attributes, if any.
1019a95c8abb366d9c39450513335f550b56da13b30aztenghui            mThemeAttrs = a.extractThemeAttrs();
1020a95c8abb366d9c39450513335f550b56da13b30aztenghui
1021a95c8abb366d9c39450513335f550b56da13b30aztenghui            mRotate = a.getFloat(R.styleable.VectorDrawableGroup_rotation, mRotate);
1022a95c8abb366d9c39450513335f550b56da13b30aztenghui            mPivotX = a.getFloat(R.styleable.VectorDrawableGroup_pivotX, mPivotX);
1023a95c8abb366d9c39450513335f550b56da13b30aztenghui            mPivotY = a.getFloat(R.styleable.VectorDrawableGroup_pivotY, mPivotY);
1024a95c8abb366d9c39450513335f550b56da13b30aztenghui            mScaleX = a.getFloat(R.styleable.VectorDrawableGroup_scaleX, mScaleX);
1025a95c8abb366d9c39450513335f550b56da13b30aztenghui            mScaleY = a.getFloat(R.styleable.VectorDrawableGroup_scaleY, mScaleY);
1026a95c8abb366d9c39450513335f550b56da13b30aztenghui            mTranslateX = a.getFloat(R.styleable.VectorDrawableGroup_translateX, mTranslateX);
1027a95c8abb366d9c39450513335f550b56da13b30aztenghui            mTranslateY = a.getFloat(R.styleable.VectorDrawableGroup_translateY, mTranslateY);
1028a95c8abb366d9c39450513335f550b56da13b30aztenghui            mGroupAlpha = a.getFloat(R.styleable.VectorDrawableGroup_alpha, mGroupAlpha);
1029a95c8abb366d9c39450513335f550b56da13b30aztenghui
1030a95c8abb366d9c39450513335f550b56da13b30aztenghui            final String groupName = a.getString(R.styleable.VectorDrawableGroup_name);
1031a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (groupName != null) {
1032a95c8abb366d9c39450513335f550b56da13b30aztenghui                mGroupName = groupName;
1033a95c8abb366d9c39450513335f550b56da13b30aztenghui            }
1034a95c8abb366d9c39450513335f550b56da13b30aztenghui
1035a95c8abb366d9c39450513335f550b56da13b30aztenghui            updateLocalMatrix();
1036a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1037a95c8abb366d9c39450513335f550b56da13b30aztenghui
1038a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void applyTheme(Theme t) {
1039a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (mThemeAttrs == null) {
1040a95c8abb366d9c39450513335f550b56da13b30aztenghui                return;
1041a95c8abb366d9c39450513335f550b56da13b30aztenghui            }
1042a95c8abb366d9c39450513335f550b56da13b30aztenghui
1043a95c8abb366d9c39450513335f550b56da13b30aztenghui            final TypedArray a = t.resolveAttributes(mThemeAttrs,
1044a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawableGroup);
1045a95c8abb366d9c39450513335f550b56da13b30aztenghui            updateStateFromTypedArray(a);
1046a95c8abb366d9c39450513335f550b56da13b30aztenghui            a.recycle();
1047a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1048a95c8abb366d9c39450513335f550b56da13b30aztenghui
1049a95c8abb366d9c39450513335f550b56da13b30aztenghui        private void updateLocalMatrix() {
1050a95c8abb366d9c39450513335f550b56da13b30aztenghui            // The order we apply is the same as the
1051a95c8abb366d9c39450513335f550b56da13b30aztenghui            // RenderNode.cpp::applyViewPropertyTransforms().
1052a95c8abb366d9c39450513335f550b56da13b30aztenghui            mLocalMatrix.reset();
1053a95c8abb366d9c39450513335f550b56da13b30aztenghui            mLocalMatrix.postTranslate(-mPivotX, -mPivotY);
1054a95c8abb366d9c39450513335f550b56da13b30aztenghui            mLocalMatrix.postScale(mScaleX, mScaleY);
1055a95c8abb366d9c39450513335f550b56da13b30aztenghui            mLocalMatrix.postRotate(mRotate, 0, 0);
1056a95c8abb366d9c39450513335f550b56da13b30aztenghui            mLocalMatrix.postTranslate(mTranslateX + mPivotX, mTranslateY + mPivotY);
1057a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1058a95c8abb366d9c39450513335f550b56da13b30aztenghui
1059a95c8abb366d9c39450513335f550b56da13b30aztenghui        /* Setters and Getters, used by animator from AnimatedVectorDrawable. */
1060a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1061e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getRotation() {
1062e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mRotate;
1063e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1064e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1065a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1066e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setRotation(float rotation) {
1067e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (rotation != mRotate) {
1068e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mRotate = rotation;
1069e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1070e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1071e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1072e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1073a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1074e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getPivotX() {
1075e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mPivotX;
1076e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1077e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1078a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1079e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setPivotX(float pivotX) {
1080e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (pivotX != mPivotX) {
1081e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mPivotX = pivotX;
1082e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1083e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1084e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1085e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1086a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1087e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getPivotY() {
1088e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mPivotY;
1089e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1090e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1091a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1092e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setPivotY(float pivotY) {
1093e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (pivotY != mPivotY) {
1094e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mPivotY = pivotY;
1095e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1096e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1097e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1098e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1099a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1100e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getScaleX() {
1101e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mScaleX;
1102e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
11034d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1104a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1105e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setScaleX(float scaleX) {
1106e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (scaleX != mScaleX) {
1107e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mScaleX = scaleX;
1108e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1109e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1110e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1111e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1112a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1113e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getScaleY() {
1114e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mScaleY;
1115e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1116e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1117a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1118e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setScaleY(float scaleY) {
1119e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (scaleY != mScaleY) {
1120e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mScaleY = scaleY;
1121e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1122e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1123e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1124e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1125a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1126e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getTranslateX() {
1127e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mTranslateX;
1128e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1129e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1130a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1131e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setTranslateX(float translateX) {
1132e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (translateX != mTranslateX) {
1133e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mTranslateX = translateX;
1134e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1135e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1136e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1137e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1138a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1139e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getTranslateY() {
1140e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mTranslateY;
1141e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1142e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1143a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1144e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setTranslateY(float translateY) {
1145e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (translateY != mTranslateY) {
1146e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mTranslateY = translateY;
1147e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1148e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1149e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1150e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1151a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1152e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getAlpha() {
1153e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mGroupAlpha;
1154e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1155e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1156a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1157e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setAlpha(float groupAlpha) {
1158e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (groupAlpha != mGroupAlpha) {
1159e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mGroupAlpha = groupAlpha;
1160e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1161e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1162a95c8abb366d9c39450513335f550b56da13b30aztenghui    }
1163e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1164a95c8abb366d9c39450513335f550b56da13b30aztenghui    /**
1165a95c8abb366d9c39450513335f550b56da13b30aztenghui     * Common Path information for clip path and normal path.
1166a95c8abb366d9c39450513335f550b56da13b30aztenghui     */
1167a95c8abb366d9c39450513335f550b56da13b30aztenghui    private static class VPath {
1168a95c8abb366d9c39450513335f550b56da13b30aztenghui        protected PathParser.PathDataNode[] mNodes = null;
1169a95c8abb366d9c39450513335f550b56da13b30aztenghui        String mPathName;
1170a95c8abb366d9c39450513335f550b56da13b30aztenghui        int mChangingConfigurations;
1171a95c8abb366d9c39450513335f550b56da13b30aztenghui
1172a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VPath() {
1173a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Empty constructor.
11744d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
11754d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1176a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VPath(VPath copy) {
1177a95c8abb366d9c39450513335f550b56da13b30aztenghui            mPathName = copy.mPathName;
1178a95c8abb366d9c39450513335f550b56da13b30aztenghui            mChangingConfigurations = copy.mChangingConfigurations;
1179a95c8abb366d9c39450513335f550b56da13b30aztenghui            mNodes = PathParser.deepCopyNodes(copy.mNodes);
11804d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
11814d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1182a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void toPath(Path path) {
1183a95c8abb366d9c39450513335f550b56da13b30aztenghui            path.reset();
1184a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (mNodes != null) {
1185a95c8abb366d9c39450513335f550b56da13b30aztenghui                PathParser.PathDataNode.nodesToPath(mNodes, path);
1186a95c8abb366d9c39450513335f550b56da13b30aztenghui            }
11874d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
11884d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1189a95c8abb366d9c39450513335f550b56da13b30aztenghui        public String getPathName() {
1190a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mPathName;
11918e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette        }
11928e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette
1193a95c8abb366d9c39450513335f550b56da13b30aztenghui        public boolean canApplyTheme() {
1194a95c8abb366d9c39450513335f550b56da13b30aztenghui            return false;
1195a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
119663cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
1197a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void applyTheme(Theme t) {
1198a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
119963cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
1200a95c8abb366d9c39450513335f550b56da13b30aztenghui        public boolean isClipPath() {
1201a95c8abb366d9c39450513335f550b56da13b30aztenghui            return false;
1202a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
120363cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
1204a95c8abb366d9c39450513335f550b56da13b30aztenghui        /* Setters and Getters, used by animator from AnimatedVectorDrawable. */
1205a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1206a95c8abb366d9c39450513335f550b56da13b30aztenghui        public PathParser.PathDataNode[] getPathData() {
1207a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mNodes;
1208a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1209a95c8abb366d9c39450513335f550b56da13b30aztenghui
1210a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1211a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void setPathData(PathParser.PathDataNode[] nodes) {
1212a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (!PathParser.canMorph(mNodes, nodes)) {
1213a95c8abb366d9c39450513335f550b56da13b30aztenghui                // This should not happen in the middle of animation.
1214a95c8abb366d9c39450513335f550b56da13b30aztenghui                mNodes = PathParser.deepCopyNodes(nodes);
1215a95c8abb366d9c39450513335f550b56da13b30aztenghui            } else {
1216a95c8abb366d9c39450513335f550b56da13b30aztenghui                PathParser.updateNodes(mNodes, nodes);
121763cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui            }
1218a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1219a95c8abb366d9c39450513335f550b56da13b30aztenghui    }
122063cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
1221a95c8abb366d9c39450513335f550b56da13b30aztenghui    /**
1222a95c8abb366d9c39450513335f550b56da13b30aztenghui     * Clip path, which only has name and pathData.
1223a95c8abb366d9c39450513335f550b56da13b30aztenghui     */
1224a95c8abb366d9c39450513335f550b56da13b30aztenghui    private static class VClipPath extends VPath{
1225a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VClipPath() {
1226a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Empty constructor.
12278e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette        }
12284d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1229a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VClipPath(VClipPath copy) {
1230a95c8abb366d9c39450513335f550b56da13b30aztenghui            super(copy);
1231a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
12324d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1233a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void inflate(Resources r, AttributeSet attrs, Theme theme) {
1234a95c8abb366d9c39450513335f550b56da13b30aztenghui            final TypedArray a = obtainAttributes(r, theme, attrs,
1235a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawableClipPath);
12368e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette            updateStateFromTypedArray(a);
123763cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui            a.recycle();
123863cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui        }
123963cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
1240a95c8abb366d9c39450513335f550b56da13b30aztenghui        private void updateStateFromTypedArray(TypedArray a) {
1241a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Account for any configuration changes.
1242a95c8abb366d9c39450513335f550b56da13b30aztenghui            mChangingConfigurations |= a.getChangingConfigurations();
1243a95c8abb366d9c39450513335f550b56da13b30aztenghui
1244a95c8abb366d9c39450513335f550b56da13b30aztenghui            mPathName = a.getString(R.styleable.VectorDrawableClipPath_name);
1245a95c8abb366d9c39450513335f550b56da13b30aztenghui            mNodes = PathParser.createNodesFromPathData(a.getString(
1246a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawableClipPath_pathData));
1247a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1248a95c8abb366d9c39450513335f550b56da13b30aztenghui
1249a95c8abb366d9c39450513335f550b56da13b30aztenghui        @Override
1250a95c8abb366d9c39450513335f550b56da13b30aztenghui        public boolean isClipPath() {
1251a95c8abb366d9c39450513335f550b56da13b30aztenghui            return true;
12524d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
1253abb7d134c02ac60091108c491dafb00877093170John Hoford    }
1254abb7d134c02ac60091108c491dafb00877093170John Hoford
1255a95c8abb366d9c39450513335f550b56da13b30aztenghui    /**
1256a95c8abb366d9c39450513335f550b56da13b30aztenghui     * Normal path, which contains all the fill / paint information.
1257a95c8abb366d9c39450513335f550b56da13b30aztenghui     */
1258a95c8abb366d9c39450513335f550b56da13b30aztenghui    private static class VFullPath extends VPath {
125955f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        /////////////////////////////////////////////////////
126055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // Variables below need to be copied (deep copy if applicable) for mutation.
12619453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        private int[] mThemeAttrs;
12629453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
1263a70b4742a7a0b2edc57cbbbf83d2c6d43ebc300dztenghui        int mStrokeColor = Color.TRANSPARENT;
1264abb7d134c02ac60091108c491dafb00877093170John Hoford        float mStrokeWidth = 0;
1265a70b4742a7a0b2edc57cbbbf83d2c6d43ebc300dztenghui        int mFillColor = Color.TRANSPARENT;
1266abb7d134c02ac60091108c491dafb00877093170John Hoford        int mFillRule;
1267abb7d134c02ac60091108c491dafb00877093170John Hoford        float mTrimPathStart = 0;
1268abb7d134c02ac60091108c491dafb00877093170John Hoford        float mTrimPathEnd = 1;
1269abb7d134c02ac60091108c491dafb00877093170John Hoford        float mTrimPathOffset = 0;
12709453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
12714b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        Paint.Cap mStrokeLineCap = Paint.Cap.BUTT;
12724b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        Paint.Join mStrokeLineJoin = Paint.Join.MITER;
1273abb7d134c02ac60091108c491dafb00877093170John Hoford        float mStrokeMiterlimit = 4;
12749453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
1275a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VFullPath() {
12769453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette            // Empty constructor.
12779453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        }
12789453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
1279a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VFullPath(VFullPath copy) {
1280a95c8abb366d9c39450513335f550b56da13b30aztenghui            super(copy);
128155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mThemeAttrs = copy.mThemeAttrs;
128255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
128355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mStrokeColor = copy.mStrokeColor;
128455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mStrokeWidth = copy.mStrokeWidth;
128555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mFillColor = copy.mFillColor;
128655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mFillRule = copy.mFillRule;
128755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mTrimPathStart = copy.mTrimPathStart;
128855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mTrimPathEnd = copy.mTrimPathEnd;
128955f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mTrimPathOffset = copy.mTrimPathOffset;
129055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
129155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mStrokeLineCap = copy.mStrokeLineCap;
129255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mStrokeLineJoin = copy.mStrokeLineJoin;
129355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mStrokeMiterlimit = copy.mStrokeMiterlimit;
1294abb7d134c02ac60091108c491dafb00877093170John Hoford        }
1295abb7d134c02ac60091108c491dafb00877093170John Hoford
12967f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette        private Paint.Cap getStrokeLineCap(int id, Paint.Cap defValue) {
12977f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette            switch (id) {
12987f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINECAP_BUTT:
12997f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Cap.BUTT;
13007f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINECAP_ROUND:
13017f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Cap.ROUND;
13027f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINECAP_SQUARE:
13037f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Cap.SQUARE;
13047f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                default:
13057f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return defValue;
13067f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette            }
13077f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette        }
13087f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette
13097f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette        private Paint.Join getStrokeLineJoin(int id, Paint.Join defValue) {
13107f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette            switch (id) {
13117f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINEJOIN_MITER:
13127f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Join.MITER;
13137f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINEJOIN_ROUND:
13147f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Join.ROUND;
13157f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINEJOIN_BEVEL:
13167f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Join.BEVEL;
13177f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                default:
13187f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return defValue;
13197f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette            }
13207f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette        }
13217f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette
1322a95c8abb366d9c39450513335f550b56da13b30aztenghui        @Override
1323a95c8abb366d9c39450513335f550b56da13b30aztenghui        public boolean canApplyTheme() {
1324a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mThemeAttrs != null;
1325eb034fbca40006c55db143047eb628c4b657730aztenghui        }
1326eb034fbca40006c55db143047eb628c4b657730aztenghui
1327a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void inflate(Resources r, AttributeSet attrs, Theme theme) {
1328a95c8abb366d9c39450513335f550b56da13b30aztenghui            final TypedArray a = obtainAttributes(r, theme, attrs,
1329a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath);
1330a95c8abb366d9c39450513335f550b56da13b30aztenghui            updateStateFromTypedArray(a);
1331a95c8abb366d9c39450513335f550b56da13b30aztenghui            a.recycle();
1332a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1333a95c8abb366d9c39450513335f550b56da13b30aztenghui
1334a95c8abb366d9c39450513335f550b56da13b30aztenghui        private void updateStateFromTypedArray(TypedArray a) {
1335a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Account for any configuration changes.
1336a95c8abb366d9c39450513335f550b56da13b30aztenghui            mChangingConfigurations |= a.getChangingConfigurations();
1337a95c8abb366d9c39450513335f550b56da13b30aztenghui
1338a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Extract the theme attributes, if any.
1339a95c8abb366d9c39450513335f550b56da13b30aztenghui            mThemeAttrs = a.extractThemeAttrs();
1340a95c8abb366d9c39450513335f550b56da13b30aztenghui
1341a95c8abb366d9c39450513335f550b56da13b30aztenghui            mPathName = a.getString(R.styleable.VectorDrawablePath_name);
1342a95c8abb366d9c39450513335f550b56da13b30aztenghui            mNodes = PathParser.createNodesFromPathData(a.getString(
1343a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_pathData));
1344a95c8abb366d9c39450513335f550b56da13b30aztenghui
1345a95c8abb366d9c39450513335f550b56da13b30aztenghui            mFillColor = a.getColor(R.styleable.VectorDrawablePath_fillColor,
1346a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mFillColor);
1347a95c8abb366d9c39450513335f550b56da13b30aztenghui            mStrokeLineCap = getStrokeLineCap(a.getInt(
1348a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_strokeLineCap, -1), mStrokeLineCap);
1349a95c8abb366d9c39450513335f550b56da13b30aztenghui            mStrokeLineJoin = getStrokeLineJoin(a.getInt(
1350a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_strokeLineJoin, -1), mStrokeLineJoin);
1351a95c8abb366d9c39450513335f550b56da13b30aztenghui            mStrokeMiterlimit = a.getFloat(
1352a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_strokeMiterLimit, mStrokeMiterlimit);
1353a95c8abb366d9c39450513335f550b56da13b30aztenghui            mStrokeColor = a.getColor(R.styleable.VectorDrawablePath_strokeColor,
1354a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mStrokeColor);
1355a95c8abb366d9c39450513335f550b56da13b30aztenghui            mStrokeWidth = a.getFloat(R.styleable.VectorDrawablePath_strokeWidth,
1356a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mStrokeWidth);
1357a95c8abb366d9c39450513335f550b56da13b30aztenghui            mTrimPathEnd = a.getFloat(R.styleable.VectorDrawablePath_trimPathEnd,
1358a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mTrimPathEnd);
1359a95c8abb366d9c39450513335f550b56da13b30aztenghui            mTrimPathOffset = a.getFloat(
1360a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_trimPathOffset, mTrimPathOffset);
1361a95c8abb366d9c39450513335f550b56da13b30aztenghui            mTrimPathStart = a.getFloat(
1362a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_trimPathStart, mTrimPathStart);
1363a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1364a95c8abb366d9c39450513335f550b56da13b30aztenghui
1365a95c8abb366d9c39450513335f550b56da13b30aztenghui        @Override
1366a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void applyTheme(Theme t) {
1367a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (mThemeAttrs == null) {
1368a95c8abb366d9c39450513335f550b56da13b30aztenghui                return;
1369a95c8abb366d9c39450513335f550b56da13b30aztenghui            }
1370a95c8abb366d9c39450513335f550b56da13b30aztenghui
1371a95c8abb366d9c39450513335f550b56da13b30aztenghui            final TypedArray a = t.resolveAttributes(mThemeAttrs,
1372a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath);
1373a95c8abb366d9c39450513335f550b56da13b30aztenghui            updateStateFromTypedArray(a);
1374a95c8abb366d9c39450513335f550b56da13b30aztenghui            a.recycle();
1375a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1376a95c8abb366d9c39450513335f550b56da13b30aztenghui
1377a95c8abb366d9c39450513335f550b56da13b30aztenghui        /* Setters and Getters, used by animator from AnimatedVectorDrawable. */
1378eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1379e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        int getStroke() {
1380e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mStrokeColor;
1381e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1382e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1383eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1384e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setStroke(int strokeColor) {
1385e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mStrokeColor = strokeColor;
1386e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1387e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1388eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1389e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        float getStrokeWidth() {
1390e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mStrokeWidth;
1391e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1392e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1393eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1394e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setStrokeWidth(float strokeWidth) {
1395e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mStrokeWidth = strokeWidth;
1396e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1397e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1398eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1399e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        int getFill() {
1400e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mFillColor;
1401e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1402e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1403eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1404e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setFill(int fillColor) {
1405e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mFillColor = fillColor;
1406e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1407e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1408eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1409e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        float getTrimPathStart() {
1410e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mTrimPathStart;
1411e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1412e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1413eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1414e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setTrimPathStart(float trimPathStart) {
1415e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mTrimPathStart = trimPathStart;
1416e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1417e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1418eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1419e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        float getTrimPathEnd() {
1420e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mTrimPathEnd;
1421e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1422e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1423eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1424e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setTrimPathEnd(float trimPathEnd) {
1425e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mTrimPathEnd = trimPathEnd;
1426e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1427e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1428eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1429e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        float getTrimPathOffset() {
1430e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mTrimPathOffset;
1431e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1432e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1433eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1434e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setTrimPathOffset(float trimPathOffset) {
1435e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mTrimPathOffset = trimPathOffset;
1436e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1437abb7d134c02ac60091108c491dafb00877093170John Hoford    }
1438abb7d134c02ac60091108c491dafb00877093170John Hoford}
1439