Java Code Examples for com.facebook.rebound.Spring#getSpringConfig()

The following examples show how to use com.facebook.rebound.Spring#getSpringConfig() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MinimizedArrangement.java    From springy-heads with Apache License 2.0 4 votes vote down vote up
@Override
public void onSpringUpdate(ChatHead activeChatHead, boolean isDragging, int maxWidth, int maxHeight, Spring spring, Spring activeHorizontalSpring, Spring activeVerticalSpring, int totalVelocity) {
    /** This method does a bounds Check **/
    double xVelocity = activeHorizontalSpring.getVelocity();
    double yVelocity = activeVerticalSpring.getVelocity();
    if (!isDragging && Math.abs(totalVelocity) < MIN_VELOCITY_TO_POSITION_BACK && activeChatHead == hero) {

        if (Math.abs(totalVelocity) < MAX_VELOCITY_FOR_IDLING && activeChatHead.getState() == ChatHead.State.FREE && hasActivated) {
            setIdleStateX((int) activeHorizontalSpring.getCurrentValue());
            setIdleStateY((int) activeVerticalSpring.getCurrentValue());
        }
        if (spring == activeHorizontalSpring) {

            double xPosition = activeHorizontalSpring.getCurrentValue();
            if (xPosition + manager.getConfig().getHeadWidth() > maxWidth && activeHorizontalSpring.getVelocity() > 0) {
                //outside the right bound
                //System.out.println("outside the right bound !! xPosition = " + xPosition);
                int newPos = maxWidth - manager.getConfig().getHeadWidth();
                activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
                activeHorizontalSpring.setEndValue(newPos);
            } else if (xPosition < 0 && activeHorizontalSpring.getVelocity() < 0) {
                //outside the left bound
                //System.out.println("outside the left bound !! xPosition = " + xPosition);
                activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
                activeHorizontalSpring.setEndValue(0);

            } else {
                //within bound


            }
        } else if (spring == activeVerticalSpring) {
            double yPosition = activeVerticalSpring.getCurrentValue();
            if (yPosition + manager.getConfig().getHeadWidth() > maxHeight && activeVerticalSpring.getVelocity() > 0) {
                //outside the bottom bound
                //System.out.println("outside the bottom bound !! yPosition = " + yPosition);

                activeVerticalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
                activeVerticalSpring.setEndValue(maxHeight - manager.getConfig().getHeadHeight());
            } else if (yPosition < 0 && activeVerticalSpring.getVelocity() < 0) {
                //outside the top bound
                //System.out.println("outside the top bound !! yPosition = " + yPosition);

                activeVerticalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
                activeVerticalSpring.setEndValue(0);
            } else {
                //within bound
            }

        }
    }

    if (!isDragging && activeChatHead == hero) {

        /** Capturing check **/


        int[] coords = manager.getChatHeadCoordsForCloseButton(activeChatHead);
        double distanceCloseButtonFromHead = manager.getDistanceCloseButtonFromHead((float) activeHorizontalSpring.getCurrentValue() + manager.getConfig().getHeadWidth() / 2, (float) activeVerticalSpring.getCurrentValue() + manager.getConfig().getHeadHeight() / 2);

        if (distanceCloseButtonFromHead < activeChatHead.CLOSE_ATTRACTION_THRESHOLD && activeHorizontalSpring.getSpringConfig() == SpringConfigsHolder.DRAGGING && activeVerticalSpring.getSpringConfig() == SpringConfigsHolder.DRAGGING) {
            activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
            activeVerticalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
            activeChatHead.setState(ChatHead.State.CAPTURED);

        }
        if (activeChatHead.getState() == ChatHead.State.CAPTURED && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.CAPTURING) {
            activeHorizontalSpring.setAtRest();
            activeVerticalSpring.setAtRest();
            activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.CAPTURING);
            activeVerticalSpring.setSpringConfig(SpringConfigsHolder.CAPTURING);
            activeHorizontalSpring.setEndValue(coords[0]);
            activeVerticalSpring.setEndValue(coords[1]);

        }
        if (activeChatHead.getState() == ChatHead.State.CAPTURED && activeVerticalSpring.isAtRest()) {
            manager.getCloseButton().disappear(false, true);
            manager.captureChatHeads(activeChatHead);
        }
        if (!activeVerticalSpring.isAtRest() && !isTransitioning) {
            manager.getCloseButton().appear();
        } else {
            manager.getCloseButton().disappear(true, true);
        }
    }


}
 
