├── .gitignore
├── .idea
├── caches
│ ├── build_file_checksums.ser
│ └── gradle_models.ser
├── codeStyles
│ └── Project.xml
├── compiler.xml
├── deploymentTargetDropDown.xml
├── gradle.xml
├── jarRepositories.xml
├── markdown-navigator.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── sonarlint
│ ├── issuestore
│ │ ├── 0
│ │ │ └── 7
│ │ │ │ └── 0799de7a5e4520895c664db6a9055f5543abafd7
│ │ ├── 1
│ │ │ ├── 3
│ │ │ │ └── 130e4e4a7f0670184230ed75f2e74c844cd2699e
│ │ │ ├── 9
│ │ │ │ └── 198bd847149ebd0bd4327f53f649eda8cc9d54bd
│ │ │ └── d
│ │ │ │ └── 1d00df18e7ecf1361a03cbc96a450a38fea922eb
│ │ ├── 2
│ │ │ └── a
│ │ │ │ └── 2afbb999f001938c88fa43fc2ef52abf0f8213e4
│ │ ├── 3
│ │ │ └── f
│ │ │ │ └── 3f2a2c6b8252e6d44ebea0bdcbf843bfc75b3ff3
│ │ ├── 8
│ │ │ └── c
│ │ │ │ └── 8c55c3ccc257e5907959013f99656e4c8ec3903e
│ │ ├── c
│ │ │ └── 2
│ │ │ │ └── c2c5a913aa3d555b08350d25804f5cdac9112098
│ │ ├── d
│ │ │ └── 9
│ │ │ │ └── d91d3ccb06052809e4f59c2cfce4c56f918fcea8
│ │ ├── e
│ │ │ └── 5
│ │ │ │ └── e56f3969db025650ef4296282e0fd05e85fc0f70
│ │ ├── f
│ │ │ ├── 0
│ │ │ │ └── f07866736216be0ee2aba49e392191aeae700a35
│ │ │ └── 4
│ │ │ │ └── f4a01d6a4fcb971362ec00a83903fd3902f52164
│ │ └── index.pb
│ └── securityhotspotstore
│ │ ├── 0
│ │ └── 7
│ │ │ └── 0799de7a5e4520895c664db6a9055f5543abafd7
│ │ ├── 1
│ │ ├── 3
│ │ │ └── 130e4e4a7f0670184230ed75f2e74c844cd2699e
│ │ ├── 9
│ │ │ └── 198bd847149ebd0bd4327f53f649eda8cc9d54bd
│ │ └── d
│ │ │ └── 1d00df18e7ecf1361a03cbc96a450a38fea922eb
│ │ ├── 2
│ │ └── a
│ │ │ └── 2afbb999f001938c88fa43fc2ef52abf0f8213e4
│ │ ├── 3
│ │ └── f
│ │ │ └── 3f2a2c6b8252e6d44ebea0bdcbf843bfc75b3ff3
│ │ ├── 8
│ │ └── c
│ │ │ └── 8c55c3ccc257e5907959013f99656e4c8ec3903e
│ │ ├── c
│ │ └── 2
│ │ │ └── c2c5a913aa3d555b08350d25804f5cdac9112098
│ │ ├── d
│ │ └── 9
│ │ │ └── d91d3ccb06052809e4f59c2cfce4c56f918fcea8
│ │ ├── e
│ │ └── 5
│ │ │ └── e56f3969db025650ef4296282e0fd05e85fc0f70
│ │ ├── f
│ │ ├── 0
│ │ │ └── f07866736216be0ee2aba49e392191aeae700a35
│ │ └── 4
│ │ │ └── f4a01d6a4fcb971362ec00a83903fd3902f52164
│ │ └── index.pb
└── vcs.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── devs
│ │ └── vectorchildfinderdemo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── devs
│ │ │ └── vectorchildfinderdemo
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── boy.xml
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── devs
│ └── vectorchildfinderdemo
│ └── ExampleUnitTest.java
├── assets
├── gym.png
└── vector1.0.0.gif
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── vectorchildfinder
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── devs
│ └── vectorchildfinder
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── devs
│ │ └── vectorchildfinder
│ │ ├── AndroidResources.java
│ │ ├── PathParser.java
│ │ ├── TypedArrayUtils.java
│ │ ├── VectorChildFinder.java
│ │ ├── VectorDrawableCommon.java
│ │ └── VectorDrawableCompat.java
└── res
│ └── values
│ └── strings.xml
└── test
└── java
└── com
└── devs
└── vectorchildfinder
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/caches/gradle_models.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/caches/gradle_models.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetDropDown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | 1.8
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/0/7/0799de7a5e4520895c664db6a9055f5543abafd7:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/0/7/0799de7a5e4520895c664db6a9055f5543abafd7
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/1/3/130e4e4a7f0670184230ed75f2e74c844cd2699e:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/1/3/130e4e4a7f0670184230ed75f2e74c844cd2699e
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/1/9/198bd847149ebd0bd4327f53f649eda8cc9d54bd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/1/9/198bd847149ebd0bd4327f53f649eda8cc9d54bd
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/1/d/1d00df18e7ecf1361a03cbc96a450a38fea922eb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/1/d/1d00df18e7ecf1361a03cbc96a450a38fea922eb
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/3/f/3f2a2c6b8252e6d44ebea0bdcbf843bfc75b3ff3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/3/f/3f2a2c6b8252e6d44ebea0bdcbf843bfc75b3ff3
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/8/c/8c55c3ccc257e5907959013f99656e4c8ec3903e:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/8/c/8c55c3ccc257e5907959013f99656e4c8ec3903e
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/c/2/c2c5a913aa3d555b08350d25804f5cdac9112098:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/c/2/c2c5a913aa3d555b08350d25804f5cdac9112098
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/d/9/d91d3ccb06052809e4f59c2cfce4c56f918fcea8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/d/9/d91d3ccb06052809e4f59c2cfce4c56f918fcea8
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/e/5/e56f3969db025650ef4296282e0fd05e85fc0f70:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/e/5/e56f3969db025650ef4296282e0fd05e85fc0f70
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/f/0/f07866736216be0ee2aba49e392191aeae700a35:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/f/0/f07866736216be0ee2aba49e392191aeae700a35
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/f/4/f4a01d6a4fcb971362ec00a83903fd3902f52164:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/f/4/f4a01d6a4fcb971362ec00a83903fd3902f52164
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/index.pb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/issuestore/index.pb
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/0/7/0799de7a5e4520895c664db6a9055f5543abafd7:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/0/7/0799de7a5e4520895c664db6a9055f5543abafd7
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/1/3/130e4e4a7f0670184230ed75f2e74c844cd2699e:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/1/3/130e4e4a7f0670184230ed75f2e74c844cd2699e
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/1/9/198bd847149ebd0bd4327f53f649eda8cc9d54bd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/1/9/198bd847149ebd0bd4327f53f649eda8cc9d54bd
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/1/d/1d00df18e7ecf1361a03cbc96a450a38fea922eb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/1/d/1d00df18e7ecf1361a03cbc96a450a38fea922eb
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/3/f/3f2a2c6b8252e6d44ebea0bdcbf843bfc75b3ff3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/3/f/3f2a2c6b8252e6d44ebea0bdcbf843bfc75b3ff3
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/8/c/8c55c3ccc257e5907959013f99656e4c8ec3903e:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/8/c/8c55c3ccc257e5907959013f99656e4c8ec3903e
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/c/2/c2c5a913aa3d555b08350d25804f5cdac9112098:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/c/2/c2c5a913aa3d555b08350d25804f5cdac9112098
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/d/9/d91d3ccb06052809e4f59c2cfce4c56f918fcea8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/d/9/d91d3ccb06052809e4f59c2cfce4c56f918fcea8
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/e/5/e56f3969db025650ef4296282e0fd05e85fc0f70:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/e/5/e56f3969db025650ef4296282e0fd05e85fc0f70
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/f/0/f07866736216be0ee2aba49e392191aeae700a35:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/f/0/f07866736216be0ee2aba49e392191aeae700a35
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/f/4/f4a01d6a4fcb971362ec00a83903fd3902f52164:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/f/4/f4a01d6a4fcb971362ec00a83903fd3902f52164
--------------------------------------------------------------------------------
/.idea/sonarlint/securityhotspotstore/index.pb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/.idea/sonarlint/securityhotspotstore/index.pb
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # VectorChildFinder
2 | []( https://android-arsenal.com/details/1/6733 )
3 | [](https://jitpack.io/#devsideal/VectorChildFinder/1.0.0)
4 | [](http://www.apache.org/licenses/LICENSE-2.0.html)
5 |
6 | VectorChildFinder helps to find inner elements of vector drawable like path and group.
7 | ## Demo
8 | 
9 |
10 | ## Dependency
11 | - Add the dependencies to your gradle files:
12 |
13 | #### Step 1. Add it in your root build.gradle at the end of repositories
14 | ```gradle
15 | allprojects {
16 | repositories {
17 | ...
18 | maven { url 'https://jitpack.io' }
19 | }
20 | }
21 | ```
22 |
23 | #### Step 2. Add the dependency
24 | ```gradle
25 | dependencies {
26 | compile 'com.github.devsideal:VectorChildFinder:1.0.0'
27 | }
28 |
29 | ```
30 |
31 | ## Usage
32 | ```java
33 | VectorChildFinder vector = new VectorChildFinder(this, R.drawable.my_vector, imageView);
34 |
35 | VectorDrawableCompat.VFullPath path1 = vector.findPathByName("path1");
36 | path1.setFillColor(Color.RED);
37 |
38 | VectorDrawableCompat.VGroup group1 = vector.findGroupByName("group1");
39 | group1.setTranslateX(10);
40 |
41 | imageView.invalidate();
42 |
43 | ```
44 |
45 | ## Used by
46 |
47 |
48 |
49 | [Gym Scheduler][Gym Scheduler]
50 |
51 | ## License
52 | ```
53 | Copyright 2018 Deven Singh
54 |
55 | Licensed under the Apache License, Version 2.0 (the "License");
56 | you may not use this file except in compliance with the License.
57 | You may obtain a copy of the License at
58 |
59 | http://www.apache.org/licenses/LICENSE-2.0
60 |
61 | Unless required by applicable law or agreed to in writing, software
62 | distributed under the License is distributed on an "AS IS" BASIS,
63 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
64 | See the License for the specific language governing permissions and
65 | limitations under the License.
66 | ```
67 |
68 | [Gym Scheduler]: https://play.google.com/store/apps/details?id=com.devs.gym
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdk 33
5 | defaultConfig {
6 | applicationId "com.devs.vectorchildfinderdemo"
7 | minSdkVersion 16
8 | targetSdkVersion 33
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
12 | vectorDrawables.useSupportLibrary = true
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | compileOptions {
22 | sourceCompatibility JavaVersion.VERSION_17
23 | targetCompatibility JavaVersion.VERSION_17
24 | }
25 | namespace 'com.devs.vectorchildfinderdemo'
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 | implementation 'androidx.appcompat:appcompat:1.6.1'
31 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
32 | testImplementation 'junit:junit:4.13.2'
33 | androidTestImplementation 'androidx.test.ext:junit:1.1.5'
34 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
35 |
36 | implementation project(':vectorchildfinder')
37 | //compile 'com.github.devsideal:VectorChildFinder:1.0.0'
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/devs/vectorchildfinderdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.devs.vectorchildfinderdemo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import android.content.Context;
6 |
7 | import androidx.test.ext.junit.runners.AndroidJUnit4;
8 | import androidx.test.platform.app.InstrumentationRegistry;
9 |
10 | import org.junit.Test;
11 | import org.junit.runner.RunWith;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() throws Exception {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.devs.vectorchildfinderdemo", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/devs/vectorchildfinderdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.devs.vectorchildfinderdemo;
2 |
3 | import static android.graphics.drawable.Drawable.createFromPath;
4 |
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.graphics.drawable.Drawable;
8 | import android.media.Image;
9 | import android.os.Bundle;
10 | import android.util.Log;
11 | import android.view.MotionEvent;
12 | import android.view.View;
13 | import android.widget.ImageView;
14 | import android.widget.Toast;
15 |
16 | import androidx.appcompat.app.AppCompatActivity;
17 | import androidx.core.graphics.PathParser;
18 |
19 | import com.devs.vectorchildfinder.VectorChildFinder;
20 | import com.devs.vectorchildfinder.VectorDrawableCompat;
21 | //import android.support.graphics.drawable.VectorDrawableCompat;
22 |
23 |
24 | public class MainActivity extends AppCompatActivity {
25 |
26 | VectorDrawableCompat.VFullPath dressPath;
27 | VectorDrawableCompat.VGroup mouthGroup, eyesGroup;
28 | ImageView image;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 |
35 |
36 | image = findViewById(R.id.image);
37 |
38 | VectorChildFinder vector = new VectorChildFinder(this,
39 | R.drawable.boy, image);
40 | dressPath = vector.findPathByName("dress_path");
41 | mouthGroup = vector.findGroupByName("mouth_group");
42 | eyesGroup = vector.findGroupByName("eyes_group");
43 |
44 |
45 |
46 | for (int i=0; i < dressPath.getPathData().length; i++){
47 | String path =dressPath.getPathData()[i].toString();
48 | Log.d("savedInstanceState", ""+path);
49 |
50 | }
51 |
52 |
53 | image.setOnTouchListener((v, event) -> {
54 | switch (event.getAction()){
55 | case MotionEvent.ACTION_UP:
56 | // TODO
57 | Toast.makeText(MainActivity.this,
58 | mouthGroup.getScaleX() +"__"+
59 | mouthGroup.getLocalMatrix(),
60 | Toast.LENGTH_SHORT).show();
61 | break;
62 | }
63 | return true;
64 | });
65 |
66 | }
67 |
68 | boolean e = true, m = true;
69 | public void onButtonClick(View view){
70 | switch (view.getId()) {
71 | case R.id.button1:
72 | dressPath.setFillColor(getResources().getColor(android.R.color.holo_red_light));
73 | break;
74 |
75 | case R.id.button2:
76 | dressPath.setFillColor(getResources().getColor(android.R.color.holo_green_dark));
77 | break;
78 |
79 | case R.id.button3:
80 | dressPath.setFillColor(getResources().getColor(android.R.color.holo_blue_dark));
81 | break;
82 |
83 | case R.id.button4:
84 | dressPath.setFillColor(getResources().getColor(android.R.color.holo_purple));
85 | break;
86 |
87 | case R.id.btn_eyes:
88 | if (e) {
89 | e = false;
90 | eyesGroup.setTranslateX(-10);
91 | }
92 | else {
93 | e = true;
94 | eyesGroup.setTranslateX(0);
95 | }
96 |
97 | break;
98 |
99 | case R.id.btn_mouth:
100 | if(m) {
101 | m = false;
102 | mouthGroup.setTranslateX(-10);
103 | }
104 | else {
105 | m = true;
106 | mouthGroup.setTranslateX(0);
107 | }
108 | break;
109 | }
110 |
111 | image.invalidate();
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/boy.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
20 |
33 |
34 |
47 |
48 |
61 |
62 |
73 |
74 |
85 |
86 |
99 |
100 |
113 |
114 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #ff4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | VectorChildFinderDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/devs/vectorchildfinderdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.devs.vectorchildfinderdemo;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Test;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/assets/gym.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/assets/gym.png
--------------------------------------------------------------------------------
/assets/vector1.0.0.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/assets/vector1.0.0.gif
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | mavenCentral()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:8.0.2'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | mavenCentral()
22 | maven { url 'https://jitpack.io' }
23 | }
24 | }
25 |
26 | tasks.register('clean', Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 | # android.disableAutomaticComponentCreation=true
16 | android.defaults.buildfeatures.buildconfig=true
17 | android.nonTransitiveRClass=false
18 | android.nonFinalResIds=false
19 |
20 | # When configured, Gradle will run in incubating parallel mode.
21 | # This option should only be used with decoupled projects. More details, visit
22 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
23 | # org.gradle.parallel=true
24 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devendroid/VectorChildFinder/6f6d99e6f66ee5c282a4afae76e21cb39af3da94/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jun 13 14:28:07 BST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':vectorchildfinder'
2 |
--------------------------------------------------------------------------------
/vectorchildfinder/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/vectorchildfinder/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven-publish'
3 | group = 'com.github.devsideal'
4 |
5 | android {
6 | compileSdk 33
7 |
8 |
9 |
10 | defaultConfig {
11 | minSdkVersion 16
12 | targetSdkVersion 33
13 |
14 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
15 | vectorDrawables.useSupportLibrary = true
16 | }
17 |
18 | compileOptions {
19 | sourceCompatibility JavaVersion.VERSION_17
20 | targetCompatibility JavaVersion.VERSION_17
21 | }
22 |
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
27 | }
28 | }
29 | namespace 'com.devs.vectorchildfinder'
30 |
31 | }
32 |
33 | dependencies {
34 | implementation fileTree(dir: 'libs', include: ['*.jar'])
35 |
36 | // implementation 'com.android.support:appcompat-v7:26.1.0'
37 | implementation 'androidx.appcompat:appcompat:1.6.1'
38 | testImplementation 'junit:junit:4.13.2'
39 | androidTestImplementation 'androidx.test.ext:junit:1.1.5'
40 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
41 | }
42 |
--------------------------------------------------------------------------------
/vectorchildfinder/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/vectorchildfinder/src/androidTest/java/com/devs/vectorchildfinder/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.devs.vectorchildfinder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import android.content.Context;
6 |
7 | import androidx.test.ext.junit.runners.AndroidJUnit4;
8 | import androidx.test.platform.app.InstrumentationRegistry;
9 |
10 | import org.junit.Test;
11 | import org.junit.runner.RunWith;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() throws Exception {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.devs.vectorchildfinder.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/vectorchildfinder/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/vectorchildfinder/src/main/java/com/devs/vectorchildfinder/AndroidResources.java:
--------------------------------------------------------------------------------
1 | package com.devs.vectorchildfinder;
2 |
3 | /**
4 | * Created by ${Deven} on 1/31/18.
5 | */
6 |
7 | public class AndroidResources {
8 | // Resources ID generated in the latest R.java for framework.
9 | static final int[] styleable_VectorDrawableTypeArray = {
10 | android.R.attr.name, android.R.attr.tint, android.R.attr.height,
11 | android.R.attr.width, android.R.attr.alpha, android.R.attr.autoMirrored,
12 | android.R.attr.tintMode, android.R.attr.viewportWidth, android.R.attr.viewportHeight
13 | };
14 | static final int styleable_VectorDrawable_alpha = 4;
15 | static final int styleable_VectorDrawable_autoMirrored = 5;
16 | static final int styleable_VectorDrawable_height = 2;
17 | static final int styleable_VectorDrawable_name = 0;
18 | static final int styleable_VectorDrawable_tint = 1;
19 | static final int styleable_VectorDrawable_tintMode = 6;
20 | static final int styleable_VectorDrawable_viewportHeight = 8;
21 | static final int styleable_VectorDrawable_viewportWidth = 7;
22 | static final int styleable_VectorDrawable_width = 3;
23 | static final int[] styleable_VectorDrawableGroup = {
24 | android.R.attr.name, android.R.attr.pivotX, android.R.attr.pivotY,
25 | android.R.attr.scaleX, android.R.attr.scaleY, android.R.attr.rotation,
26 | android.R.attr.translateX, android.R.attr.translateY
27 | };
28 | static final int styleable_VectorDrawableGroup_name = 0;
29 | static final int styleable_VectorDrawableGroup_pivotX = 1;
30 | static final int styleable_VectorDrawableGroup_pivotY = 2;
31 | static final int styleable_VectorDrawableGroup_rotation = 5;
32 | static final int styleable_VectorDrawableGroup_scaleX = 3;
33 | static final int styleable_VectorDrawableGroup_scaleY = 4;
34 | static final int styleable_VectorDrawableGroup_translateX = 6;
35 | static final int styleable_VectorDrawableGroup_translateY = 7;
36 | static final int[] styleable_VectorDrawablePath = {
37 | android.R.attr.name, android.R.attr.fillColor, android.R.attr.pathData,
38 | android.R.attr.strokeColor, android.R.attr.strokeWidth, android.R.attr.trimPathStart,
39 | android.R.attr.trimPathEnd, android.R.attr.trimPathOffset, android.R.attr.strokeLineCap,
40 | android.R.attr.strokeLineJoin, android.R.attr.strokeMiterLimit,
41 | android.R.attr.strokeAlpha, android.R.attr.fillAlpha
42 | };
43 | static final int styleable_VectorDrawablePath_fillAlpha = 12;
44 | static final int styleable_VectorDrawablePath_fillColor = 1;
45 | static final int styleable_VectorDrawablePath_name = 0;
46 | static final int styleable_VectorDrawablePath_pathData = 2;
47 | static final int styleable_VectorDrawablePath_strokeAlpha = 11;
48 | static final int styleable_VectorDrawablePath_strokeColor = 3;
49 | static final int styleable_VectorDrawablePath_strokeLineCap = 8;
50 | static final int styleable_VectorDrawablePath_strokeLineJoin = 9;
51 | static final int styleable_VectorDrawablePath_strokeMiterLimit = 10;
52 | static final int styleable_VectorDrawablePath_strokeWidth = 4;
53 | static final int styleable_VectorDrawablePath_trimPathEnd = 6;
54 | static final int styleable_VectorDrawablePath_trimPathOffset = 7;
55 | static final int styleable_VectorDrawablePath_trimPathStart = 5;
56 | static final int[] styleable_VectorDrawableClipPath = {
57 | android.R.attr.name, android.R.attr.pathData
58 | };
59 | static final int styleable_VectorDrawableClipPath_name = 0;
60 | static final int styleable_VectorDrawableClipPath_pathData = 1;
61 |
62 | static final int[] styleable_AnimatedVectorDrawable = {
63 | android.R.attr.drawable
64 | };
65 | static final int styleable_AnimatedVectorDrawable_drawable = 0;
66 | static final int[] styleable_AnimatedVectorDrawableTarget = {
67 | android.R.attr.name, android.R.attr.animation
68 | };
69 | static final int styleable_AnimatedVectorDrawableTarget_animation = 1;
70 | static final int styleable_AnimatedVectorDrawableTarget_name = 0;
71 | }
72 |
--------------------------------------------------------------------------------
/vectorchildfinder/src/main/java/com/devs/vectorchildfinder/PathParser.java:
--------------------------------------------------------------------------------
1 | package com.devs.vectorchildfinder;
2 |
3 | /**
4 | * Created by ${Deven} on 1/31/18.
5 | */
6 |
7 | import android.graphics.Path;
8 | import android.util.Log;
9 |
10 | import java.util.ArrayList;
11 |
12 | // This class is a duplicate from the PathParser.java of frameworks/base, with slight
13 | // update on incompatible API like copyOfRange().
14 | class PathParser {
15 | private static final String LOGTAG = "PathParser";
16 |
17 | // Copy from Arrays.copyOfRange() which is only available from API level 9.
18 |
19 | /**
20 | * Copies elements from {@code original} into a new array, from indexes start (inclusive) to
21 | * end (exclusive). The original order of elements is preserved.
22 | * If {@code end} is greater than {@code original.length}, the result is padded
23 | * with the value {@code 0.0f}.
24 | *
25 | * @param original the original array
26 | * @param start the start index, inclusive
27 | * @param end the end index, exclusive
28 | * @return the new array
29 | * @throws ArrayIndexOutOfBoundsException if {@code start < 0 || start > original.length}
30 | * @throws IllegalArgumentException if {@code start > end}
31 | * @throws NullPointerException if {@code original == null}
32 | */
33 | static float[] copyOfRange(float[] original, int start, int end) {
34 | if (start > end) {
35 | throw new IllegalArgumentException();
36 | }
37 | int originalLength = original.length;
38 | if (start < 0 || start > originalLength) {
39 | throw new ArrayIndexOutOfBoundsException();
40 | }
41 | int resultLength = end - start;
42 | int copyLength = Math.min(resultLength, originalLength - start);
43 | float[] result = new float[resultLength];
44 | System.arraycopy(original, start, result, 0, copyLength);
45 | return result;
46 | }
47 |
48 | /**
49 | * @param pathData The string representing a path, the same as "d" string in svg file.
50 | * @return the generated Path object.
51 | */
52 | public static Path createPathFromPathData(String pathData) {
53 | Path path = new Path();
54 | PathDataNode[] nodes = createNodesFromPathData(pathData);
55 | if (nodes != null) {
56 | try {
57 | PathDataNode.nodesToPath(nodes, path);
58 | } catch (RuntimeException e) {
59 | throw new RuntimeException("Error in parsing " + pathData, e);
60 | }
61 | return path;
62 | }
63 | return null;
64 | }
65 |
66 | /**
67 | * @param pathData The string representing a path, the same as "d" string in svg file.
68 | * @return an array of the PathDataNode.
69 | */
70 | public static PathDataNode[] createNodesFromPathData(String pathData) {
71 | if (pathData == null) {
72 | return null;
73 | }
74 | int start = 0;
75 | int end = 1;
76 |
77 | ArrayList list = new ArrayList();
78 | while (end < pathData.length()) {
79 | end = nextStart(pathData, end);
80 | String s = pathData.substring(start, end).trim();
81 | if (s.length() > 0) {
82 | float[] val = getFloats(s);
83 | addNode(list, s.charAt(0), val);
84 | }
85 |
86 | start = end;
87 | end++;
88 | }
89 | if ((end - start) == 1 && start < pathData.length()) {
90 | addNode(list, pathData.charAt(start), new float[0]);
91 | }
92 | return list.toArray(new PathDataNode[list.size()]);
93 | }
94 |
95 | /**
96 | * @param source The array of PathDataNode to be duplicated.
97 | * @return a deep copy of the source
.
98 | */
99 | public static PathDataNode[] deepCopyNodes(PathDataNode[] source) {
100 | if (source == null) {
101 | return null;
102 | }
103 | PathDataNode[] copy = new PathDataNode[source.length];
104 | for (int i = 0; i < source.length; i++) {
105 | copy[i] = new PathDataNode(source[i]);
106 | }
107 | return copy;
108 | }
109 |
110 | /**
111 | * @param nodesFrom The source path represented in an array of PathDataNode
112 | * @param nodesTo The target path represented in an array of PathDataNode
113 | * @return whether the nodesFrom
can morph into nodesTo
114 | */
115 | public static boolean canMorph(PathDataNode[] nodesFrom,
116 | PathDataNode[] nodesTo) {
117 | if (nodesFrom == null || nodesTo == null) {
118 | return false;
119 | }
120 |
121 | if (nodesFrom.length != nodesTo.length) {
122 | return false;
123 | }
124 |
125 | for (int i = 0; i < nodesFrom.length; i++) {
126 | if (nodesFrom[i].type != nodesTo[i].type
127 | || nodesFrom[i].params.length != nodesTo[i].params.length) {
128 | return false;
129 | }
130 | }
131 | return true;
132 | }
133 |
134 | /**
135 | * Update the target's data to match the source.
136 | * Before calling this, make sure canMorph(target, source) is true.
137 | *
138 | * @param target The target path represented in an array of PathDataNode
139 | * @param source The source path represented in an array of PathDataNode
140 | */
141 | public static void updateNodes(PathDataNode[] target, PathDataNode[] source) {
142 | for (int i = 0; i < source.length; i++) {
143 | target[i].type = source[i].type;
144 | for (int j = 0; j < source[i].params.length; j++) {
145 | target[i].params[j] = source[i].params[j];
146 | }
147 | }
148 | }
149 |
150 | private static int nextStart(String s, int end) {
151 | char c;
152 |
153 | while (end < s.length()) {
154 | c = s.charAt(end);
155 | // Note that 'e' or 'E' are not valid path commands, but could be
156 | // used for floating point numbers' scientific notation.
157 | // Therefore, when searching for next command, we should ignore 'e'
158 | // and 'E'.
159 | if ((((c - 'A') * (c - 'Z') <= 0) || ((c - 'a') * (c - 'z') <= 0))
160 | && c != 'e' && c != 'E') {
161 | return end;
162 | }
163 | end++;
164 | }
165 | return end;
166 | }
167 |
168 | private static void addNode(ArrayList list, char cmd, float[] val) {
169 | list.add(new PathDataNode(cmd, val));
170 | }
171 |
172 | private static class ExtractFloatResult {
173 | // We need to return the position of the next separator and whether the
174 | // next float starts with a '-' or a '.'.
175 | int mEndPosition;
176 | boolean mEndWithNegOrDot;
177 |
178 | ExtractFloatResult() {
179 | }
180 | }
181 |
182 | /**
183 | * Parse the floats in the string.
184 | * This is an optimized version of parseFloat(s.split(",|\\s"));
185 | *
186 | * @param s the string containing a command and list of floats
187 | * @return array of floats
188 | */
189 | private static float[] getFloats(String s) {
190 | if (s.charAt(0) == 'z' | s.charAt(0) == 'Z') {
191 | return new float[0];
192 | }
193 | try {
194 | float[] results = new float[s.length()];
195 | int count = 0;
196 | int startPosition = 1;
197 | int endPosition = 0;
198 |
199 | ExtractFloatResult result = new ExtractFloatResult();
200 | int totalLength = s.length();
201 |
202 | // The startPosition should always be the first character of the
203 | // current number, and endPosition is the character after the current
204 | // number.
205 | while (startPosition < totalLength) {
206 | extract(s, startPosition, result);
207 | endPosition = result.mEndPosition;
208 |
209 | if (startPosition < endPosition) {
210 | results[count++] = Float.parseFloat(
211 | s.substring(startPosition, endPosition));
212 | }
213 |
214 | if (result.mEndWithNegOrDot) {
215 | // Keep the '-' or '.' sign with next number.
216 | startPosition = endPosition;
217 | } else {
218 | startPosition = endPosition + 1;
219 | }
220 | }
221 | return copyOfRange(results, 0, count);
222 | } catch (NumberFormatException e) {
223 | throw new RuntimeException("error in parsing \"" + s + "\"", e);
224 | }
225 | }
226 |
227 | /**
228 | * Calculate the position of the next comma or space or negative sign
229 | *
230 | * @param s the string to search
231 | * @param start the position to start searching
232 | * @param result the result of the extraction, including the position of the
233 | * the starting position of next number, whether it is ending with a '-'.
234 | */
235 | private static void extract(String s, int start, ExtractFloatResult result) {
236 | // Now looking for ' ', ',', '.' or '-' from the start.
237 | int currentIndex = start;
238 | boolean foundSeparator = false;
239 | result.mEndWithNegOrDot = false;
240 | boolean secondDot = false;
241 | boolean isExponential = false;
242 | for (; currentIndex < s.length(); currentIndex++) {
243 | boolean isPrevExponential = isExponential;
244 | isExponential = false;
245 | char currentChar = s.charAt(currentIndex);
246 | switch (currentChar) {
247 | case ' ':
248 | case ',':
249 | foundSeparator = true;
250 | break;
251 | case '-':
252 | // The negative sign following a 'e' or 'E' is not a separator.
253 | if (currentIndex != start && !isPrevExponential) {
254 | foundSeparator = true;
255 | result.mEndWithNegOrDot = true;
256 | }
257 | break;
258 | case '.':
259 | if (!secondDot) {
260 | secondDot = true;
261 | } else {
262 | // This is the second dot, and it is considered as a separator.
263 | foundSeparator = true;
264 | result.mEndWithNegOrDot = true;
265 | }
266 | break;
267 | case 'e':
268 | case 'E':
269 | isExponential = true;
270 | break;
271 | }
272 | if (foundSeparator) {
273 | break;
274 | }
275 | }
276 | // When there is nothing found, then we put the end position to the end
277 | // of the string.
278 | result.mEndPosition = currentIndex;
279 | }
280 |
281 | /**
282 | * Each PathDataNode represents one command in the "d" attribute of the svg
283 | * file.
284 | * An array of PathDataNode can represent the whole "d" attribute.
285 | */
286 | public static class PathDataNode {
287 | /*package*/
288 | char type;
289 | float[] params;
290 |
291 | PathDataNode(char type, float[] params) {
292 | this.type = type;
293 | this.params = params;
294 | }
295 |
296 | PathDataNode(PathDataNode n) {
297 | type = n.type;
298 | params = copyOfRange(n.params, 0, n.params.length);
299 | }
300 |
301 | /**
302 | * Convert an array of PathDataNode to Path.
303 | *
304 | * @param node The source array of PathDataNode.
305 | * @param path The target Path object.
306 | */
307 | public static void nodesToPath(PathDataNode[] node, Path path) {
308 | float[] current = new float[6];
309 | char previousCommand = 'm';
310 | for (int i = 0; i < node.length; i++) {
311 | addCommand(path, current, previousCommand, node[i].type, node[i].params);
312 | previousCommand = node[i].type;
313 | }
314 | }
315 |
316 | /**
317 | * The current PathDataNode will be interpolated between the
318 | * nodeFrom
and nodeTo
according to the
319 | * fraction
.
320 | *
321 | * @param nodeFrom The start value as a PathDataNode.
322 | * @param nodeTo The end value as a PathDataNode
323 | * @param fraction The fraction to interpolate.
324 | */
325 | public void interpolatePathDataNode(PathDataNode nodeFrom,
326 | PathDataNode nodeTo, float fraction) {
327 | for (int i = 0; i < nodeFrom.params.length; i++) {
328 | params[i] = nodeFrom.params[i] * (1 - fraction)
329 | + nodeTo.params[i] * fraction;
330 | }
331 | }
332 |
333 | private static void addCommand(Path path, float[] current,
334 | char previousCmd, char cmd, float[] val) {
335 |
336 | int incr = 2;
337 | float currentX = current[0];
338 | float currentY = current[1];
339 | float ctrlPointX = current[2];
340 | float ctrlPointY = current[3];
341 | float currentSegmentStartX = current[4];
342 | float currentSegmentStartY = current[5];
343 | float reflectiveCtrlPointX;
344 | float reflectiveCtrlPointY;
345 |
346 | switch (cmd) {
347 | case 'z':
348 | case 'Z':
349 | path.close();
350 | // Path is closed here, but we need to move the pen to the
351 | // closed position. So we cache the segment's starting position,
352 | // and restore it here.
353 | currentX = currentSegmentStartX;
354 | currentY = currentSegmentStartY;
355 | ctrlPointX = currentSegmentStartX;
356 | ctrlPointY = currentSegmentStartY;
357 | path.moveTo(currentX, currentY);
358 | break;
359 | case 'm':
360 | case 'M':
361 | case 'l':
362 | case 'L':
363 | case 't':
364 | case 'T':
365 | incr = 2;
366 | break;
367 | case 'h':
368 | case 'H':
369 | case 'v':
370 | case 'V':
371 | incr = 1;
372 | break;
373 | case 'c':
374 | case 'C':
375 | incr = 6;
376 | break;
377 | case 's':
378 | case 'S':
379 | case 'q':
380 | case 'Q':
381 | incr = 4;
382 | break;
383 | case 'a':
384 | case 'A':
385 | incr = 7;
386 | break;
387 | }
388 |
389 | for (int k = 0; k < val.length; k += incr) {
390 | switch (cmd) {
391 | case 'm': // moveto - Start a new sub-path (relative)
392 | currentX += val[k + 0];
393 | currentY += val[k + 1];
394 | if (k > 0) {
395 | // According to the spec, if a moveto is followed by multiple
396 | // pairs of coordinates, the subsequent pairs are treated as
397 | // implicit lineto commands.
398 | path.rLineTo(val[k + 0], val[k + 1]);
399 | } else {
400 | path.rMoveTo(val[k + 0], val[k + 1]);
401 | currentSegmentStartX = currentX;
402 | currentSegmentStartY = currentY;
403 | }
404 | break;
405 | case 'M': // moveto - Start a new sub-path
406 | currentX = val[k + 0];
407 | currentY = val[k + 1];
408 | if (k > 0) {
409 | // According to the spec, if a moveto is followed by multiple
410 | // pairs of coordinates, the subsequent pairs are treated as
411 | // implicit lineto commands.
412 | path.lineTo(val[k + 0], val[k + 1]);
413 | } else {
414 | path.moveTo(val[k + 0], val[k + 1]);
415 | currentSegmentStartX = currentX;
416 | currentSegmentStartY = currentY;
417 | }
418 | break;
419 | case 'l': // lineto - Draw a line from the current point (relative)
420 | path.rLineTo(val[k + 0], val[k + 1]);
421 | currentX += val[k + 0];
422 | currentY += val[k + 1];
423 | break;
424 | case 'L': // lineto - Draw a line from the current point
425 | path.lineTo(val[k + 0], val[k + 1]);
426 | currentX = val[k + 0];
427 | currentY = val[k + 1];
428 | break;
429 | case 'h': // horizontal lineto - Draws a horizontal line (relative)
430 | path.rLineTo(val[k + 0], 0);
431 | currentX += val[k + 0];
432 | break;
433 | case 'H': // horizontal lineto - Draws a horizontal line
434 | path.lineTo(val[k + 0], currentY);
435 | currentX = val[k + 0];
436 | break;
437 | case 'v': // vertical lineto - Draws a vertical line from the current point (r)
438 | path.rLineTo(0, val[k + 0]);
439 | currentY += val[k + 0];
440 | break;
441 | case 'V': // vertical lineto - Draws a vertical line from the current point
442 | path.lineTo(currentX, val[k + 0]);
443 | currentY = val[k + 0];
444 | break;
445 | case 'c': // curveto - Draws a cubic Bézier curve (relative)
446 | path.rCubicTo(val[k + 0], val[k + 1], val[k + 2], val[k + 3],
447 | val[k + 4], val[k + 5]);
448 |
449 | ctrlPointX = currentX + val[k + 2];
450 | ctrlPointY = currentY + val[k + 3];
451 | currentX += val[k + 4];
452 | currentY += val[k + 5];
453 |
454 | break;
455 | case 'C': // curveto - Draws a cubic Bézier curve
456 | path.cubicTo(val[k + 0], val[k + 1], val[k + 2], val[k + 3],
457 | val[k + 4], val[k + 5]);
458 | currentX = val[k + 4];
459 | currentY = val[k + 5];
460 | ctrlPointX = val[k + 2];
461 | ctrlPointY = val[k + 3];
462 | break;
463 | case 's': // smooth curveto - Draws a cubic Bézier curve (reflective cp)
464 | reflectiveCtrlPointX = 0;
465 | reflectiveCtrlPointY = 0;
466 | if (previousCmd == 'c' || previousCmd == 's'
467 | || previousCmd == 'C' || previousCmd == 'S') {
468 | reflectiveCtrlPointX = currentX - ctrlPointX;
469 | reflectiveCtrlPointY = currentY - ctrlPointY;
470 | }
471 | path.rCubicTo(reflectiveCtrlPointX, reflectiveCtrlPointY,
472 | val[k + 0], val[k + 1],
473 | val[k + 2], val[k + 3]);
474 |
475 | ctrlPointX = currentX + val[k + 0];
476 | ctrlPointY = currentY + val[k + 1];
477 | currentX += val[k + 2];
478 | currentY += val[k + 3];
479 | break;
480 | case 'S': // shorthand/smooth curveto Draws a cubic Bézier curve(reflective cp)
481 | reflectiveCtrlPointX = currentX;
482 | reflectiveCtrlPointY = currentY;
483 | if (previousCmd == 'c' || previousCmd == 's'
484 | || previousCmd == 'C' || previousCmd == 'S') {
485 | reflectiveCtrlPointX = 2 * currentX - ctrlPointX;
486 | reflectiveCtrlPointY = 2 * currentY - ctrlPointY;
487 | }
488 | path.cubicTo(reflectiveCtrlPointX, reflectiveCtrlPointY,
489 | val[k + 0], val[k + 1], val[k + 2], val[k + 3]);
490 | ctrlPointX = val[k + 0];
491 | ctrlPointY = val[k + 1];
492 | currentX = val[k + 2];
493 | currentY = val[k + 3];
494 | break;
495 | case 'q': // Draws a quadratic Bézier (relative)
496 | path.rQuadTo(val[k + 0], val[k + 1], val[k + 2], val[k + 3]);
497 | ctrlPointX = currentX + val[k + 0];
498 | ctrlPointY = currentY + val[k + 1];
499 | currentX += val[k + 2];
500 | currentY += val[k + 3];
501 | break;
502 | case 'Q': // Draws a quadratic Bézier
503 | path.quadTo(val[k + 0], val[k + 1], val[k + 2], val[k + 3]);
504 | ctrlPointX = val[k + 0];
505 | ctrlPointY = val[k + 1];
506 | currentX = val[k + 2];
507 | currentY = val[k + 3];
508 | break;
509 | case 't': // Draws a quadratic Bézier curve(reflective control point)(relative)
510 | reflectiveCtrlPointX = 0;
511 | reflectiveCtrlPointY = 0;
512 | if (previousCmd == 'q' || previousCmd == 't'
513 | || previousCmd == 'Q' || previousCmd == 'T') {
514 | reflectiveCtrlPointX = currentX - ctrlPointX;
515 | reflectiveCtrlPointY = currentY - ctrlPointY;
516 | }
517 | path.rQuadTo(reflectiveCtrlPointX, reflectiveCtrlPointY,
518 | val[k + 0], val[k + 1]);
519 | ctrlPointX = currentX + reflectiveCtrlPointX;
520 | ctrlPointY = currentY + reflectiveCtrlPointY;
521 | currentX += val[k + 0];
522 | currentY += val[k + 1];
523 | break;
524 | case 'T': // Draws a quadratic Bézier curve (reflective control point)
525 | reflectiveCtrlPointX = currentX;
526 | reflectiveCtrlPointY = currentY;
527 | if (previousCmd == 'q' || previousCmd == 't'
528 | || previousCmd == 'Q' || previousCmd == 'T') {
529 | reflectiveCtrlPointX = 2 * currentX - ctrlPointX;
530 | reflectiveCtrlPointY = 2 * currentY - ctrlPointY;
531 | }
532 | path.quadTo(reflectiveCtrlPointX, reflectiveCtrlPointY,
533 | val[k + 0], val[k + 1]);
534 | ctrlPointX = reflectiveCtrlPointX;
535 | ctrlPointY = reflectiveCtrlPointY;
536 | currentX = val[k + 0];
537 | currentY = val[k + 1];
538 | break;
539 | case 'a': // Draws an elliptical arc
540 | // (rx ry x-axis-rotation large-arc-flag sweep-flag x y)
541 | drawArc(path,
542 | currentX,
543 | currentY,
544 | val[k + 5] + currentX,
545 | val[k + 6] + currentY,
546 | val[k + 0],
547 | val[k + 1],
548 | val[k + 2],
549 | val[k + 3] != 0,
550 | val[k + 4] != 0);
551 | currentX += val[k + 5];
552 | currentY += val[k + 6];
553 | ctrlPointX = currentX;
554 | ctrlPointY = currentY;
555 | break;
556 | case 'A': // Draws an elliptical arc
557 | drawArc(path,
558 | currentX,
559 | currentY,
560 | val[k + 5],
561 | val[k + 6],
562 | val[k + 0],
563 | val[k + 1],
564 | val[k + 2],
565 | val[k + 3] != 0,
566 | val[k + 4] != 0);
567 | currentX = val[k + 5];
568 | currentY = val[k + 6];
569 | ctrlPointX = currentX;
570 | ctrlPointY = currentY;
571 | break;
572 | }
573 | previousCmd = cmd;
574 | }
575 |
576 |
577 | current[0] = currentX;
578 | current[1] = currentY;
579 | current[2] = ctrlPointX;
580 | current[3] = ctrlPointY;
581 | current[4] = currentSegmentStartX;
582 | current[5] = currentSegmentStartY;
583 | }
584 |
585 | private static void drawArc(Path p,
586 | float x0,
587 | float y0,
588 | float x1,
589 | float y1,
590 | float a,
591 | float b,
592 | float theta,
593 | boolean isMoreThanHalf,
594 | boolean isPositiveArc) {
595 |
596 | /* Convert rotation angle from degrees to radians */
597 | double thetaD = Math.toRadians(theta);
598 | /* Pre-compute rotation matrix entries */
599 | double cosTheta = Math.cos(thetaD);
600 | double sinTheta = Math.sin(thetaD);
601 | /* Transform (x0, y0) and (x1, y1) into unit space */
602 | /* using (inverse) rotation, followed by (inverse) scale */
603 | double x0p = (x0 * cosTheta + y0 * sinTheta) / a;
604 | double y0p = (-x0 * sinTheta + y0 * cosTheta) / b;
605 | double x1p = (x1 * cosTheta + y1 * sinTheta) / a;
606 | double y1p = (-x1 * sinTheta + y1 * cosTheta) / b;
607 |
608 | /* Compute differences and averages */
609 | double dx = x0p - x1p;
610 | double dy = y0p - y1p;
611 | double xm = (x0p + x1p) / 2;
612 | double ym = (y0p + y1p) / 2;
613 | /* Solve for intersecting unit circles */
614 | double dsq = dx * dx + dy * dy;
615 | if (dsq == 0.0) {
616 | Log.w(LOGTAG, " Points are coincident");
617 | return; /* Points are coincident */
618 | }
619 | double disc = 1.0 / dsq - 1.0 / 4.0;
620 | if (disc < 0.0) {
621 | Log.w(LOGTAG, "Points are too far apart " + dsq);
622 | float adjust = (float) (Math.sqrt(dsq) / 1.99999);
623 | drawArc(p, x0, y0, x1, y1, a * adjust,
624 | b * adjust, theta, isMoreThanHalf, isPositiveArc);
625 | return; /* Points are too far apart */
626 | }
627 | double s = Math.sqrt(disc);
628 | double sdx = s * dx;
629 | double sdy = s * dy;
630 | double cx;
631 | double cy;
632 | if (isMoreThanHalf == isPositiveArc) {
633 | cx = xm - sdy;
634 | cy = ym + sdx;
635 | } else {
636 | cx = xm + sdy;
637 | cy = ym - sdx;
638 | }
639 |
640 | double eta0 = Math.atan2((y0p - cy), (x0p - cx));
641 |
642 | double eta1 = Math.atan2((y1p - cy), (x1p - cx));
643 |
644 | double sweep = (eta1 - eta0);
645 | if (isPositiveArc != (sweep >= 0)) {
646 | if (sweep > 0) {
647 | sweep -= 2 * Math.PI;
648 | } else {
649 | sweep += 2 * Math.PI;
650 | }
651 | }
652 |
653 | cx *= a;
654 | cy *= b;
655 | double tcx = cx;
656 | cx = cx * cosTheta - cy * sinTheta;
657 | cy = tcx * sinTheta + cy * cosTheta;
658 |
659 | arcToBezier(p, cx, cy, a, b, x0, y0, thetaD, eta0, sweep);
660 | }
661 |
662 | /**
663 | * Converts an arc to cubic Bezier segments and records them in p.
664 | *
665 | * @param p The target for the cubic Bezier segments
666 | * @param cx The x coordinate center of the ellipse
667 | * @param cy The y coordinate center of the ellipse
668 | * @param a The radius of the ellipse in the horizontal direction
669 | * @param b The radius of the ellipse in the vertical direction
670 | * @param e1x E(eta1) x coordinate of the starting point of the arc
671 | * @param e1y E(eta2) y coordinate of the starting point of the arc
672 | * @param theta The angle that the ellipse bounding rectangle makes with horizontal plane
673 | * @param start The start angle of the arc on the ellipse
674 | * @param sweep The angle (positive or negative) of the sweep of the arc on the ellipse
675 | */
676 | private static void arcToBezier(Path p,
677 | double cx,
678 | double cy,
679 | double a,
680 | double b,
681 | double e1x,
682 | double e1y,
683 | double theta,
684 | double start,
685 | double sweep) {
686 | // Taken from equations at: http://spaceroots.org/documents/ellipse/node8.html
687 | // and http://www.spaceroots.org/documents/ellipse/node22.html
688 |
689 | // Maximum of 45 degrees per cubic Bezier segment
690 | int numSegments = (int) Math.ceil(Math.abs(sweep * 4 / Math.PI));
691 |
692 | double eta1 = start;
693 | double cosTheta = Math.cos(theta);
694 | double sinTheta = Math.sin(theta);
695 | double cosEta1 = Math.cos(eta1);
696 | double sinEta1 = Math.sin(eta1);
697 | double ep1x = (-a * cosTheta * sinEta1) - (b * sinTheta * cosEta1);
698 | double ep1y = (-a * sinTheta * sinEta1) + (b * cosTheta * cosEta1);
699 |
700 | double anglePerSegment = sweep / numSegments;
701 | for (int i = 0; i < numSegments; i++) {
702 | double eta2 = eta1 + anglePerSegment;
703 | double sinEta2 = Math.sin(eta2);
704 | double cosEta2 = Math.cos(eta2);
705 | double e2x = cx + (a * cosTheta * cosEta2) - (b * sinTheta * sinEta2);
706 | double e2y = cy + (a * sinTheta * cosEta2) + (b * cosTheta * sinEta2);
707 | double ep2x = -a * cosTheta * sinEta2 - b * sinTheta * cosEta2;
708 | double ep2y = -a * sinTheta * sinEta2 + b * cosTheta * cosEta2;
709 | double tanDiff2 = Math.tan((eta2 - eta1) / 2);
710 | double alpha =
711 | Math.sin(eta2 - eta1) * (Math.sqrt(4 + (3 * tanDiff2 * tanDiff2)) - 1) / 3;
712 | double q1x = e1x + alpha * ep1x;
713 | double q1y = e1y + alpha * ep1y;
714 | double q2x = e2x - alpha * ep2x;
715 | double q2y = e2y - alpha * ep2y;
716 |
717 | // Adding this no-op call to workaround a proguard related issue.
718 | p.rLineTo(0, 0);
719 |
720 | p.cubicTo((float) q1x,
721 | (float) q1y,
722 | (float) q2x,
723 | (float) q2y,
724 | (float) e2x,
725 | (float) e2y);
726 | eta1 = eta2;
727 | e1x = e2x;
728 | e1y = e2y;
729 | ep1x = ep2x;
730 | ep1y = ep2y;
731 | }
732 | }
733 | }
734 | }
735 |
736 |
--------------------------------------------------------------------------------
/vectorchildfinder/src/main/java/com/devs/vectorchildfinder/TypedArrayUtils.java:
--------------------------------------------------------------------------------
1 | package com.devs.vectorchildfinder;
2 |
3 | import android.content.res.TypedArray;
4 |
5 | import org.xmlpull.v1.XmlPullParser;
6 |
7 | /**
8 | * Created by ${Deven} on 1/31/18.
9 | */
10 |
11 | public class TypedArrayUtils {
12 | private static final String NAMESPACE = "http://schemas.android.com/apk/res/android";
13 |
14 | public static boolean hasAttribute(XmlPullParser parser, String attrName) {
15 | return parser.getAttributeValue(NAMESPACE, attrName) != null;
16 | }
17 |
18 | public static float getNamedFloat(TypedArray a, XmlPullParser parser, String attrName,
19 | int resId, float defaultValue) {
20 | final boolean hasAttr = hasAttribute(parser, attrName);
21 | if (!hasAttr) {
22 | return defaultValue;
23 | } else {
24 | return a.getFloat(resId, defaultValue);
25 | }
26 | }
27 |
28 | public static boolean getNamedBoolean(TypedArray a, XmlPullParser parser, String attrName,
29 | int resId, boolean defaultValue) {
30 | final boolean hasAttr = hasAttribute(parser, attrName);
31 | if (!hasAttr) {
32 | return defaultValue;
33 | } else {
34 | return a.getBoolean(resId, defaultValue);
35 | }
36 | }
37 |
38 | public static int getNamedInt(TypedArray a, XmlPullParser parser, String attrName,
39 | int resId, int defaultValue) {
40 | final boolean hasAttr = hasAttribute(parser, attrName);
41 | if (!hasAttr) {
42 | return defaultValue;
43 | } else {
44 | return a.getInt(resId, defaultValue);
45 | }
46 | }
47 |
48 | public static int getNamedColor(TypedArray a, XmlPullParser parser, String attrName,
49 | int resId, int defaultValue) {
50 | final boolean hasAttr = hasAttribute(parser, attrName);
51 | if (!hasAttr) {
52 | return defaultValue;
53 | } else {
54 | return a.getColor(resId, defaultValue);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/vectorchildfinder/src/main/java/com/devs/vectorchildfinder/VectorChildFinder.java:
--------------------------------------------------------------------------------
1 | package com.devs.vectorchildfinder;
2 |
3 | import android.content.Context;
4 | import android.widget.ImageView;
5 |
6 | /**
7 | * Created by ${Deven} on 2/1/18.
8 | * PorterDuffColorFilter porterDuffColorFilter = new PorterDuffColorFilter(Color.BLUE, PorterDuff.Mode.SRC_ATOP);
9 | * myImageView.setColorFilter(porterDuffColorFilter);
10 | */
11 |
12 | public class VectorChildFinder {
13 |
14 | private VectorDrawableCompat vectorDrawable;
15 |
16 | /**
17 | * @param context Your Activity Context
18 | * @param vectorRes Path of your vector drawable resource
19 | * @param imageView ImaveView that are showing vector drawable
20 | */
21 | public VectorChildFinder(Context context, int vectorRes, ImageView imageView) {
22 | vectorDrawable = VectorDrawableCompat.create(context.getResources(),
23 | vectorRes, null);
24 | vectorDrawable.setAllowCaching(false);
25 | imageView.setImageDrawable(vectorDrawable);
26 | }
27 |
28 |
29 | /**
30 | * @param pathName Path name that you gave in vector drawable file
31 | * @return A Object type of VectorDrawableCompat.VFullPath
32 | */
33 | public VectorDrawableCompat.VFullPath findPathByName(String pathName) {
34 | return (VectorDrawableCompat.VFullPath) vectorDrawable.getTargetByName(pathName);
35 | }
36 |
37 |
38 | /**
39 | * @param groupName Group name that you gave in vector drawable file
40 | * @return A Object type of VectorDrawableCompat.VGroup
41 | */
42 | public VectorDrawableCompat.VGroup findGroupByName(String groupName) {
43 | return (VectorDrawableCompat.VGroup) vectorDrawable.getTargetByName(groupName);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/vectorchildfinder/src/main/java/com/devs/vectorchildfinder/VectorDrawableCommon.java:
--------------------------------------------------------------------------------
1 | package com.devs.vectorchildfinder;
2 |
3 | /**
4 | * Created by ${Deven} on 1/31/18.
5 | */
6 |
7 | import android.content.res.Resources;
8 | import android.content.res.TypedArray;
9 | import android.graphics.ColorFilter;
10 | import android.graphics.Rect;
11 | import android.graphics.Region;
12 | import android.graphics.drawable.Drawable;
13 | import android.util.AttributeSet;
14 |
15 | import androidx.core.graphics.drawable.DrawableCompat;
16 |
17 | /**
18 | * Internal common delegation shared by VectorDrawableCompat and AnimatedVectorDrawableCompat
19 | */
20 | abstract class VectorDrawableCommon extends Drawable {
21 | /**
22 | * Obtains styled attributes from the theme, if available, or unstyled
23 | * resources if the theme is null.
24 | *
25 | * @hide
26 | */
27 | protected static TypedArray obtainAttributes(
28 | Resources res, Resources.Theme theme, AttributeSet set, int[] attrs) {
29 | if (theme == null) {
30 | return res.obtainAttributes(set, attrs);
31 | }
32 | return theme.obtainStyledAttributes(set, attrs, 0, 0);
33 | }
34 |
35 | // Drawable delegation for Lollipop and above.
36 | Drawable mDelegateDrawable;
37 |
38 | @Override
39 | public void setColorFilter(ColorFilter colorFilter) {
40 | if (mDelegateDrawable != null) {
41 | mDelegateDrawable.setColorFilter(colorFilter);
42 | }
43 | }
44 |
45 | @Override
46 | public ColorFilter getColorFilter() {
47 | if (mDelegateDrawable != null) {
48 | return DrawableCompat.getColorFilter(mDelegateDrawable);
49 | }
50 | return null;
51 | }
52 |
53 | @Override
54 | protected boolean onLevelChange(int level) {
55 | if (mDelegateDrawable != null) {
56 | return mDelegateDrawable.setLevel(level);
57 | }
58 | return super.onLevelChange(level);
59 | }
60 |
61 | @Override
62 | protected void onBoundsChange(Rect bounds) {
63 | if (mDelegateDrawable != null) {
64 | mDelegateDrawable.setBounds(bounds);
65 | return;
66 | }
67 | super.onBoundsChange(bounds);
68 | }
69 |
70 | @Override
71 | public void setHotspot(float x, float y) {
72 | // API >= 21 only.
73 | if (mDelegateDrawable != null) {
74 | DrawableCompat.setHotspot(mDelegateDrawable, x, y);
75 | }
76 | }
77 |
78 | @Override
79 | public void setHotspotBounds(int left, int top, int right, int bottom) {
80 | if (mDelegateDrawable != null) {
81 | DrawableCompat.setHotspotBounds(mDelegateDrawable, left, top, right, bottom);
82 | }
83 | }
84 |
85 | @Override
86 | public void setFilterBitmap(boolean filter) {
87 | if (mDelegateDrawable != null) {
88 | mDelegateDrawable.setFilterBitmap(filter);
89 | }
90 | }
91 |
92 | @Override
93 | public void jumpToCurrentState() {
94 | if (mDelegateDrawable != null) {
95 | mDelegateDrawable.jumpToCurrentState();
96 | }
97 | }
98 |
99 | @Override
100 | public void applyTheme(Resources.Theme t) {
101 | // API >= 21 only.
102 | if (mDelegateDrawable != null) {
103 | DrawableCompat.applyTheme(mDelegateDrawable, t);
104 | }
105 | }
106 |
107 | @Override
108 | public void clearColorFilter() {
109 | if (mDelegateDrawable != null) {
110 | mDelegateDrawable.clearColorFilter();
111 | return;
112 | }
113 | super.clearColorFilter();
114 | }
115 |
116 | @Override
117 | public Drawable getCurrent() {
118 | if (mDelegateDrawable != null) {
119 | return mDelegateDrawable.getCurrent();
120 | }
121 | return super.getCurrent();
122 | }
123 |
124 | @Override
125 | public int getMinimumWidth() {
126 | if (mDelegateDrawable != null) {
127 | return mDelegateDrawable.getMinimumWidth();
128 | }
129 | return super.getMinimumWidth();
130 | }
131 |
132 | @Override
133 | public int getMinimumHeight() {
134 | if (mDelegateDrawable != null) {
135 | return mDelegateDrawable.getMinimumHeight();
136 | }
137 | return super.getMinimumHeight();
138 | }
139 |
140 | @Override
141 | public boolean getPadding(Rect padding) {
142 | if (mDelegateDrawable != null) {
143 | return mDelegateDrawable.getPadding(padding);
144 | }
145 | return super.getPadding(padding);
146 | }
147 |
148 | @Override
149 | public int[] getState() {
150 | if (mDelegateDrawable != null) {
151 | return mDelegateDrawable.getState();
152 | }
153 | return super.getState();
154 | }
155 |
156 |
157 | @Override
158 | public Region getTransparentRegion() {
159 | if (mDelegateDrawable != null) {
160 | return mDelegateDrawable.getTransparentRegion();
161 | }
162 | return super.getTransparentRegion();
163 | }
164 |
165 | @Override
166 | public void setChangingConfigurations(int configs) {
167 | if (mDelegateDrawable != null) {
168 | mDelegateDrawable.setChangingConfigurations(configs);
169 | return;
170 | }
171 | super.setChangingConfigurations(configs);
172 | }
173 |
174 | @Override
175 | public boolean setState(int[] stateSet) {
176 | if (mDelegateDrawable != null) {
177 | return mDelegateDrawable.setState(stateSet);
178 | }
179 | return super.setState(stateSet);
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/vectorchildfinder/src/main/java/com/devs/vectorchildfinder/VectorDrawableCompat.java:
--------------------------------------------------------------------------------
1 | package com.devs.vectorchildfinder;
2 |
3 | /**
4 | * Created by ${Deven} on 1/31/18.
5 | */
6 |
7 | /*
8 | * Copyright (C) 2015 The Android Open Source Project
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11 | * in compliance with the License. You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software distributed under the License
16 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17 | * or implied. See the License for the specific language governing permissions and limitations under
18 | * the License.
19 | */
20 |
21 | import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
22 |
23 | import android.annotation.SuppressLint;
24 | import android.content.res.ColorStateList;
25 | import android.content.res.Resources;
26 | import android.content.res.TypedArray;
27 | import android.graphics.Bitmap;
28 | import android.graphics.Canvas;
29 | import android.graphics.Color;
30 | import android.graphics.ColorFilter;
31 | import android.graphics.Matrix;
32 | import android.graphics.Paint;
33 | import android.graphics.Path;
34 | import android.graphics.PathMeasure;
35 | import android.graphics.PixelFormat;
36 | import android.graphics.PorterDuff;
37 | import android.graphics.PorterDuffColorFilter;
38 | import android.graphics.Rect;
39 | import android.graphics.drawable.Drawable;
40 | import android.graphics.drawable.VectorDrawable;
41 | import android.os.Build;
42 | import android.util.AttributeSet;
43 | import android.util.LayoutDirection;
44 | import android.util.Log;
45 | import android.util.Xml;
46 |
47 | import androidx.annotation.DrawableRes;
48 | import androidx.annotation.NonNull;
49 | import androidx.annotation.Nullable;
50 | import androidx.annotation.RequiresApi;
51 | import androidx.annotation.RestrictTo;
52 | import androidx.collection.ArrayMap;
53 | import androidx.core.graphics.drawable.DrawableCompat;
54 |
55 | import org.xmlpull.v1.XmlPullParser;
56 | import org.xmlpull.v1.XmlPullParserException;
57 |
58 | import java.io.IOException;
59 | import java.util.ArrayList;
60 | import java.util.Stack;
61 |
62 |
63 | public class VectorDrawableCompat extends VectorDrawableCommon {
64 | static final String LOGTAG = "VectorDrawableCompat";
65 |
66 | static final PorterDuff.Mode DEFAULT_TINT_MODE = PorterDuff.Mode.SRC_IN;
67 |
68 | private static final String SHAPE_CLIP_PATH = "clip-path";
69 | private static final String SHAPE_GROUP = "group";
70 | private static final String SHAPE_PATH = "path";
71 | private static final String SHAPE_VECTOR = "vector";
72 |
73 | private static final int LINECAP_BUTT = 0;
74 | private static final int LINECAP_ROUND = 1;
75 | private static final int LINECAP_SQUARE = 2;
76 |
77 | private static final int LINEJOIN_MITER = 0;
78 | private static final int LINEJOIN_ROUND = 1;
79 | private static final int LINEJOIN_BEVEL = 2;
80 |
81 | // Cap the bitmap size, such that it won't hurt the performance too much
82 | // and it won't crash due to a very large scale.
83 | // The drawable will look blurry above this size.
84 | private static final int MAX_CACHED_BITMAP_SIZE = 2048;
85 |
86 | private static final boolean DBG_VECTOR_DRAWABLE = false;
87 |
88 | private VectorDrawableCompatState mVectorState;
89 |
90 | private PorterDuffColorFilter mTintFilter;
91 | private ColorFilter mColorFilter;
92 |
93 | private boolean mMutated;
94 |
95 | // AnimatedVectorDrawable needs to turn off the cache all the time, otherwise,
96 | // caching the bitmap by default is allowed.
97 | private boolean mAllowCaching = true;
98 |
99 | // The Constant state associated with the mDelegateDrawable
.
100 | private ConstantState mCachedConstantStateDelegate;
101 |
102 | // Temp variable, only for saving "new" operation at the draw() time.
103 | private final float[] mTmpFloats = new float[9];
104 | private final Matrix mTmpMatrix = new Matrix();
105 | private final Rect mTmpBounds = new Rect();
106 |
107 | VectorDrawableCompat() {
108 | mVectorState = new VectorDrawableCompatState();
109 | }
110 |
111 | VectorDrawableCompat(@NonNull VectorDrawableCompatState state) {
112 | mVectorState = state;
113 | mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
114 | }
115 |
116 | @Override
117 | public Drawable mutate() {
118 | if (mDelegateDrawable != null) {
119 | mDelegateDrawable.mutate();
120 | return this;
121 | }
122 |
123 | if (!mMutated && super.mutate() == this) {
124 | mVectorState = new VectorDrawableCompatState(mVectorState);
125 | mMutated = true;
126 | }
127 | return this;
128 | }
129 |
130 | public Object getTargetByName(String name) {
131 | return mVectorState.mVPathRenderer.mVGTargetsMap.get(name);
132 | }
133 |
134 | @Override
135 | public ConstantState getConstantState() {
136 | if (mDelegateDrawable != null) {
137 | // Such that the configuration can be refreshed.
138 | return new VectorDrawableDelegateState(mDelegateDrawable.getConstantState());
139 | }
140 | mVectorState.mChangingConfigurations = getChangingConfigurations();
141 | return mVectorState;
142 | }
143 |
144 | @Override
145 | public void draw(Canvas canvas) {
146 | if (mDelegateDrawable != null) {
147 | mDelegateDrawable.draw(canvas);
148 | return;
149 | }
150 | // We will offset the bounds for drawBitmap, so copyBounds() here instead
151 | // of getBounds().
152 | copyBounds(mTmpBounds);
153 | if (mTmpBounds.width() <= 0 || mTmpBounds.height() <= 0) {
154 | // Nothing to draw
155 | return;
156 | }
157 |
158 | // Color filters always override tint filters.
159 | final ColorFilter colorFilter = (mColorFilter == null ? mTintFilter : mColorFilter);
160 |
161 | // The imageView can scale the canvas in different ways, in order to
162 | // avoid blurry scaling, we have to draw into a bitmap with exact pixel
163 | // size first. This bitmap size is determined by the bounds and the
164 | // canvas scale.
165 | canvas.getMatrix(mTmpMatrix);
166 | mTmpMatrix.getValues(mTmpFloats);
167 | float canvasScaleX = Math.abs(mTmpFloats[Matrix.MSCALE_X]);
168 | float canvasScaleY = Math.abs(mTmpFloats[Matrix.MSCALE_Y]);
169 |
170 | float canvasSkewX = Math.abs(mTmpFloats[Matrix.MSKEW_X]);
171 | float canvasSkewY = Math.abs(mTmpFloats[Matrix.MSKEW_Y]);
172 |
173 | // When there is any rotation / skew, then the scale value is not valid.
174 | if (canvasSkewX != 0 || canvasSkewY != 0) {
175 | canvasScaleX = 1.0f;
176 | canvasScaleY = 1.0f;
177 | }
178 |
179 | int scaledWidth = (int) (mTmpBounds.width() * canvasScaleX);
180 | int scaledHeight = (int) (mTmpBounds.height() * canvasScaleY);
181 | scaledWidth = Math.min(MAX_CACHED_BITMAP_SIZE, scaledWidth);
182 | scaledHeight = Math.min(MAX_CACHED_BITMAP_SIZE, scaledHeight);
183 |
184 | if (scaledWidth <= 0 || scaledHeight <= 0) {
185 | return;
186 | }
187 |
188 | final int saveCount = canvas.save();
189 | canvas.translate(mTmpBounds.left, mTmpBounds.top);
190 |
191 | // Handle RTL mirroring.
192 | final boolean needMirroring = needMirroring();
193 | if (needMirroring) {
194 | canvas.translate(mTmpBounds.width(), 0);
195 | canvas.scale(-1.0f, 1.0f);
196 | }
197 |
198 | // At this point, canvas has been translated to the right position.
199 | // And we use this bound for the destination rect for the drawBitmap, so
200 | // we offset to (0, 0);
201 | mTmpBounds.offsetTo(0, 0);
202 |
203 | mVectorState.createCachedBitmapIfNeeded(scaledWidth, scaledHeight);
204 | if (!mAllowCaching) {
205 | mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
206 | } else {
207 | if (!mVectorState.canReuseCache()) {
208 | mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
209 | mVectorState.updateCacheStates();
210 | }
211 | }
212 | mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter, mTmpBounds);
213 | canvas.restoreToCount(saveCount);
214 | }
215 |
216 | @Override
217 | public int getAlpha() {
218 | if (mDelegateDrawable != null) {
219 | return DrawableCompat.getAlpha(mDelegateDrawable);
220 | }
221 |
222 | return mVectorState.mVPathRenderer.getRootAlpha();
223 | }
224 |
225 | @Override
226 | public void setAlpha(int alpha) {
227 | if (mDelegateDrawable != null) {
228 | mDelegateDrawable.setAlpha(alpha);
229 | return;
230 | }
231 |
232 | if (mVectorState.mVPathRenderer.getRootAlpha() != alpha) {
233 | mVectorState.mVPathRenderer.setRootAlpha(alpha);
234 | invalidateSelf();
235 | }
236 | }
237 |
238 | @Override
239 | public void setColorFilter(ColorFilter colorFilter) {
240 | if (mDelegateDrawable != null) {
241 | mDelegateDrawable.setColorFilter(colorFilter);
242 | return;
243 | }
244 |
245 | mColorFilter = colorFilter;
246 | invalidateSelf();
247 | }
248 |
249 | /**
250 | * Ensures the tint filter is consistent with the current tint color and
251 | * mode.
252 | */
253 | PorterDuffColorFilter updateTintFilter(PorterDuffColorFilter tintFilter, ColorStateList tint,
254 | PorterDuff.Mode tintMode) {
255 | if (tint == null || tintMode == null) {
256 | return null;
257 | }
258 | // setMode, setColor of PorterDuffColorFilter are not public method in SDK v7.
259 | // Therefore we create a new one all the time here. Don't expect this is called often.
260 | final int color = tint.getColorForState(getState(), Color.TRANSPARENT);
261 | return new PorterDuffColorFilter(color, tintMode);
262 | }
263 |
264 | @SuppressLint("NewApi")
265 | @Override
266 | public void setTint(int tint) {
267 | if (mDelegateDrawable != null) {
268 | DrawableCompat.setTint(mDelegateDrawable, tint);
269 | return;
270 | }
271 |
272 | setTintList(ColorStateList.valueOf(tint));
273 | }
274 |
275 | @Override
276 | public void setTintList(ColorStateList tint) {
277 | if (mDelegateDrawable != null) {
278 | DrawableCompat.setTintList(mDelegateDrawable, tint);
279 | return;
280 | }
281 |
282 | final VectorDrawableCompatState state = mVectorState;
283 | if (state.mTint != tint) {
284 | state.mTint = tint;
285 | mTintFilter = updateTintFilter(mTintFilter, tint, state.mTintMode);
286 | invalidateSelf();
287 | }
288 | }
289 |
290 | @Override
291 | public void setTintMode(PorterDuff.Mode tintMode) {
292 | if (mDelegateDrawable != null) {
293 | DrawableCompat.setTintMode(mDelegateDrawable, tintMode);
294 | return;
295 | }
296 |
297 | final VectorDrawableCompatState state = mVectorState;
298 | if (state.mTintMode != tintMode) {
299 | state.mTintMode = tintMode;
300 | mTintFilter = updateTintFilter(mTintFilter, state.mTint, tintMode);
301 | invalidateSelf();
302 | }
303 | }
304 |
305 | @Override
306 | public boolean isStateful() {
307 | if (mDelegateDrawable != null) {
308 | return mDelegateDrawable.isStateful();
309 | }
310 |
311 | return super.isStateful() || (mVectorState != null && mVectorState.mTint != null
312 | && mVectorState.mTint.isStateful());
313 | }
314 |
315 | @Override
316 | protected boolean onStateChange(int[] stateSet) {
317 | if (mDelegateDrawable != null) {
318 | return mDelegateDrawable.setState(stateSet);
319 | }
320 |
321 | final VectorDrawableCompatState state = mVectorState;
322 | if (state.mTint != null && state.mTintMode != null) {
323 | mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
324 | invalidateSelf();
325 | return true;
326 | }
327 | return false;
328 | }
329 |
330 | @Override
331 | public int getOpacity() {
332 | if (mDelegateDrawable != null) {
333 | return mDelegateDrawable.getOpacity();
334 | }
335 |
336 | return PixelFormat.TRANSLUCENT;
337 | }
338 |
339 | @Override
340 | public int getIntrinsicWidth() {
341 | if (mDelegateDrawable != null) {
342 | return mDelegateDrawable.getIntrinsicWidth();
343 | }
344 |
345 | return (int) mVectorState.mVPathRenderer.mBaseWidth;
346 | }
347 |
348 | @Override
349 | public int getIntrinsicHeight() {
350 | if (mDelegateDrawable != null) {
351 | return mDelegateDrawable.getIntrinsicHeight();
352 | }
353 |
354 | return (int) mVectorState.mVPathRenderer.mBaseHeight;
355 | }
356 |
357 | // Don't support re-applying themes. The initial theme loading is working.
358 | @Override
359 | public boolean canApplyTheme() {
360 | if (mDelegateDrawable != null) {
361 | DrawableCompat.canApplyTheme(mDelegateDrawable);
362 | }
363 |
364 | return false;
365 | }
366 |
367 | @Override
368 | public boolean isAutoMirrored() {
369 | if (mDelegateDrawable != null) {
370 | return DrawableCompat.isAutoMirrored(mDelegateDrawable);
371 | }
372 | return mVectorState.mAutoMirrored;
373 | }
374 |
375 | @Override
376 | public void setAutoMirrored(boolean mirrored) {
377 | if (mDelegateDrawable != null) {
378 | DrawableCompat.setAutoMirrored(mDelegateDrawable, mirrored);
379 | return;
380 | }
381 | mVectorState.mAutoMirrored = mirrored;
382 | }
383 | /**
384 | * The size of a pixel when scaled from the intrinsic dimension to the viewport dimension. This
385 | * is used to calculate the path animation accuracy.
386 | *
387 | * @hide
388 | */
389 | @RestrictTo(LIBRARY_GROUP)
390 | public float getPixelSize() {
391 | if (mVectorState == null && mVectorState.mVPathRenderer == null ||
392 | mVectorState.mVPathRenderer.mBaseWidth == 0 ||
393 | mVectorState.mVPathRenderer.mBaseHeight == 0 ||
394 | mVectorState.mVPathRenderer.mViewportHeight == 0 ||
395 | mVectorState.mVPathRenderer.mViewportWidth == 0) {
396 | return 1; // fall back to 1:1 pixel mapping.
397 | }
398 | float intrinsicWidth = mVectorState.mVPathRenderer.mBaseWidth;
399 | float intrinsicHeight = mVectorState.mVPathRenderer.mBaseHeight;
400 | float viewportWidth = mVectorState.mVPathRenderer.mViewportWidth;
401 | float viewportHeight = mVectorState.mVPathRenderer.mViewportHeight;
402 | float scaleX = viewportWidth / intrinsicWidth;
403 | float scaleY = viewportHeight / intrinsicHeight;
404 | return Math.min(scaleX, scaleY);
405 | }
406 |
407 | /**
408 | * Create a VectorDrawableCompat object.
409 | *
410 | * @param res the resources.
411 | * @param resId the resource ID for VectorDrawableCompat object.
412 | * @param theme the theme of this vector drawable, it can be null.
413 | * @return a new VectorDrawableCompat or null if parsing error is found.
414 | */
415 | @Nullable
416 | public static VectorDrawableCompat create(@NonNull Resources res, @DrawableRes int resId,
417 | @Nullable Resources.Theme theme) {
418 | // if (Build.VERSION.SDK_INT >= 24) {
419 | // final VectorDrawableCompat drawable = new VectorDrawableCompat();
420 | // drawable.mDelegateDrawable = ResourcesCompat.getDrawable(res, resId, theme);
421 | // drawable.mCachedConstantStateDelegate = new VectorDrawableCompat.VectorDrawableDelegateState(
422 | // drawable.mDelegateDrawable.getConstantState());
423 | // return drawable;
424 | // }
425 |
426 | try {
427 | final XmlPullParser parser = res.getXml(resId);
428 | final AttributeSet attrs = Xml.asAttributeSet(parser);
429 | int type;
430 | while ((type = parser.next()) != XmlPullParser.START_TAG &&
431 | type != XmlPullParser.END_DOCUMENT) {
432 | // Empty loop
433 | }
434 | if (type != XmlPullParser.START_TAG) {
435 | throw new XmlPullParserException("No start tag found");
436 | }
437 | return createFromXmlInner(res, parser, attrs, theme);
438 | } catch (XmlPullParserException e) {
439 | Log.e(LOGTAG, "parser error", e);
440 | } catch (IOException e) {
441 | Log.e(LOGTAG, "parser error", e);
442 | }
443 | return null;
444 | }
445 |
446 | /**
447 | * Create a VectorDrawableCompat from inside an XML document using an optional
448 | * {@link Resources.Theme}. Called on a parser positioned at a tag in an XML
449 | * document, tries to create a Drawable from that tag. Returns {@code null}
450 | * if the tag is not a valid drawable.
451 | */
452 | @SuppressLint("NewApi")
453 | public static VectorDrawableCompat createFromXmlInner(Resources r, XmlPullParser parser,
454 | AttributeSet attrs, Resources.Theme theme) throws XmlPullParserException, IOException {
455 | final VectorDrawableCompat drawable = new VectorDrawableCompat();
456 | drawable.inflate(r, parser, attrs, theme);
457 | return drawable;
458 | }
459 |
460 | static int applyAlpha(int color, float alpha) {
461 | int alphaBytes = Color.alpha(color);
462 | color &= 0x00FFFFFF;
463 | color |= ((int) (alphaBytes * alpha)) << 24;
464 | return color;
465 | }
466 |
467 | @SuppressLint("NewApi")
468 | @Override
469 | public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs)
470 | throws XmlPullParserException, IOException {
471 | if (mDelegateDrawable != null) {
472 | mDelegateDrawable.inflate(res, parser, attrs);
473 | return;
474 | }
475 |
476 | inflate(res, parser, attrs, null);
477 | }
478 |
479 | @Override
480 | public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
481 | throws XmlPullParserException, IOException {
482 | if (mDelegateDrawable != null) {
483 | DrawableCompat.inflate(mDelegateDrawable, res, parser, attrs, theme);
484 | return;
485 | }
486 |
487 | final VectorDrawableCompatState state = mVectorState;
488 | final VPathRenderer pathRenderer = new VPathRenderer();
489 | state.mVPathRenderer = pathRenderer;
490 |
491 | final TypedArray a = obtainAttributes(res, theme, attrs,
492 | AndroidResources.styleable_VectorDrawableTypeArray);
493 |
494 | updateStateFromTypedArray(a, parser);
495 | a.recycle();
496 | state.mChangingConfigurations = getChangingConfigurations();
497 | state.mCacheDirty = true;
498 | inflateInternal(res, parser, attrs, theme);
499 |
500 | mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
501 | }
502 |
503 |
504 | /**
505 | * Parses a {@link PorterDuff.Mode} from a tintMode
506 | * attribute's enum value.
507 | */
508 | private static PorterDuff.Mode parseTintModeCompat(int value, PorterDuff.Mode defaultMode) {
509 | switch (value) {
510 | case 3:
511 | return PorterDuff.Mode.SRC_OVER;
512 | case 5:
513 | return PorterDuff.Mode.SRC_IN;
514 | case 9:
515 | return PorterDuff.Mode.SRC_ATOP;
516 | case 14:
517 | return PorterDuff.Mode.MULTIPLY;
518 | case 15:
519 | return PorterDuff.Mode.SCREEN;
520 | case 16:
521 | if (Build.VERSION.SDK_INT >= 11) {
522 | return PorterDuff.Mode.ADD;
523 | } else {
524 | return defaultMode;
525 | }
526 | default:
527 | return defaultMode;
528 | }
529 | }
530 |
531 | private void updateStateFromTypedArray(TypedArray a, XmlPullParser parser)
532 | throws XmlPullParserException {
533 | final VectorDrawableCompatState state = mVectorState;
534 | final VPathRenderer pathRenderer = state.mVPathRenderer;
535 |
536 | // Account for any configuration changes.
537 | // state.mChangingConfigurations |= Utils.getChangingConfigurations(a);
538 |
539 | final int mode = TypedArrayUtils.getNamedInt(a, parser, "tintMode",
540 | AndroidResources.styleable_VectorDrawable_tintMode, -1);
541 | state.mTintMode = parseTintModeCompat(mode, PorterDuff.Mode.SRC_IN);
542 |
543 | final ColorStateList tint =
544 | a.getColorStateList(AndroidResources.styleable_VectorDrawable_tint);
545 | if (tint != null) {
546 | state.mTint = tint;
547 | }
548 |
549 | state.mAutoMirrored = TypedArrayUtils.getNamedBoolean(a, parser, "autoMirrored",
550 | AndroidResources.styleable_VectorDrawable_autoMirrored, state.mAutoMirrored);
551 |
552 | pathRenderer.mViewportWidth = TypedArrayUtils.getNamedFloat(a, parser, "viewportWidth",
553 | AndroidResources.styleable_VectorDrawable_viewportWidth,
554 | pathRenderer.mViewportWidth);
555 |
556 | pathRenderer.mViewportHeight = TypedArrayUtils.getNamedFloat(a, parser, "viewportHeight",
557 | AndroidResources.styleable_VectorDrawable_viewportHeight,
558 | pathRenderer.mViewportHeight);
559 |
560 | if (pathRenderer.mViewportWidth <= 0) {
561 | throw new XmlPullParserException(a.getPositionDescription() +
562 | " tag requires viewportWidth > 0");
563 | } else if (pathRenderer.mViewportHeight <= 0) {
564 | throw new XmlPullParserException(a.getPositionDescription() +
565 | " tag requires viewportHeight > 0");
566 | }
567 |
568 | pathRenderer.mBaseWidth = a.getDimension(
569 | AndroidResources.styleable_VectorDrawable_width, pathRenderer.mBaseWidth);
570 | pathRenderer.mBaseHeight = a.getDimension(
571 | AndroidResources.styleable_VectorDrawable_height, pathRenderer.mBaseHeight);
572 | if (pathRenderer.mBaseWidth <= 0) {
573 | throw new XmlPullParserException(a.getPositionDescription() +
574 | " tag requires width > 0");
575 | } else if (pathRenderer.mBaseHeight <= 0) {
576 | throw new XmlPullParserException(a.getPositionDescription() +
577 | " tag requires height > 0");
578 | }
579 |
580 | // shown up from API 11.
581 | final float alphaInFloat = TypedArrayUtils.getNamedFloat(a, parser, "alpha",
582 | AndroidResources.styleable_VectorDrawable_alpha, pathRenderer.getAlpha());
583 | pathRenderer.setAlpha(alphaInFloat);
584 |
585 | final String name = a.getString(AndroidResources.styleable_VectorDrawable_name);
586 | if (name != null) {
587 | pathRenderer.mRootName = name;
588 | pathRenderer.mVGTargetsMap.put(name, pathRenderer);
589 | }
590 | }
591 |
592 | private void inflateInternal(Resources res, XmlPullParser parser, AttributeSet attrs,
593 | Resources.Theme theme) throws XmlPullParserException, IOException {
594 | final VectorDrawableCompatState state = mVectorState;
595 | final VPathRenderer pathRenderer = state.mVPathRenderer;
596 | boolean noPathTag = true;
597 |
598 | // Use a stack to help to build the group tree.
599 | // The top of the stack is always the current group.
600 | final Stack groupStack = new Stack();
601 | groupStack.push(pathRenderer.mRootGroup);
602 |
603 | int eventType = parser.getEventType();
604 | final int innerDepth = parser.getDepth() + 1;
605 |
606 | // Parse everything until the end of the vector element.
607 | while (eventType != XmlPullParser.END_DOCUMENT
608 | && (parser.getDepth() >= innerDepth || eventType != XmlPullParser.END_TAG)) {
609 | if (eventType == XmlPullParser.START_TAG) {
610 | final String tagName = parser.getName();
611 | final VGroup currentGroup = groupStack.peek();
612 | if (SHAPE_PATH.equals(tagName)) {
613 | final VFullPath path = new VFullPath();
614 | path.inflate(res, attrs, theme, parser);
615 | currentGroup.mChildren.add(path);
616 | if (path.getPathName() != null) {
617 | pathRenderer.mVGTargetsMap.put(path.getPathName(), path);
618 | }
619 | noPathTag = false;
620 | state.mChangingConfigurations |= path.mChangingConfigurations;
621 | } else if (SHAPE_CLIP_PATH.equals(tagName)) {
622 | final VClipPath path = new VClipPath();
623 | path.inflate(res, attrs, theme, parser);
624 | currentGroup.mChildren.add(path);
625 | if (path.getPathName() != null) {
626 | pathRenderer.mVGTargetsMap.put(path.getPathName(), path);
627 | }
628 | state.mChangingConfigurations |= path.mChangingConfigurations;
629 | } else if (SHAPE_GROUP.equals(tagName)) {
630 | VGroup newChildGroup = new VGroup();
631 | newChildGroup.inflate(res, attrs, theme, parser);
632 | currentGroup.mChildren.add(newChildGroup);
633 | groupStack.push(newChildGroup);
634 | if (newChildGroup.getGroupName() != null) {
635 | pathRenderer.mVGTargetsMap.put(newChildGroup.getGroupName(),
636 | newChildGroup);
637 | }
638 | state.mChangingConfigurations |= newChildGroup.mChangingConfigurations;
639 | }
640 | } else if (eventType == XmlPullParser.END_TAG) {
641 | final String tagName = parser.getName();
642 | if (SHAPE_GROUP.equals(tagName)) {
643 | groupStack.pop();
644 | }
645 | }
646 | eventType = parser.next();
647 | }
648 |
649 | // Print the tree out for debug.
650 | if (DBG_VECTOR_DRAWABLE) {
651 | printGroupTree(pathRenderer.mRootGroup, 0);
652 | }
653 |
654 | if (noPathTag) {
655 | final StringBuffer tag = new StringBuffer();
656 |
657 | if (tag.length() > 0) {
658 | tag.append(" or ");
659 | }
660 | tag.append(SHAPE_PATH);
661 |
662 | throw new XmlPullParserException("no " + tag + " defined");
663 | }
664 | }
665 |
666 | private void printGroupTree(VGroup currentGroup, int level) {
667 | String indent = "";
668 | for (int i = 0; i < level; i++) {
669 | indent += " ";
670 | }
671 | // Print the current node
672 | Log.v(LOGTAG, indent + "current group is :" + currentGroup.getGroupName()
673 | + " rotation is " + currentGroup.mRotate);
674 | Log.v(LOGTAG, indent + "matrix is :" + currentGroup.getLocalMatrix().toString());
675 | // Then print all the children groups
676 | for (int i = 0; i < currentGroup.mChildren.size(); i++) {
677 | Object child = currentGroup.mChildren.get(i);
678 | if (child instanceof VGroup) {
679 | printGroupTree((VGroup) child, level + 1);
680 | } else {
681 | ((VPath) child).printVPath(level + 1);
682 | }
683 | }
684 | }
685 |
686 | public void setAllowCaching(boolean allowCaching) {
687 | mAllowCaching = allowCaching;
688 | }
689 |
690 | // We don't support RTL auto mirroring since the getLayoutDirection() is for API 17+.
691 | @SuppressLint({"NewApi", "WrongConstant"})
692 | private boolean needMirroring() {
693 | if (Build.VERSION.SDK_INT < 17) {
694 | return false;
695 | } else {
696 | return isAutoMirrored() && getLayoutDirection() == LayoutDirection.RTL;
697 | }
698 | }
699 |
700 | // Extra override functions for delegation for SDK >= 7.
701 | @Override
702 | protected void onBoundsChange(Rect bounds) {
703 | if (mDelegateDrawable != null) {
704 | mDelegateDrawable.setBounds(bounds);
705 | }
706 | }
707 |
708 | @Override
709 | public int getChangingConfigurations() {
710 | if (mDelegateDrawable != null) {
711 | return mDelegateDrawable.getChangingConfigurations();
712 | }
713 | return super.getChangingConfigurations() | mVectorState.getChangingConfigurations();
714 | }
715 |
716 | @Override
717 | public void invalidateSelf() {
718 | if (mDelegateDrawable != null) {
719 | mDelegateDrawable.invalidateSelf();
720 | return;
721 | }
722 | super.invalidateSelf();
723 | }
724 |
725 | @Override
726 | public void scheduleSelf(Runnable what, long when) {
727 | if (mDelegateDrawable != null) {
728 | mDelegateDrawable.scheduleSelf(what, when);
729 | return;
730 | }
731 | super.scheduleSelf(what, when);
732 | }
733 |
734 | @Override
735 | public boolean setVisible(boolean visible, boolean restart) {
736 | if (mDelegateDrawable != null) {
737 | return mDelegateDrawable.setVisible(visible, restart);
738 | }
739 | return super.setVisible(visible, restart);
740 | }
741 |
742 | @Override
743 | public void unscheduleSelf(Runnable what) {
744 | if (mDelegateDrawable != null) {
745 | mDelegateDrawable.unscheduleSelf(what);
746 | return;
747 | }
748 | super.unscheduleSelf(what);
749 | }
750 |
751 | /**
752 | * Constant state for delegating the creating drawable job for SDK >= 24.
753 | * Instead of creating a VectorDrawable, create a VectorDrawableCompat instance which contains
754 | * a delegated VectorDrawable instance.
755 | */
756 | private static class VectorDrawableDelegateState extends ConstantState {
757 | private final ConstantState mDelegateState;
758 |
759 | public VectorDrawableDelegateState(ConstantState state) {
760 | mDelegateState = state;
761 | }
762 |
763 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
764 | @Override
765 | public Drawable newDrawable() {
766 | VectorDrawableCompat drawableCompat = new VectorDrawableCompat();
767 | drawableCompat.mDelegateDrawable = (VectorDrawable) mDelegateState.newDrawable();
768 | return drawableCompat;
769 | }
770 |
771 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
772 | @Override
773 | public Drawable newDrawable(Resources res) {
774 | VectorDrawableCompat drawableCompat = new VectorDrawableCompat();
775 | drawableCompat.mDelegateDrawable = mDelegateState.newDrawable(res);
776 | return drawableCompat;
777 | }
778 |
779 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
780 | @Override
781 | public Drawable newDrawable(Resources res, Resources.Theme theme) {
782 | VectorDrawableCompat drawableCompat = new VectorDrawableCompat();
783 | drawableCompat.mDelegateDrawable =
784 | (VectorDrawable) mDelegateState.newDrawable(res, theme);
785 | return drawableCompat;
786 | }
787 |
788 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
789 | @Override
790 | public boolean canApplyTheme() {
791 | return mDelegateState.canApplyTheme();
792 | }
793 |
794 | @Override
795 | public int getChangingConfigurations() {
796 | return mDelegateState.getChangingConfigurations();
797 | }
798 | }
799 |
800 | private static class VectorDrawableCompatState extends ConstantState {
801 | int mChangingConfigurations;
802 | VPathRenderer mVPathRenderer;
803 | ColorStateList mTint = null;
804 | PorterDuff.Mode mTintMode = DEFAULT_TINT_MODE;
805 | boolean mAutoMirrored;
806 |
807 | Bitmap mCachedBitmap;
808 | int[] mCachedThemeAttrs;
809 | ColorStateList mCachedTint;
810 | PorterDuff.Mode mCachedTintMode;
811 | int mCachedRootAlpha;
812 | boolean mCachedAutoMirrored;
813 | boolean mCacheDirty;
814 |
815 | /**
816 | * Temporary paint object used to draw cached bitmaps.
817 | */
818 | Paint mTempPaint;
819 |
820 | // Deep copy for mutate() or implicitly mutate.
821 | public VectorDrawableCompatState(VectorDrawableCompatState copy) {
822 | if (copy != null) {
823 | mChangingConfigurations = copy.mChangingConfigurations;
824 | mVPathRenderer = new VPathRenderer(copy.mVPathRenderer);
825 | if (copy.mVPathRenderer.mFillPaint != null) {
826 | mVPathRenderer.mFillPaint = new Paint(copy.mVPathRenderer.mFillPaint);
827 | }
828 | if (copy.mVPathRenderer.mStrokePaint != null) {
829 | mVPathRenderer.mStrokePaint = new Paint(copy.mVPathRenderer.mStrokePaint);
830 | }
831 | mTint = copy.mTint;
832 | mTintMode = copy.mTintMode;
833 | mAutoMirrored = copy.mAutoMirrored;
834 | }
835 | }
836 |
837 | public void drawCachedBitmapWithRootAlpha(Canvas canvas, ColorFilter filter,
838 | Rect originalBounds) {
839 | // The bitmap's size is the same as the bounds.
840 | final Paint p = getPaint(filter);
841 | canvas.drawBitmap(mCachedBitmap, null, originalBounds, p);
842 | }
843 |
844 | public boolean hasTranslucentRoot() {
845 | return mVPathRenderer.getRootAlpha() < 255;
846 | }
847 |
848 | /**
849 | * @return null when there is no need for alpha paint.
850 | */
851 | public Paint getPaint(ColorFilter filter) {
852 | if (!hasTranslucentRoot() && filter == null) {
853 | return null;
854 | }
855 |
856 | if (mTempPaint == null) {
857 | mTempPaint = new Paint();
858 | mTempPaint.setFilterBitmap(true);
859 | }
860 | mTempPaint.setAlpha(mVPathRenderer.getRootAlpha());
861 | mTempPaint.setColorFilter(filter);
862 | return mTempPaint;
863 | }
864 |
865 | public void updateCachedBitmap(int width, int height) {
866 | mCachedBitmap.eraseColor(Color.TRANSPARENT);
867 | Canvas tmpCanvas = new Canvas(mCachedBitmap);
868 | mVPathRenderer.draw(tmpCanvas, width, height, null);
869 | }
870 |
871 | public void createCachedBitmapIfNeeded(int width, int height) {
872 | if (mCachedBitmap == null || !canReuseBitmap(width, height)) {
873 | mCachedBitmap = Bitmap.createBitmap(width, height,
874 | Bitmap.Config.ARGB_8888);
875 | mCacheDirty = true;
876 | }
877 |
878 | }
879 |
880 | public boolean canReuseBitmap(int width, int height) {
881 | if (width == mCachedBitmap.getWidth()
882 | && height == mCachedBitmap.getHeight()) {
883 | return true;
884 | }
885 | return false;
886 | }
887 |
888 | public boolean canReuseCache() {
889 | if (!mCacheDirty
890 | && mCachedTint == mTint
891 | && mCachedTintMode == mTintMode
892 | && mCachedAutoMirrored == mAutoMirrored
893 | && mCachedRootAlpha == mVPathRenderer.getRootAlpha()) {
894 | return true;
895 | }
896 | return false;
897 | }
898 |
899 | public void updateCacheStates() {
900 | // Use shallow copy here and shallow comparison in canReuseCache(),
901 | // likely hit cache miss more, but practically not much difference.
902 | mCachedTint = mTint;
903 | mCachedTintMode = mTintMode;
904 | mCachedRootAlpha = mVPathRenderer.getRootAlpha();
905 | mCachedAutoMirrored = mAutoMirrored;
906 | mCacheDirty = false;
907 | }
908 |
909 | public VectorDrawableCompatState() {
910 | mVPathRenderer = new VPathRenderer();
911 | }
912 |
913 | @Override
914 | public Drawable newDrawable() {
915 | return new VectorDrawableCompat(this);
916 | }
917 |
918 | @Override
919 | public Drawable newDrawable(Resources res) {
920 | return new VectorDrawableCompat(this);
921 | }
922 |
923 | @Override
924 | public int getChangingConfigurations() {
925 | return mChangingConfigurations;
926 | }
927 | }
928 |
929 | private static class VPathRenderer {
930 | /* Right now the internal data structure is organized as a tree.
931 | * Each node can be a group node, or a path.
932 | * A group node can have groups or paths as children, but a path node has
933 | * no children.
934 | * One example can be:
935 | * Root Group
936 | * / | \
937 | * Group Path Group
938 | * / \ |
939 | * Path Path Path
940 | *
941 | */
942 | // Variables that only used temporarily inside the draw() call, so there
943 | // is no need for deep copying.
944 | private final Path mPath;
945 | private final Path mRenderPath;
946 | private static final Matrix IDENTITY_MATRIX = new Matrix();
947 | private final Matrix mFinalPathMatrix = new Matrix();
948 |
949 | private Paint mStrokePaint;
950 | private Paint mFillPaint;
951 | private PathMeasure mPathMeasure;
952 |
953 | /////////////////////////////////////////////////////
954 | // Variables below need to be copied (deep copy if applicable) for mutation.
955 | private int mChangingConfigurations;
956 | final VGroup mRootGroup;
957 | float mBaseWidth = 0;
958 | float mBaseHeight = 0;
959 | float mViewportWidth = 0;
960 | float mViewportHeight = 0;
961 | int mRootAlpha = 0xFF;
962 | String mRootName = null;
963 |
964 | final ArrayMap mVGTargetsMap = new ArrayMap();
965 |
966 | public VPathRenderer() {
967 | mRootGroup = new VGroup();
968 | mPath = new Path();
969 | mRenderPath = new Path();
970 | }
971 |
972 | public void setRootAlpha(int alpha) {
973 | mRootAlpha = alpha;
974 | }
975 |
976 | public int getRootAlpha() {
977 | return mRootAlpha;
978 | }
979 |
980 | // setAlpha() and getAlpha() are used mostly for animation purpose, since
981 | // Animator like to use alpha from 0 to 1.
982 | public void setAlpha(float alpha) {
983 | setRootAlpha((int) (alpha * 255));
984 | }
985 |
986 | @SuppressWarnings("unused")
987 | public float getAlpha() {
988 | return getRootAlpha() / 255.0f;
989 | }
990 |
991 | public VPathRenderer(VPathRenderer copy) {
992 | mRootGroup = new VGroup(copy.mRootGroup, mVGTargetsMap);
993 | mPath = new Path(copy.mPath);
994 | mRenderPath = new Path(copy.mRenderPath);
995 | mBaseWidth = copy.mBaseWidth;
996 | mBaseHeight = copy.mBaseHeight;
997 | mViewportWidth = copy.mViewportWidth;
998 | mViewportHeight = copy.mViewportHeight;
999 | mChangingConfigurations = copy.mChangingConfigurations;
1000 | mRootAlpha = copy.mRootAlpha;
1001 | mRootName = copy.mRootName;
1002 | if (copy.mRootName != null) {
1003 | mVGTargetsMap.put(copy.mRootName, this);
1004 | }
1005 | }
1006 |
1007 | private void drawGroupTree(VGroup currentGroup, Matrix currentMatrix,
1008 | Canvas canvas, int w, int h, ColorFilter filter) {
1009 | // Calculate current group's matrix by preConcat the parent's and
1010 | // and the current one on the top of the stack.
1011 | // Basically the Mfinal = Mviewport * M0 * M1 * M2;
1012 | // Mi the local matrix at level i of the group tree.
1013 | currentGroup.mStackedMatrix.set(currentMatrix);
1014 |
1015 | currentGroup.mStackedMatrix.preConcat(currentGroup.mLocalMatrix);
1016 |
1017 | // Save the current clip information, which is local to this group.
1018 | canvas.save();
1019 |
1020 | // Draw the group tree in the same order as the XML file.
1021 | for (int i = 0; i < currentGroup.mChildren.size(); i++) {
1022 | Object child = currentGroup.mChildren.get(i);
1023 | if (child instanceof VGroup) {
1024 | VGroup childGroup = (VGroup) child;
1025 | drawGroupTree(childGroup, currentGroup.mStackedMatrix,
1026 | canvas, w, h, filter);
1027 | } else if (child instanceof VPath) {
1028 | VPath childPath = (VPath) child;
1029 | drawPath(currentGroup, childPath, canvas, w, h, filter);
1030 | }
1031 | }
1032 |
1033 | canvas.restore();
1034 | }
1035 |
1036 | public void draw(Canvas canvas, int w, int h, ColorFilter filter) {
1037 | // Traverse the tree in pre-order to draw.
1038 | drawGroupTree(mRootGroup, IDENTITY_MATRIX, canvas, w, h, filter);
1039 | }
1040 |
1041 | private void drawPath(VGroup vGroup, VPath vPath, Canvas canvas, int w, int h,
1042 | ColorFilter filter) {
1043 | final float scaleX = w / mViewportWidth;
1044 | final float scaleY = h / mViewportHeight;
1045 | final float minScale = Math.min(scaleX, scaleY);
1046 | final Matrix groupStackedMatrix = vGroup.mStackedMatrix;
1047 |
1048 | mFinalPathMatrix.set(groupStackedMatrix);
1049 | mFinalPathMatrix.postScale(scaleX, scaleY);
1050 |
1051 |
1052 | final float matrixScale = getMatrixScale(groupStackedMatrix);
1053 | if (matrixScale == 0) {
1054 | // When either x or y is scaled to 0, we don't need to draw anything.
1055 | return;
1056 | }
1057 | vPath.toPath(mPath);
1058 | final Path path = mPath;
1059 |
1060 | mRenderPath.reset();
1061 |
1062 | if (vPath.isClipPath()) {
1063 | mRenderPath.addPath(path, mFinalPathMatrix);
1064 | canvas.clipPath(mRenderPath);
1065 | } else {
1066 | VFullPath fullPath = (VFullPath) vPath;
1067 | if (fullPath.mTrimPathStart != 0.0f || fullPath.mTrimPathEnd != 1.0f) {
1068 | float start = (fullPath.mTrimPathStart + fullPath.mTrimPathOffset) % 1.0f;
1069 | float end = (fullPath.mTrimPathEnd + fullPath.mTrimPathOffset) % 1.0f;
1070 |
1071 | if (mPathMeasure == null) {
1072 | mPathMeasure = new PathMeasure();
1073 | }
1074 | mPathMeasure.setPath(mPath, false);
1075 |
1076 | float len = mPathMeasure.getLength();
1077 | start = start * len;
1078 | end = end * len;
1079 | path.reset();
1080 | if (start > end) {
1081 | mPathMeasure.getSegment(start, len, path, true);
1082 | mPathMeasure.getSegment(0f, end, path, true);
1083 | } else {
1084 | mPathMeasure.getSegment(start, end, path, true);
1085 | }
1086 | path.rLineTo(0, 0); // fix bug in measure
1087 | }
1088 | mRenderPath.addPath(path, mFinalPathMatrix);
1089 |
1090 | if (fullPath.mFillColor != Color.TRANSPARENT) {
1091 | if (mFillPaint == null) {
1092 | mFillPaint = new Paint();
1093 | mFillPaint.setStyle(Paint.Style.FILL);
1094 | mFillPaint.setAntiAlias(true);
1095 | }
1096 |
1097 | final Paint fillPaint = mFillPaint;
1098 | fillPaint.setColor(applyAlpha(fullPath.mFillColor, fullPath.mFillAlpha));
1099 | fillPaint.setColorFilter(filter);
1100 | canvas.drawPath(mRenderPath, fillPaint);
1101 | }
1102 |
1103 | if (fullPath.mStrokeColor != Color.TRANSPARENT) {
1104 | if (mStrokePaint == null) {
1105 | mStrokePaint = new Paint();
1106 | mStrokePaint.setStyle(Paint.Style.STROKE);
1107 | mStrokePaint.setAntiAlias(true);
1108 | }
1109 |
1110 | final Paint strokePaint = mStrokePaint;
1111 | if (fullPath.mStrokeLineJoin != null) {
1112 | strokePaint.setStrokeJoin(fullPath.mStrokeLineJoin);
1113 | }
1114 |
1115 | if (fullPath.mStrokeLineCap != null) {
1116 | strokePaint.setStrokeCap(fullPath.mStrokeLineCap);
1117 | }
1118 |
1119 | strokePaint.setStrokeMiter(fullPath.mStrokeMiterlimit);
1120 | strokePaint.setColor(applyAlpha(fullPath.mStrokeColor, fullPath.mStrokeAlpha));
1121 | strokePaint.setColorFilter(filter);
1122 | final float finalStrokeScale = minScale * matrixScale;
1123 | strokePaint.setStrokeWidth(fullPath.mStrokeWidth * finalStrokeScale);
1124 | canvas.drawPath(mRenderPath, strokePaint);
1125 | }
1126 | }
1127 | }
1128 |
1129 | private static float cross(float v1x, float v1y, float v2x, float v2y) {
1130 | return v1x * v2y - v1y * v2x;
1131 | }
1132 |
1133 | private float getMatrixScale(Matrix groupStackedMatrix) {
1134 | // Given unit vectors A = (0, 1) and B = (1, 0).
1135 | // After matrix mapping, we got A' and B'. Let theta = the angel b/t A' and B'.
1136 | // Therefore, the final scale we want is min(|A'| * sin(theta), |B'| * sin(theta)),
1137 | // which is (|A'| * |B'| * sin(theta)) / max (|A'|, |B'|);
1138 | // If max (|A'|, |B'|) = 0, that means either x or y has a scale of 0.
1139 | //
1140 | // For non-skew case, which is most of the cases, matrix scale is computing exactly the
1141 | // scale on x and y axis, and take the minimal of these two.
1142 | // For skew case, an unit square will mapped to a parallelogram. And this function will
1143 | // return the minimal height of the 2 bases.
1144 | float[] unitVectors = new float[]{0, 1, 1, 0};
1145 | groupStackedMatrix.mapVectors(unitVectors);
1146 | float scaleX = (float) Math.hypot(unitVectors[0], unitVectors[1]);
1147 | float scaleY = (float) Math.hypot(unitVectors[2], unitVectors[3]);
1148 | float crossProduct = cross(unitVectors[0], unitVectors[1], unitVectors[2],
1149 | unitVectors[3]);
1150 | float maxScale = Math.max(scaleX, scaleY);
1151 |
1152 | float matrixScale = 0;
1153 | if (maxScale > 0) {
1154 | matrixScale = Math.abs(crossProduct) / maxScale;
1155 | }
1156 | if (DBG_VECTOR_DRAWABLE) {
1157 | Log.d(LOGTAG, "Scale x " + scaleX + " y " + scaleY + " final " + matrixScale);
1158 | }
1159 | return matrixScale;
1160 | }
1161 | }
1162 |
1163 | public static class VGroup {
1164 | // mStackedMatrix is only used temporarily when drawing, it combines all
1165 | // the parents' local matrices with the current one.
1166 | private final Matrix mStackedMatrix = new Matrix();
1167 |
1168 | /////////////////////////////////////////////////////
1169 | // Variables below need to be copied (deep copy if applicable) for mutation.
1170 | final ArrayList