Skip to content

Commit 559bae5

Browse files
committedJun 26, 2017
Updates README to include Custom Drawable example
1 parent 5da9fe2 commit 559bae5

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
 

‎README.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Features :
1717
Just add the following dependency in your app's `build.gradle`
1818
```groovy
1919
dependencies {
20-
compile 'com.sdsmdg.harjot:vectormaster:1.0.3'
20+
compile 'com.sdsmdg.harjot:vectormaster:1.0.5'
2121
}
2222
```
2323

@@ -206,6 +206,46 @@ heartVector.setOnClickListener(new View.OnClickListener() {
206206
The above examples are just the basic use cases and are meant to serve as a quick start to using the library. For more complex animations and use cases involving **clip-paths** and **groups**, head to [AnimationExamples](AnimationExamples)<br>
207207
<div align="center"><img src="/screens/more_animations.gif" width="500"/></div>
208208

209+
# Using as a Custom Drawable
210+
The library also provide custom drawable implementation in form of `VecotrMasterDrawable`. It provides the same control over the vector, but allows the user to use the drawable as per its wish, for e.g. as a `Compound Drawable` in `TextView`, or as the source drawable in `ImageView`; basically any use case that involves a `Drawable` can be replaced by `VectorMasterDrawable`.
211+
212+
## Example
213+
#### XML
214+
```xml
215+
<TextView
216+
android:id="@+id/text_view"
217+
android:layout_width="wrap_content"
218+
android:layout_height="wrap_content"
219+
android:text="Heart"
220+
android:textSize="30sp" />
221+
222+
<ImageView
223+
android:id="@+id/image_view"
224+
android:layout_width="75dp"
225+
android:layout_height="75dp"/>
226+
```
227+
228+
#### Java
229+
```java
230+
// Instantiate the custom drawable
231+
VectorMasterDrawable vectorMasterDrawable = new VectorMasterDrawable(this, R.drawable.ic_heart);
232+
233+
// Set top drawable for TextView
234+
TextView textView = (TextView) findViewById(R.id.text_view);
235+
textView.setCompoundDrawablesWithIntrinsicBounds(null, vectorMasterDrawable, null, null);
236+
237+
// Set background drawable for ImageView
238+
ImageView imageView = (ImageView) findViewById(R.id.image_view);
239+
imageView.setImageDrawable(vectorMasterDrawable);
240+
241+
// Set tht stroke color of the drawable
242+
PathModel pathModel = vectorMasterDrawable.getPathModelByName("outline");
243+
pathModel.setStrokeColor(Color.parseColor("#ED4337"));
244+
```
245+
246+
#### Result
247+
<div align="center"><img src="/screens/result_5.png" width="600"/></div>
248+
209249
# Limitations
210250
1. The `PathParser.java` has been extracted from Android source code of version 5.1.1. After this version all the parsing code was shifted to native for efficiency. I have incorporated some of the changes from the native code into the `PathParser.java`, but still sometimes parsing errors occur. I have also included a 3rd party parser from [Android-Image-Shape](https://github.com/sathishmscict/Android-Image-Shape/blob/master/library/src/main/java/com/github/siyamed/shapeimageview/path/parser/PathParser.java). To use this parser instead of the default one, set `use_legacy_parser="false"`. This may help in certain situations but not always. If you find any vector that is not being drawn properly, please file an issue and include the vector.
211251
2. Path morphing is not supported as of now. I would like to support path morphing between incompatible vectors as well (using techniques mentioned [here](https://github.com/alexjlockwood/ShapeShifter#how-does-it-work) by [Alex Lockwood](https://github.com/alexjlockwood)).

‎screens/result_5.png

31.3 KB
Loading

1 commit comments

Comments
 (1)

vivonk commented on Jun 29, 2017

@vivonk

👦 very cool library

Please sign in to comment.