This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
177 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
animator/src/main/java/com/richpathanimator/PathEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.richpathanimator; | ||
|
||
import android.animation.TypeEvaluator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Created by tarek on 7/14/17. | ||
*/ | ||
|
||
public class PathEvaluator implements TypeEvaluator<String> { | ||
|
||
private String pathHolder; | ||
private String startPath; | ||
private String endPath; | ||
|
||
private List<Float> startFloats = new ArrayList<>(); | ||
private List<Float> endFloats = new ArrayList<>(); | ||
|
||
@Override | ||
public String evaluate(float fraction, String startPath, String endPath) { | ||
|
||
|
||
if (pathHolder == null | ||
|| !this.startPath.equals(startPath) || !this.endPath.equals(endPath)) { | ||
|
||
this.pathHolder = endPath; | ||
this.startPath = startPath; | ||
this.endPath = endPath; | ||
|
||
startFloats.clear(); | ||
endFloats.clear(); | ||
|
||
Pattern p = Pattern.compile("[-]?[0-9]*\\.?[0-9]+"); | ||
|
||
Matcher startMatcher = p.matcher(startPath); | ||
Matcher endMatcher = p.matcher(endPath); | ||
|
||
while (startMatcher.find() && endMatcher.find()) { | ||
startFloats.add(Float.parseFloat(startMatcher.group())); | ||
endFloats.add(Float.parseFloat(endMatcher.group())); | ||
pathHolder = p.matcher(pathHolder).replaceFirst("#"); | ||
} | ||
} | ||
|
||
String evaluatedPath = pathHolder; | ||
|
||
for (int i = 0; i < startFloats.size(); i++) { | ||
|
||
float startFloat = startFloats.get(i); | ||
float value = startFloat + fraction * (endFloats.get(i) - startFloat); | ||
|
||
evaluatedPath = evaluatedPath.replaceFirst("#", String.valueOf(value)); | ||
} | ||
|
||
return evaluatedPath; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="34.08dp" | ||
android:height="24.08dp" | ||
android:viewportWidth="409" | ||
android:viewportHeight="280"> | ||
<path | ||
android:name="path" | ||
android:pathData="@string/hippo_path" | ||
android:fillColor="#FFF7F7F7"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="32" | ||
android:viewportHeight="32"> | ||
|
||
<path | ||
android:name="square" | ||
android:fillColor="#FF2254" | ||
android:pathData="M0,0 L32,0 L32,32 L0,32z" /> | ||
|
||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.