Example 2
Source File: MaximizedArrangement.java    From springy-heads with Apache License 2.0 4 votes vote down vote up
@Override
public void onSpringUpdate(ChatHead activeChatHead, boolean isDragging, int maxWidth, int maxHeight, Spring spring, Spring activeHorizontalSpring, Spring activeVerticalSpring, int totalVelocity) {
    /** Bounds Check **/
    if (spring == activeHorizontalSpring && !isDragging) {
        double xPosition = activeHorizontalSpring.getCurrentValue();
        if (xPosition + manager.getConfig().getHeadWidth() > maxWidth && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.NOT_DRAGGING && !activeHorizontalSpring.isOvershooting()) {
            positionToOriginal(activeChatHead, activeHorizontalSpring, activeVerticalSpring);
        }
        if (xPosition < 0 && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.NOT_DRAGGING && !activeHorizontalSpring.isOvershooting()) {
            positionToOriginal(activeChatHead, activeHorizontalSpring, activeVerticalSpring);
        }
    } else if (spring == activeVerticalSpring && !isDragging) {
        double yPosition = activeVerticalSpring.getCurrentValue();

        if (yPosition + manager.getConfig().getHeadHeight() > maxHeight && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.NOT_DRAGGING && !activeHorizontalSpring.isOvershooting()) {
            positionToOriginal(activeChatHead, activeHorizontalSpring, activeVerticalSpring);
        }
        if (yPosition < 0 && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.NOT_DRAGGING && !activeHorizontalSpring.isOvershooting()) {
            positionToOriginal(activeChatHead, activeHorizontalSpring, activeVerticalSpring);
        }

    }

    /** position it back **/
    if (!isDragging && totalVelocity < MIN_VELOCITY_TO_POSITION_BACK && activeHorizontalSpring.getSpringConfig() == SpringConfigsHolder.DRAGGING) {
        positionToOriginal(activeChatHead, activeHorizontalSpring, activeVerticalSpring);

    }

    if (activeChatHead == currentChatHead)

        showOrHideView(activeChatHead);

    if (!isDragging) {
        /** Capturing check **/
        int[] coords = manager.getChatHeadCoordsForCloseButton(activeChatHead);
        double distanceCloseButtonFromHead = manager.getDistanceCloseButtonFromHead((float) activeHorizontalSpring.getCurrentValue() + manager.getConfig().getHeadWidth() / 2, (float) activeVerticalSpring.getCurrentValue() + manager.getConfig().getHeadHeight() / 2);

        if (distanceCloseButtonFromHead < activeChatHead.CLOSE_ATTRACTION_THRESHOLD && activeHorizontalSpring.getSpringConfig() == SpringConfigsHolder.DRAGGING && activeVerticalSpring.getSpringConfig() == SpringConfigsHolder.DRAGGING && !activeChatHead.isSticky()) {

            activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
            activeVerticalSpring.setSpringConfig(SpringConfigsHolder.NOT_DRAGGING);
            activeChatHead.setState(ChatHead.State.CAPTURED);
        }
        if (activeChatHead.getState() == ChatHead.State.CAPTURED && activeHorizontalSpring.getSpringConfig() != SpringConfigsHolder.CAPTURING) {
            activeHorizontalSpring.setAtRest();
            activeVerticalSpring.setAtRest();
            activeHorizontalSpring.setSpringConfig(SpringConfigsHolder.CAPTURING);
            activeVerticalSpring.setSpringConfig(SpringConfigsHolder.CAPTURING);
            activeHorizontalSpring.setEndValue(coords[0]);
            activeVerticalSpring.setEndValue(coords[1]);

        }
        if (activeChatHead.getState() == ChatHead.State.CAPTURED && activeVerticalSpring.isAtRest()) {
            manager.getCloseButton().disappear(false, true);
            manager.captureChatHeads(activeChatHead);
        }
        if (!activeVerticalSpring.isAtRest() && !isTransitioning) {
            manager.getCloseButton().appear();
        } else {
            manager.getCloseButton().disappear(true, true);
        }
    }
}
 
Example 3
Source File: InertialImitator.java    From Backboard with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the {@link com.facebook.rebound.Spring} that this imitator should use. This class
 * attaches itself as a {@link com.facebook.rebound.SpringListener} and stores the
 * {@link com.facebook.rebound.SpringConfig} to use when the user is dragging.
 *
 * @param spring
 * 		the spring to use
 */
@Override
public void setSpring(@NonNull final Spring spring) {
	super.setSpring(spring);
	spring.addListener(this);

	mOriginalConfig = spring.getSpringConfig();
}