Java Code Examples for androidx.appcompat.widget.Toolbar#startAnimation()

The following examples show how to use androidx.appcompat.widget.Toolbar#startAnimation() . 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: AnimationService.java    From Twire with GNU General Public License v3.0 6 votes vote down vote up
public static void setActivityToolbarReset(Toolbar aMainToolbar, Toolbar aDecorativeToolbar, Activity aActivity, float fromToolbarPosition, float fromMainToolbarPosition) {
    final int TOOLBAR_TRANSLATION_DURATION = 700;
    float DECORATIVE_TOOLBAR_HEIGHT = -1 * aActivity.getResources().getDimension(R.dimen.additional_toolbar_height);
    if (fromMainToolbarPosition == 0) {
        DECORATIVE_TOOLBAR_HEIGHT += aActivity.getResources().getDimension(R.dimen.main_toolbar_height);
    } else {
        Animation moveMainToolbarAnimation = new TranslateAnimation(0, 0, fromMainToolbarPosition, 0);
        moveMainToolbarAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
        moveMainToolbarAnimation.setDuration(TOOLBAR_TRANSLATION_DURATION);

        aMainToolbar.startAnimation(moveMainToolbarAnimation);
    }
    float fromTranslationY = Math.max(fromToolbarPosition, DECORATIVE_TOOLBAR_HEIGHT);

    Animation moveToolbarAnimation = new TranslateAnimation(0, 0, fromTranslationY, 0);
    moveToolbarAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    moveToolbarAnimation.setDuration(TOOLBAR_TRANSLATION_DURATION);

    aDecorativeToolbar.startAnimation(moveToolbarAnimation);
}
 
Example 2
Source File: AnimationService.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 6 votes vote down vote up
public static void setActivityToolbarReset(Toolbar aMainToolbar, Toolbar aDecorativeToolbar, Activity aActivity, float fromToolbarPosition, float fromMainToolbarPosition) {
	final int TOOLBAR_TRANSLATION_DURATION = 700;
	float DECORATIVE_TOOLBAR_HEIGHT = -1 * aActivity.getResources().getDimension(R.dimen.additional_toolbar_height);
	if(fromMainToolbarPosition == 0) {
		DECORATIVE_TOOLBAR_HEIGHT += aActivity.getResources().getDimension(R.dimen.main_toolbar_height);
	} else {
		Animation moveMainToolbarAnimation = new TranslateAnimation(0, 0, fromMainToolbarPosition, 0);
		moveMainToolbarAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
		moveMainToolbarAnimation.setDuration(TOOLBAR_TRANSLATION_DURATION);

		aMainToolbar.startAnimation(moveMainToolbarAnimation);
	}
	float fromTranslationY = (fromToolbarPosition < DECORATIVE_TOOLBAR_HEIGHT) ? DECORATIVE_TOOLBAR_HEIGHT : fromToolbarPosition;

	Animation moveToolbarAnimation = new TranslateAnimation(0, 0, fromTranslationY, 0);
	moveToolbarAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
	moveToolbarAnimation.setDuration(TOOLBAR_TRANSLATION_DURATION);

	aDecorativeToolbar.startAnimation(moveToolbarAnimation);
}
 
Example 3
Source File: AnimationService.java    From Twire with GNU General Public License v3.0 5 votes vote down vote up
public static void setActivityToolbarPosition(int duration, Toolbar aMainToolbar, Toolbar aDecorativeToolbar, Activity aActivity, float fromToolbarPosition, float toToolbarPosition, float fromMainToolbarPosition, float toMainToolbarPosition) {
    duration = Math.max(duration, 0);

    float distanceToMoveY = toToolbarPosition - fromToolbarPosition;
    float DECORATIVE_TOOLBAR_HEIGHT = -1 * aActivity.getResources().getDimension(R.dimen.additional_toolbar_height);
    float toTranslationY = Math.max(distanceToMoveY, DECORATIVE_TOOLBAR_HEIGHT);

    // We want to make sure the toolbar is as close to the final position as possible without being visible.
    // This ensures that the animation is only running when the toolbar is visible to the user.
    if (aDecorativeToolbar.getY() < DECORATIVE_TOOLBAR_HEIGHT) {
        aDecorativeToolbar.setY(DECORATIVE_TOOLBAR_HEIGHT);
        toTranslationY = (DECORATIVE_TOOLBAR_HEIGHT - toToolbarPosition) * -1;
    }

    Animation moveToolbarAnimation = new TranslateAnimation(0, 0, 0, toTranslationY);
    moveToolbarAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    moveToolbarAnimation.setDuration(duration);
    moveToolbarAnimation.setFillAfter(true);

    float toDeltaY = toMainToolbarPosition - fromMainToolbarPosition;
    Animation moveMainToolbarAnimation = new TranslateAnimation(0, 0, 0, toDeltaY);
    moveMainToolbarAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    moveMainToolbarAnimation.setDuration(duration);
    moveMainToolbarAnimation.setFillAfter(true);

    aMainToolbar.setBackgroundColor(Service.getColorAttribute(R.attr.colorPrimary, R.color.primary, aActivity));
    aMainToolbar.startAnimation(moveMainToolbarAnimation);
    aDecorativeToolbar.startAnimation(moveToolbarAnimation);
}
 
Example 4
Source File: AnimationService.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 5 votes vote down vote up
public static void setActivityToolbarPosition(int duration, Toolbar aMainToolbar, Toolbar aDecorativeToolbar, Activity aActivity, float fromToolbarPosition, float toToolbarPosition, float fromMainToolbarPosition, float toMainToolbarPosition) {
	duration = duration < 0 ? 0 : duration;

	float distanceToMoveY = toToolbarPosition - fromToolbarPosition;
	float DECORATIVE_TOOLBAR_HEIGHT = -1 * aActivity.getResources().getDimension(R.dimen.additional_toolbar_height);
	float toTranslationY = (distanceToMoveY < DECORATIVE_TOOLBAR_HEIGHT) ? DECORATIVE_TOOLBAR_HEIGHT : distanceToMoveY;

	// We want to make sure the toolbar is as close to the final position as possible without being visible.
	// This ensures that the animation is only running when the toolbar is visible to the user.
	if(aDecorativeToolbar.getY() < DECORATIVE_TOOLBAR_HEIGHT) {
		aDecorativeToolbar.setY(DECORATIVE_TOOLBAR_HEIGHT);
		toTranslationY = (DECORATIVE_TOOLBAR_HEIGHT - toToolbarPosition) * -1;
	}

	Animation moveToolbarAnimation = new TranslateAnimation(0, 0, 0, toTranslationY);
	moveToolbarAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
	moveToolbarAnimation.setDuration(duration);
	moveToolbarAnimation.setFillAfter(true);

	float toDeltaY = toMainToolbarPosition - fromMainToolbarPosition;
	Animation moveMainToolbarAnimation = new TranslateAnimation(0, 0, 0, toDeltaY);
	moveMainToolbarAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
	moveMainToolbarAnimation.setDuration(duration);
	moveMainToolbarAnimation.setFillAfter(true);

	aMainToolbar.setBackgroundColor(Service.getColorAttribute(R.attr.colorPrimary, R.color.primary, aActivity));
	aMainToolbar.startAnimation(moveMainToolbarAnimation);
	aDecorativeToolbar.startAnimation(moveToolbarAnimation);
}