diff --git a/animator/src/main/java/com/richpathanimator/AnimationBuilder.java b/animator/src/main/java/com/richpathanimator/AnimationBuilder.java index 02b7aa0..992b26c 100644 --- a/animator/src/main/java/com/richpathanimator/AnimationBuilder.java +++ b/animator/src/main/java/com/richpathanimator/AnimationBuilder.java @@ -174,6 +174,15 @@ private AnimationBuilder color(String propertyName, int... colors) { return this; } + public AnimationBuilder pathData(String... pathData) { + for (final RichPath path : paths) { + ObjectAnimator objectAnimator = + ObjectAnimator.ofObject(path, "pathData", new PathEvaluator(), pathData); + applyAnimatorProperties(objectAnimator, path); + } + return this; + } + private void applyAnimatorProperties(ValueAnimator animator, final RichPath path) { if (path == null) { diff --git a/animator/src/main/java/com/richpathanimator/PathEvaluator.java b/animator/src/main/java/com/richpathanimator/PathEvaluator.java new file mode 100644 index 0000000..ba60f6d --- /dev/null +++ b/animator/src/main/java/com/richpathanimator/PathEvaluator.java @@ -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 { + + private String pathHolder; + private String startPath; + private String endPath; + + private List startFloats = new ArrayList<>(); + private List 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; + } + +} diff --git a/app/src/main/java/com/richpathanimator/sample/MainActivity.java b/app/src/main/java/com/richpathanimator/sample/MainActivity.java index bdad739..3a2bc78 100644 --- a/app/src/main/java/com/richpathanimator/sample/MainActivity.java +++ b/app/src/main/java/com/richpathanimator/sample/MainActivity.java @@ -21,6 +21,7 @@ public class MainActivity extends AppCompatActivity { private RichPathView notificationsRichPathView; private RichPathView playlistAddCheckRichPathView; private RichPathView loveFaceRichPathView; + private RichPathView animalRichPathView; @Override protected void onCreate(Bundle savedInstanceState) { @@ -33,6 +34,7 @@ protected void onCreate(Bundle savedInstanceState) { notificationsRichPathView = (RichPathView) findViewById(R.id.ic_notifications); playlistAddCheckRichPathView = (RichPathView) findViewById(R.id.ic_playlist_add_check); loveFaceRichPathView = (RichPathView) findViewById(R.id.love_face); + animalRichPathView = (RichPathView) findViewById(R.id.animal); animateCommand(); } @@ -122,6 +124,30 @@ public void onStop() { .start(); } + public void animateAnimal(View view) { + + String hippoPathData = getString(R.string.hippo_path); + String elephantPathData = getString(R.string.elephant_path); + String bullPathData = getString(R.string.bull_path); + + final RichPath richPath = animalRichPathView.findRichPathByName("path"); + + RichPathAnimator + .animate(richPath) + .pathData(elephantPathData) + .duration(600) + + .thenAnimate(richPath) + .pathData(bullPathData) + .duration(600) + + .thenAnimate(richPath) + .pathData(hippoPathData) + .duration(600) + + .start(); + } + private boolean reverse = false; public void animateArrowToSearch(View view) { diff --git a/app/src/main/res/drawable/animal.xml b/app/src/main/res/drawable/animal.xml new file mode 100644 index 0000000..fcc9177 --- /dev/null +++ b/app/src/main/res/drawable/animal.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/square.xml b/app/src/main/res/drawable/square.xml new file mode 100644 index 0000000..433cc38 --- /dev/null +++ b/app/src/main/res/drawable/square.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index cbb84fb..969ca27 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -35,6 +35,14 @@ android:onClick="animateAndroid" app:vector="@drawable/ic_android" /> + + RichPath M18,3a3,3 0,0 0,-3 3v12a3,3 0,0 0,3 3,3 3,0 0,0 3,-3 3,3 0,0 0,-3 -3H6a3,3 0,0 0,-3 3,3 3,0 0,0 3,3 3,3 0,0 0,3 -3V6a3,3 0,0 0,-3 -3,3 3,0 0,0 -3,3 3,3 0,0 0,3 3h12a3,3 0,0 0,3 -3,3 3,0 0,0 -3,-3z + + M 217.765 29.683 C 225.855 29.683 235.734 31.193 247.403 34.209 C 259.072 37.224 272.53 41.744 287.779 47.764 C 293.183 49.818 299.71 55.439 307.378 64.555 C 311.735 69.94 318.479 78.055 327.602 88.844 C 329.676 90.305 332.381 92.475 335.705 95.396 C 339.023 98.28 341.3 99.537 342.532 99.122 C 342.952 97.866 343.999 96.117 345.658 93.84 C 346.487 93.004 346.998 92.589 347.202 92.589 C 347.84 93.004 348.452 93.419 349.077 93.84 C 349.696 94.261 349.9 95.492 349.696 97.566 C 349.275 101.304 349.077 102.44 349.077 100.979 C 348.854 103.065 348.561 104.399 348.14 105.043 C 345.441 109.599 344.395 113.133 345.033 115.608 C 345.658 117.879 347.603 121.528 350.934 126.505 C 354.258 131.482 356.115 135.22 356.529 137.708 C 356.325 139.572 356.235 142.57 356.235 146.73 C 355.975 147.377 355.715 148.025 355.455 148.672 C 355.195 149.32 354.935 149.968 354.675 150.615 C 354.416 151.263 354.156 151.91 353.896 152.558 C 353.636 153.205 353.376 153.852 353.116 154.5 C 353.116 155.953 353.537 157.666 354.379 159.639 C 355.222 161.612 356.485 163.844 358.17 166.336 C 361.541 171.32 366.596 177.34 373.34 184.397 C 379.784 187.281 382.981 197.253 382.981 214.249 C 382.981 227.545 371.994 234.167 350.015 234.167 C 347.106 234.167 343.999 234.078 340.675 233.848 C 338.398 233.031 335.074 232.1 330.722 231.066 C 325.542 230.428 322.008 228.68 320.151 225.758 C 316.821 221.012 311.423 216.532 303.959 212.386 C 302.714 211.786 300.896 209.503 298.51 205.547 C 296.118 201.604 293.993 199.116 292.136 198.069 C 290.28 197.048 287.575 196.831 284.04 197.47 C 278.024 198.49 274.7 199.014 274.087 199.014 C 272.627 199.014 270.502 198.605 267.707 197.763 C 266.304 197.348 265.1 197.035 264.09 196.826 C 263.079 196.617 262.263 196.512 261.634 196.512 C 260.191 203.16 259.866 209.591 260.703 215.805 C 260.906 217.477 261.953 218.829 263.816 219.85 C 266.731 221.93 268.276 223.066 268.493 223.296 C 270.349 224.737 272.327 227.123 274.394 230.428 C 274.815 231.691 274.037 233.81 272.059 236.808 C 270.087 239.82 268.493 241.593 267.235 242.091 C 265.997 242.627 263.298 242.895 259.145 242.895 C 253.122 242.895 250.749 242.984 251.999 243.188 C 243.706 241.938 239.036 241.223 237.989 241.032 C 232.808 239.986 228.342 238.339 224.616 236.043 C 222.734 234.805 220.578 228.987 218.09 218.613 C 217.252 214.878 216.463 211.64 215.722 208.897 C 214.981 206.154 214.289 203.906 213.644 202.153 C 212.999 200.4 212.401 199.141 211.85 198.375 C 211.442 197.763 210.925 197.47 210.306 197.47 C 209.26 197.47 207.544 198.491 205.164 200.583 C 202.778 202.625 201.164 203.76 200.347 204.003 C 197.451 216.227 195.977 222.032 195.977 221.395 C 195.977 226.18 197.323 230.199 200.022 233.529 C 202.715 236.847 205.529 240.063 208.438 243.163 C 211.959 247.106 213.72 250.526 213.72 253.435 C 213.72 255.081 213.21 256.523 212.163 257.786 C 207.806 263.171 200.539 265.876 190.376 265.876 C 178.962 265.876 171.498 264.319 167.982 261.206 C 163.408 257.263 160.505 253.104 159.267 248.778 C 159.063 247.731 158.547 244.618 157.71 239.438 C 157.295 236.312 156.358 234.462 154.922 233.849 C 152.839 233.536 150.502 233.096 147.911 232.527 C 145.319 231.957 142.472 231.258 139.368 230.429 C 138.111 229.6 136.765 227.52 135.31 224.203 C 132.625 217.784 130.646 213.421 129.396 211.137 C 123.162 208.023 113.21 204.514 99.512 200.584 C 99.304 201.001 99.132 201.471 98.996 201.998 C 98.86 202.525 98.76 203.109 98.693 203.75 C 98.627 204.392 98.594 205.093 98.594 205.854 C 100.871 208.763 104.291 213.229 108.859 219.226 C 112.591 224.203 114.461 228.988 114.461 233.542 C 114.461 242.271 108.859 246.609 97.656 246.609 C 94.821 246.609 92.286 246.542 90.051 246.407 C 87.815 246.272 85.879 246.068 84.242 245.794 C 82.605 245.52 81.267 245.175 80.227 244.758 C 75.671 242.896 71.83 238.519 68.717 231.692 C 63.53 220.259 60.627 213.829 60.002 212.387 C 56.678 204.718 54.4 197.956 53.169 192.137 C 53.029 191.448 52.877 190.697 52.714 189.885 C 52.551 189.074 52.377 188.201 52.191 187.267 C 52.006 186.333 51.809 185.338 51.601 184.282 C 51.549 184.018 51.496 183.751 51.442 183.479 C 51.389 183.208 51.335 182.932 51.28 182.653 C 51.225 182.374 51.17 182.091 51.113 181.805 C 51.057 181.518 51 181.228 50.942 180.934 C 50.712 179.757 50.47 178.52 50.217 177.222 C 49.964 175.925 49.7 174.567 49.424 173.15 C 48.7 169.635 47.768 166.5 46.629 163.752 C 45.489 161.005 44.142 158.642 42.585 156.671 C 31.164 141.925 25.87 129.159 26.705 118.377 C 26.705 118.377 26.705 118.377 26.705 118.377 C 27.328 110.015 28.758 101.986 30.994 94.29 C 33.23 86.593 36.273 79.229 40.122 72.197 C 43.971 65.165 48.626 58.464 54.087 52.095 C 72.551 30.519 95.691 19.736 123.488 19.736 C 134.06 19.736 149.767 21.408 170.623 24.712 C 175.837 25.546 180.729 26.274 185.3 26.897 C 189.87 27.519 194.119 28.036 198.046 28.449 C 201.974 28.862 205.581 29.17 208.867 29.376 C 212.153 29.581 215.119 29.683 217.765 29.683 + M 223.174 43.413 C 229.201 43.413 235.048 46.903 240.731 53.875 C 246.401 60.846 249.686 64.336 250.575 64.336 C 253.418 64.336 256.262 64.336 259.105 64.336 C 277.541 64.336 291.822 73.563 301.939 92.016 C 304.605 97.181 308.678 104.766 314.19 114.788 C 314.8 115.903 315.42 116.986 316.053 118.037 C 316.685 119.087 317.328 120.105 317.983 121.091 C 318.637 122.076 319.303 123.029 319.98 123.95 C 320.657 124.871 321.345 125.759 322.044 126.615 C 322.743 127.471 323.453 128.294 324.175 129.085 C 324.896 129.877 325.628 130.635 326.372 131.362 C 327.115 132.088 327.869 132.782 328.635 133.444 C 329.4 134.106 330.176 134.735 330.963 135.332 C 331.75 135.93 332.548 136.494 333.357 137.027 C 337.435 139.692 341.536 141.759 345.659 143.225 C 349.783 144.69 353.928 145.554 358.096 145.813 C 361.993 145.993 366.265 145.279 370.882 143.671 C 374.961 141.887 379.035 140.097 383.111 138.313 C 383.111 138.313 383.111 138.313 385.774 144.222 C 372.65 154.296 360.143 159.491 348.252 159.851 C 335.485 160.206 321.725 157.104 307.009 150.561 C 319.598 165.115 330.43 173.985 339.48 177.164 C 338.771 177.879 338.061 178.594 337.352 179.309 C 329.368 177.889 321.693 175.136 314.329 171.053 C 306.965 166.97 299.912 161.557 293.172 154.818 C 289.623 156.939 286.075 159.06 282.526 161.181 C 282.526 161.895 281.863 162.646 280.531 163.44 C 279.2 164.237 278.613 164.889 278.791 165.423 C 279.505 167.729 283.148 173.395 289.707 182.397 C 296.272 191.431 299.552 196.206 299.552 196.725 C 299.552 198.318 297.508 199.906 293.429 201.502 C 289.352 203.093 287.14 204.864 286.785 206.812 C 286.425 208.405 286.949 210.353 288.379 212.645 C 289.789 214.951 290.503 216.348 290.503 216.896 C 290.503 218.072 290.158 219.101 289.469 219.984 C 288.779 220.867 287.745 221.603 286.367 222.193 C 284.989 222.784 283.266 223.228 281.2 223.526 C 280.122 223.69 276.746 223.788 271.077 223.788 C 269.304 223.788 267.614 223.722 266.008 223.589 C 264.402 223.456 262.88 223.257 261.441 222.992 C 260.002 222.727 258.647 222.396 257.375 221.998 C 256.739 221.799 256.124 221.584 255.53 221.352 C 254.936 221.121 254.363 220.872 253.811 220.608 C 252.707 220.078 251.686 219.482 250.75 218.821 C 249.813 218.16 248.96 217.432 248.191 216.639 C 247.571 215.963 246.972 215.192 246.395 214.329 C 245.819 213.466 245.264 212.509 244.731 211.459 C 243.666 209.359 242.688 206.885 241.8 204.04 C 240.911 201.194 240.112 197.976 239.402 194.386 C 238.688 190.683 237.454 184.056 235.681 174.503 C 226.635 176.809 217.453 178.539 208.137 179.692 C 198.821 180.846 189.37 181.423 179.785 181.423 C 178.72 181.423 177.647 181.416 176.566 181.401 C 175.486 181.387 174.397 181.365 173.3 181.336 C 172.203 181.307 171.098 181.27 169.985 181.226 C 168.872 181.183 167.75 181.131 166.621 181.073 C 165.492 181.015 164.355 180.949 163.21 180.876 C 162.828 180.851 162.445 180.826 162.062 180.8 C 161.678 180.774 161.294 180.747 160.908 180.72 C 160.523 180.692 160.137 180.664 159.75 180.634 C 158.588 180.546 157.419 180.451 156.241 180.348 C 155.064 180.246 153.878 180.136 152.685 180.018 C 151.491 179.901 150.289 179.776 149.08 179.643 C 147.87 179.511 146.652 179.371 145.426 179.224 C 144.2 179.077 142.966 178.922 141.724 178.76 C 144.034 184.62 147.317 194.386 151.589 208.045 C 142.716 206.798 132.062 205.027 119.65 202.719 C 119.038 203.645 118.436 204.517 117.843 205.336 C 117.251 206.154 116.669 206.92 116.096 207.631 C 115.523 208.343 114.961 209.001 114.408 209.605 C 112.75 211.419 111.181 212.75 109.702 213.598 C 108.222 214.446 106.833 214.811 105.533 214.692 C 103.803 214.561 101.884 214.247 99.777 213.75 C 98.723 213.501 97.622 213.207 96.474 212.866 C 95.326 212.526 94.131 212.14 92.889 211.708 C 92.06 211.42 91.211 211.112 90.341 210.783 C 89.471 210.454 88.581 210.105 87.669 209.736 C 86.757 209.367 85.824 208.977 84.871 208.567 C 82.01 207.337 78.961 205.925 75.724 204.329 C 72.527 202.735 70.933 200.332 70.933 197.134 C 70.933 196.072 71.209 194.712 71.762 193.056 C 72.314 191.4 73.143 189.447 74.247 187.199 C 75.352 184.951 76.732 182.408 78.387 179.57 C 80.866 175.315 82.771 171.701 84.101 168.729 C 85.431 165.757 86.186 163.426 86.365 161.737 C 86.723 158.712 85.849 154.559 83.719 149.228 C 81.055 142.305 79.544 137.796 79.189 135.651 C 79.545 135.651 79.902 135.651 80.258 135.651 C 79.548 133.522 78.838 131.392 78.128 129.263 C 69.959 138.133 62.505 144.613 55.763 148.692 C 47.948 153.481 38.721 156.6 28.082 157.997 C 25.954 155.885 24.541 154.818 23.826 154.818 C 36.952 149.132 49.916 140.18 62.682 127.929 C 63.22 127.395 66.581 125.01 72.805 120.734 C 76.344 118.432 78.472 115.701 79.189 112.503 C 83.618 94.765 92.668 82.239 106.33 74.962 C 117.505 69.112 133.216 66.19 153.436 66.19 C 162.664 66.19 171.453 66.807 179.785 68.042 C 183.687 69.112 189.905 70.364 198.418 71.775 C 199.133 64.713 201.619 58.443 205.875 52.967 C 210.669 46.598 216.434 43.413 223.174 43.413 C 223.174 43.413 223.174 43.413 223.174 43.413 + M 257.626 36.194 C 265.402 36.194 275.248 36.678 287.192 37.616 C 304.062 38.951 314.87 42.093 319.604 47.036 C 322.069 49.519 325.106 54.381 328.703 61.598 C 332.312 69.403 335.343 74.731 337.808 77.576 C 338.849 76.249 339.793 75.135 340.645 74.235 C 341.497 73.335 342.256 72.65 342.926 72.184 C 346.908 69.141 349.834 67.147 351.722 66.214 C 351.722 71.14 352.061 73.933 352.731 74.597 C 353.384 75.25 356.1 75.775 360.834 76.154 C 364.716 76.393 368.114 77.448 371.028 79.32 C 373.941 81.192 376.37 83.882 378.313 87.388 C 380.256 90.894 381.714 95.218 382.686 100.359 C 383.659 105.5 384.145 111.459 384.145 118.235 C 384.145 123.353 383.865 129.136 383.294 135.583 C 382.992 138.992 382.591 142.194 382.09 145.188 C 381.59 148.183 380.99 150.97 380.291 153.549 C 379.593 156.128 378.796 158.499 377.901 160.661 C 377.006 162.824 376.012 164.778 374.921 166.523 C 373.83 168.268 372.642 169.804 371.356 171.131 C 370.207 172.25 367.129 173.433 362.099 174.669 C 357.091 175.899 353.908 177.84 352.591 180.492 C 351.731 182.107 350.877 184.476 350.026 187.605 C 349.175 190.734 348.327 194.622 347.479 199.274 C 345.754 209.89 344.331 216.692 343.207 219.729 C 341.782 217.838 340.358 215.948 338.933 214.057 C 336.473 209.216 334.318 204.999 332.469 201.397 C 330.621 197.796 329.079 194.812 327.846 192.436 C 322.722 183.337 317.61 178.603 312.492 178.219 C 308.895 177.84 303.305 179.175 295.732 182.194 C 290.032 184.666 284.447 187.126 278.95 189.586 C 277.308 190.03 275.665 190.475 274.023 190.919 C 272.38 191.363 270.738 191.808 269.095 192.252 C 267.453 192.696 265.81 193.141 264.168 193.585 C 259.049 195.66 255.546 199.443 253.646 204.946 C 252.894 211.766 253.08 216.983 254.217 220.58 C 254.777 222.282 256.823 224.434 260.326 226.981 C 262.081 228.257 263.398 229.407 264.276 230.427 C 265.155 231.446 265.595 232.335 265.595 233.09 C 265.595 234.801 264.957 236.368 263.678 237.789 C 262.4 239.209 260.481 240.484 257.918 241.612 C 253.733 243.518 249.652 244.457 245.689 244.457 C 239.247 242.761 234.601 241.053 231.745 239.356 C 229.477 238.592 228.353 235.934 228.353 231.394 C 228.353 229.307 228.521 226.276 228.906 222.282 C 229.285 218.324 229.477 215.269 229.477 213.183 C 229.477 210.723 229.285 208.601 228.906 206.8 C 228.522 204.999 226.493 203.71 222.803 202.947 C 219.107 202.201 216.962 201.356 216.408 200.4 C 213.184 194.902 212.042 185.704 212.998 172.821 C 201.058 172.821 189.117 172.821 177.177 172.821 C 165.407 172.617 153.854 168.56 142.493 160.592 C 141.152 162.678 138.499 164.707 134.53 166.718 C 130.537 168.694 128.368 170.175 127.983 171.108 C 127.887 171.582 127.72 172.112 127.483 172.7 C 127.246 173.287 126.938 173.931 126.56 174.63 C 126.181 175.329 125.732 176.085 125.212 176.895 C 124.691 177.705 124.099 178.571 123.436 179.49 C 120.784 183.209 119.362 186.193 119.169 188.444 C 117.659 203.437 128.088 220.581 150.455 239.91 C 142.871 242.947 135.655 244.458 128.834 244.458 C 127.138 244.458 125.412 244.37 123.716 244.184 C 123.716 242.668 123.815 239.741 124.007 235.364 C 124.2 231.773 124.007 229.12 123.436 227.418 C 121.734 222.283 118.131 215.847 112.629 208.065 C 106.572 199.554 102.684 193.299 100.982 189.312 C 101.503 185.899 102.024 182.486 102.544 179.072 C 103.065 175.659 103.586 172.246 104.107 168.833 C 101.833 171.009 99.56 173.186 97.286 175.362 C 93.492 181.611 89.597 187.849 85.628 194.097 C 81.827 201.285 79.659 208.193 79.081 214.803 C 78.703 219.817 80.053 224.996 83.134 230.34 C 86.215 235.684 91.025 241.192 97.566 246.864 C 96.802 246.678 95.491 246.917 93.591 247.581 C 91.696 248.24 90.746 248.846 90.746 249.417 C 87.14 248.806 84.058 248.181 81.501 247.543 C 76.942 246.406 74.052 245.229 72.838 244.019 C 70.372 240.627 68.757 235.608 68 228.98 C 67.802 223.494 67.615 217.998 67.429 212.495 C 67.231 210.035 66.869 205.417 66.292 198.574 C 65.721 192.535 65.447 187.802 65.447 184.386 C 65.447 180.982 67.802 176.294 72.547 170.325 C 77.281 164.356 80.038 160.159 80.807 157.693 C 81.361 155.227 80.323 149.083 77.665 139.231 C 74.43 127.689 72.838 119.727 72.838 115.39 C 72.838 112.732 73.206 110.563 73.958 108.85 C 71.504 126.67 68.186 138.503 64.025 144.385 C 53.78 158.807 43.462 165.989 33.028 165.989 C 29.991 165.989 27.805 165.057 26.488 163.144 C 24.984 160.894 25.118 158.213 26.919 155.182 C 28.709 152.139 34.02 149.434 42.839 147.073 C 51.653 144.701 57.005 142.288 58.905 139.822 C 61.557 136.213 64.023 127.761 66.29 114.487 C 67.337 108.69 68.734 103.897 70.487 100.102 C 72.239 96.308 74.346 93.511 76.812 91.707 C 85.437 85.63 94.273 80.374 103.32 75.938 C 112.368 71.502 121.628 67.886 131.101 65.085 C 150.052 59.482 164.282 55.349 173.759 52.714 C 181.671 49.962 189.352 47.554 196.803 45.49 C 204.253 43.425 211.473 41.704 218.462 40.327 C 225.451 38.95 232.209 37.916 238.737 37.228 C 245.264 36.539 251.56 36.194 257.626 36.194 C 257.626 36.194 257.626 36.194 257.626 36.194 diff --git a/richpath/src/main/java/com/richpath/RichPath.java b/richpath/src/main/java/com/richpath/RichPath.java index 3ce8263..a35c56d 100644 --- a/richpath/src/main/java/com/richpath/RichPath.java +++ b/richpath/src/main/java/com/richpath/RichPath.java @@ -15,6 +15,9 @@ import com.richpath.util.PathUtils; import com.richpath.util.XmlParser; +import java.util.ArrayList; +import java.util.List; + /** * Created by tarek on 6/29/17. */ @@ -57,6 +60,9 @@ public class RichPath extends Path { private Path originalPath; + private String pathData; + private List matrices; + public RichPath(String pathData) { this(PathParser.createPathFromPathData(pathData)); } @@ -70,7 +76,7 @@ public RichPath(Path src) { private void init() { paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.STROKE); - + matrices = new ArrayList<>(); updateOriginalDimens(); } @@ -353,6 +359,7 @@ public void applyGroup(Group group) { } void mapToMatrix(Matrix matrix) { + matrices.add(matrix); transform(matrix); originalPath.transform(matrix); mapPoints(matrix); @@ -370,8 +377,26 @@ void scaleStrokeWidth(float scale) { paint.setStrokeWidth(strokeWidth * scale); } + + public String getPathData() { + return pathData; + } + + public void setPathData(String pathData) { + PathUtils.setPathData(this, pathData); + this.pathData = pathData; + + for (Matrix matrix : matrices) { + transform(matrix); + } + + onPathUpdated(); + } + public void inflate(Context context, XmlResourceParser xpp) { + pathData = XmlParser.getAttributeString(context, xpp, "pathData", name); + name = XmlParser.getAttributeString(context, xpp, "name", name); fillAlpha = XmlParser.getAttributeFloat(xpp, "fillAlpha", fillAlpha); diff --git a/richpath/src/main/java/com/richpath/pathparser/PathParser.java b/richpath/src/main/java/com/richpath/pathparser/PathParser.java index 7617f67..93b865a 100644 --- a/richpath/src/main/java/com/richpath/pathparser/PathParser.java +++ b/richpath/src/main/java/com/richpath/pathparser/PathParser.java @@ -21,4 +21,8 @@ public static Path createPathFromPathData(String pathData) { } } + public static void createPathFromPathData(Path path, String pathData) { + PathParserCompat.createPathFromPathData(path, pathData); + } + } diff --git a/richpath/src/main/java/com/richpath/pathparser/PathParserCompat.java b/richpath/src/main/java/com/richpath/pathparser/PathParserCompat.java index e44f183..c15d5a3 100644 --- a/richpath/src/main/java/com/richpath/pathparser/PathParserCompat.java +++ b/richpath/src/main/java/com/richpath/pathparser/PathParserCompat.java @@ -61,6 +61,11 @@ static float[] copyOfRange(float[] original, int start, int end) { */ static Path createPathFromPathData(String pathData) { Path path = new Path(); + createPathFromPathData(path, pathData); + return path; + } + + static void createPathFromPathData(Path path, String pathData) { PathDataNode[] nodes = createNodesFromPathData(pathData); if (nodes != null) { try { @@ -68,9 +73,7 @@ static Path createPathFromPathData(String pathData) { } catch (RuntimeException e) { throw new RuntimeException("Error in parsing " + pathData, e); } - return path; } - return null; } /** diff --git a/richpath/src/main/java/com/richpath/util/PathUtils.java b/richpath/src/main/java/com/richpath/util/PathUtils.java index 010e6c4..006783c 100644 --- a/richpath/src/main/java/com/richpath/util/PathUtils.java +++ b/richpath/src/main/java/com/richpath/util/PathUtils.java @@ -4,6 +4,8 @@ import android.graphics.Path; import android.graphics.RectF; +import com.richpath.pathparser.PathParser; + /** * Created by tarek on 6/29/17. */ @@ -99,4 +101,10 @@ public static void setPathScaleY(Path path, float scale) { path.computeBounds(rect, true); setPathScaleY(path, scale, rect.centerX(), rect.centerY()); } + + public static void setPathData(Path path, String pathData) { + path.reset(); + PathParser.createPathFromPathData(path, pathData); + } + } diff --git a/richpath/src/test/java/com/richpath/util/UtilsTest.java b/richpath/src/test/java/com/richpath/util/UtilsTest.java index 7ae3a4e..9fcdafd 100644 --- a/richpath/src/test/java/com/richpath/util/UtilsTest.java +++ b/richpath/src/test/java/com/richpath/util/UtilsTest.java @@ -1,7 +1,5 @@ package com.richpath.util; -import com.richpath.util.Utils; - import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -18,6 +16,4 @@ public void testGetDimenFromString() throws Exception { assertEquals(22f, Utils.getDimenFromString("22px"), 0); } - - } \ No newline at end of file