Search in sources :

Example 26 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project CircularFloatingActionMenu by oguzbilgener.

the class MenuWithFABActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menu_with_fab);
    // Set up the white button on the lower right corner
    // more or less with default parameter
    final ImageView fabIconNew = new ImageView(this);
    fabIconNew.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_new_light));
    final FloatingActionButton rightLowerButton = new FloatingActionButton.Builder(this).setContentView(fabIconNew).build();
    SubActionButton.Builder rLSubBuilder = new SubActionButton.Builder(this);
    ImageView rlIcon1 = new ImageView(this);
    ImageView rlIcon2 = new ImageView(this);
    ImageView rlIcon3 = new ImageView(this);
    ImageView rlIcon4 = new ImageView(this);
    rlIcon1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_chat_light));
    rlIcon2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_camera_light));
    rlIcon3.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_video_light));
    rlIcon4.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_place_light));
    // Build the menu with default options: light theme, 90 degrees, 72dp radius.
    // Set 4 default SubActionButtons
    final FloatingActionMenu rightLowerMenu = new FloatingActionMenu.Builder(this).addSubActionView(rLSubBuilder.setContentView(rlIcon1).build()).addSubActionView(rLSubBuilder.setContentView(rlIcon2).build()).addSubActionView(rLSubBuilder.setContentView(rlIcon3).build()).addSubActionView(rLSubBuilder.setContentView(rlIcon4).build()).attachTo(rightLowerButton).build();
    // Listen menu open and close events to animate the button content view
    rightLowerMenu.setStateChangeListener(new FloatingActionMenu.MenuStateChangeListener() {

        @Override
        public void onMenuOpened(FloatingActionMenu menu) {
            // Rotate the icon of rightLowerButton 45 degrees clockwise
            fabIconNew.setRotation(0);
            PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 45);
            ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(fabIconNew, pvhR);
            animation.start();
        }

        @Override
        public void onMenuClosed(FloatingActionMenu menu) {
            // Rotate the icon of rightLowerButton 45 degrees counter-clockwise
            fabIconNew.setRotation(45);
            PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 0);
            ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(fabIconNew, pvhR);
            animation.start();
        }
    });
    // Set up the large red button on the center right side
    // With custom button and content sizes and margins
    int redActionButtonSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_size);
    int redActionButtonMargin = getResources().getDimensionPixelOffset(R.dimen.action_button_margin);
    int redActionButtonContentSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size);
    int redActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_margin);
    int redActionMenuRadius = getResources().getDimensionPixelSize(R.dimen.red_action_menu_radius);
    int blueSubActionButtonSize = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_size);
    int blueSubActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_content_margin);
    ImageView fabIconStar = new ImageView(this);
    fabIconStar.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_important));
    FloatingActionButton.LayoutParams starParams = new FloatingActionButton.LayoutParams(redActionButtonSize, redActionButtonSize);
    starParams.setMargins(redActionButtonMargin, redActionButtonMargin, redActionButtonMargin, redActionButtonMargin);
    fabIconStar.setLayoutParams(starParams);
    FloatingActionButton.LayoutParams fabIconStarParams = new FloatingActionButton.LayoutParams(redActionButtonContentSize, redActionButtonContentSize);
    fabIconStarParams.setMargins(redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin);
    final FloatingActionButton leftCenterButton = new FloatingActionButton.Builder(this).setContentView(fabIconStar, fabIconStarParams).setBackgroundDrawable(R.drawable.button_action_red_selector).setPosition(FloatingActionButton.POSITION_LEFT_CENTER).setLayoutParams(starParams).build();
    // Set up customized SubActionButtons for the right center menu
    SubActionButton.Builder lCSubBuilder = new SubActionButton.Builder(this);
    lCSubBuilder.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_action_blue_selector));
    FrameLayout.LayoutParams blueContentParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    blueContentParams.setMargins(blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin);
    lCSubBuilder.setLayoutParams(blueContentParams);
    // Set custom layout params
    FrameLayout.LayoutParams blueParams = new FrameLayout.LayoutParams(blueSubActionButtonSize, blueSubActionButtonSize);
    lCSubBuilder.setLayoutParams(blueParams);
    ImageView lcIcon1 = new ImageView(this);
    ImageView lcIcon2 = new ImageView(this);
    ImageView lcIcon3 = new ImageView(this);
    ImageView lcIcon4 = new ImageView(this);
    ImageView lcIcon5 = new ImageView(this);
    lcIcon1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_camera));
    lcIcon2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_picture));
    lcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_video));
    lcIcon4.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_location_found));
    lcIcon5.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_headphones));
    // Build another menu with custom options
    final FloatingActionMenu leftCenterMenu = new FloatingActionMenu.Builder(this).addSubActionView(lCSubBuilder.setContentView(lcIcon1, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon2, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon3, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon4, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon5, blueContentParams).build()).setRadius(redActionMenuRadius).setStartAngle(70).setEndAngle(-70).attachTo(leftCenterButton).build();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) SubActionButton(com.oguzdev.circularfloatingactionmenu.library.SubActionButton) FloatingActionMenu(com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu) FrameLayout(android.widget.FrameLayout) FloatingActionButton(com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton) PropertyValuesHolder(android.animation.PropertyValuesHolder) ImageView(android.widget.ImageView)

