Search in sources :

Example 1 with CubicBezierInterpolator

use of org.telegram.ui.Components.CubicBezierInterpolator in project Telegram-FOSS by Telegram-FOSS-Team.

the class ActionBarLayout method movePreviewFragment.

public void movePreviewFragment(float dy) {
    if (!inPreviewMode || transitionAnimationPreviewMode || previewMenu != null) {
        return;
    }
    float currentTranslation = containerView.getTranslationY();
    float nextTranslation = -dy;
    if (nextTranslation > 0) {
        nextTranslation = 0;
    } else if (nextTranslation < -AndroidUtilities.dp(60)) {
        previewOpenAnimationInProgress = true;
        inPreviewMode = false;
        nextTranslation = 0;
        BaseFragment prevFragment = fragmentsStack.get(fragmentsStack.size() - 2);
        BaseFragment fragment = fragmentsStack.get(fragmentsStack.size() - 1);
        if (Build.VERSION.SDK_INT >= 21) {
            fragment.fragmentView.setOutlineProvider(null);
            fragment.fragmentView.setClipToOutline(false);
        }
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) fragment.fragmentView.getLayoutParams();
        layoutParams.topMargin = layoutParams.bottomMargin = layoutParams.rightMargin = layoutParams.leftMargin = 0;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        fragment.fragmentView.setLayoutParams(layoutParams);
        presentFragmentInternalRemoveOld(false, prevFragment);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(fragment.fragmentView, View.SCALE_X, 1.0f, 1.05f, 1.0f), ObjectAnimator.ofFloat(fragment.fragmentView, View.SCALE_Y, 1.0f, 1.05f, 1.0f));
        animatorSet.setDuration(200);
        animatorSet.setInterpolator(new CubicBezierInterpolator(0.42, 0.0, 0.58, 1.0));
        animatorSet.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                previewOpenAnimationInProgress = false;
                fragment.onPreviewOpenAnimationEnd();
            }
        });
        animatorSet.start();
        performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
        fragment.setInPreviewMode(false);
    }
    if (currentTranslation != nextTranslation) {
        containerView.setTranslationY(nextTranslation);
        invalidate();
    }
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) FrameLayout(android.widget.FrameLayout) AnimatorSet(android.animation.AnimatorSet)

Example 2 with CubicBezierInterpolator

use of org.telegram.ui.Components.CubicBezierInterpolator in project Telegram-FOSS by Telegram-FOSS-Team.

the class PhotoViewer method switchToPip.

