VectorDrawable.java revision 6f6578e81c1df207da47e2e1337382341f271206
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);
6326f6578e81c1df207da47e2e1337382341f271206Chet Haase                if (copy.mVPathRenderer.mFillPaint != null) {
6336f6578e81c1df207da47e2e1337382341f271206Chet Haase                    mVPathRenderer.mFillPaint = new Paint(copy.mVPathRenderer.mFillPaint);
6346f6578e81c1df207da47e2e1337382341f271206Chet Haase                }
6356f6578e81c1df207da47e2e1337382341f271206Chet Haase                if (copy.mVPathRenderer.mStrokePaint != null) {
6366f6578e81c1df207da47e2e1337382341f271206Chet Haase                    mVPathRenderer.mStrokePaint = new Paint(copy.mVPathRenderer.mStrokePaint);
6376f6578e81c1df207da47e2e1337382341f271206Chet Haase                }
6386f6578e81c1df207da47e2e1337382341f271206Chet Haase                if (copy.mVPathRenderer.mColorFilter != null) {
6396f6578e81c1df207da47e2e1337382341f271206Chet Haase                    mVPathRenderer.mColorFilter = copy.mVPathRenderer.mColorFilter;
6406f6578e81c1df207da47e2e1337382341f271206Chet Haase                }
641b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette                mTint = copy.mTint;
642b3c56086d802ae28888dd97ba1f49bd6cee0b673Alan Viverette                mTintMode = copy.mTintMode;
643738177caf6a755a59ca6b17bb968be0aa4e8e10fztenghui                mAutoMirrored = copy.mAutoMirrored;
6445c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette            }
6455c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        }
6465c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette
647482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        public boolean canReuseCache(int width, int height) {
648670689af43358568bf2b5916284f1cac5762f428ztenghui            if (!mCacheDirty
649670689af43358568bf2b5916284f1cac5762f428ztenghui                    && mCachedThemeAttrs == mThemeAttrs
650482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                    && mCachedTint == mTint
651482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                    && mCachedTintMode == mTintMode
652670689af43358568bf2b5916284f1cac5762f428ztenghui                    && mCachedAutoMirrored == mAutoMirrored
653482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                    && width == mCachedBitmap.getWidth()
654482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                    && height == mCachedBitmap.getHeight()
655482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                    && mCachedRootAlpha == mVPathRenderer.getRootAlpha())  {
656482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui                return true;
657482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            }
658482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            return false;
659482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        }
660482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui
661482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        public void updateCacheStates() {
662482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            // Use shallow copy here and shallow comparison in canReuseCache(),
663482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            // likely hit cache miss more, but practically not much difference.
664482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            mCachedThemeAttrs = mThemeAttrs;
665482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            mCachedTint = mTint;
666482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            mCachedTintMode = mTintMode;
667482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui            mCachedRootAlpha = mVPathRenderer.getRootAlpha();
668670689af43358568bf2b5916284f1cac5762f428ztenghui            mCachedAutoMirrored = mAutoMirrored;
669670689af43358568bf2b5916284f1cac5762f428ztenghui            mCacheDirty = false;
670482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui        }
671482eb53c8a7d5180a2d0ce3b0a779c18960aa8cdztenghui
67255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        public VectorDrawableState() {
67355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mVPathRenderer = new VPathRenderer();
67455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        }
67555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
6765c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        @Override
6775c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        public Drawable newDrawable() {
6785c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette            return new VectorDrawable(this, null, null);
6795c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        }
6805c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette
6815c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        @Override
6825c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        public Drawable newDrawable(Resources res) {
6835c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette            return new VectorDrawable(this, res, null);
6845c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        }
6855c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette
6865c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        @Override
6875c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        public Drawable newDrawable(Resources res, Theme theme) {
6885c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette            return new VectorDrawable(this, res, theme);
6895c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        }
6905c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette
6915c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        @Override
6925c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        public int getChangingConfigurations() {
6935c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette            return mChangingConfigurations;
6945c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette        }
6955c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette    }
6965c981a100ef30d2925588b69f8b9fe349ee5bfdeAlan Viverette
697ddbbb8ae8561c9e61becd03faa40997d76ab5a51ztenghui    private static class VPathRenderer {
6984d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        /* Right now the internal data structure is organized as a tree.
6994d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         * Each node can be a group node, or a path.
7004d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         * A group node can have groups or paths as children, but a path node has
7014d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         * no children.
7024d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         * One example can be:
7034d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *                 Root Group
7044d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *                /    |     \
7054d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *           Group    Path    Group
7064d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *          /     \             |
7074d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *         Path   Path         Path
7084d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         *
7094d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui         */
71055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // Variables that only used temporarily inside the draw() call, so there
71155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // is no need for deep copying.
7126f6578e81c1df207da47e2e1337382341f271206Chet Haase        private final Path mPath;
7136f6578e81c1df207da47e2e1337382341f271206Chet Haase        private final Path mRenderPath;
7144d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        private static final Matrix IDENTITY_MATRIX = new Matrix();
71555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        private final Matrix mFinalPathMatrix = new Matrix();
7164b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette
7174b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        private Paint mStrokePaint;
7184b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        private Paint mFillPaint;
719fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette        private ColorFilter mColorFilter;
720abb7d134c02ac60091108c491dafb00877093170John Hoford        private PathMeasure mPathMeasure;
7214b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette
72255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        /////////////////////////////////////////////////////
72355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // Variables below need to be copied (deep copy if applicable) for mutation.
7248e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette        private int mChangingConfigurations;
72555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        private final VGroup mRootGroup;
726a95c8abb366d9c39450513335f550b56da13b30aztenghui        float mBaseWidth = 0;
727a95c8abb366d9c39450513335f550b56da13b30aztenghui        float mBaseHeight = 0;
728a95c8abb366d9c39450513335f550b56da13b30aztenghui        float mViewportWidth = 0;
729a95c8abb366d9c39450513335f550b56da13b30aztenghui        float mViewportHeight = 0;
7302af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        private int mRootAlpha = 0xFF;
7319453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
73255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        final ArrayMap<String, Object> mVGTargetsMap = new ArrayMap<String, Object>();
733abb7d134c02ac60091108c491dafb00877093170John Hoford
734ddbbb8ae8561c9e61becd03faa40997d76ab5a51ztenghui        public VPathRenderer() {
7354d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            mRootGroup = new VGroup();
7366f6578e81c1df207da47e2e1337382341f271206Chet Haase            mPath = new Path();
7376f6578e81c1df207da47e2e1337382341f271206Chet Haase            mRenderPath = new Path();
738abb7d134c02ac60091108c491dafb00877093170John Hoford        }
7399453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
7402af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        public void setRootAlpha(int alpha) {
7412af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui            mRootAlpha = alpha;
7422af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        }
7432af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui
7442af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        public int getRootAlpha() {
7452af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui            return mRootAlpha;
7462af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        }
7472af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui
748ddbbb8ae8561c9e61becd03faa40997d76ab5a51ztenghui        public VPathRenderer(VPathRenderer copy) {
74955f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mRootGroup = new VGroup(copy.mRootGroup, mVGTargetsMap);
7506f6578e81c1df207da47e2e1337382341f271206Chet Haase            mPath = new Path(copy.mPath);
7516f6578e81c1df207da47e2e1337382341f271206Chet Haase            mRenderPath = new Path(copy.mRenderPath);
752abb7d134c02ac60091108c491dafb00877093170John Hoford            mBaseWidth = copy.mBaseWidth;
753abb7d134c02ac60091108c491dafb00877093170John Hoford            mBaseHeight = copy.mBaseHeight;
7545eb5cde467081d1af628e5463ba55f110265a86fztenghui            mViewportWidth = copy.mViewportWidth;
755abb7d134c02ac60091108c491dafb00877093170John Hoford            mViewportHeight = copy.mViewportHeight;
7568e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette            mChangingConfigurations = copy.mChangingConfigurations;
75755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mRootAlpha = copy.mRootAlpha;
758abb7d134c02ac60091108c491dafb00877093170John Hoford        }
759abb7d134c02ac60091108c491dafb00877093170John Hoford
7609453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        public boolean canApplyTheme() {
7614d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // If one of the paths can apply theme, then return true;
7624d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            return recursiveCanApplyTheme(mRootGroup);
7634d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
7644d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
7654d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        private boolean recursiveCanApplyTheme(VGroup currentGroup) {
7664d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // We can do a tree traverse here, if there is one path return true,
7674d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // then we return true for the whole tree.
7688d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            final ArrayList<Object> children = currentGroup.mChildren;
7698d0d24f7a2b1a59060aa18926984491691d3c667ztenghui
7708d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            for (int i = 0; i < children.size(); i++) {
7718d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                Object child = children.get(i);
7728d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                if (child instanceof VGroup) {
7738d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VGroup childGroup = (VGroup) child;
7748d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (childGroup.canApplyTheme()
7758d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                            || recursiveCanApplyTheme(childGroup)) {
7768d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        return true;
7778d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
7788d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                } else if (child instanceof VPath) {
7798d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VPath childPath = (VPath) child;
7808d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (childPath.canApplyTheme()) {
7818d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        return true;
7828d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
7834d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                }
7844d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            }
7859453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette            return false;
7869453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        }
7879453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
7889453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        public void applyTheme(Theme t) {
7894d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // Apply theme to every path of the tree.
7904d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            recursiveApplyTheme(mRootGroup, t);
7914d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
7924d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
7934d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        private void recursiveApplyTheme(VGroup currentGroup, Theme t) {
7944d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // We can do a tree traverse here, apply theme to all paths which
7954d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // can apply theme.
7968d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            final ArrayList<Object> children = currentGroup.mChildren;
7978d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            for (int i = 0; i < children.size(); i++) {
7988d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                Object child = children.get(i);
7998d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                if (child instanceof VGroup) {
8008d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VGroup childGroup = (VGroup) child;
8018d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (childGroup.canApplyTheme()) {
8028d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        childGroup.applyTheme(t);
8038d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
8048d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    recursiveApplyTheme(childGroup, t);
8058d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                } else if (child instanceof VPath) {
8068d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VPath childPath = (VPath) child;
8078d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (childPath.canApplyTheme()) {
8088d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        childPath.applyTheme(t);
8098d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
8104d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui                }
8114d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            }
812abb7d134c02ac60091108c491dafb00877093170John Hoford        }
813abb7d134c02ac60091108c491dafb00877093170John Hoford
814fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette        public void setColorFilter(ColorFilter colorFilter) {
815fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette            mColorFilter = colorFilter;
816fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette
817fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette            if (mFillPaint != null) {
818fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette                mFillPaint.setColorFilter(colorFilter);
819fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette            }
820fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette
821fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette            if (mStrokePaint != null) {
822fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette                mStrokePaint.setColorFilter(colorFilter);
823fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette            }
8246d9c422de5e0a3890dd723cb1b9264d4507053e9ztenghui
825fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette        }
826fd6e411767735478ee0f69ba01d77def4c6b2627Alan Viverette
8274d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        private void drawGroupTree(VGroup currentGroup, Matrix currentMatrix,
8282af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui                float currentAlpha, Canvas canvas, int w, int h) {
8294d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // Calculate current group's matrix by preConcat the parent's and
8304d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // and the current one on the top of the stack.
8314d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // Basically the Mfinal = Mviewport * M0 * M1 * M2;
8324d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // Mi the local matrix at level i of the group tree.
8334d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            currentGroup.mStackedMatrix.set(currentMatrix);
8344d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
8354d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            currentGroup.mStackedMatrix.preConcat(currentGroup.mLocalMatrix);
8364d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
8372af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui            float stackedAlpha = currentAlpha * currentGroup.mGroupAlpha;
8388d0d24f7a2b1a59060aa18926984491691d3c667ztenghui
8398d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            // Draw the group tree in the same order as the XML file.
8408d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            for (int i = 0; i < currentGroup.mChildren.size(); i++) {
8418d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                Object child = currentGroup.mChildren.get(i);
8428d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                if (child instanceof VGroup) {
8438d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VGroup childGroup = (VGroup) child;
8448d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    drawGroupTree(childGroup, currentGroup.mStackedMatrix,
8458d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                            stackedAlpha, canvas, w, h);
8468d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                } else if (child instanceof VPath) {
8478d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VPath childPath = (VPath) child;
8488d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    drawPath(currentGroup, childPath, stackedAlpha, canvas, w, h);
8498d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                }
850abb7d134c02ac60091108c491dafb00877093170John Hoford            }
8514d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
852abb7d134c02ac60091108c491dafb00877093170John Hoford
8534d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        public void draw(Canvas canvas, int w, int h) {
8544d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            // Travese the tree in pre-order to draw.
855a95c8abb366d9c39450513335f550b56da13b30aztenghui            drawGroupTree(mRootGroup, IDENTITY_MATRIX, ((float) mRootAlpha) / 0xFF,
856a95c8abb366d9c39450513335f550b56da13b30aztenghui                    canvas, w, h);
857abb7d134c02ac60091108c491dafb00877093170John Hoford        }
858abb7d134c02ac60091108c491dafb00877093170John Hoford
8598d0d24f7a2b1a59060aa18926984491691d3c667ztenghui        private void drawPath(VGroup vGroup, VPath vPath, float stackedAlpha,
8608d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                Canvas canvas, int w, int h) {
8619d59a76dd0e850558e83ef1a48fefd865fac1336ztenghui            final float scaleX =  w / mViewportWidth;
8629d59a76dd0e850558e83ef1a48fefd865fac1336ztenghui            final float scaleY = h / mViewportHeight;
8639d59a76dd0e850558e83ef1a48fefd865fac1336ztenghui            final float minScale = Math.min(scaleX, scaleY);
864abb7d134c02ac60091108c491dafb00877093170John Hoford
8654d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui            mFinalPathMatrix.set(vGroup.mStackedMatrix);
8665a836f74df027bb568da17fbde4e641b6a56d2a9ztenghui            mFinalPathMatrix.postScale(scaleX, scaleY);
867abb7d134c02ac60091108c491dafb00877093170John Hoford
8688d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            vPath.toPath(mPath);
8698d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            final Path path = mPath;
870abb7d134c02ac60091108c491dafb00877093170John Hoford
8718d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            mRenderPath.reset();
8729453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
873a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (vPath.isClipPath()) {
874a95c8abb366d9c39450513335f550b56da13b30aztenghui                mRenderPath.addPath(path, mFinalPathMatrix);
8758d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                canvas.clipPath(mRenderPath, Region.Op.REPLACE);
8768d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            } else {
877a95c8abb366d9c39450513335f550b56da13b30aztenghui                VFullPath fullPath = (VFullPath) vPath;
878a95c8abb366d9c39450513335f550b56da13b30aztenghui                if (fullPath.mTrimPathStart != 0.0f || fullPath.mTrimPathEnd != 1.0f) {
879a95c8abb366d9c39450513335f550b56da13b30aztenghui                    float start = (fullPath.mTrimPathStart + fullPath.mTrimPathOffset) % 1.0f;
880a95c8abb366d9c39450513335f550b56da13b30aztenghui                    float end = (fullPath.mTrimPathEnd + fullPath.mTrimPathOffset) % 1.0f;
881a95c8abb366d9c39450513335f550b56da13b30aztenghui
882a95c8abb366d9c39450513335f550b56da13b30aztenghui                    if (mPathMeasure == null) {
883a95c8abb366d9c39450513335f550b56da13b30aztenghui                        mPathMeasure = new PathMeasure();
884a95c8abb366d9c39450513335f550b56da13b30aztenghui                    }
885a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mPathMeasure.setPath(mPath, false);
886a95c8abb366d9c39450513335f550b56da13b30aztenghui
887a95c8abb366d9c39450513335f550b56da13b30aztenghui                    float len = mPathMeasure.getLength();
888a95c8abb366d9c39450513335f550b56da13b30aztenghui                    start = start * len;
889a95c8abb366d9c39450513335f550b56da13b30aztenghui                    end = end * len;
890a95c8abb366d9c39450513335f550b56da13b30aztenghui                    path.reset();
891a95c8abb366d9c39450513335f550b56da13b30aztenghui                    if (start > end) {
892a95c8abb366d9c39450513335f550b56da13b30aztenghui                        mPathMeasure.getSegment(start, len, path, true);
893a95c8abb366d9c39450513335f550b56da13b30aztenghui                        mPathMeasure.getSegment(0f, end, path, true);
894a95c8abb366d9c39450513335f550b56da13b30aztenghui                    } else {
895a95c8abb366d9c39450513335f550b56da13b30aztenghui                        mPathMeasure.getSegment(start, end, path, true);
896a95c8abb366d9c39450513335f550b56da13b30aztenghui                    }
897a95c8abb366d9c39450513335f550b56da13b30aztenghui                    path.rLineTo(0, 0); // fix bug in measure
898a95c8abb366d9c39450513335f550b56da13b30aztenghui                }
899a95c8abb366d9c39450513335f550b56da13b30aztenghui                mRenderPath.addPath(path, mFinalPathMatrix);
900a95c8abb366d9c39450513335f550b56da13b30aztenghui
901a70b4742a7a0b2edc57cbbbf83d2c6d43ebc300dztenghui                if (fullPath.mFillColor != Color.TRANSPARENT) {
9028d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (mFillPaint == null) {
9038d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mFillPaint = new Paint();
9048d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mFillPaint.setColorFilter(mColorFilter);
9058d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mFillPaint.setStyle(Paint.Style.FILL);
9068d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mFillPaint.setAntiAlias(true);
90763cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui                    }
908a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mFillPaint.setColor(applyAlpha(fullPath.mFillColor, stackedAlpha));
9098d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    canvas.drawPath(mRenderPath, mFillPaint);
9108d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                }
91163cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
912a70b4742a7a0b2edc57cbbbf83d2c6d43ebc300dztenghui                if (fullPath.mStrokeColor != Color.TRANSPARENT) {
9138d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (mStrokePaint == null) {
9148d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mStrokePaint = new Paint();
9158d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mStrokePaint.setColorFilter(mColorFilter);
9168d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mStrokePaint.setStyle(Paint.Style.STROKE);
9178d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        mStrokePaint.setAntiAlias(true);
9188d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
9194b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette
9208d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    final Paint strokePaint = mStrokePaint;
921a95c8abb366d9c39450513335f550b56da13b30aztenghui                    if (fullPath.mStrokeLineJoin != null) {
922a95c8abb366d9c39450513335f550b56da13b30aztenghui                        strokePaint.setStrokeJoin(fullPath.mStrokeLineJoin);
9238d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
924abb7d134c02ac60091108c491dafb00877093170John Hoford
925a95c8abb366d9c39450513335f550b56da13b30aztenghui                    if (fullPath.mStrokeLineCap != null) {
926a95c8abb366d9c39450513335f550b56da13b30aztenghui                        strokePaint.setStrokeCap(fullPath.mStrokeLineCap);
9278d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
92863cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
929c4d651ec8a8c190c5df173166357c2fdf47472ceztenghui                    strokePaint.setStrokeMiter(fullPath.mStrokeMiterlimit);
93063cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
931a95c8abb366d9c39450513335f550b56da13b30aztenghui                    strokePaint.setColor(applyAlpha(fullPath.mStrokeColor, stackedAlpha));
932a95c8abb366d9c39450513335f550b56da13b30aztenghui                    strokePaint.setStrokeWidth(fullPath.mStrokeWidth * minScale);
9338d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    canvas.drawPath(mRenderPath, strokePaint);
93463cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui                }
935abb7d134c02ac60091108c491dafb00877093170John Hoford            }
936abb7d134c02ac60091108c491dafb00877093170John Hoford        }
937abb7d134c02ac60091108c491dafb00877093170John Hoford    }
938abb7d134c02ac60091108c491dafb00877093170John Hoford
939a95c8abb366d9c39450513335f550b56da13b30aztenghui    private static class VGroup {
94055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // mStackedMatrix is only used temporarily when drawing, it combines all
94155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // the parents' local matrices with the current one.
94255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        private final Matrix mStackedMatrix = new Matrix();
94355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
94455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        /////////////////////////////////////////////////////
94555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // Variables below need to be copied (deep copy if applicable) for mutation.
9468d0d24f7a2b1a59060aa18926984491691d3c667ztenghui        final ArrayList<Object> mChildren = new ArrayList<Object>();
947abb7d134c02ac60091108c491dafb00877093170John Hoford
94863cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui        private float mRotate = 0;
94963cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui        private float mPivotX = 0;
95063cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui        private float mPivotY = 0;
951452f6ece7fe2fd1a85fca53f54e90bf041083b21ztenghui        private float mScaleX = 1;
952452f6ece7fe2fd1a85fca53f54e90bf041083b21ztenghui        private float mScaleY = 1;
953452f6ece7fe2fd1a85fca53f54e90bf041083b21ztenghui        private float mTranslateX = 0;
954452f6ece7fe2fd1a85fca53f54e90bf041083b21ztenghui        private float mTranslateY = 0;
9552af745b56cf4bdfdd9c05d90a4ccc740bf77a4feztenghui        private float mGroupAlpha = 1;
9564d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
95755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // mLocalMatrix is updated based on the update of transformation information,
95855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // either parsed from the XML or by animation.
9594d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        private final Matrix mLocalMatrix = new Matrix();
9608e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette        private int mChangingConfigurations;
96163cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui        private int[] mThemeAttrs;
962e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        private String mGroupName = null;
963e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
96455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        public VGroup(VGroup copy, ArrayMap<String, Object> targetsMap) {
96555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mRotate = copy.mRotate;
96655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mPivotX = copy.mPivotX;
96755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mPivotY = copy.mPivotY;
96855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mScaleX = copy.mScaleX;
96955f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mScaleY = copy.mScaleY;
97055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mTranslateX = copy.mTranslateX;
97155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mTranslateY = copy.mTranslateY;
97255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mGroupAlpha = copy.mGroupAlpha;
97355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mThemeAttrs = copy.mThemeAttrs;
97455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mGroupName = copy.mGroupName;
97555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mChangingConfigurations = copy.mChangingConfigurations;
97655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            if (mGroupName != null) {
97755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui                targetsMap.put(mGroupName, this);
97855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            }
97955f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
98055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mLocalMatrix.set(copy.mLocalMatrix);
98155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
9828d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            final ArrayList<Object> children = copy.mChildren;
9838d0d24f7a2b1a59060aa18926984491691d3c667ztenghui            for (int i = 0; i < children.size(); i++) {
9848d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                Object copyChild = children.get(i);
9858d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                if (copyChild instanceof VGroup) {
9868d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    VGroup copyGroup = (VGroup) copyChild;
9878d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    mChildren.add(new VGroup(copyGroup, targetsMap));
988a95c8abb366d9c39450513335f550b56da13b30aztenghui                } else {
989a95c8abb366d9c39450513335f550b56da13b30aztenghui                    VPath newPath = null;
990a95c8abb366d9c39450513335f550b56da13b30aztenghui                    if (copyChild instanceof VFullPath) {
991a95c8abb366d9c39450513335f550b56da13b30aztenghui                        newPath = new VFullPath((VFullPath) copyChild);
992a95c8abb366d9c39450513335f550b56da13b30aztenghui                    } else if (copyChild instanceof VClipPath) {
993a95c8abb366d9c39450513335f550b56da13b30aztenghui                        newPath = new VClipPath((VClipPath) copyChild);
994a95c8abb366d9c39450513335f550b56da13b30aztenghui                    } else {
995a95c8abb366d9c39450513335f550b56da13b30aztenghui                        throw new IllegalStateException("Unknown object in the tree!");
996a95c8abb366d9c39450513335f550b56da13b30aztenghui                    }
9978d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    mChildren.add(newPath);
9988d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    if (newPath.mPathName != null) {
9998d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                        targetsMap.put(newPath.mPathName, newPath);
10008d0d24f7a2b1a59060aa18926984491691d3c667ztenghui                    }
100155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui                }
100255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            }
100355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        }
100455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
100555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        public VGroup() {
100655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        }
100755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
1008a95c8abb366d9c39450513335f550b56da13b30aztenghui        public String getGroupName() {
1009a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mGroupName;
1010a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1011a95c8abb366d9c39450513335f550b56da13b30aztenghui
1012a95c8abb366d9c39450513335f550b56da13b30aztenghui        public Matrix getLocalMatrix() {
1013a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mLocalMatrix;
1014a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1015a95c8abb366d9c39450513335f550b56da13b30aztenghui
1016a95c8abb366d9c39450513335f550b56da13b30aztenghui        public boolean canApplyTheme() {
1017a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mThemeAttrs != null;
1018a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1019a95c8abb366d9c39450513335f550b56da13b30aztenghui
1020a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void inflate(Resources res, AttributeSet attrs, Theme theme) {
1021a95c8abb366d9c39450513335f550b56da13b30aztenghui            final TypedArray a = obtainAttributes(res, theme, attrs,
1022a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawableGroup);
1023a95c8abb366d9c39450513335f550b56da13b30aztenghui            updateStateFromTypedArray(a);
1024a95c8abb366d9c39450513335f550b56da13b30aztenghui            a.recycle();
1025a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1026a95c8abb366d9c39450513335f550b56da13b30aztenghui
1027a95c8abb366d9c39450513335f550b56da13b30aztenghui        private void updateStateFromTypedArray(TypedArray a) {
1028a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Account for any configuration changes.
1029a95c8abb366d9c39450513335f550b56da13b30aztenghui            mChangingConfigurations |= a.getChangingConfigurations();
1030a95c8abb366d9c39450513335f550b56da13b30aztenghui
1031a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Extract the theme attributes, if any.
1032a95c8abb366d9c39450513335f550b56da13b30aztenghui            mThemeAttrs = a.extractThemeAttrs();
1033a95c8abb366d9c39450513335f550b56da13b30aztenghui
1034a95c8abb366d9c39450513335f550b56da13b30aztenghui            mRotate = a.getFloat(R.styleable.VectorDrawableGroup_rotation, mRotate);
1035a95c8abb366d9c39450513335f550b56da13b30aztenghui            mPivotX = a.getFloat(R.styleable.VectorDrawableGroup_pivotX, mPivotX);
1036a95c8abb366d9c39450513335f550b56da13b30aztenghui            mPivotY = a.getFloat(R.styleable.VectorDrawableGroup_pivotY, mPivotY);
1037a95c8abb366d9c39450513335f550b56da13b30aztenghui            mScaleX = a.getFloat(R.styleable.VectorDrawableGroup_scaleX, mScaleX);
1038a95c8abb366d9c39450513335f550b56da13b30aztenghui            mScaleY = a.getFloat(R.styleable.VectorDrawableGroup_scaleY, mScaleY);
1039a95c8abb366d9c39450513335f550b56da13b30aztenghui            mTranslateX = a.getFloat(R.styleable.VectorDrawableGroup_translateX, mTranslateX);
1040a95c8abb366d9c39450513335f550b56da13b30aztenghui            mTranslateY = a.getFloat(R.styleable.VectorDrawableGroup_translateY, mTranslateY);
1041a95c8abb366d9c39450513335f550b56da13b30aztenghui            mGroupAlpha = a.getFloat(R.styleable.VectorDrawableGroup_alpha, mGroupAlpha);
1042a95c8abb366d9c39450513335f550b56da13b30aztenghui
1043a95c8abb366d9c39450513335f550b56da13b30aztenghui            final String groupName = a.getString(R.styleable.VectorDrawableGroup_name);
1044a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (groupName != null) {
1045a95c8abb366d9c39450513335f550b56da13b30aztenghui                mGroupName = groupName;
1046a95c8abb366d9c39450513335f550b56da13b30aztenghui            }
1047a95c8abb366d9c39450513335f550b56da13b30aztenghui
1048a95c8abb366d9c39450513335f550b56da13b30aztenghui            updateLocalMatrix();
1049a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1050a95c8abb366d9c39450513335f550b56da13b30aztenghui
1051a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void applyTheme(Theme t) {
1052a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (mThemeAttrs == null) {
1053a95c8abb366d9c39450513335f550b56da13b30aztenghui                return;
1054a95c8abb366d9c39450513335f550b56da13b30aztenghui            }
1055a95c8abb366d9c39450513335f550b56da13b30aztenghui
1056a95c8abb366d9c39450513335f550b56da13b30aztenghui            final TypedArray a = t.resolveAttributes(mThemeAttrs,
1057a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawableGroup);
1058a95c8abb366d9c39450513335f550b56da13b30aztenghui            updateStateFromTypedArray(a);
1059a95c8abb366d9c39450513335f550b56da13b30aztenghui            a.recycle();
1060a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1061a95c8abb366d9c39450513335f550b56da13b30aztenghui
1062a95c8abb366d9c39450513335f550b56da13b30aztenghui        private void updateLocalMatrix() {
1063a95c8abb366d9c39450513335f550b56da13b30aztenghui            // The order we apply is the same as the
1064a95c8abb366d9c39450513335f550b56da13b30aztenghui            // RenderNode.cpp::applyViewPropertyTransforms().
1065a95c8abb366d9c39450513335f550b56da13b30aztenghui            mLocalMatrix.reset();
1066a95c8abb366d9c39450513335f550b56da13b30aztenghui            mLocalMatrix.postTranslate(-mPivotX, -mPivotY);
1067a95c8abb366d9c39450513335f550b56da13b30aztenghui            mLocalMatrix.postScale(mScaleX, mScaleY);
1068a95c8abb366d9c39450513335f550b56da13b30aztenghui            mLocalMatrix.postRotate(mRotate, 0, 0);
1069a95c8abb366d9c39450513335f550b56da13b30aztenghui            mLocalMatrix.postTranslate(mTranslateX + mPivotX, mTranslateY + mPivotY);
1070a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1071a95c8abb366d9c39450513335f550b56da13b30aztenghui
1072a95c8abb366d9c39450513335f550b56da13b30aztenghui        /* Setters and Getters, used by animator from AnimatedVectorDrawable. */
1073a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1074e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getRotation() {
1075e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mRotate;
1076e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1077e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1078a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1079e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setRotation(float rotation) {
1080e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (rotation != mRotate) {
1081e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mRotate = rotation;
1082e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1083e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1084e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1085e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1086a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1087e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getPivotX() {
1088e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mPivotX;
1089e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1090e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1091a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1092e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setPivotX(float pivotX) {
1093e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (pivotX != mPivotX) {
1094e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mPivotX = pivotX;
1095e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1096e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1097e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1098e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1099a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1100e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getPivotY() {
1101e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mPivotY;
1102e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1103e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1104a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1105e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setPivotY(float pivotY) {
1106e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (pivotY != mPivotY) {
1107e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mPivotY = pivotY;
1108e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1109e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1110e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1111e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1112a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1113e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getScaleX() {
1114e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mScaleX;
1115e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
11164d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1117a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1118e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setScaleX(float scaleX) {
1119e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (scaleX != mScaleX) {
1120e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mScaleX = scaleX;
1121e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1122e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1123e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1124e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1125a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1126e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getScaleY() {
1127e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mScaleY;
1128e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1129e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1130a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1131e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setScaleY(float scaleY) {
1132e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (scaleY != mScaleY) {
1133e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mScaleY = scaleY;
1134e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1135e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1136e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1137e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1138a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1139e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getTranslateX() {
1140e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mTranslateX;
1141e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1142e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1143a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1144e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setTranslateX(float translateX) {
1145e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (translateX != mTranslateX) {
1146e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mTranslateX = translateX;
1147e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1148e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1149e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1150e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1151a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1152e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getTranslateY() {
1153e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mTranslateY;
1154e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1155e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1156a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1157e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setTranslateY(float translateY) {
1158e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (translateY != mTranslateY) {
1159e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mTranslateY = translateY;
1160e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                updateLocalMatrix();
1161e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1162e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1163e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1164a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1165e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public float getAlpha() {
1166e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mGroupAlpha;
1167e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1168e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1169a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1170e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        public void setAlpha(float groupAlpha) {
1171e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            if (groupAlpha != mGroupAlpha) {
1172e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui                mGroupAlpha = groupAlpha;
1173e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            }
1174e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1175a95c8abb366d9c39450513335f550b56da13b30aztenghui    }
1176e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1177a95c8abb366d9c39450513335f550b56da13b30aztenghui    /**
1178a95c8abb366d9c39450513335f550b56da13b30aztenghui     * Common Path information for clip path and normal path.
1179a95c8abb366d9c39450513335f550b56da13b30aztenghui     */
1180a95c8abb366d9c39450513335f550b56da13b30aztenghui    private static class VPath {
1181a95c8abb366d9c39450513335f550b56da13b30aztenghui        protected PathParser.PathDataNode[] mNodes = null;
1182a95c8abb366d9c39450513335f550b56da13b30aztenghui        String mPathName;
1183a95c8abb366d9c39450513335f550b56da13b30aztenghui        int mChangingConfigurations;
1184a95c8abb366d9c39450513335f550b56da13b30aztenghui
1185a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VPath() {
1186a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Empty constructor.
11874d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
11884d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1189a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VPath(VPath copy) {
1190a95c8abb366d9c39450513335f550b56da13b30aztenghui            mPathName = copy.mPathName;
1191a95c8abb366d9c39450513335f550b56da13b30aztenghui            mChangingConfigurations = copy.mChangingConfigurations;
1192a95c8abb366d9c39450513335f550b56da13b30aztenghui            mNodes = PathParser.deepCopyNodes(copy.mNodes);
11934d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
11944d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1195a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void toPath(Path path) {
1196a95c8abb366d9c39450513335f550b56da13b30aztenghui            path.reset();
1197a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (mNodes != null) {
1198a95c8abb366d9c39450513335f550b56da13b30aztenghui                PathParser.PathDataNode.nodesToPath(mNodes, path);
1199a95c8abb366d9c39450513335f550b56da13b30aztenghui            }
12004d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
12014d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1202a95c8abb366d9c39450513335f550b56da13b30aztenghui        public String getPathName() {
1203a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mPathName;
12048e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette        }
12058e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette
1206a95c8abb366d9c39450513335f550b56da13b30aztenghui        public boolean canApplyTheme() {
1207a95c8abb366d9c39450513335f550b56da13b30aztenghui            return false;
1208a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
120963cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
1210a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void applyTheme(Theme t) {
1211a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
121263cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
1213a95c8abb366d9c39450513335f550b56da13b30aztenghui        public boolean isClipPath() {
1214a95c8abb366d9c39450513335f550b56da13b30aztenghui            return false;
1215a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
121663cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
1217a95c8abb366d9c39450513335f550b56da13b30aztenghui        /* Setters and Getters, used by animator from AnimatedVectorDrawable. */
1218a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1219a95c8abb366d9c39450513335f550b56da13b30aztenghui        public PathParser.PathDataNode[] getPathData() {
1220a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mNodes;
1221a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1222a95c8abb366d9c39450513335f550b56da13b30aztenghui
1223a95c8abb366d9c39450513335f550b56da13b30aztenghui        @SuppressWarnings("unused")
1224a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void setPathData(PathParser.PathDataNode[] nodes) {
1225a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (!PathParser.canMorph(mNodes, nodes)) {
1226a95c8abb366d9c39450513335f550b56da13b30aztenghui                // This should not happen in the middle of animation.
1227a95c8abb366d9c39450513335f550b56da13b30aztenghui                mNodes = PathParser.deepCopyNodes(nodes);
1228a95c8abb366d9c39450513335f550b56da13b30aztenghui            } else {
1229a95c8abb366d9c39450513335f550b56da13b30aztenghui                PathParser.updateNodes(mNodes, nodes);
123063cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui            }
1231a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1232a95c8abb366d9c39450513335f550b56da13b30aztenghui    }
123363cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
1234a95c8abb366d9c39450513335f550b56da13b30aztenghui    /**
1235a95c8abb366d9c39450513335f550b56da13b30aztenghui     * Clip path, which only has name and pathData.
1236a95c8abb366d9c39450513335f550b56da13b30aztenghui     */
1237a95c8abb366d9c39450513335f550b56da13b30aztenghui    private static class VClipPath extends VPath{
1238a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VClipPath() {
1239a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Empty constructor.
12408e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette        }
12414d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1242a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VClipPath(VClipPath copy) {
1243a95c8abb366d9c39450513335f550b56da13b30aztenghui            super(copy);
1244a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
12454d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui
1246a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void inflate(Resources r, AttributeSet attrs, Theme theme) {
1247a95c8abb366d9c39450513335f550b56da13b30aztenghui            final TypedArray a = obtainAttributes(r, theme, attrs,
1248a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawableClipPath);
12498e5e11b99fac942122ee2d6cdd30af51564861aeAlan Viverette            updateStateFromTypedArray(a);
125063cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui            a.recycle();
125163cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui        }
125263cfd85bcce488a3f3952bd1db523a727d30ca39ztenghui
1253a95c8abb366d9c39450513335f550b56da13b30aztenghui        private void updateStateFromTypedArray(TypedArray a) {
1254a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Account for any configuration changes.
1255a95c8abb366d9c39450513335f550b56da13b30aztenghui            mChangingConfigurations |= a.getChangingConfigurations();
1256a95c8abb366d9c39450513335f550b56da13b30aztenghui
1257a95c8abb366d9c39450513335f550b56da13b30aztenghui            mPathName = a.getString(R.styleable.VectorDrawableClipPath_name);
1258a95c8abb366d9c39450513335f550b56da13b30aztenghui            mNodes = PathParser.createNodesFromPathData(a.getString(
1259a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawableClipPath_pathData));
1260a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1261a95c8abb366d9c39450513335f550b56da13b30aztenghui
1262a95c8abb366d9c39450513335f550b56da13b30aztenghui        @Override
1263a95c8abb366d9c39450513335f550b56da13b30aztenghui        public boolean isClipPath() {
1264a95c8abb366d9c39450513335f550b56da13b30aztenghui            return true;
12654d24caf1dec2babf273b18c99638fe2a0635ced4ztenghui        }
1266abb7d134c02ac60091108c491dafb00877093170John Hoford    }
1267abb7d134c02ac60091108c491dafb00877093170John Hoford
1268a95c8abb366d9c39450513335f550b56da13b30aztenghui    /**
1269a95c8abb366d9c39450513335f550b56da13b30aztenghui     * Normal path, which contains all the fill / paint information.
1270a95c8abb366d9c39450513335f550b56da13b30aztenghui     */
1271a95c8abb366d9c39450513335f550b56da13b30aztenghui    private static class VFullPath extends VPath {
127255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        /////////////////////////////////////////////////////
127355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui        // Variables below need to be copied (deep copy if applicable) for mutation.
12749453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        private int[] mThemeAttrs;
12759453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
1276a70b4742a7a0b2edc57cbbbf83d2c6d43ebc300dztenghui        int mStrokeColor = Color.TRANSPARENT;
1277abb7d134c02ac60091108c491dafb00877093170John Hoford        float mStrokeWidth = 0;
1278a70b4742a7a0b2edc57cbbbf83d2c6d43ebc300dztenghui        int mFillColor = Color.TRANSPARENT;
1279abb7d134c02ac60091108c491dafb00877093170John Hoford        int mFillRule;
1280abb7d134c02ac60091108c491dafb00877093170John Hoford        float mTrimPathStart = 0;
1281abb7d134c02ac60091108c491dafb00877093170John Hoford        float mTrimPathEnd = 1;
1282abb7d134c02ac60091108c491dafb00877093170John Hoford        float mTrimPathOffset = 0;
12839453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
12844b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        Paint.Cap mStrokeLineCap = Paint.Cap.BUTT;
12854b3988d159e1c9faa2a7e16c9aca9951264bb429Alan Viverette        Paint.Join mStrokeLineJoin = Paint.Join.MITER;
1286abb7d134c02ac60091108c491dafb00877093170John Hoford        float mStrokeMiterlimit = 4;
12879453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
1288a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VFullPath() {
12899453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette            // Empty constructor.
12909453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette        }
12919453b7cfd4bbb35467bd7f947f850bd154982fceAlan Viverette
1292a95c8abb366d9c39450513335f550b56da13b30aztenghui        public VFullPath(VFullPath copy) {
1293a95c8abb366d9c39450513335f550b56da13b30aztenghui            super(copy);
129455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mThemeAttrs = copy.mThemeAttrs;
129555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
129655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mStrokeColor = copy.mStrokeColor;
129755f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mStrokeWidth = copy.mStrokeWidth;
129855f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mFillColor = copy.mFillColor;
129955f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mFillRule = copy.mFillRule;
130055f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mTrimPathStart = copy.mTrimPathStart;
130155f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mTrimPathEnd = copy.mTrimPathEnd;
130255f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mTrimPathOffset = copy.mTrimPathOffset;
130355f765441c6cec6b2990de12f68d1c4ac444d35cztenghui
130455f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mStrokeLineCap = copy.mStrokeLineCap;
130555f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mStrokeLineJoin = copy.mStrokeLineJoin;
130655f765441c6cec6b2990de12f68d1c4ac444d35cztenghui            mStrokeMiterlimit = copy.mStrokeMiterlimit;
1307abb7d134c02ac60091108c491dafb00877093170John Hoford        }
1308abb7d134c02ac60091108c491dafb00877093170John Hoford
13097f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette        private Paint.Cap getStrokeLineCap(int id, Paint.Cap defValue) {
13107f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette            switch (id) {
13117f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINECAP_BUTT:
13127f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Cap.BUTT;
13137f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINECAP_ROUND:
13147f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Cap.ROUND;
13157f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINECAP_SQUARE:
13167f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Cap.SQUARE;
13177f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                default:
13187f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return defValue;
13197f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette            }
13207f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette        }
13217f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette
13227f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette        private Paint.Join getStrokeLineJoin(int id, Paint.Join defValue) {
13237f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette            switch (id) {
13247f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINEJOIN_MITER:
13257f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Join.MITER;
13267f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINEJOIN_ROUND:
13277f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Join.ROUND;
13287f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                case LINEJOIN_BEVEL:
13297f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return Paint.Join.BEVEL;
13307f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                default:
13317f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette                    return defValue;
13327f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette            }
13337f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette        }
13347f1ab7a43fd7e65bbd7460334014ecc73dbb1b8dAlan Viverette
1335a95c8abb366d9c39450513335f550b56da13b30aztenghui        @Override
1336a95c8abb366d9c39450513335f550b56da13b30aztenghui        public boolean canApplyTheme() {
1337a95c8abb366d9c39450513335f550b56da13b30aztenghui            return mThemeAttrs != null;
1338eb034fbca40006c55db143047eb628c4b657730aztenghui        }
1339eb034fbca40006c55db143047eb628c4b657730aztenghui
1340a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void inflate(Resources r, AttributeSet attrs, Theme theme) {
1341a95c8abb366d9c39450513335f550b56da13b30aztenghui            final TypedArray a = obtainAttributes(r, theme, attrs,
1342a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath);
1343a95c8abb366d9c39450513335f550b56da13b30aztenghui            updateStateFromTypedArray(a);
1344a95c8abb366d9c39450513335f550b56da13b30aztenghui            a.recycle();
1345a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1346a95c8abb366d9c39450513335f550b56da13b30aztenghui
1347a95c8abb366d9c39450513335f550b56da13b30aztenghui        private void updateStateFromTypedArray(TypedArray a) {
1348a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Account for any configuration changes.
1349a95c8abb366d9c39450513335f550b56da13b30aztenghui            mChangingConfigurations |= a.getChangingConfigurations();
1350a95c8abb366d9c39450513335f550b56da13b30aztenghui
1351a95c8abb366d9c39450513335f550b56da13b30aztenghui            // Extract the theme attributes, if any.
1352a95c8abb366d9c39450513335f550b56da13b30aztenghui            mThemeAttrs = a.extractThemeAttrs();
1353a95c8abb366d9c39450513335f550b56da13b30aztenghui
1354a95c8abb366d9c39450513335f550b56da13b30aztenghui            mPathName = a.getString(R.styleable.VectorDrawablePath_name);
1355a95c8abb366d9c39450513335f550b56da13b30aztenghui            mNodes = PathParser.createNodesFromPathData(a.getString(
1356a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_pathData));
1357a95c8abb366d9c39450513335f550b56da13b30aztenghui
1358a95c8abb366d9c39450513335f550b56da13b30aztenghui            mFillColor = a.getColor(R.styleable.VectorDrawablePath_fillColor,
1359a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mFillColor);
1360a95c8abb366d9c39450513335f550b56da13b30aztenghui            mStrokeLineCap = getStrokeLineCap(a.getInt(
1361a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_strokeLineCap, -1), mStrokeLineCap);
1362a95c8abb366d9c39450513335f550b56da13b30aztenghui            mStrokeLineJoin = getStrokeLineJoin(a.getInt(
1363a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_strokeLineJoin, -1), mStrokeLineJoin);
1364a95c8abb366d9c39450513335f550b56da13b30aztenghui            mStrokeMiterlimit = a.getFloat(
1365a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_strokeMiterLimit, mStrokeMiterlimit);
1366a95c8abb366d9c39450513335f550b56da13b30aztenghui            mStrokeColor = a.getColor(R.styleable.VectorDrawablePath_strokeColor,
1367a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mStrokeColor);
1368a95c8abb366d9c39450513335f550b56da13b30aztenghui            mStrokeWidth = a.getFloat(R.styleable.VectorDrawablePath_strokeWidth,
1369a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mStrokeWidth);
1370a95c8abb366d9c39450513335f550b56da13b30aztenghui            mTrimPathEnd = a.getFloat(R.styleable.VectorDrawablePath_trimPathEnd,
1371a95c8abb366d9c39450513335f550b56da13b30aztenghui                    mTrimPathEnd);
1372a95c8abb366d9c39450513335f550b56da13b30aztenghui            mTrimPathOffset = a.getFloat(
1373a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_trimPathOffset, mTrimPathOffset);
1374a95c8abb366d9c39450513335f550b56da13b30aztenghui            mTrimPathStart = a.getFloat(
1375a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath_trimPathStart, mTrimPathStart);
1376a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1377a95c8abb366d9c39450513335f550b56da13b30aztenghui
1378a95c8abb366d9c39450513335f550b56da13b30aztenghui        @Override
1379a95c8abb366d9c39450513335f550b56da13b30aztenghui        public void applyTheme(Theme t) {
1380a95c8abb366d9c39450513335f550b56da13b30aztenghui            if (mThemeAttrs == null) {
1381a95c8abb366d9c39450513335f550b56da13b30aztenghui                return;
1382a95c8abb366d9c39450513335f550b56da13b30aztenghui            }
1383a95c8abb366d9c39450513335f550b56da13b30aztenghui
1384a95c8abb366d9c39450513335f550b56da13b30aztenghui            final TypedArray a = t.resolveAttributes(mThemeAttrs,
1385a95c8abb366d9c39450513335f550b56da13b30aztenghui                    R.styleable.VectorDrawablePath);
1386a95c8abb366d9c39450513335f550b56da13b30aztenghui            updateStateFromTypedArray(a);
1387a95c8abb366d9c39450513335f550b56da13b30aztenghui            a.recycle();
1388a95c8abb366d9c39450513335f550b56da13b30aztenghui        }
1389a95c8abb366d9c39450513335f550b56da13b30aztenghui
1390a95c8abb366d9c39450513335f550b56da13b30aztenghui        /* Setters and Getters, used by animator from AnimatedVectorDrawable. */
1391eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1392e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        int getStroke() {
1393e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mStrokeColor;
1394e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1395e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1396eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1397e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setStroke(int strokeColor) {
1398e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mStrokeColor = strokeColor;
1399e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1400e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1401eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1402e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        float getStrokeWidth() {
1403e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mStrokeWidth;
1404e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1405e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1406eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1407e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setStrokeWidth(float strokeWidth) {
1408e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mStrokeWidth = strokeWidth;
1409e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1410e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1411eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1412e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        int getFill() {
1413e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mFillColor;
1414e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1415e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1416eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1417e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setFill(int fillColor) {
1418e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mFillColor = fillColor;
1419e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1420e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1421eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1422e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        float getTrimPathStart() {
1423e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mTrimPathStart;
1424e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1425e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1426eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1427e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setTrimPathStart(float trimPathStart) {
1428e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mTrimPathStart = trimPathStart;
1429e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1430e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1431eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1432e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        float getTrimPathEnd() {
1433e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mTrimPathEnd;
1434e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1435e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1436eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1437e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setTrimPathEnd(float trimPathEnd) {
1438e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mTrimPathEnd = trimPathEnd;
1439e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1440e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1441eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1442e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        float getTrimPathOffset() {
1443e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            return mTrimPathOffset;
1444e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1445e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui
1446eb034fbca40006c55db143047eb628c4b657730aztenghui        @SuppressWarnings("unused")
1447e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        void setTrimPathOffset(float trimPathOffset) {
1448e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui            mTrimPathOffset = trimPathOffset;
1449e5e92602a41a4ddc7b42cd1c171a0edfbd09b8daztenghui        }
1450abb7d134c02ac60091108c491dafb00877093170John Hoford    }
1451abb7d134c02ac60091108c491dafb00877093170John Hoford}
1452