Example 27 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project CircularFloatingActionMenu by oguzbilgener.

the class SlideInAnimationHandler method animateMenuClosing.

@Override
public void animateMenuClosing(Point center) {
    super.animateMenuOpening(center);
    setAnimating(true);
    Animator lastAnimation = null;
    for (int i = 0; i < menu.getSubActionItems().size(); i++) {
        //            PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, - (menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2));
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, DIST_Y);
        //            PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 0);
        //            PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0);
        PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 0);
        final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhY, pvhA);
        animation.setDuration(DURATION);
        animation.setInterpolator(new AccelerateInterpolator());
        animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.CLOSING));
        if (i == 0) {
            lastAnimation = animation;
        }
        if (i <= menu.getSubActionItems().size() / 2) {
            animation.setStartDelay(i * LAG_BETWEEN_ITEMS);
        } else {
            animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
        }
        animation.start();
    }
    if (lastAnimation != null) {
        lastAnimation.addListener(new LastAnimationListener());
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder) Point(android.graphics.Point)

Example 28 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project CircularFloatingActionMenu by oguzbilgener.

the class SlideInAnimationHandler method animateMenuOpening.

@Override
public void animateMenuOpening(Point center) {
    super.animateMenuOpening(center);
    setAnimating(true);
    Animator lastAnimation = null;
    for (int i = 0; i < menu.getSubActionItems().size(); i++) {
        menu.getSubActionItems().get(i).view.setAlpha(0);
        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) menu.getSubActionItems().get(i).view.getLayoutParams();
        params.setMargins(menu.getSubActionItems().get(i).x, menu.getSubActionItems().get(i).y + DIST_Y, 0, 0);
        menu.getSubActionItems().get(i).view.setLayoutParams(params);
        //            PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, menu.getSubActionItems().get(i).x/* - center.x + menu.getSubActionItems().get(i).width / 2*/);
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -DIST_Y);
        //            PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
        //            PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
        PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 1);
        final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhY, pvhA);
        animation.setDuration(DURATION);
        animation.setInterpolator(new DecelerateInterpolator());
        animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.OPENING));
        if (i == 0) {
            lastAnimation = animation;
        }
        animation.setStartDelay(Math.abs(menu.getSubActionItems().size() / 2 - i) * LAG_BETWEEN_ITEMS);
        animation.start();
    }
    if (lastAnimation != null) {
        lastAnimation.addListener(new LastAnimationListener());
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) FrameLayout(android.widget.FrameLayout) PropertyValuesHolder(android.animation.PropertyValuesHolder) Point(android.graphics.Point)

Example 29 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project Bitocle by mthli.

the class DefaultAnimationHandler method animateMenuOpening.

@Override
public void animateMenuOpening(Point center) {
    super.animateMenuOpening(center);
    setAnimating(true);
    Animator lastAnimation = null;
    for (int i = 0; i < menu.getSubActionItems().size(); i++) {
        menu.getSubActionItems().get(i).view.setScaleX(0);
        menu.getSubActionItems().get(i).view.setScaleY(0);
        menu.getSubActionItems().get(i).view.setAlpha(0);
        PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2);
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2);
        PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 720);
        PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
        PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
        PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 1);
        final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
        animation.setDuration(DURATION);
        animation.setInterpolator(new OvershootInterpolator(0.9f));
        animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.OPENING));
        if (i == 0) {
            lastAnimation = animation;
        }
        // Put a slight lag between each of the menu items to make it asymmetric
        animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
        animation.start();
    }
    if (lastAnimation != null) {
        lastAnimation.addListener(new LastAnimationListener());
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) OvershootInterpolator(android.view.animation.OvershootInterpolator) ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder) Point(android.graphics.Point)

Example 30 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project XobotOS by xamarin.

the class StackView method handlePointerUp.