private void switchToPip(boolean fromGesture) {
    if (videoPlayer == null || !textureUploaded || !checkInlinePermissions() || changingTextureView || switchingInlineMode || isInline) {
        return;
    }
    if (PipInstance != null) {
        PipInstance.destroyPhotoViewer();
    }
    openedFullScreenVideo = false;
    PipInstance = Instance;
    Instance = null;
    switchingInlineMode = true;
    isVisible = false;
    AndroidUtilities.cancelRunOnUIThread(hideActionBarRunnable);
    if (currentPlaceObject != null && !currentPlaceObject.imageReceiver.getVisible()) {
        currentPlaceObject.imageReceiver.setVisible(true, true);
        AnimatedFileDrawable animation = currentPlaceObject.imageReceiver.getAnimation();
        if (animation != null) {
            Bitmap bitmap = animation.getAnimatedBitmap();
            if (bitmap != null) {
                try {
                    Bitmap src = videoTextureView.getBitmap(bitmap.getWidth(), bitmap.getHeight());
                    Canvas canvas = new Canvas(bitmap);
                    canvas.drawBitmap(src, 0, 0, null);
                    src.recycle();
                } catch (Throwable e) {
                    FileLog.e(e);
                }
            }
            animation.seekTo(videoPlayer.getCurrentPosition(), true);
            if (fromGesture) {
                currentPlaceObject.imageReceiver.setAlpha(0);
                ImageReceiver imageReceiver = currentPlaceObject.imageReceiver;
                ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1f);
                valueAnimator.addUpdateListener((a) -> imageReceiver.setAlpha((Float) a.getAnimatedValue()));
                valueAnimator.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        imageReceiver.setAlpha(1f);
                    }
                });
                valueAnimator.setDuration(250);
                valueAnimator.start();
            }
            currentPlaceObject.imageReceiver.setAllowStartAnimation(true);
            currentPlaceObject.imageReceiver.startAnimation();
        }
    }
    if (Build.VERSION.SDK_INT >= 21) {
        pipAnimationInProgress = true;
        org.telegram.ui.Components.Rect rect = PipVideoView.getPipRect(aspectRatioFrameLayout.getAspectRatio());
        float scale = rect.width / videoTextureView.getWidth();
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1f);
        float fromX = videoTextureView.getTranslationX();
        float fromY = videoTextureView.getTranslationY() + translationY;
        float fromY2 = textureImageView.getTranslationY() + translationY;
        float toX = rect.x;
        float toX2 = rect.x - aspectRatioFrameLayout.getX() + getLeftInset();
        float toY = rect.y;
        float toY2 = rect.y - aspectRatioFrameLayout.getY();
        textureImageView.setTranslationY(fromY2);
        videoTextureView.setTranslationY(fromY);
        if (firstFrameView != null) {
            firstFrameView.setTranslationY(fromY);
        }
        translationY = 0;
        containerView.invalidate();
        CubicBezierInterpolator interpolator;
        if (fromGesture) {
            if (fromY < toY2) {
                interpolator = new CubicBezierInterpolator(0.5, 0, 0.9, 0.9);
            } else {
                interpolator = new CubicBezierInterpolator(0, 0.5, 0.9, 0.9);
            }
        } else {
            interpolator = null;
        }
        valueAnimator.addUpdateListener(animation -> {
            float xValue = (float) animation.getAnimatedValue();
            float yValue = interpolator == null ? xValue : interpolator.getInterpolation(xValue);
            textureImageView.setTranslationX(fromX * (1f - xValue) + toX * xValue);
            textureImageView.setTranslationY(fromY2 * (1f - yValue) + toY * yValue);
            videoTextureView.setTranslationX(fromX * (1f - xValue) + (toX2) * xValue);
            videoTextureView.setTranslationY(fromY * (1f - yValue) + (toY2) * yValue);
            if (firstFrameView != null) {
                firstFrameView.setTranslationX(videoTextureView.getTranslationX());
                firstFrameView.setTranslationY(videoTextureView.getTranslationY());
                firstFrameView.setScaleX(videoTextureView.getScaleX());
                firstFrameView.setScaleY(videoTextureView.getScaleY());
            }
        });
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(textureImageView, View.SCALE_X, scale), ObjectAnimator.ofFloat(textureImageView, View.SCALE_Y, scale), ObjectAnimator.ofFloat(videoTextureView, View.SCALE_X, scale), ObjectAnimator.ofFloat(videoTextureView, View.SCALE_Y, scale), ObjectAnimator.ofInt(backgroundDrawable, AnimationProperties.COLOR_DRAWABLE_ALPHA, 0), valueAnimator);
        if (fromGesture) {
            animatorSet.setInterpolator(CubicBezierInterpolator.EASE_OUT);
            animatorSet.setDuration(300);
        } else {
            animatorSet.setInterpolator(new DecelerateInterpolator());
            animatorSet.setDuration(250);
        }
        animatorSet.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                pipAnimationInProgress = false;
                switchToInlineRunnable.run();
            }
        });
        animatorSet.start();
        if (!fromGesture) {
            toggleActionBar(false, true, new ActionBarToggleParams().enableStatusBarAnimation(false).enableTranslationAnimation(false).animationDuration(250).animationInterpolator(new DecelerateInterpolator()));
        }
    } else {
        switchToInlineRunnable.run();
        dismissInternal();
    }
    if (parentChatActivity != null) {
        parentChatActivity.getFragmentView().invalidate();
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Canvas(android.graphics.Canvas) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) ImageReceiver(org.telegram.messenger.ImageReceiver) Bitmap(android.graphics.Bitmap) Animator(android.animation.Animator) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) ViewPropertyAnimator(android.view.ViewPropertyAnimator) AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator)

Aggregations

Animator (android.animation.Animator)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 AnimatorSet (android.animation.AnimatorSet)2 ObjectAnimator (android.animation.ObjectAnimator)2 CubicBezierInterpolator (org.telegram.ui.Components.CubicBezierInterpolator)2 ValueAnimator (android.animation.ValueAnimator)1 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 ViewPropertyAnimator (android.view.ViewPropertyAnimator)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 FrameLayout (android.widget.FrameLayout)1 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)1 ImageReceiver (org.telegram.messenger.ImageReceiver)1 AnimatedFileDrawable (org.telegram.ui.Components.AnimatedFileDrawable)1