Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. mParam = new WindowManager.LayoutParams(
  2. WindowManager.LayoutParams.WRAP_CONTENT,
  3. WindowManager.LayoutParams.WRAP_CONTENT,
  4. WindowManager.LayoutParams.TYPE_PHONE,
  5. WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
  6. | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
  7. | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
  8. | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
  9. | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
  10. | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
  11. PixelFormat.TRANSLUCENT
  12. );
  13.  
  14. public void moveSide(int speed) {
  15. final int newPos = mBalloonSize
  16. mState = State.IDLE;
  17. snapAnimator.animate(ObjectAnimator.ofInt(this, "ViewX", newPos).setDuration(speed),
  18. new OvershootInterpolator(), null, 0, new Runnable() {
  19. public void run() {
  20. mParam.x = mViewX;
  21. mParam.y = mViewY;
  22. mWindowManager.updateViewLayout(mBalloon, mParam);
  23. }
  24. }
  25. );
  26. }
  27.  
  28. private View rootView;
  29. private Handler handler = new Handler();
  30. private ObjectAnimator animator;
  31.  
  32. public CustomObjectAnimator(View root) {
  33. rootView = root;
  34. }
  35.  
  36. public void animate(ObjectAnimator newInstance, TimeInterpolator interpolator, AnimatorUpdateListener update) {
  37. runAnimation(newInstance, interpolator, update, null);
  38. }
  39.  
  40. public void animate(final ObjectAnimator newInstance, final TimeInterpolator interpolator,
  41. final AnimatorUpdateListener update, long startDelay, final Runnable executeAfter) {
  42.  
  43. handler.postDelayed(new Runnable() {
  44. public void run() {
  45. runAnimation(newInstance, interpolator, update, executeAfter);
  46. }
  47. }, startDelay);
  48. }
  49.  
  50. private void runAnimation(ObjectAnimator newInstance, TimeInterpolator interpolator,
  51. AnimatorUpdateListener update, final Runnable executeAfter) {
  52.  
  53. // Terminate old instance, if present
  54. cancel(false);
  55. animator = newInstance;
  56.  
  57. // Invalidate
  58. if (update == null) {
  59. animator.addUpdateListener(new AnimatorUpdateListener() {
  60. @Override
  61. public void onAnimationUpdate(ValueAnimator animation) {
  62. rootView.invalidate();
  63. executeAfter.run();
  64. }
  65. });
  66. } else {
  67. animator.addUpdateListener(update);
  68. }
  69.  
  70. animator.setInterpolator(interpolator);
  71.  
  72. if (executeAfter != null) {
  73. animator.addListener(new Animator.AnimatorListener() {
  74. boolean canceled = false;
  75.  
  76. @Override
  77. public void onAnimationRepeat(Animator animation) {
  78. }
  79.  
  80. @Override
  81. public void onAnimationStart(Animator animation) {
  82. }
  83.  
  84. @Override
  85. public void onAnimationCancel(Animator animation) {
  86. canceled = true;
  87. animator = null;
  88. }
  89.  
  90. @Override
  91. public void onAnimationEnd(Animator animation) {
  92. if (!canceled) {
  93. executeAfter.run();
  94. animator = null;
  95. }
  96. }
  97. });
  98. }
  99.  
  100. animator.start();
  101. }
  102.  
  103. public void cancel(boolean unschedule) {
  104. if (unschedule) handler.removeCallbacksAndMessages(null);
  105. if (animator != null) animator.cancel();
  106. animator = null;
  107. }
  108.  
  109. public class BalloonView extends BaseView {
  110.  
  111. protected View mBalloon;
  112.  
  113. public BalloonView(Context mContext) {
  114. super(mContext);
  115.  
  116. LayoutInflater mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  117. mBalloon = mInflater.inflate(R.layout.balloon_view, null);
  118. addView(mBalloon);
  119. }
  120. }
  121.  
  122. protected int mViewX = 0, mViewY = 0;
  123. protected float mAlpha = 0;
  124.  
  125. public BaseView(Context context) {
  126. super(context);
  127. }
  128.  
  129. public BaseView(Context context, AttributeSet attrs) {
  130. super(context, attrs);
  131. }
  132.  
  133. public BaseView(Context context, AttributeSet attrs, int defStyle) {
  134. super(context, attrs, defStyle);
  135. }
  136.  
  137.  
  138. public float getmAlpha() {
  139. return mAlpha;
  140. }
  141.  
  142. public void setmAlpha(float mAlpha) {
  143. this.mAlpha = mAlpha;
  144. }
  145.  
  146. public int getViewY() {
  147. return mViewY;
  148. }
  149.  
  150. public void setViewY(int mViewY) {
  151. this.mViewY = mViewY;
  152. }
  153.  
  154. public int getViewX() {
  155. return mViewX;
  156. }
  157.  
  158. public void setViewX(int mViewX) {
  159. this.mViewX = mViewX;
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement