Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mParam = new WindowManager.LayoutParams(
- WindowManager.LayoutParams.WRAP_CONTENT,
- WindowManager.LayoutParams.WRAP_CONTENT,
- WindowManager.LayoutParams.TYPE_PHONE,
- WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
- | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
- | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
- | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
- | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
- | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
- PixelFormat.TRANSLUCENT
- );
- public void moveSide(int speed) {
- final int newPos = mBalloonSize
- mState = State.IDLE;
- snapAnimator.animate(ObjectAnimator.ofInt(this, "ViewX", newPos).setDuration(speed),
- new OvershootInterpolator(), null, 0, new Runnable() {
- public void run() {
- mParam.x = mViewX;
- mParam.y = mViewY;
- mWindowManager.updateViewLayout(mBalloon, mParam);
- }
- }
- );
- }
- private View rootView;
- private Handler handler = new Handler();
- private ObjectAnimator animator;
- public CustomObjectAnimator(View root) {
- rootView = root;
- }
- public void animate(ObjectAnimator newInstance, TimeInterpolator interpolator, AnimatorUpdateListener update) {
- runAnimation(newInstance, interpolator, update, null);
- }
- public void animate(final ObjectAnimator newInstance, final TimeInterpolator interpolator,
- final AnimatorUpdateListener update, long startDelay, final Runnable executeAfter) {
- handler.postDelayed(new Runnable() {
- public void run() {
- runAnimation(newInstance, interpolator, update, executeAfter);
- }
- }, startDelay);
- }
- private void runAnimation(ObjectAnimator newInstance, TimeInterpolator interpolator,
- AnimatorUpdateListener update, final Runnable executeAfter) {
- // Terminate old instance, if present
- cancel(false);
- animator = newInstance;
- // Invalidate
- if (update == null) {
- animator.addUpdateListener(new AnimatorUpdateListener() {
- @Override
- public void onAnimationUpdate(ValueAnimator animation) {
- rootView.invalidate();
- executeAfter.run();
- }
- });
- } else {
- animator.addUpdateListener(update);
- }
- animator.setInterpolator(interpolator);
- if (executeAfter != null) {
- animator.addListener(new Animator.AnimatorListener() {
- boolean canceled = false;
- @Override
- public void onAnimationRepeat(Animator animation) {
- }
- @Override
- public void onAnimationStart(Animator animation) {
- }
- @Override
- public void onAnimationCancel(Animator animation) {
- canceled = true;
- animator = null;
- }
- @Override
- public void onAnimationEnd(Animator animation) {
- if (!canceled) {
- executeAfter.run();
- animator = null;
- }
- }
- });
- }
- animator.start();
- }
- public void cancel(boolean unschedule) {
- if (unschedule) handler.removeCallbacksAndMessages(null);
- if (animator != null) animator.cancel();
- animator = null;
- }
- public class BalloonView extends BaseView {
- protected View mBalloon;
- public BalloonView(Context mContext) {
- super(mContext);
- LayoutInflater mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- mBalloon = mInflater.inflate(R.layout.balloon_view, null);
- addView(mBalloon);
- }
- }
- protected int mViewX = 0, mViewY = 0;
- protected float mAlpha = 0;
- public BaseView(Context context) {
- super(context);
- }
- public BaseView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public BaseView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
- public float getmAlpha() {
- return mAlpha;
- }
- public void setmAlpha(float mAlpha) {
- this.mAlpha = mAlpha;
- }
- public int getViewY() {
- return mViewY;
- }
- public void setViewY(int mViewY) {
- this.mViewY = mViewY;
- }
- public int getViewX() {
- return mViewX;
- }
- public void setViewX(int mViewX) {
- this.mViewX = mViewX;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement