diff --git a/README.md b/README.md
index 0df9340..9df4ca0 100644
--- a/README.md
+++ b/README.md
@@ -37,8 +37,12 @@ RichPathAnimator.animate(richPath)
#### 2. Find your richPath.
```java
+ // by path name
RichPath richPath = richPathView.findRichPathByName("path_name");
-
+// or if it contains one path
+RichPath richPath = richPathView.findFirstRichPath();
+// or by index
+RichPath richPath = richPathView.findRichPathByIndex(0);
```
#### 3. Use the RichPathAnimator to animate your richPath.
diff --git a/app/src/main/java/com/richpathanimator/sample/MainActivity.java b/app/src/main/java/com/richpathanimator/sample/MainActivity.java
index 3a2bc78..6f7eef1 100644
--- a/app/src/main/java/com/richpathanimator/sample/MainActivity.java
+++ b/app/src/main/java/com/richpathanimator/sample/MainActivity.java
@@ -22,6 +22,7 @@ public class MainActivity extends AppCompatActivity {
private RichPathView playlistAddCheckRichPathView;
private RichPathView loveFaceRichPathView;
private RichPathView animalRichPathView;
+ private boolean reverse = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -130,7 +131,7 @@ public void animateAnimal(View view) {
String elephantPathData = getString(R.string.elephant_path);
String bullPathData = getString(R.string.bull_path);
- final RichPath richPath = animalRichPathView.findRichPathByName("path");
+ final RichPath richPath = animalRichPathView.findFirstRichPath();
RichPathAnimator
.animate(richPath)
@@ -148,8 +149,6 @@ public void animateAnimal(View view) {
.start();
}
- private boolean reverse = false;
-
public void animateArrowToSearch(View view) {
RichPath searchCircle = arrowSearchRichPathView.findRichPathByName("search_circle");
@@ -181,8 +180,8 @@ public void animateArrowToSearch(View view) {
public void animateNotification(View view) {
- final RichPath top = notificationsRichPathView.findRichPathByName("top");
- final RichPath bottom = notificationsRichPathView.findRichPathByName("bottom");
+ final RichPath top = notificationsRichPathView.findRichPathByIndex(0);
+ final RichPath bottom = notificationsRichPathView.findRichPathByIndex(1);
RichPathAnimator.animate(top)
.interpolator(new DecelerateInterpolator())
diff --git a/app/src/main/res/drawable/animal.xml b/app/src/main/res/drawable/animal.xml
index fcc9177..0294a06 100644
--- a/app/src/main/res/drawable/animal.xml
+++ b/app/src/main/res/drawable/animal.xml
@@ -3,10 +3,9 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="34.08dp"
android:height="24.08dp"
- android:viewportWidth="409"
- android:viewportHeight="280">
+ android:viewportHeight="280"
+ android:viewportWidth="409">
+ * This can be in handy if the vector consists of 1 path only + * + * @return the {@link RichPath} object found or null + */ + @Nullable + public RichPath findFirstRichPath() { + return findRichPathByIndex(0); + } + + /** + * find {@link RichPath} by its index or null if not found + *
+ * Note that the provided index must be the flattened index of the path + *
+ * example: + *
+ * {@code+ * + * @param index the flattened index of the path + * @return the {@link RichPath} object found or null + */ + @Nullable + public RichPath findRichPathByIndex(@IntRange(from = 0) int index) { + if (vector == null || index < 0 || index >= vector.paths.size()) return null; + return vector.paths.get(index); + } + public void listenToPathsUpdates() { if (vector == null) return; diff --git a/richpath/src/main/java/com/richpath/RichPathView.java b/richpath/src/main/java/com/richpath/RichPathView.java index 94c3144..0daf7c4 100644 --- a/richpath/src/main/java/com/richpath/RichPathView.java +++ b/richpath/src/main/java/com/richpath/RichPathView.java @@ -5,6 +5,7 @@ import android.content.res.XmlResourceParser; import android.graphics.Path; import android.support.annotation.DrawableRes; +import android.support.annotation.IntRange; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View; @@ -133,11 +134,52 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(width, height); } + @Nullable public RichPath findRichPathByName(String name) { return richPathDrawable == null ? null : richPathDrawable.findRichPathByName(name); } + /** + * find the first {@link RichPath} or null if not found + *+ * } + *// index = 0 + * // index = 1 + * + * + *// index = 2 + * + * + *// index = 3 + * // index = 4 + *
+ * This can be in handy if the vector consists of 1 path only + * + * @return the {@link RichPath} object found or null + */ + @Nullable + public RichPath findFirstRichPath() { + return richPathDrawable == null ? null : richPathDrawable.findFirstRichPath(); + } + + /** + * find {@link RichPath} by its index or null if not found + *
+ * Note that the provided index must be the flattened index of the path + *
+ * example: + *
+ * {@code+ * + * @param index the flattened index of the path + * @return the {@link RichPath} object found or null + */ + @Nullable + public RichPath findRichPathByIndex(@IntRange(from = 0) int index) { + return richPathDrawable == null ? null : richPathDrawable.findRichPathByIndex(index); + } + public void addPath(String path) { if (richPathDrawable != null) { richPathDrawable.addPath(PathParser.createPathFromPathData(path));+ * } + *// index = 0 + * // index = 1 + * + * + *// index = 2 + * + * + *// index = 3 + * // index = 4 + *