| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.animation; |
| 18 |
|
| 19 |
import android.graphics.Path; |
| 20 |
import android.graphics.PointF; |
| 21 |
import android.util.FloatProperty; |
| 22 |
import android.util.IntProperty; |
| 23 |
import android.util.Log; |
| 24 |
import android.util.PathParser; |
| 25 |
import android.util.Property; |
| 26 |
|
| 27 |
import java.lang.reflect.InvocationTargetException; |
| 28 |
import java.lang.reflect.Method; |
| 29 |
import java.util.HashMap; |
| 30 |
import java.util.List; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class PropertyValuesHolder implements Cloneable { |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
String mPropertyName; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
protected Property mProperty; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
Method mSetter = null; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
private Method mGetter = null; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
Class mValueType; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
Keyframes mKeyframes = null; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
private static final TypeEvaluator sIntEvaluator = new IntEvaluator(); |
| 83 |
private static final TypeEvaluator sFloatEvaluator = new FloatEvaluator(); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
private static Class[] FLOAT_VARIANTS = {float.class, Float.class, double.class, int.class, |
| 93 |
Double.class, Integer.class}; |
| 94 |
private static Class[] INTEGER_VARIANTS = {int.class, Integer.class, float.class, double.class, |
| 95 |
Float.class, Double.class}; |
| 96 |
private static Class[] DOUBLE_VARIANTS = {double.class, Double.class, float.class, int.class, |
| 97 |
Float.class, Integer.class}; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
private static final HashMap<Class, HashMap<String, Method>> sSetterPropertyMap = |
| 103 |
new HashMap<Class, HashMap<String, Method>>(); |
| 104 |
private static final HashMap<Class, HashMap<String, Method>> sGetterPropertyMap = |
| 105 |
new HashMap<Class, HashMap<String, Method>>(); |
| 106 |
|
| 107 |
|
| 108 |
final Object[] mTmpValueArray = new Object[1]; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
private TypeEvaluator mEvaluator; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
private Object mAnimatedValue; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
private TypeConverter mConverter; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
private PropertyValuesHolder(String propertyName) { |
| 135 |
mPropertyName = propertyName; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
private PropertyValuesHolder(Property property) { |
| 143 |
mProperty = property; |
| 144 |
if (property != null) { |
| 145 |
mPropertyName = property.getName(); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
public static PropertyValuesHolder ofInt(String propertyName, int... values) { |
| 157 |
return new IntPropertyValuesHolder(propertyName, values); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
public static PropertyValuesHolder ofInt(Property<?, Integer> property, int... values) { |
| 168 |
return new IntPropertyValuesHolder(property, values); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
public static PropertyValuesHolder ofMultiInt(String propertyName, int[][] values) { |
| 186 |
if (values.length < 2) { |
| 187 |
throw new IllegalArgumentException("At least 2 values must be supplied"); |
| 188 |
} |
| 189 |
int numParameters = 0; |
| 190 |
for (int i = 0; i < values.length; i++) { |
| 191 |
if (values[i] == null) { |
| 192 |
throw new IllegalArgumentException("values must not be null"); |
| 193 |
} |
| 194 |
int length = values[i].length; |
| 195 |
if (i == 0) { |
| 196 |
numParameters = length; |
| 197 |
} else if (length != numParameters) { |
| 198 |
throw new IllegalArgumentException("Values must all have the same length"); |
| 199 |
} |
| 200 |
} |
| 201 |
IntArrayEvaluator evaluator = new IntArrayEvaluator(new int[numParameters]); |
| 202 |
return new MultiIntValuesHolder(propertyName, null, evaluator, (Object[]) values); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
public static PropertyValuesHolder ofMultiInt(String propertyName, Path path) { |
| 218 |
Keyframes keyframes = KeyframeSet.ofPath(path); |
| 219 |
PointFToIntArray converter = new PointFToIntArray(); |
| 220 |
return new MultiIntValuesHolder(propertyName, converter, null, keyframes); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
@SafeVarargs |
| 240 |
public static <V> PropertyValuesHolder ofMultiInt(String propertyName, |
| 241 |
TypeConverter<V, int[]> converter, TypeEvaluator<V> evaluator, V... values) { |
| 242 |
return new MultiIntValuesHolder(propertyName, converter, evaluator, values); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
public static <T> PropertyValuesHolder ofMultiInt(String propertyName, |
| 263 |
TypeConverter<T, int[]> converter, TypeEvaluator<T> evaluator, Keyframe... values) { |
| 264 |
KeyframeSet keyframeSet = KeyframeSet.ofKeyframe(values); |
| 265 |
return new MultiIntValuesHolder(propertyName, converter, evaluator, keyframeSet); |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
public static PropertyValuesHolder ofFloat(String propertyName, float... values) { |
| 276 |
return new FloatPropertyValuesHolder(propertyName, values); |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
public static PropertyValuesHolder ofFloat(Property<?, Float> property, float... values) { |
| 287 |
return new FloatPropertyValuesHolder(property, values); |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
public static PropertyValuesHolder ofMultiFloat(String propertyName, float[][] values) { |
| 305 |
if (values.length < 2) { |
| 306 |
throw new IllegalArgumentException("At least 2 values must be supplied"); |
| 307 |
} |
| 308 |
int numParameters = 0; |
| 309 |
for (int i = 0; i < values.length; i++) { |
| 310 |
if (values[i] == null) { |
| 311 |
throw new IllegalArgumentException("values must not be null"); |
| 312 |
} |
| 313 |
int length = values[i].length; |
| 314 |
if (i == 0) { |
| 315 |
numParameters = length; |
| 316 |
} else if (length != numParameters) { |
| 317 |
throw new IllegalArgumentException("Values must all have the same length"); |
| 318 |
} |
| 319 |
} |
| 320 |
FloatArrayEvaluator evaluator = new FloatArrayEvaluator(new float[numParameters]); |
| 321 |
return new MultiFloatValuesHolder(propertyName, null, evaluator, (Object[]) values); |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
public static PropertyValuesHolder ofMultiFloat(String propertyName, Path path) { |
| 337 |
Keyframes keyframes = KeyframeSet.ofPath(path); |
| 338 |
PointFToFloatArray converter = new PointFToFloatArray(); |
| 339 |
return new MultiFloatValuesHolder(propertyName, converter, null, keyframes); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
@SafeVarargs |
| 358 |
public static <V> PropertyValuesHolder ofMultiFloat(String propertyName, |
| 359 |
TypeConverter<V, float[]> converter, TypeEvaluator<V> evaluator, V... values) { |
| 360 |
return new MultiFloatValuesHolder(propertyName, converter, evaluator, values); |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
public static <T> PropertyValuesHolder ofMultiFloat(String propertyName, |
| 381 |
TypeConverter<T, float[]> converter, TypeEvaluator<T> evaluator, Keyframe... values) { |
| 382 |
KeyframeSet keyframeSet = KeyframeSet.ofKeyframe(values); |
| 383 |
return new MultiFloatValuesHolder(propertyName, converter, evaluator, keyframeSet); |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
public static PropertyValuesHolder ofObject(String propertyName, TypeEvaluator evaluator, |
| 404 |
Object... values) { |
| 405 |
PropertyValuesHolder pvh = new PropertyValuesHolder(propertyName); |
| 406 |
pvh.setObjectValues(values); |
| 407 |
pvh.setEvaluator(evaluator); |
| 408 |
return pvh; |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
public static PropertyValuesHolder ofObject(String propertyName, |
| 428 |
TypeConverter<PointF, ?> converter, Path path) { |
| 429 |
PropertyValuesHolder pvh = new PropertyValuesHolder(propertyName); |
| 430 |
pvh.mKeyframes = KeyframeSet.ofPath(path); |
| 431 |
pvh.mValueType = PointF.class; |
| 432 |
pvh.setConverter(converter); |
| 433 |
return pvh; |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
@SafeVarargs |
| 454 |
public static <V> PropertyValuesHolder ofObject(Property property, |
| 455 |
TypeEvaluator<V> evaluator, V... values) { |
| 456 |
PropertyValuesHolder pvh = new PropertyValuesHolder(property); |
| 457 |
pvh.setObjectValues(values); |
| 458 |
pvh.setEvaluator(evaluator); |
| 459 |
return pvh; |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
@SafeVarargs |
| 487 |
public static <T, V> PropertyValuesHolder ofObject(Property<?, V> property, |
| 488 |
TypeConverter<T, V> converter, TypeEvaluator<T> evaluator, T... values) { |
| 489 |
PropertyValuesHolder pvh = new PropertyValuesHolder(property); |
| 490 |
pvh.setConverter(converter); |
| 491 |
pvh.setObjectValues(values); |
| 492 |
pvh.setEvaluator(evaluator); |
| 493 |
return pvh; |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
public static <V> PropertyValuesHolder ofObject(Property<?, V> property, |
| 513 |
TypeConverter<PointF, V> converter, Path path) { |
| 514 |
PropertyValuesHolder pvh = new PropertyValuesHolder(property); |
| 515 |
pvh.mKeyframes = KeyframeSet.ofPath(path); |
| 516 |
pvh.mValueType = PointF.class; |
| 517 |
pvh.setConverter(converter); |
| 518 |
return pvh; |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
public static PropertyValuesHolder ofKeyframe(String propertyName, Keyframe... values) { |
| 541 |
KeyframeSet keyframeSet = KeyframeSet.ofKeyframe(values); |
| 542 |
return ofKeyframes(propertyName, keyframeSet); |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
public static PropertyValuesHolder ofKeyframe(Property property, Keyframe... values) { |
| 562 |
KeyframeSet keyframeSet = KeyframeSet.ofKeyframe(values); |
| 563 |
return ofKeyframes(property, keyframeSet); |
| 564 |
} |
| 565 |
|
| 566 |
static PropertyValuesHolder ofKeyframes(String propertyName, Keyframes keyframes) { |
| 567 |
if (keyframes instanceof Keyframes.IntKeyframes) { |
| 568 |
return new IntPropertyValuesHolder(propertyName, (Keyframes.IntKeyframes) keyframes); |
| 569 |
} else if (keyframes instanceof Keyframes.FloatKeyframes) { |
| 570 |
return new FloatPropertyValuesHolder(propertyName, |
| 571 |
(Keyframes.FloatKeyframes) keyframes); |
| 572 |
} else { |
| 573 |
PropertyValuesHolder pvh = new PropertyValuesHolder(propertyName); |
| 574 |
pvh.mKeyframes = keyframes; |
| 575 |
pvh.mValueType = keyframes.getType(); |
| 576 |
return pvh; |
| 577 |
} |
| 578 |
} |
| 579 |
|
| 580 |
static PropertyValuesHolder ofKeyframes(Property property, Keyframes keyframes) { |
| 581 |
if (keyframes instanceof Keyframes.IntKeyframes) { |
| 582 |
return new IntPropertyValuesHolder(property, (Keyframes.IntKeyframes) keyframes); |
| 583 |
} else if (keyframes instanceof Keyframes.FloatKeyframes) { |
| 584 |
return new FloatPropertyValuesHolder(property, (Keyframes.FloatKeyframes) keyframes); |
| 585 |
} else { |
| 586 |
PropertyValuesHolder pvh = new PropertyValuesHolder(property); |
| 587 |
pvh.mKeyframes = keyframes; |
| 588 |
pvh.mValueType = keyframes.getType(); |
| 589 |
return pvh; |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
public void setIntValues(int... values) { |
| 607 |
mValueType = int.class; |
| 608 |
mKeyframes = KeyframeSet.ofInt(values); |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
public void setFloatValues(float... values) { |
| 625 |
mValueType = float.class; |
| 626 |
mKeyframes = KeyframeSet.ofFloat(values); |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
public void setKeyframes(Keyframe... values) { |
| 635 |
int numKeyframes = values.length; |
| 636 |
Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)]; |
| 637 |
mValueType = ((Keyframe)values[0]).getType(); |
| 638 |
for (int i = 0; i < numKeyframes; ++i) { |
| 639 |
keyframes[i] = (Keyframe)values[i]; |
| 640 |
} |
| 641 |
mKeyframes = new KeyframeSet(keyframes); |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
public void setObjectValues(Object... values) { |
| 663 |
mValueType = values[0].getClass(); |
| 664 |
mKeyframes = KeyframeSet.ofObject(values); |
| 665 |
if (mEvaluator != null) { |
| 666 |
mKeyframes.setEvaluator(mEvaluator); |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
public void setConverter(TypeConverter converter) { |
| 677 |
mConverter = converter; |
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
private Method getPropertyFunction(Class targetClass, String prefix, Class valueType) { |
| 696 |
|
| 697 |
Method returnVal = null; |
| 698 |
String methodName = getMethodName(prefix, mPropertyName); |
| 699 |
Class args[] = null; |
| 700 |
if (valueType == null) { |
| 701 |
try { |
| 702 |
returnVal = targetClass.getMethod(methodName, args); |
| 703 |
} catch (NoSuchMethodException e) { |
| 704 |
|
| 705 |
} |
| 706 |
} else { |
| 707 |
args = new Class[1]; |
| 708 |
Class typeVariants[]; |
| 709 |
if (valueType.equals(Float.class)) { |
| 710 |
typeVariants = FLOAT_VARIANTS; |
| 711 |
} else if (valueType.equals(Integer.class)) { |
| 712 |
typeVariants = INTEGER_VARIANTS; |
| 713 |
} else if (valueType.equals(Double.class)) { |
| 714 |
typeVariants = DOUBLE_VARIANTS; |
| 715 |
} else { |
| 716 |
typeVariants = new Class[1]; |
| 717 |
typeVariants[0] = valueType; |
| 718 |
} |
| 719 |
for (Class typeVariant : typeVariants) { |
| 720 |
args[0] = typeVariant; |
| 721 |
try { |
| 722 |
returnVal = targetClass.getMethod(methodName, args); |
| 723 |
if (mConverter == null) { |
| 724 |
|
| 725 |
mValueType = typeVariant; |
| 726 |
} |
| 727 |
return returnVal; |
| 728 |
} catch (NoSuchMethodException e) { |
| 729 |
|
| 730 |
} |
| 731 |
} |
| 732 |
|
| 733 |
} |
| 734 |
|
| 735 |
if (returnVal == null) { |
| 736 |
Log.w("PropertyValuesHolder", "Method " + |
| 737 |
getMethodName(prefix, mPropertyName) + "() with type " + valueType + |
| 738 |
" not found on target class " + targetClass); |
| 739 |
} |
| 740 |
|
| 741 |
return returnVal; |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
private Method setupSetterOrGetter(Class targetClass, |
| 756 |
HashMap<Class, HashMap<String, Method>> propertyMapMap, |
| 757 |
String prefix, Class valueType) { |
| 758 |
Method setterOrGetter = null; |
| 759 |
synchronized(propertyMapMap) { |
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
HashMap<String, Method> propertyMap = propertyMapMap.get(targetClass); |
| 764 |
boolean wasInMap = false; |
| 765 |
if (propertyMap != null) { |
| 766 |
wasInMap = propertyMap.containsKey(mPropertyName); |
| 767 |
if (wasInMap) { |
| 768 |
setterOrGetter = propertyMap.get(mPropertyName); |
| 769 |
} |
| 770 |
} |
| 771 |
if (!wasInMap) { |
| 772 |
setterOrGetter = getPropertyFunction(targetClass, prefix, valueType); |
| 773 |
if (propertyMap == null) { |
| 774 |
propertyMap = new HashMap<String, Method>(); |
| 775 |
propertyMapMap.put(targetClass, propertyMap); |
| 776 |
} |
| 777 |
propertyMap.put(mPropertyName, setterOrGetter); |
| 778 |
} |
| 779 |
} |
| 780 |
return setterOrGetter; |
| 781 |
} |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
void setupSetter(Class targetClass) { |
| 788 |
Class<?> propertyType = mConverter == null ? mValueType : mConverter.getTargetType(); |
| 789 |
mSetter = setupSetterOrGetter(targetClass, sSetterPropertyMap, "set", propertyType); |
| 790 |
} |
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
private void setupGetter(Class targetClass) { |
| 796 |
mGetter = setupSetterOrGetter(targetClass, sGetterPropertyMap, "get", null); |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
void setupSetterAndGetter(Object target) { |
| 810 |
if (mProperty != null) { |
| 811 |
|
| 812 |
try { |
| 813 |
Object testValue = null; |
| 814 |
List<Keyframe> keyframes = mKeyframes.getKeyframes(); |
| 815 |
int keyframeCount = keyframes == null ? 0 : keyframes.size(); |
| 816 |
for (int i = 0; i < keyframeCount; i++) { |
| 817 |
Keyframe kf = keyframes.get(i); |
| 818 |
if (!kf.hasValue() || kf.valueWasSetOnStart()) { |
| 819 |
if (testValue == null) { |
| 820 |
testValue = convertBack(mProperty.get(target)); |
| 821 |
} |
| 822 |
kf.setValue(testValue); |
| 823 |
kf.setValueWasSetOnStart(true); |
| 824 |
} |
| 825 |
} |
| 826 |
return; |
| 827 |
} catch (ClassCastException e) { |
| 828 |
Log.w("PropertyValuesHolder","No such property (" + mProperty.getName() + |
| 829 |
") on target object " + target + ". Trying reflection instead"); |
| 830 |
mProperty = null; |
| 831 |
} |
| 832 |
} |
| 833 |
|
| 834 |
if (mProperty == null) { |
| 835 |
Class targetClass = target.getClass(); |
| 836 |
if (mSetter == null) { |
| 837 |
setupSetter(targetClass); |
| 838 |
} |
| 839 |
List<Keyframe> keyframes = mKeyframes.getKeyframes(); |
| 840 |
int keyframeCount = keyframes == null ? 0 : keyframes.size(); |
| 841 |
for (int i = 0; i < keyframeCount; i++) { |
| 842 |
Keyframe kf = keyframes.get(i); |
| 843 |
if (!kf.hasValue() || kf.valueWasSetOnStart()) { |
| 844 |
if (mGetter == null) { |
| 845 |
setupGetter(targetClass); |
| 846 |
if (mGetter == null) { |
| 847 |
|
| 848 |
return; |
| 849 |
} |
| 850 |
} |
| 851 |
try { |
| 852 |
Object value = convertBack(mGetter.invoke(target)); |
| 853 |
kf.setValue(value); |
| 854 |
kf.setValueWasSetOnStart(true); |
| 855 |
} catch (InvocationTargetException e) { |
| 856 |
Log.e("PropertyValuesHolder", e.toString()); |
| 857 |
} catch (IllegalAccessException e) { |
| 858 |
Log.e("PropertyValuesHolder", e.toString()); |
| 859 |
} |
| 860 |
} |
| 861 |
} |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
private Object convertBack(Object value) { |
| 866 |
if (mConverter != null) { |
| 867 |
if (!(mConverter instanceof BidirectionalTypeConverter)) { |
| 868 |
throw new IllegalArgumentException("Converter " |
| 869 |
+ mConverter.getClass().getName() |
| 870 |
+ " must be a BidirectionalTypeConverter"); |
| 871 |
} |
| 872 |
value = ((BidirectionalTypeConverter) mConverter).convertBack(value); |
| 873 |
} |
| 874 |
return value; |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
private void setupValue(Object target, Keyframe kf) { |
| 885 |
if (mProperty != null) { |
| 886 |
Object value = convertBack(mProperty.get(target)); |
| 887 |
kf.setValue(value); |
| 888 |
} else { |
| 889 |
try { |
| 890 |
if (mGetter == null) { |
| 891 |
Class targetClass = target.getClass(); |
| 892 |
setupGetter(targetClass); |
| 893 |
if (mGetter == null) { |
| 894 |
|
| 895 |
return; |
| 896 |
} |
| 897 |
} |
| 898 |
Object value = convertBack(mGetter.invoke(target)); |
| 899 |
kf.setValue(value); |
| 900 |
} catch (InvocationTargetException e) { |
| 901 |
Log.e("PropertyValuesHolder", e.toString()); |
| 902 |
} catch (IllegalAccessException e) { |
| 903 |
Log.e("PropertyValuesHolder", e.toString()); |
| 904 |
} |
| 905 |
} |
| 906 |
} |
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
void setupStartValue(Object target) { |
| 917 |
List<Keyframe> keyframes = mKeyframes.getKeyframes(); |
| 918 |
if (!keyframes.isEmpty()) { |
| 919 |
setupValue(target, keyframes.get(0)); |
| 920 |
} |
| 921 |
} |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
void setupEndValue(Object target) { |
| 932 |
List<Keyframe> keyframes = mKeyframes.getKeyframes(); |
| 933 |
if (!keyframes.isEmpty()) { |
| 934 |
setupValue(target, keyframes.get(keyframes.size() - 1)); |
| 935 |
} |
| 936 |
} |
| 937 |
|
| 938 |
@Override |
| 939 |
public PropertyValuesHolder clone() { |
| 940 |
try { |
| 941 |
PropertyValuesHolder newPVH = (PropertyValuesHolder) super.clone(); |
| 942 |
newPVH.mPropertyName = mPropertyName; |
| 943 |
newPVH.mProperty = mProperty; |
| 944 |
newPVH.mKeyframes = mKeyframes.clone(); |
| 945 |
newPVH.mEvaluator = mEvaluator; |
| 946 |
return newPVH; |
| 947 |
} catch (CloneNotSupportedException e) { |
| 948 |
|
| 949 |
return null; |
| 950 |
} |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
void setAnimatedValue(Object target) { |
| 961 |
if (mProperty != null) { |
| 962 |
mProperty.set(target, getAnimatedValue()); |
| 963 |
} |
| 964 |
if (mSetter != null) { |
| 965 |
try { |
| 966 |
mTmpValueArray[0] = getAnimatedValue(); |
| 967 |
mSetter.invoke(target, mTmpValueArray); |
| 968 |
} catch (InvocationTargetException e) { |
| 969 |
Log.e("PropertyValuesHolder", e.toString()); |
| 970 |
} catch (IllegalAccessException e) { |
| 971 |
Log.e("PropertyValuesHolder", e.toString()); |
| 972 |
} |
| 973 |
} |
| 974 |
} |
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
void init() { |
| 981 |
if (mEvaluator == null) { |
| 982 |
|
| 983 |
|
| 984 |
mEvaluator = (mValueType == Integer.class) ? sIntEvaluator : |
| 985 |
(mValueType == Float.class) ? sFloatEvaluator : |
| 986 |
null; |
| 987 |
} |
| 988 |
if (mEvaluator != null) { |
| 989 |
|
| 990 |
|
| 991 |
mKeyframes.setEvaluator(mEvaluator); |
| 992 |
} |
| 993 |
} |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
public void setEvaluator(TypeEvaluator evaluator) { |
| 1006 |
mEvaluator = evaluator; |
| 1007 |
mKeyframes.setEvaluator(evaluator); |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
void calculateValue(float fraction) { |
| 1017 |
Object value = mKeyframes.getValue(fraction); |
| 1018 |
mAnimatedValue = mConverter == null ? value : mConverter.convert(value); |
| 1019 |
} |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
public void setPropertyName(String propertyName) { |
| 1037 |
mPropertyName = propertyName; |
| 1038 |
} |
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
public void setProperty(Property property) { |
| 1049 |
mProperty = property; |
| 1050 |
} |
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
public String getPropertyName() { |
| 1061 |
return mPropertyName; |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
Object getAnimatedValue() { |
| 1070 |
return mAnimatedValue; |
| 1071 |
} |
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
public void getPropertyValues(PropertyValues values) { |
| 1080 |
init(); |
| 1081 |
values.propertyName = mPropertyName; |
| 1082 |
values.type = mValueType; |
| 1083 |
values.startValue = mKeyframes.getValue(0); |
| 1084 |
if (values.startValue instanceof PathParser.PathData) { |
| 1085 |
|
| 1086 |
|
| 1087 |
values.startValue = new PathParser.PathData((PathParser.PathData) values.startValue); |
| 1088 |
} |
| 1089 |
values.endValue = mKeyframes.getValue(1); |
| 1090 |
if (values.endValue instanceof PathParser.PathData) { |
| 1091 |
|
| 1092 |
|
| 1093 |
values.endValue = new PathParser.PathData((PathParser.PathData) values.endValue); |
| 1094 |
} |
| 1095 |
|
| 1096 |
if (mKeyframes instanceof PathKeyframes.FloatKeyframesBase |
| 1097 |
|| mKeyframes instanceof PathKeyframes.IntKeyframesBase |
| 1098 |
|| (mKeyframes.getKeyframes() != null && mKeyframes.getKeyframes().size() > 2)) { |
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
values.dataSource = new PropertyValues.DataSource() { |
| 1104 |
@Override |
| 1105 |
public Object getValueAtFraction(float fraction) { |
| 1106 |
return mKeyframes.getValue(fraction); |
| 1107 |
} |
| 1108 |
}; |
| 1109 |
} else { |
| 1110 |
values.dataSource = null; |
| 1111 |
} |
| 1112 |
} |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
public Class getValueType() { |
| 1118 |
return mValueType; |
| 1119 |
} |
| 1120 |
|
| 1121 |
@Override |
| 1122 |
public String toString() { |
| 1123 |
return mPropertyName + ": " + mKeyframes.toString(); |
| 1124 |
} |
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
static String getMethodName(String prefix, String propertyName) { |
| 1140 |
if (propertyName == null || propertyName.length() == 0) { |
| 1141 |
|
| 1142 |
return prefix; |
| 1143 |
} |
| 1144 |
char firstLetter = Character.toUpperCase(propertyName.charAt(0)); |
| 1145 |
String theRest = propertyName.substring(1); |
| 1146 |
return prefix + firstLetter + theRest; |
| 1147 |
} |
| 1148 |
|
| 1149 |
static class IntPropertyValuesHolder extends PropertyValuesHolder { |
| 1150 |
|
| 1151 |
|
| 1152 |
private static final HashMap<Class, HashMap<String, Long>> sJNISetterPropertyMap = |
| 1153 |
new HashMap<Class, HashMap<String, Long>>(); |
| 1154 |
long mJniSetter; |
| 1155 |
private IntProperty mIntProperty; |
| 1156 |
|
| 1157 |
Keyframes.IntKeyframes mIntKeyframes; |
| 1158 |
int mIntAnimatedValue; |
| 1159 |
|
| 1160 |
public IntPropertyValuesHolder(String propertyName, Keyframes.IntKeyframes keyframes) { |
| 1161 |
super(propertyName); |
| 1162 |
mValueType = int.class; |
| 1163 |
mKeyframes = keyframes; |
| 1164 |
mIntKeyframes = keyframes; |
| 1165 |
} |
| 1166 |
|
| 1167 |
public IntPropertyValuesHolder(Property property, Keyframes.IntKeyframes keyframes) { |
| 1168 |
super(property); |
| 1169 |
mValueType = int.class; |
| 1170 |
mKeyframes = keyframes; |
| 1171 |
mIntKeyframes = keyframes; |
| 1172 |
if (property instanceof IntProperty) { |
| 1173 |
mIntProperty = (IntProperty) mProperty; |
| 1174 |
} |
| 1175 |
} |
| 1176 |
|
| 1177 |
public IntPropertyValuesHolder(String propertyName, int... values) { |
| 1178 |
super(propertyName); |
| 1179 |
setIntValues(values); |
| 1180 |
} |
| 1181 |
|
| 1182 |
public IntPropertyValuesHolder(Property property, int... values) { |
| 1183 |
super(property); |
| 1184 |
setIntValues(values); |
| 1185 |
if (property instanceof IntProperty) { |
| 1186 |
mIntProperty = (IntProperty) mProperty; |
| 1187 |
} |
| 1188 |
} |
| 1189 |
|
| 1190 |
@Override |
| 1191 |
public void setProperty(Property property) { |
| 1192 |
if (property instanceof IntProperty) { |
| 1193 |
mIntProperty = (IntProperty) property; |
| 1194 |
} else { |
| 1195 |
super.setProperty(property); |
| 1196 |
} |
| 1197 |
} |
| 1198 |
|
| 1199 |
@Override |
| 1200 |
public void setIntValues(int... values) { |
| 1201 |
super.setIntValues(values); |
| 1202 |
mIntKeyframes = (Keyframes.IntKeyframes) mKeyframes; |
| 1203 |
} |
| 1204 |
|
| 1205 |
@Override |
| 1206 |
void calculateValue(float fraction) { |
| 1207 |
mIntAnimatedValue = mIntKeyframes.getIntValue(fraction); |
| 1208 |
} |
| 1209 |
|
| 1210 |
@Override |
| 1211 |
Object getAnimatedValue() { |
| 1212 |
return mIntAnimatedValue; |
| 1213 |
} |
| 1214 |
|
| 1215 |
@Override |
| 1216 |
public IntPropertyValuesHolder clone() { |
| 1217 |
IntPropertyValuesHolder newPVH = (IntPropertyValuesHolder) super.clone(); |
| 1218 |
newPVH.mIntKeyframes = (Keyframes.IntKeyframes) newPVH.mKeyframes; |
| 1219 |
return newPVH; |
| 1220 |
} |
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
@Override |
| 1230 |
void setAnimatedValue(Object target) { |
| 1231 |
if (mIntProperty != null) { |
| 1232 |
mIntProperty.setValue(target, mIntAnimatedValue); |
| 1233 |
return; |
| 1234 |
} |
| 1235 |
if (mProperty != null) { |
| 1236 |
mProperty.set(target, mIntAnimatedValue); |
| 1237 |
return; |
| 1238 |
} |
| 1239 |
if (mJniSetter != 0) { |
| 1240 |
nCallIntMethod(target, mJniSetter, mIntAnimatedValue); |
| 1241 |
return; |
| 1242 |
} |
| 1243 |
if (mSetter != null) { |
| 1244 |
try { |
| 1245 |
mTmpValueArray[0] = mIntAnimatedValue; |
| 1246 |
mSetter.invoke(target, mTmpValueArray); |
| 1247 |
} catch (InvocationTargetException e) { |
| 1248 |
Log.e("PropertyValuesHolder", e.toString()); |
| 1249 |
} catch (IllegalAccessException e) { |
| 1250 |
Log.e("PropertyValuesHolder", e.toString()); |
| 1251 |
} |
| 1252 |
} |
| 1253 |
} |
| 1254 |
|
| 1255 |
@Override |
| 1256 |
void setupSetter(Class targetClass) { |
| 1257 |
if (mProperty != null) { |
| 1258 |
return; |
| 1259 |
} |
| 1260 |
|
| 1261 |
synchronized(sJNISetterPropertyMap) { |
| 1262 |
HashMap<String, Long> propertyMap = sJNISetterPropertyMap.get(targetClass); |
| 1263 |
boolean wasInMap = false; |
| 1264 |
if (propertyMap != null) { |
| 1265 |
wasInMap = propertyMap.containsKey(mPropertyName); |
| 1266 |
if (wasInMap) { |
| 1267 |
Long jniSetter = propertyMap.get(mPropertyName); |
| 1268 |
if (jniSetter != null) { |
| 1269 |
mJniSetter = jniSetter; |
| 1270 |
} |
| 1271 |
} |
| 1272 |
} |
| 1273 |
if (!wasInMap) { |
| 1274 |
String methodName = getMethodName("set", mPropertyName); |
| 1275 |
try { |
| 1276 |
mJniSetter = nGetIntMethod(targetClass, methodName); |
| 1277 |
} catch (NoSuchMethodError e) { |
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
} |
| 1282 |
if (propertyMap == null) { |
| 1283 |
propertyMap = new HashMap<String, Long>(); |
| 1284 |
sJNISetterPropertyMap.put(targetClass, propertyMap); |
| 1285 |
} |
| 1286 |
propertyMap.put(mPropertyName, mJniSetter); |
| 1287 |
} |
| 1288 |
} |
| 1289 |
if (mJniSetter == 0) { |
| 1290 |
|
| 1291 |
super.setupSetter(targetClass); |
| 1292 |
} |
| 1293 |
} |
| 1294 |
} |
| 1295 |
|
| 1296 |
static class FloatPropertyValuesHolder extends PropertyValuesHolder { |
| 1297 |
|
| 1298 |
|
| 1299 |
private static final HashMap<Class, HashMap<String, Long>> sJNISetterPropertyMap = |
| 1300 |
new HashMap<Class, HashMap<String, Long>>(); |
| 1301 |
long mJniSetter; |
| 1302 |
private FloatProperty mFloatProperty; |
| 1303 |
|
| 1304 |
Keyframes.FloatKeyframes mFloatKeyframes; |
| 1305 |
float mFloatAnimatedValue; |
| 1306 |
|
| 1307 |
public FloatPropertyValuesHolder(String propertyName, Keyframes.FloatKeyframes keyframes) { |
| 1308 |
super(propertyName); |
| 1309 |
mValueType = float.class; |
| 1310 |
mKeyframes = keyframes; |
| 1311 |
mFloatKeyframes = keyframes; |
| 1312 |
} |
| 1313 |
|
| 1314 |
public FloatPropertyValuesHolder(Property property, Keyframes.FloatKeyframes keyframes) { |
| 1315 |
super(property); |
| 1316 |
mValueType = float.class; |
| 1317 |
mKeyframes = keyframes; |
| 1318 |
mFloatKeyframes = keyframes; |
| 1319 |
if (property instanceof FloatProperty) { |
| 1320 |
mFloatProperty = (FloatProperty) mProperty; |
| 1321 |
} |
| 1322 |
} |
| 1323 |
|
| 1324 |
public FloatPropertyValuesHolder(String propertyName, float... values) { |
| 1325 |
super(propertyName); |
| 1326 |
setFloatValues(values); |
| 1327 |
} |
| 1328 |
|
| 1329 |
public FloatPropertyValuesHolder(Property property, float... values) { |
| 1330 |
super(property); |
| 1331 |
setFloatValues(values); |
| 1332 |
if (property instanceof FloatProperty) { |
| 1333 |
mFloatProperty = (FloatProperty) mProperty; |
| 1334 |
} |
| 1335 |
} |
| 1336 |
|
| 1337 |
@Override |
| 1338 |
public void setProperty(Property property) { |
| 1339 |
if (property instanceof FloatProperty) { |
| 1340 |
mFloatProperty = (FloatProperty) property; |
| 1341 |
} else { |
| 1342 |
super.setProperty(property); |
| 1343 |
} |
| 1344 |
} |
| 1345 |
|
| 1346 |
@Override |
| 1347 |
public void setFloatValues(float... values) { |
| 1348 |
super.setFloatValues(values); |
| 1349 |
mFloatKeyframes = (Keyframes.FloatKeyframes) mKeyframes; |
| 1350 |
} |
| 1351 |
|
| 1352 |
@Override |
| 1353 |
void calculateValue(float fraction) { |
| 1354 |
mFloatAnimatedValue = mFloatKeyframes.getFloatValue(fraction); |
| 1355 |
} |
| 1356 |
|
| 1357 |
@Override |
| 1358 |
Object getAnimatedValue() { |
| 1359 |
return mFloatAnimatedValue; |
| 1360 |
} |
| 1361 |
|
| 1362 |
@Override |
| 1363 |
public FloatPropertyValuesHolder clone() { |
| 1364 |
FloatPropertyValuesHolder newPVH = (FloatPropertyValuesHolder) super.clone(); |
| 1365 |
newPVH.mFloatKeyframes = (Keyframes.FloatKeyframes) newPVH.mKeyframes; |
| 1366 |
return newPVH; |
| 1367 |
} |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
@Override |
| 1377 |
void setAnimatedValue(Object target) { |
| 1378 |
if (mFloatProperty != null) { |
| 1379 |
mFloatProperty.setValue(target, mFloatAnimatedValue); |
| 1380 |
return; |
| 1381 |
} |
| 1382 |
if (mProperty != null) { |
| 1383 |
mProperty.set(target, mFloatAnimatedValue); |
| 1384 |
return; |
| 1385 |
} |
| 1386 |
if (mJniSetter != 0) { |
| 1387 |
nCallFloatMethod(target, mJniSetter, mFloatAnimatedValue); |
| 1388 |
return; |
| 1389 |
} |
| 1390 |
if (mSetter != null) { |
| 1391 |
try { |
| 1392 |
mTmpValueArray[0] = mFloatAnimatedValue; |
| 1393 |
mSetter.invoke(target, mTmpValueArray); |
| 1394 |
} catch (InvocationTargetException e) { |
| 1395 |
Log.e("PropertyValuesHolder", e.toString()); |
| 1396 |
} catch (IllegalAccessException e) { |
| 1397 |
Log.e("PropertyValuesHolder", e.toString()); |
| 1398 |
} |
| 1399 |
} |
| 1400 |
} |
| 1401 |
|
| 1402 |
@Override |
| 1403 |
void setupSetter(Class targetClass) { |
| 1404 |
if (mProperty != null) { |
| 1405 |
return; |
| 1406 |
} |
| 1407 |
|
| 1408 |
synchronized (sJNISetterPropertyMap) { |
| 1409 |
HashMap<String, Long> propertyMap = sJNISetterPropertyMap.get(targetClass); |
| 1410 |
boolean wasInMap = false; |
| 1411 |
if (propertyMap != null) { |
| 1412 |
wasInMap = propertyMap.containsKey(mPropertyName); |
| 1413 |
if (wasInMap) { |
| 1414 |
Long jniSetter = propertyMap.get(mPropertyName); |
| 1415 |
if (jniSetter != null) { |
| 1416 |
mJniSetter = jniSetter; |
| 1417 |
} |
| 1418 |
} |
| 1419 |
} |
| 1420 |
if (!wasInMap) { |
| 1421 |
String methodName = getMethodName("set", mPropertyName); |
| 1422 |
try { |
| 1423 |
mJniSetter = nGetFloatMethod(targetClass, methodName); |
| 1424 |
} catch (NoSuchMethodError e) { |
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
} |
| 1429 |
if (propertyMap == null) { |
| 1430 |
propertyMap = new HashMap<String, Long>(); |
| 1431 |
sJNISetterPropertyMap.put(targetClass, propertyMap); |
| 1432 |
} |
| 1433 |
propertyMap.put(mPropertyName, mJniSetter); |
| 1434 |
} |
| 1435 |
} |
| 1436 |
if (mJniSetter == 0) { |
| 1437 |
|
| 1438 |
super.setupSetter(targetClass); |
| 1439 |
} |
| 1440 |
} |
| 1441 |
|
| 1442 |
} |
| 1443 |
|
| 1444 |
static class MultiFloatValuesHolder extends PropertyValuesHolder { |
| 1445 |
private long mJniSetter; |
| 1446 |
private static final HashMap<Class, HashMap<String, Long>> sJNISetterPropertyMap = |
| 1447 |
new HashMap<Class, HashMap<String, Long>>(); |
| 1448 |
|
| 1449 |
public MultiFloatValuesHolder(String propertyName, TypeConverter converter, |
| 1450 |
TypeEvaluator evaluator, Object... values) { |
| 1451 |
super(propertyName); |
| 1452 |
setConverter(converter); |
| 1453 |
setObjectValues(values); |
| 1454 |
setEvaluator(evaluator); |
| 1455 |
} |
| 1456 |
|
| 1457 |
public MultiFloatValuesHolder(String propertyName, TypeConverter converter, |
| 1458 |
TypeEvaluator evaluator, Keyframes keyframes) { |
| 1459 |
super(propertyName); |
| 1460 |
setConverter(converter); |
| 1461 |
mKeyframes = keyframes; |
| 1462 |
setEvaluator(evaluator); |
| 1463 |
} |
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
@Override |
| 1474 |
void setAnimatedValue(Object target) { |
| 1475 |
float[] values = (float[]) getAnimatedValue(); |
| 1476 |
int numParameters = values.length; |
| 1477 |
if (mJniSetter != 0) { |
| 1478 |
switch (numParameters) { |
| 1479 |
case 1: |
| 1480 |
nCallFloatMethod(target, mJniSetter, values[0]); |
| 1481 |
break; |
| 1482 |
case 2: |
| 1483 |
nCallTwoFloatMethod(target, mJniSetter, values[0], values[1]); |
| 1484 |
break; |
| 1485 |
case 4: |
| 1486 |
nCallFourFloatMethod(target, mJniSetter, values[0], values[1], |
| 1487 |
values[2], values[3]); |
| 1488 |
break; |
| 1489 |
default: { |
| 1490 |
nCallMultipleFloatMethod(target, mJniSetter, values); |
| 1491 |
break; |
| 1492 |
} |
| 1493 |
} |
| 1494 |
} |
| 1495 |
} |
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
@Override |
| 1504 |
void setupSetterAndGetter(Object target) { |
| 1505 |
setupSetter(target.getClass()); |
| 1506 |
} |
| 1507 |
|
| 1508 |
@Override |
| 1509 |
void setupSetter(Class targetClass) { |
| 1510 |
if (mJniSetter != 0) { |
| 1511 |
return; |
| 1512 |
} |
| 1513 |
synchronized(sJNISetterPropertyMap) { |
| 1514 |
HashMap<String, Long> propertyMap = sJNISetterPropertyMap.get(targetClass); |
| 1515 |
boolean wasInMap = false; |
| 1516 |
if (propertyMap != null) { |
| 1517 |
wasInMap = propertyMap.containsKey(mPropertyName); |
| 1518 |
if (wasInMap) { |
| 1519 |
Long jniSetter = propertyMap.get(mPropertyName); |
| 1520 |
if (jniSetter != null) { |
| 1521 |
mJniSetter = jniSetter; |
| 1522 |
} |
| 1523 |
} |
| 1524 |
} |
| 1525 |
if (!wasInMap) { |
| 1526 |
String methodName = getMethodName("set", mPropertyName); |
| 1527 |
calculateValue(0f); |
| 1528 |
float[] values = (float[]) getAnimatedValue(); |
| 1529 |
int numParams = values.length; |
| 1530 |
try { |
| 1531 |
mJniSetter = nGetMultipleFloatMethod(targetClass, methodName, numParams); |
| 1532 |
} catch (NoSuchMethodError e) { |
| 1533 |
|
| 1534 |
try { |
| 1535 |
mJniSetter = nGetMultipleFloatMethod(targetClass, mPropertyName, |
| 1536 |
numParams); |
| 1537 |
} catch (NoSuchMethodError e2) { |
| 1538 |
|
| 1539 |
} |
| 1540 |
} |
| 1541 |
if (propertyMap == null) { |
| 1542 |
propertyMap = new HashMap<String, Long>(); |
| 1543 |
sJNISetterPropertyMap.put(targetClass, propertyMap); |
| 1544 |
} |
| 1545 |
propertyMap.put(mPropertyName, mJniSetter); |
| 1546 |
} |
| 1547 |
} |
| 1548 |
} |
| 1549 |
} |
| 1550 |
|
| 1551 |
static class MultiIntValuesHolder extends PropertyValuesHolder { |
| 1552 |
private long mJniSetter; |
| 1553 |
private static final HashMap<Class, HashMap<String, Long>> sJNISetterPropertyMap = |
| 1554 |
new HashMap<Class, HashMap<String, Long>>(); |
| 1555 |
|
| 1556 |
public MultiIntValuesHolder(String propertyName, TypeConverter converter, |
| 1557 |
TypeEvaluator evaluator, Object... values) { |
| 1558 |
super(propertyName); |
| 1559 |
setConverter(converter); |
| 1560 |
setObjectValues(values); |
| 1561 |
setEvaluator(evaluator); |
| 1562 |
} |
| 1563 |
|
| 1564 |
public MultiIntValuesHolder(String propertyName, TypeConverter converter, |
| 1565 |
TypeEvaluator evaluator, Keyframes keyframes) { |
| 1566 |
super(propertyName); |
| 1567 |
setConverter(converter); |
| 1568 |
mKeyframes = keyframes; |
| 1569 |
setEvaluator(evaluator); |
| 1570 |
} |
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
@Override |
| 1581 |
void setAnimatedValue(Object target) { |
| 1582 |
int[] values = (int[]) getAnimatedValue(); |
| 1583 |
int numParameters = values.length; |
| 1584 |
if (mJniSetter != 0) { |
| 1585 |
switch (numParameters) { |
| 1586 |
case 1: |
| 1587 |
nCallIntMethod(target, mJniSetter, values[0]); |
| 1588 |
break; |
| 1589 |
case 2: |
| 1590 |
nCallTwoIntMethod(target, mJniSetter, values[0], values[1]); |
| 1591 |
break; |
| 1592 |
case 4: |
| 1593 |
nCallFourIntMethod(target, mJniSetter, values[0], values[1], |
| 1594 |
values[2], values[3]); |
| 1595 |
break; |
| 1596 |
default: { |
| 1597 |
nCallMultipleIntMethod(target, mJniSetter, values); |
| 1598 |
break; |
| 1599 |
} |
| 1600 |
} |
| 1601 |
} |
| 1602 |
} |
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
@Override |
| 1611 |
void setupSetterAndGetter(Object target) { |
| 1612 |
setupSetter(target.getClass()); |
| 1613 |
} |
| 1614 |
|
| 1615 |
@Override |
| 1616 |
void setupSetter(Class targetClass) { |
| 1617 |
if (mJniSetter != 0) { |
| 1618 |
return; |
| 1619 |
} |
| 1620 |
synchronized(sJNISetterPropertyMap) { |
| 1621 |
HashMap<String, Long> propertyMap = sJNISetterPropertyMap.get(targetClass); |
| 1622 |
boolean wasInMap = false; |
| 1623 |
if (propertyMap != null) { |
| 1624 |
wasInMap = propertyMap.containsKey(mPropertyName); |
| 1625 |
if (wasInMap) { |
| 1626 |
Long jniSetter = propertyMap.get(mPropertyName); |
| 1627 |
if (jniSetter != null) { |
| 1628 |
mJniSetter = jniSetter; |
| 1629 |
} |
| 1630 |
} |
| 1631 |
} |
| 1632 |
if (!wasInMap) { |
| 1633 |
String methodName = getMethodName("set", mPropertyName); |
| 1634 |
calculateValue(0f); |
| 1635 |
int[] values = (int[]) getAnimatedValue(); |
| 1636 |
int numParams = values.length; |
| 1637 |
try { |
| 1638 |
mJniSetter = nGetMultipleIntMethod(targetClass, methodName, numParams); |
| 1639 |
} catch (NoSuchMethodError e) { |
| 1640 |
|
| 1641 |
try { |
| 1642 |
mJniSetter = nGetMultipleIntMethod(targetClass, mPropertyName, |
| 1643 |
numParams); |
| 1644 |
} catch (NoSuchMethodError e2) { |
| 1645 |
|
| 1646 |
} |
| 1647 |
} |
| 1648 |
if (propertyMap == null) { |
| 1649 |
propertyMap = new HashMap<String, Long>(); |
| 1650 |
sJNISetterPropertyMap.put(targetClass, propertyMap); |
| 1651 |
} |
| 1652 |
propertyMap.put(mPropertyName, mJniSetter); |
| 1653 |
} |
| 1654 |
} |
| 1655 |
} |
| 1656 |
} |
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
private static class PointFToFloatArray extends TypeConverter<PointF, float[]> { |
| 1662 |
private float[] mCoordinates = new float[2]; |
| 1663 |
|
| 1664 |
public PointFToFloatArray() { |
| 1665 |
super(PointF.class, float[].class); |
| 1666 |
} |
| 1667 |
|
| 1668 |
@Override |
| 1669 |
public float[] convert(PointF value) { |
| 1670 |
mCoordinates[0] = value.x; |
| 1671 |
mCoordinates[1] = value.y; |
| 1672 |
return mCoordinates; |
| 1673 |
} |
| 1674 |
}; |
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
private static class PointFToIntArray extends TypeConverter<PointF, int[]> { |
| 1680 |
private int[] mCoordinates = new int[2]; |
| 1681 |
|
| 1682 |
public PointFToIntArray() { |
| 1683 |
super(PointF.class, int[].class); |
| 1684 |
} |
| 1685 |
|
| 1686 |
@Override |
| 1687 |
public int[] convert(PointF value) { |
| 1688 |
mCoordinates[0] = Math.round(value.x); |
| 1689 |
mCoordinates[1] = Math.round(value.y); |
| 1690 |
return mCoordinates; |
| 1691 |
} |
| 1692 |
}; |
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
public static class PropertyValues { |
| 1698 |
public String propertyName; |
| 1699 |
public Class type; |
| 1700 |
public Object startValue; |
| 1701 |
public Object endValue; |
| 1702 |
public DataSource dataSource = null; |
| 1703 |
public interface DataSource { |
| 1704 |
Object getValueAtFraction(float fraction); |
| 1705 |
} |
| 1706 |
public String toString() { |
| 1707 |
return ("property name: " + propertyName + ", type: " + type + ", startValue: " |
| 1708 |
+ startValue.toString() + ", endValue: " + endValue.toString()); |
| 1709 |
} |
| 1710 |
} |
| 1711 |
|
| 1712 |
native static private long nGetIntMethod(Class targetClass, String methodName); |
| 1713 |
native static private long nGetFloatMethod(Class targetClass, String methodName); |
| 1714 |
native static private long nGetMultipleIntMethod(Class targetClass, String methodName, |
| 1715 |
int numParams); |
| 1716 |
native static private long nGetMultipleFloatMethod(Class targetClass, String methodName, |
| 1717 |
int numParams); |
| 1718 |
native static private void nCallIntMethod(Object target, long methodID, int arg); |
| 1719 |
native static private void nCallFloatMethod(Object target, long methodID, float arg); |
| 1720 |
native static private void nCallTwoIntMethod(Object target, long methodID, int arg1, int arg2); |
| 1721 |
native static private void nCallFourIntMethod(Object target, long methodID, int arg1, int arg2, |
| 1722 |
int arg3, int arg4); |
| 1723 |
native static private void nCallMultipleIntMethod(Object target, long methodID, int[] args); |
| 1724 |
native static private void nCallTwoFloatMethod(Object target, long methodID, float arg1, |
| 1725 |
float arg2); |
| 1726 |
native static private void nCallFourFloatMethod(Object target, long methodID, float arg1, |
| 1727 |
float arg2, float arg3, float arg4); |
| 1728 |
native static private void nCallMultipleFloatMethod(Object target, long methodID, float[] args); |
| 1729 |
} |