private void handlePointerUp(MotionEvent ev) {
    int pointerIndex = ev.findPointerIndex(mActivePointerId);
    float newY = ev.getY(pointerIndex);
    int deltaY = (int) (newY - mInitialY);
    mLastInteractionTime = System.currentTimeMillis();
    if (mVelocityTracker != null) {
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
        mYVelocity = (int) mVelocityTracker.getYVelocity(mActivePointerId);
    }
    if (mVelocityTracker != null) {
        mVelocityTracker.recycle();
        mVelocityTracker = null;
    }
    if (deltaY > mSwipeThreshold && mSwipeGestureType == GESTURE_SLIDE_DOWN && mStackSlider.mMode == StackSlider.NORMAL_MODE) {
        // We reset the gesture variable, because otherwise we will ignore showPrevious() /
        // showNext();
        mSwipeGestureType = GESTURE_NONE;
        // Swipe threshold exceeded, swipe down
        if (mStackMode == ITEMS_SLIDE_UP) {
            showPrevious();
        } else {
            showNext();
        }
        mHighlight.bringToFront();
    } else if (deltaY < -mSwipeThreshold && mSwipeGestureType == GESTURE_SLIDE_UP && mStackSlider.mMode == StackSlider.NORMAL_MODE) {
        // We reset the gesture variable, because otherwise we will ignore showPrevious() /
        // showNext();
        mSwipeGestureType = GESTURE_NONE;
        // Swipe threshold exceeded, swipe up
        if (mStackMode == ITEMS_SLIDE_UP) {
            showNext();
        } else {
            showPrevious();
        }
        mHighlight.bringToFront();
    } else if (mSwipeGestureType == GESTURE_SLIDE_UP) {
        // Didn't swipe up far enough, snap back down
        int duration;
        float finalYProgress = (mStackMode == ITEMS_SLIDE_DOWN) ? 1 : 0;
        if (mStackMode == ITEMS_SLIDE_UP || mStackSlider.mMode != StackSlider.NORMAL_MODE) {
            duration = Math.round(mStackSlider.getDurationForNeutralPosition());
        } else {
            duration = Math.round(mStackSlider.getDurationForOffscreenPosition());
        }
        StackSlider animationSlider = new StackSlider(mStackSlider);
        PropertyValuesHolder snapBackY = PropertyValuesHolder.ofFloat("YProgress", finalYProgress);
        PropertyValuesHolder snapBackX = PropertyValuesHolder.ofFloat("XProgress", 0.0f);
        ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, snapBackX, snapBackY);
        pa.setDuration(duration);
        pa.setInterpolator(new LinearInterpolator());
        pa.start();
    } else if (mSwipeGestureType == GESTURE_SLIDE_DOWN) {
        // Didn't swipe down far enough, snap back up
        float finalYProgress = (mStackMode == ITEMS_SLIDE_DOWN) ? 0 : 1;
        int duration;
        if (mStackMode == ITEMS_SLIDE_DOWN || mStackSlider.mMode != StackSlider.NORMAL_MODE) {
            duration = Math.round(mStackSlider.getDurationForNeutralPosition());
        } else {
            duration = Math.round(mStackSlider.getDurationForOffscreenPosition());
        }
        StackSlider animationSlider = new StackSlider(mStackSlider);
        PropertyValuesHolder snapBackY = PropertyValuesHolder.ofFloat("YProgress", finalYProgress);
        PropertyValuesHolder snapBackX = PropertyValuesHolder.ofFloat("XProgress", 0.0f);
        ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, snapBackX, snapBackY);
        pa.setDuration(duration);
        pa.start();
    }
    mActivePointerId = INVALID_POINTER;
    mSwipeGestureType = GESTURE_NONE;
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder) Paint(android.graphics.Paint)

Aggregations

PropertyValuesHolder (android.animation.PropertyValuesHolder)210 ObjectAnimator (android.animation.ObjectAnimator)144 Animator (android.animation.Animator)96 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)70 ValueAnimator (android.animation.ValueAnimator)64 Paint (android.graphics.Paint)33 AnimatorSet (android.animation.AnimatorSet)25 NonNull (android.support.annotation.NonNull)18 LinearInterpolator (android.view.animation.LinearInterpolator)18 Interpolator (android.view.animation.Interpolator)16 ArrayList (java.util.ArrayList)16 ViewGroup (android.view.ViewGroup)14 View (android.view.View)12 IntEvaluator (android.animation.IntEvaluator)11 Point (android.graphics.Point)11 Keyframe (android.animation.Keyframe)10 TimeAnimator (android.animation.TimeAnimator)10 Path (android.graphics.Path)10 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)8 Rect (android.graphics.Rect)7