PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/TMessagesProj/src/main/java/org/telegram/messenger/AnimationCompat/AnimatorSetProxy.java

https://gitlab.com/envieidoc/Telegram
Java | 137 lines | 112 code | 18 blank | 7 comment | 24 complexity | ca1963fd4a3025caa4b5d7530b311c3e MD5 | raw file
  1. /*
  2. * This is the source code of Telegram for Android v. 3.x.x.
  3. * It is licensed under GNU GPL v. 2 or later.
  4. * You should have received a copy of the license in this archive (see LICENSE).
  5. *
  6. * Copyright Nikolai Kudashov, 2013-2016.
  7. */
  8. package org.telegram.messenger.AnimationCompat;
  9. import android.animation.Animator;
  10. import android.animation.AnimatorListenerAdapter;
  11. import android.animation.AnimatorSet;
  12. import android.view.animation.Interpolator;
  13. import org.telegram.messenger.Animation.Animator10;
  14. import org.telegram.messenger.Animation.AnimatorListenerAdapter10;
  15. import org.telegram.messenger.Animation.AnimatorSet10;
  16. import org.telegram.messenger.Animation.View10;
  17. import java.lang.reflect.Array;
  18. import java.util.ArrayList;
  19. public class AnimatorSetProxy {
  20. private Object animatorSet;
  21. public static <T, U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {
  22. return copyOfRange(original, 0, newLength, newType);
  23. }
  24. @SuppressWarnings("unchecked")
  25. public static <T, U> T[] copyOfRange(U[] original, int start, int end, Class<? extends T[]> newType) {
  26. if (start > end) {
  27. throw new IllegalArgumentException();
  28. }
  29. int originalLength = original.length;
  30. if (start < 0 || start > originalLength) {
  31. throw new ArrayIndexOutOfBoundsException();
  32. }
  33. int resultLength = end - start;
  34. int copyLength = Math.min(resultLength, originalLength - start);
  35. T[] result = (T[]) Array.newInstance(newType.getComponentType(), resultLength);
  36. System.arraycopy(original, start, result, 0, copyLength);
  37. return result;
  38. }
  39. public AnimatorSetProxy() {
  40. if (View10.NEED_PROXY) {
  41. animatorSet = new AnimatorSet10();
  42. } else {
  43. animatorSet = new AnimatorSet();
  44. }
  45. }
  46. @SuppressWarnings("unchecked")
  47. public void playTogether(Object... items) {
  48. if (View10.NEED_PROXY) {
  49. Animator10[] animators = copyOf(items, items.length, Animator10[].class);
  50. ((AnimatorSet10) animatorSet).playTogether(animators);
  51. } else {
  52. Animator[] animators = copyOf(items, items.length, Animator[].class);
  53. ((AnimatorSet) animatorSet).playTogether(animators);
  54. }
  55. }
  56. public void playTogether(ArrayList<Object> items) {
  57. if (View10.NEED_PROXY) {
  58. ArrayList<Animator10> animators = new ArrayList<>();
  59. for (Object obj : items) {
  60. animators.add((Animator10)obj);
  61. }
  62. ((AnimatorSet10) animatorSet).playTogether(animators);
  63. } else {
  64. ArrayList<Animator> animators = new ArrayList<>();
  65. for (Object obj : items) {
  66. animators.add((Animator)obj);
  67. }
  68. ((AnimatorSet) animatorSet).playTogether(animators);
  69. }
  70. }
  71. public AnimatorSetProxy setDuration(long duration) {
  72. if (View10.NEED_PROXY) {
  73. ((AnimatorSet10) animatorSet).setDuration(duration);
  74. } else {
  75. ((AnimatorSet) animatorSet).setDuration(duration);
  76. }
  77. return this;
  78. }
  79. public AnimatorSetProxy setStartDelay(long delay) {
  80. if (View10.NEED_PROXY) {
  81. ((AnimatorSet10) animatorSet).setStartDelay(delay);
  82. } else {
  83. ((AnimatorSet) animatorSet).setStartDelay(delay);
  84. }
  85. return this;
  86. }
  87. public void start() {
  88. if (View10.NEED_PROXY) {
  89. ((AnimatorSet10) animatorSet).start();
  90. } else {
  91. ((AnimatorSet) animatorSet).start();
  92. }
  93. }
  94. public void cancel() {
  95. if (View10.NEED_PROXY) {
  96. ((AnimatorSet10) animatorSet).cancel();
  97. } else {
  98. ((AnimatorSet) animatorSet).cancel();
  99. }
  100. }
  101. public void addListener(AnimatorListenerAdapterProxy listener) {
  102. if (View10.NEED_PROXY) {
  103. ((AnimatorSet10) animatorSet).addListener((AnimatorListenerAdapter10) listener.animatorListenerAdapter);
  104. } else {
  105. ((AnimatorSet) animatorSet).addListener((AnimatorListenerAdapter) listener.animatorListenerAdapter);
  106. }
  107. }
  108. public void setInterpolator(Interpolator interpolator) {
  109. if (View10.NEED_PROXY) {
  110. ((AnimatorSet10) animatorSet).setInterpolator(interpolator);
  111. } else {
  112. ((AnimatorSet) animatorSet).setInterpolator(interpolator);
  113. }
  114. }
  115. @Override
  116. public boolean equals(Object o) {
  117. return animatorSet == o;
  118. }
  119. }