Search in sources :

Example 6 with AnimationListener

use of android.view.animation.Animation.AnimationListener in project Fairphone by Kwamecorp.

the class PeaceOfMindActivity method peaceOfMindStarted.

@Override
public synchronized void peaceOfMindStarted(long targetTime) {
    FlurryAgent.logEvent(FlurryHelper.PEACE_OF_MIND_STARTED, true);
    try {
        mSemaphore.tryAcquire(1, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    Animation fadeOut = AnimationUtils.loadAnimation(this, R.anim.fade_out_fast);
    mSeekbarBackgroundOff.startAnimation(fadeOut);
    Animation fadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in_fast);
    mSeekbarBackgroundOn.startAnimation(fadeIn);
    fadeIn.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mSeekbarBackgroundOff.setVisibility(View.GONE);
            mSeekbarBackgroundOn.setVisibility(View.VISIBLE);
            mSemaphore.release();
        }
    });
    mVerticalSeekBar.setThumb(getResources().getDrawable(R.drawable.seekbar_thumb_on));
    mVerticalSeekBar.setThumbOffset(0);
    // fix thumb position
    float targetTimePercent = (float) targetTime / (float) PeaceOfMindStats.MAX_TIME;
    updateTextForNewTime(0, targetTime);
    mVerticalSeekBar.setInvertedProgress((int) (targetTimePercent * mVerticalSeekBar.getHeight()));
    startPeaceOfMindVideo();
}
Also used : Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener)

Example 7 with AnimationListener

use of android.view.animation.Animation.AnimationListener in project FloatingStickies by MohammadAdib.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
    boolean key = prefs.getBoolean("key", false);
    if (!key) {
        setContentView(R.layout.tutorial);
        final ImageView iv1 = (ImageView) findViewById(R.id.imageView1);
        final ImageView iv2 = (ImageView) findViewById(R.id.imageView2);
        final ImageView iv3 = (ImageView) findViewById(R.id.imageView3);
        final ImageView iv4 = (ImageView) findViewById(R.id.done);
        final CheckBox cb = (CheckBox) findViewById(R.id.checkBox);
        final Animation anim1 = AnimationUtils.loadAnimation(this, R.anim.show);
        final Animation anim2 = AnimationUtils.loadAnimation(this, R.anim.show);
        final Animation anim3 = AnimationUtils.loadAnimation(this, R.anim.show);
        final Animation anim4 = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
        final Animation anim5 = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
        final Animation anim6 = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
        anim1.setDuration(500);
        anim2.setDuration(500);
        anim3.setDuration(500);
        anim1.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                iv1.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                iv2.startAnimation(anim2);
            }
        });
        anim2.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                iv2.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                iv3.startAnimation(anim3);
            }
        });
        anim3.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                iv3.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                iv4.startAnimation(anim4);
                iv4.setOnTouchListener(MainActivity.this);
            }
        });
        anim4.setDuration(1000);
        anim4.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                iv4.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                iv4.startAnimation(anim5);
            }
        });
        anim5.setDuration(1000);
        anim5.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                iv4.startAnimation(anim4);
            }
        });
        iv1.startAnimation(anim1);
        cb.startAnimation(anim6);
    } else {
        finish();
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) CheckBox(android.widget.CheckBox) Animation(android.view.animation.Animation) ImageView(android.widget.ImageView) AnimationListener(android.view.animation.Animation.AnimationListener)

Example 8 with AnimationListener

use of android.view.animation.Animation.AnimationListener in project FloatingStickies by MohammadAdib.

the class StandOutWindow method hide.

/**
     * Hide a window corresponding to the id. Show a notification for the hidden
     * window.
     *
     * @param id The id of the window.
     */
public final synchronized void hide(int id) {
    // get the view corresponding to the id
    final Window window = getWindow(id);
    if (window == null) {
        throw new IllegalArgumentException("Tried to hide(" + id + ") a null window.");
    }
    if (window.visibility == Window.VISIBILITY_GONE) {
        throw new IllegalStateException("Tried to hide(" + id + ") a window that is not shown.");
    }
    // alert callbacks and cancel if instructed
    if (onHide(id, window)) {
        Log.w(TAG, "Window " + id + " hide cancelled by implementation.");
        return;
    }
    // check if hide enabled
    if (Utils.isSet(window.flags, StandOutFlags.FLAG_WINDOW_HIDE_ENABLE)) {
        window.visibility = Window.VISIBILITY_TRANSITION;
        // get the hidden notification for this view
        Notification notification = getHiddenNotification(id);
        // get animation
        Animation animation = getHideAnimation(id);
        try {
            // animate
            if (animation != null) {
                animation.setAnimationListener(new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        // remove the window from the window manager
                        mWindowManager.removeView(window);
                        window.visibility = Window.VISIBILITY_GONE;
                    }
                });
                window.getChildAt(0).startAnimation(animation);
            } else {
                // remove the window from the window manager
                mWindowManager.removeView(window);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        // display the notification
        notification.flags = notification.flags | Notification.FLAG_NO_CLEAR | Notification.FLAG_AUTO_CANCEL;
        mNotificationManager.notify(getClass().hashCode() + id, notification);
    } else {
        // if hide not enabled, close window
        close(id);
    }
}
Also used : Window(wei.mark.standout.ui.Window) PopupWindow(android.widget.PopupWindow) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener) Notification(android.app.Notification)

