Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Add other options to find RichPaths in RichPathView (#6)
Browse files Browse the repository at this point in the history
* Add other options to find RichPaths in RichPathView by index or by getting the first one directly
  • Loading branch information
AmrElmasry authored and tarek360 committed Aug 1, 2017
1 parent 94e88c3 commit a1598df
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 11 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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");
Expand Down Expand Up @@ -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())
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/res/drawable/animal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<path
android:name="path"
android:pathData="@string/hippo_path"
android:fillColor="#FFF7F7F7"/>
android:fillColor="#FFF7F7F7"
android:pathData="@string/hippo_path" />
</vector>
41 changes: 41 additions & 0 deletions richpath/src/main/java/com/richpath/RichPathDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,47 @@ public RichPath findRichPathByName(String name) {
return null;
}

/**
* find the first {@link RichPath} or null if not found
* <p>
* 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
* <p>
* Note that the provided index must be the flattened index of the path
* <p>
* example:
* <pre>
* {@code <vector>
* <path> // index = 0
* <path> // index = 1
* <group>
* <path> // index = 2
* <group>
* <path> // index = 3
* </group>
* </group>
* <path> // index = 4
* </vector>}
* </pre>
*
* @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;
Expand Down
42 changes: 42 additions & 0 deletions richpath/src/main/java/com/richpath/RichPathView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
* <p>
* 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
* <p>
* Note that the provided index must be the flattened index of the path
* <p>
* example:
* <pre>
* {@code <vector>
* <path> // index = 0
* <path> // index = 1
* <group>
* <path> // index = 2
* <group>
* <path> // index = 3
* </group>
* </group>
* <path> // index = 4
* </vector>}
* </pre>
*
* @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));
Expand Down

0 comments on commit a1598df

Please sign in to comment.