Example 9 with AnimationListener

use of android.view.animation.Animation.AnimationListener in project FloatingStickies by MohammadAdib.

the class StandOutWindow method onTouchHandleMove.

@SuppressWarnings("deprecation")
public boolean onTouchHandleMove(final int id, final Window window, View view, MotionEvent event) {
    try {
        StandOutLayoutParams params = window.getLayoutParams();
        // how much you have to move in either direction in order for the
        // gesture to be a move and not tap
        int totalDeltaX = window.touchInfo.lastX - window.touchInfo.firstX;
        int totalDeltaY = window.touchInfo.lastY - window.touchInfo.firstY;
        Animation mFadeOut = AnimationUtils.loadAnimation(this, R.anim.dock);
        final Animation mFadeOut2 = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
        final Animation mFadeIn = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
        final Animation mFadeIn2 = AnimationUtils.loadAnimation(this, R.anim.show);
        final Animation mFadeInG = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
        final Animation mFadeOutG = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
        final View win = window.findViewById(R.id.window);
        final ImageView dockIcon = (ImageView) window.findViewById(R.id.preview);
        final ImageView dockGlow = (ImageView) window.findViewById(R.id.dockglow);
        final Drawable drawable = getResources().getDrawable(R.drawable.pencil);
        FrameLayout body = (FrameLayout) window.findViewById(R.id.body);
        dockIcon.setImageDrawable(getResources().getDrawable((Integer) body.getTag()));
        switch(event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                window.touchInfo.lastX = (int) event.getRawX();
                window.touchInfo.lastY = (int) event.getRawY();
                window.touchInfo.firstX = window.touchInfo.lastX;
                window.touchInfo.firstY = window.touchInfo.lastY;
                break;
            case MotionEvent.ACTION_MOVE:
                int deltaX = (int) event.getRawX() - window.touchInfo.lastX;
                int deltaY = (int) event.getRawY() - window.touchInfo.lastY;
                window.touchInfo.lastX = (int) event.getRawX();
                window.touchInfo.lastY = (int) event.getRawY();
                if (window.touchInfo.moving || Math.abs(totalDeltaX) >= params.threshold || Math.abs(totalDeltaY) >= params.threshold) {
                    window.touchInfo.moving = true;
                    // if window is moveable
                    if (Utils.isSet(window.flags, StandOutFlags.FLAG_BODY_MOVE_ENABLE)) {
                        // update the position of the window
                        if (event.getPointerCount() == 1) {
                            params.x += deltaX;
                            params.y += deltaY;
                        }
                        window.edit().setPosition(params.x, params.y).commit();
                        if (window.getWidth() < mWindowManager.getDefaultDisplay().getWidth()) {
                            if (params.x > 0 && window.touchEdge && window.fullSize) {
                                dockGlow.startAnimation(mFadeOutG);
                                dockGlow.setVisibility(View.GONE);
                                window.touchEdge = false;
                            }
                            if (params.x > pxFromDp(8)) {
                                window.touchEdge = false;
                                // Attempt at undocking.
                                if (!window.fullSize) {
                                    window.fullSize = true;
                                    undocking = true;
                                    dockIcon.setVisibility(View.GONE);
                                    mFadeOut2.setAnimationListener(new AnimationListener() {

                                        @Override
                                        public void onAnimationStart(Animation animation) {
                                            Log.d("FloatingFolder", "Animation started");
                                        }

                                        @Override
                                        public void onAnimationRepeat(Animation animation) {
                                        }

                                        @Override
                                        public void onAnimationEnd(Animation animation) {
                                            Log.d("FloatingFolder", "Animation ended");
                                            // post so that screenshot
                                            // is
                                            // invisible
                                            // before anything else
                                            // happens
                                            dockIcon.post(new Runnable() {

                                                @Override
                                                public void run() {
                                                    StandOutLayoutParams params = window.getLayoutParams();
                                                    Drawable drawable = dockIcon.getDrawable();
                                                    dockIcon.setImageDrawable(null);
                                                    params.y = params.y - window.dockH / 2 + drawable.getIntrinsicHeight() / 2;
                                                    params.width = window.dockW;
                                                    params.height = window.dockH;
                                                    updateViewLayout(id, params);
                                                    win.setVisibility(View.VISIBLE);
                                                    gracePeriod = System.currentTimeMillis();
                                                    win.startAnimation(mFadeIn2);
                                                    undocking = false;
                                                }
                                            });
                                        }
                                    });
                                    gracePeriod = System.currentTimeMillis();
                                    dockIcon.startAnimation(mFadeOut2);
                                }
                            } else {
                                if (!window.touchEdge && params.x <= 0) {
                                    dockGlow.setVisibility(View.VISIBLE);
                                    dockGlow.startAnimation(mFadeInG);
                                    window.touchEdge = true;
                                }
                            }
                        }
                    } else {
                        window.edit().setPosition(params.x, params.y).commit();
                    }
                }
                break;
            case MotionEvent.ACTION_UP:
                if (window.fullSize && window.getWidth() < mWindowManager.getDefaultDisplay().getWidth()) {
                    // Attempt at docking
                    if (params.x <= 0 && !undocking) {
                        window.dockH = window.getHeight();
                        window.dockW = window.getWidth();
                        window.fullSize = false;
                        mFadeOut.setAnimationListener(new AnimationListener() {

                            @Override
                            public void onAnimationStart(Animation animation) {
                            }

                            @Override
                            public void onAnimationRepeat(Animation animation) {
                            }

                            @Override
                            public void onAnimationEnd(Animation animation) {
                                dockGlow.setVisibility(View.GONE);
                                win.setVisibility(View.GONE);
                                // post so that the folder is invisible
                                // before
                                // anything else happens
                                dockIcon.post(new Runnable() {

                                    @Override
                                    public void run() {
                                        StandOutLayoutParams params = window.getLayoutParams();
                                        params.y = params.y + params.height / 2 - pxFromDp(40) / 2;
                                        params.width = pxFromDp(40);
                                        params.height = pxFromDp(40);
                                        updateViewLayout(id, params);
                                        dockIcon.setVisibility(View.VISIBLE);
                                        dockIcon.startAnimation(mFadeIn);
                                    }
                                });
                            }
                        });
                        gracePeriod = System.currentTimeMillis();
                        win.startAnimation(mFadeOut);
                    }
                    window.touchInfo.moving = false;
                    onMove(id, window, view, event);
                    break;
                }
                if (!window.fullSize && params.x > 0 && params.x <= pxFromDp(8)) {
                    window.edit().setPosition(0, params.y).commit();
                }
                // bring to front on tap
                boolean tap = Math.abs(totalDeltaX) < params.threshold && Math.abs(totalDeltaY) < params.threshold;
                if (tap) {
                    StandOutWindow.this.bringToFront(id);
                }
        }
    } catch (Exception e) {
    }
    return true;
}
Also used : Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) View(android.view.View) FrameLayout(android.widget.FrameLayout) Animation(android.view.animation.Animation) ImageView(android.widget.ImageView) AnimationListener(android.view.animation.Animation.AnimationListener)

Example 10 with AnimationListener

use of android.view.animation.Animation.AnimationListener in project Lazy by l123456789jy.

the class ViewAnimationUtils method invisibleViewByAlpha.

// /**
// * 默认动画持续时间
// */
// public static final long DEFAULT_ANIMATION_DURATION = 300;
/*
     *  ************************************************************* 视图透明度渐变动画
	 * ********************************************************************
	 */
/**
     * 将给定视图渐渐隐去(view.setVisibility(View.INVISIBLE))
     *
     * @param view              被处理的视图
     * @param isBanClick        在执行动画的过程中是否禁止点击
     * @param durationMillis    持续时间,毫秒
     * @param animationListener 动画监听器
     */
public static void invisibleViewByAlpha(final View view, long durationMillis, final boolean isBanClick, final AnimationListener animationListener) {
    if (view.getVisibility() != View.INVISIBLE) {
        view.setVisibility(View.INVISIBLE);
        AlphaAnimation hiddenAlphaAnimation = AnimationUtils.getHiddenAlphaAnimation(durationMillis);
        hiddenAlphaAnimation.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                if (isBanClick) {
                    view.setClickable(false);
                }
                if (animationListener != null) {
                    animationListener.onAnimationStart(animation);
                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                if (animationListener != null) {
                    animationListener.onAnimationRepeat(animation);
                }
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if (isBanClick) {
                    view.setClickable(true);
                }
                if (animationListener != null) {
                    animationListener.onAnimationEnd(animation);
                }
            }
        });
        view.startAnimation(hiddenAlphaAnimation);
    }
}
Also used : TranslateAnimation(android.view.animation.TranslateAnimation) AlphaAnimation(android.view.animation.AlphaAnimation) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener) AlphaAnimation(android.view.animation.AlphaAnimation)

Aggregations

Animation (android.view.animation.Animation)80 AnimationListener (android.view.animation.Animation.AnimationListener)80 AlphaAnimation (android.view.animation.AlphaAnimation)25 TranslateAnimation (android.view.animation.TranslateAnimation)20 View (android.view.View)14 LinearInterpolator (android.view.animation.LinearInterpolator)12 RotateAnimation (android.view.animation.RotateAnimation)10 ScaleAnimation (android.view.animation.ScaleAnimation)10 ImageView (android.widget.ImageView)10 Rect (android.graphics.Rect)7 PopupWindow (android.widget.PopupWindow)6 Window (wei.mark.standout.ui.Window)6 ViewGroup (android.view.ViewGroup)5 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)5 SuppressLint (android.annotation.SuppressLint)4 Interpolator (android.view.animation.Interpolator)4 OvershootInterpolator (android.view.animation.OvershootInterpolator)4 TextView (android.widget.TextView)4 Notification (android.app.Notification)3 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)3