Search in sources :

Example 6 with VideoEditTextureView

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

the class PhotoViewer method createPaintView.

private void createPaintView() {
    if (photoPaintView == null) {
        int w;
        int h;
        if (videoTextureView != null) {
            VideoEditTextureView textureView = (VideoEditTextureView) videoTextureView;
            w = textureView.getVideoWidth();
            h = textureView.getVideoHeight();
            while (w > 1280 || h > 1280) {
                w /= 2;
                h /= 2;
            }
        } else {
            w = centerImage.getBitmapWidth();
            h = centerImage.getBitmapHeight();
        }
        Bitmap bitmap = paintingOverlay.getBitmap();
        if (bitmap == null) {
            bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        }
        MediaController.CropState state;
        if (sendPhotoType == SELECT_TYPE_AVATAR) {
            state = new MediaController.CropState();
            state.transformRotation = cropTransform.getOrientation();
        } else {
            state = editState.cropState;
        }
        photoPaintView = new PhotoPaintView(parentActivity, bitmap, isCurrentVideo ? null : centerImage.getBitmap(), centerImage.getOrientation(), editState.mediaEntities, state, () -> paintingOverlay.hideBitmap(), resourcesProvider) {

            @Override
            protected void onOpenCloseStickersAlert(boolean open) {
                if (videoPlayer == null) {
                    return;
                }
                manuallyPaused = false;
                cancelVideoPlayRunnable();
                if (open) {
                    videoPlayer.pause();
                } else {
                    videoPlayer.play();
                }
            }

            @Override
            protected void didSetAnimatedSticker(RLottieDrawable drawable) {
                if (videoPlayer == null) {
                    return;
                }
                drawable.setProgressMs(videoPlayer.getCurrentPosition() - (startTime > 0 ? startTime / 1000 : 0));
            }

            @Override
            protected void onTextAdd() {
                if (!windowView.isFocusable()) {
                    makeFocusable();
                }
            }
        };
        containerView.addView(photoPaintView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        photoPaintView.getDoneTextView().setOnClickListener(v -> {
            savedState = null;
            applyCurrentEditMode();
            switchToEditMode(0);
        });
        photoPaintView.getCancelTextView().setOnClickListener(v -> closePaintMode());
        photoPaintView.getColorPicker().setTranslationY(AndroidUtilities.dp(126));
        photoPaintView.getToolsView().setTranslationY(AndroidUtilities.dp(126));
    }
}
Also used : Bitmap(android.graphics.Bitmap) MediaController(org.telegram.messenger.MediaController) VideoEditTextureView(org.telegram.ui.Components.VideoEditTextureView) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) PhotoPaintView(org.telegram.ui.Components.PhotoPaintView) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Example 7 with VideoEditTextureView

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

the class PhotoViewer method setCropBitmap.

private void setCropBitmap() {
    if (cropInitied || sendPhotoType != SELECT_TYPE_AVATAR) {
        return;
    }
    if (isCurrentVideo) {
        VideoEditTextureView textureView = (VideoEditTextureView) videoTextureView;
        if (textureView == null || textureView.getVideoWidth() <= 0 || textureView.getVideoHeight() <= 0) {
            return;
        }
    }
    cropInitied = true;
    Bitmap bitmap = centerImage.getBitmap();
    int orientation = centerImage.getOrientation();
    if (bitmap == null) {
        bitmap = animatingImageView.getBitmap();
        orientation = animatingImageView.getOrientation();
    }
    if (bitmap != null || videoTextureView != null) {
        photoCropView.setBitmap(bitmap, orientation, false, false, paintingOverlay, cropTransform, isCurrentVideo ? (VideoEditTextureView) videoTextureView : null, editState.cropState);
    }
}
Also used : Bitmap(android.graphics.Bitmap) VideoEditTextureView(org.telegram.ui.Components.VideoEditTextureView) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Example 8 with VideoEditTextureView

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

the class PhotoViewer method switchToEditMode.

private void switchToEditMode(final int mode) {
    if (currentEditMode == mode || (isCurrentVideo && photoProgressViews[0].backgroundState != 3) && !isCurrentVideo && (centerImage.getBitmap() == null || photoProgressViews[0].backgroundState != -1) || changeModeAnimation != null || imageMoveAnimation != null || captionEditText.getTag() != null) {
        return;
    }
    switchingToMode = mode;
    if (mode == 0) {
        // no edit mode
        Bitmap bitmap = centerImage.getBitmap();
        if (bitmap != null) {
            int bitmapWidth = centerImage.getBitmapWidth();
            int bitmapHeight = centerImage.getBitmapHeight();
            float newScale;
            float oldScale;
            if (currentEditMode == 3) {
                if (sendPhotoType != SELECT_TYPE_AVATAR) {
                    if (cropTransform.getOrientation() == 90 || cropTransform.getOrientation() == 270) {
                        int temp = bitmapWidth;
                        bitmapWidth = bitmapHeight;
                        bitmapHeight = temp;
                    }
                } else {
                    if (editState.cropState != null) {
                        if (editState.cropState.transformRotation == 90 || editState.cropState.transformRotation == 270) {
                            int temp = bitmapWidth;
                            bitmapWidth = bitmapHeight;
                            bitmapHeight = temp;
                        }
                        bitmapWidth *= editState.cropState.cropPw;
                        bitmapHeight *= editState.cropState.cropPh;
                    }
                }
                newScale = Math.min(getContainerViewWidth(0) / (float) bitmapWidth, getContainerViewHeight(0) / (float) bitmapHeight);
                oldScale = Math.min(getContainerViewWidth() / (float) bitmapWidth, getContainerViewHeight() / (float) bitmapHeight);
            } else {
                if (currentEditMode != 1 && editState.cropState != null && (editState.cropState.transformRotation == 90 || editState.cropState.transformRotation == 270)) {
                    float scaleToFitX = getContainerViewWidth() / (float) bitmapHeight;
                    if (scaleToFitX * bitmapWidth > getContainerViewHeight()) {
                        scaleToFitX = getContainerViewHeight() / (float) bitmapWidth;
                    }
                    float sc = Math.min(getContainerViewWidth() / (float) bitmapWidth, getContainerViewHeight() / (float) bitmapHeight);
                    float cropScale = scaleToFitX / sc;
                    scale = 1.0f / cropScale;
                } else if (sendPhotoType == SELECT_TYPE_AVATAR && (cropTransform.getOrientation() == 90 || cropTransform.getOrientation() == 270)) {
                    float scaleToFitX = getContainerViewWidth() / (float) bitmapHeight;
                    if (scaleToFitX * bitmapWidth > getContainerViewHeight()) {
                        scaleToFitX = getContainerViewHeight() / (float) bitmapWidth;
                    }
                    float sc = Math.min(getContainerViewWidth() / (float) bitmapWidth, getContainerViewHeight() / (float) bitmapHeight);
                    float cropScale = cropTransform.getScale() / cropTransform.getTrueCropScale() * scaleToFitX / sc / cropTransform.getMinScale();
                    scale = 1.0f / cropScale;
                }
                if (editState.cropState != null) {
                    if (editState.cropState.transformRotation == 90 || editState.cropState.transformRotation == 270) {
                        int temp = bitmapWidth;
                        bitmapWidth = bitmapHeight;
                        bitmapHeight = temp;
                    }
                    bitmapWidth *= editState.cropState.cropPw;
                    bitmapHeight *= editState.cropState.cropPh;
                } else if (sendPhotoType == SELECT_TYPE_AVATAR && (cropTransform.getOrientation() == 90 || cropTransform.getOrientation() == 270)) {
                    int temp = bitmapWidth;
                    bitmapWidth = bitmapHeight;
                    bitmapHeight = temp;
                }
                oldScale = Math.min(getContainerViewWidth() / (float) bitmapWidth, getContainerViewHeight() / (float) bitmapHeight);
                if (sendPhotoType == SELECT_TYPE_AVATAR) {
                    newScale = getCropFillScale(cropTransform.getOrientation() == 90 || cropTransform.getOrientation() == 270);
                } else {
                    newScale = Math.min(getContainerViewWidth(0) / (float) bitmapWidth, getContainerViewHeight(0) / (float) bitmapHeight);
                }
            }
            animateToScale = newScale / oldScale;
            animateToX = 0;
            translationX = getLeftInset() / 2 - getRightInset() / 2;
            if (sendPhotoType == SELECT_TYPE_AVATAR) {
                if (currentEditMode == 2) {
                    animateToY = AndroidUtilities.dp(36);
                } else if (currentEditMode == 3) {
                    animateToY = -AndroidUtilities.dp(12);
                }
            } else {
                if (currentEditMode == 1) {
                    animateToY = AndroidUtilities.dp(24 + 32);
                } else if (currentEditMode == 2) {
                    animateToY = AndroidUtilities.dp(93);
                } else if (currentEditMode == 3) {
                    animateToY = AndroidUtilities.dp(44);
                }
                if (isStatusBarVisible()) {
                    animateToY -= AndroidUtilities.statusBarHeight / 2;
                }
            }
            animationStartTime = System.currentTimeMillis();
            zoomAnimation = true;
        }
        padImageForHorizontalInsets = false;
        imageMoveAnimation = new AnimatorSet();
        ArrayList<Animator> animators = new ArrayList<>(4);
        if (currentEditMode == 1) {
            animators.add(ObjectAnimator.ofFloat(editorDoneLayout, View.TRANSLATION_Y, AndroidUtilities.dp(48)));
            animators.add(ObjectAnimator.ofFloat(PhotoViewer.this, AnimationProperties.PHOTO_VIEWER_ANIMATION_VALUE, 0, 1));
            animators.add(ObjectAnimator.ofFloat(photoCropView, View.ALPHA, 0));
        } else if (currentEditMode == 2) {
            photoFilterView.shutdown();
            animators.add(ObjectAnimator.ofFloat(photoFilterView.getToolsView(), View.TRANSLATION_Y, AndroidUtilities.dp(186)));
            animators.add(ObjectAnimator.ofFloat(photoFilterView.getCurveControl(), View.ALPHA, 0.0f));
            animators.add(ObjectAnimator.ofFloat(photoFilterView.getBlurControl(), View.ALPHA, 0.0f));
            animators.add(ObjectAnimator.ofFloat(PhotoViewer.this, AnimationProperties.PHOTO_VIEWER_ANIMATION_VALUE, 0, 1));
        } else if (currentEditMode == 3) {
            paintingOverlay.showAll();
            containerView.invalidate();
            photoPaintView.shutdown();
            animators.add(ObjectAnimator.ofFloat(photoPaintView.getToolsView(), View.TRANSLATION_Y, AndroidUtilities.dp(126)));
            animators.add(ObjectAnimator.ofFloat(photoPaintView.getColorPicker(), View.TRANSLATION_Y, AndroidUtilities.dp(126)));
            animators.add(ObjectAnimator.ofFloat(PhotoViewer.this, AnimationProperties.PHOTO_VIEWER_ANIMATION_VALUE, 0, 1));
        }
        imageMoveAnimation.playTogether(animators);
        imageMoveAnimation.setDuration(200);
        imageMoveAnimation.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                if (currentEditMode == 1) {
                    photoCropView.onDisappear();
                    photoCropView.onHide();
                    editorDoneLayout.setVisibility(View.GONE);
                    photoCropView.setVisibility(View.GONE);
                } else if (currentEditMode == 2) {
                    try {
                        containerView.removeView(photoFilterView);
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                    photoFilterView = null;
                } else if (currentEditMode == 3) {
                    try {
                        containerView.removeView(photoPaintView);
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                    photoPaintView = null;
                }
                imageMoveAnimation = null;
                currentEditMode = mode;
                switchingToMode = -1;
                applying = false;
                if (sendPhotoType == SELECT_TYPE_AVATAR) {
                    photoCropView.setVisibility(View.VISIBLE);
                }
                animateToScale = 1;
                animateToX = 0;
                animateToY = 0;
                scale = 1;
                updateMinMax(scale);
                containerView.invalidate();
                if (savedState != null) {
                    savedState.restore();
                    savedState = null;
                    final ActionBarToggleParams toggleParams = new ActionBarToggleParams().enableStatusBarAnimation(false);
                    toggleActionBar(false, false, toggleParams);
                    toggleActionBar(true, true, toggleParams);
                    return;
                }
                AnimatorSet animatorSet = new AnimatorSet();
                ArrayList<Animator> arrayList = new ArrayList<>();
                arrayList.add(ObjectAnimator.ofFloat(pickerView, View.TRANSLATION_Y, 0));
                arrayList.add(ObjectAnimator.ofFloat(pickerViewSendButton, View.TRANSLATION_Y, 0));
                if (sendPhotoType != SELECT_TYPE_AVATAR) {
                    arrayList.add(ObjectAnimator.ofFloat(actionBar, View.TRANSLATION_Y, 0));
                }
                if (needCaptionLayout) {
                    arrayList.add(ObjectAnimator.ofFloat(captionTextViewSwitcher, View.TRANSLATION_Y, 0));
                }
                if (sendPhotoType == 0 || sendPhotoType == 4) {
                    arrayList.add(ObjectAnimator.ofFloat(checkImageView, View.ALPHA, 1));
                    arrayList.add(ObjectAnimator.ofFloat(photosCounterView, View.ALPHA, 1));
                } else if (sendPhotoType == SELECT_TYPE_AVATAR) {
                    arrayList.add(ObjectAnimator.ofFloat(photoCropView, View.ALPHA, 1));
                }
                if (cameraItem.getTag() != null) {
                    cameraItem.setVisibility(View.VISIBLE);
                    arrayList.add(ObjectAnimator.ofFloat(cameraItem, View.ALPHA, 1));
                }
                if (muteItem.getTag() != null) {
                    muteItem.setVisibility(View.VISIBLE);
                    arrayList.add(ObjectAnimator.ofFloat(muteItem, View.ALPHA, 1));
                }
                animatorSet.playTogether(arrayList);
                animatorSet.setDuration(200);
                animatorSet.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationStart(Animator animation) {
                        pickerView.setVisibility(View.VISIBLE);
                        pickerViewSendButton.setVisibility(View.VISIBLE);
                        actionBar.setVisibility(View.VISIBLE);
                        if (needCaptionLayout) {
                            captionTextViewSwitcher.setVisibility(captionTextViewSwitcher.getTag() != null ? View.VISIBLE : View.INVISIBLE);
                        }
                        if (sendPhotoType == 0 || sendPhotoType == 4 || (sendPhotoType == 2 || sendPhotoType == 5) && imagesArrLocals.size() > 1) {
                            checkImageView.setVisibility(View.VISIBLE);
                            photosCounterView.setVisibility(View.VISIBLE);
                        }
                    }
                });
                animatorSet.start();
            }
        });
        imageMoveAnimation.start();
    } else if (mode == 1) {
        // crop
        startVideoPlayer();
        createCropView();
        previousHasTransform = cropTransform.hasViewTransform();
        previousCropPx = cropTransform.getCropPx();
        previousCropPy = cropTransform.getCropPy();
        previousCropScale = cropTransform.getScale();
        previousCropRotation = cropTransform.getRotation();
        previousCropOrientation = cropTransform.getOrientation();
        previousCropPw = cropTransform.getCropPw();
        previousCropPh = cropTransform.getCropPh();
        previousCropMirrored = cropTransform.isMirrored();
        photoCropView.onAppear();
        editorDoneLayout.doneButton.setText(LocaleController.getString("Crop", R.string.Crop));
        editorDoneLayout.doneButton.setTextColor(getThemedColor(Theme.key_dialogFloatingButton));
        changeModeAnimation = new AnimatorSet();
        ArrayList<Animator> arrayList = new ArrayList<>();
        arrayList.add(ObjectAnimator.ofFloat(pickerView, View.TRANSLATION_Y, 0, AndroidUtilities.dp(isCurrentVideo ? 154 : 96)));
        arrayList.add(ObjectAnimator.ofFloat(pickerViewSendButton, View.TRANSLATION_Y, 0, AndroidUtilities.dp(isCurrentVideo ? 154 : 96)));
        arrayList.add(ObjectAnimator.ofFloat(actionBar, View.TRANSLATION_Y, 0, -actionBar.getHeight()));
        if (needCaptionLayout) {
            arrayList.add(ObjectAnimator.ofFloat(captionTextViewSwitcher, View.TRANSLATION_Y, 0, AndroidUtilities.dp(isCurrentVideo ? 154 : 96)));
        }
        if (sendPhotoType == 0 || sendPhotoType == 4) {
            arrayList.add(ObjectAnimator.ofFloat(checkImageView, View.ALPHA, 1, 0));
            arrayList.add(ObjectAnimator.ofFloat(photosCounterView, View.ALPHA, 1, 0));
        }
        if (selectedPhotosListView.getVisibility() == View.VISIBLE) {
            arrayList.add(ObjectAnimator.ofFloat(selectedPhotosListView, View.ALPHA, 1, 0));
        }
        if (cameraItem.getTag() != null) {
            arrayList.add(ObjectAnimator.ofFloat(cameraItem, View.ALPHA, 1, 0));
        }
        if (muteItem.getTag() != null) {
            arrayList.add(ObjectAnimator.ofFloat(muteItem, View.ALPHA, 1, 0));
        }
        changeModeAnimation.playTogether(arrayList);
        changeModeAnimation.setDuration(200);
        changeModeAnimation.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                changeModeAnimation = null;
                pickerView.setVisibility(View.GONE);
                pickerViewSendButton.setVisibility(View.GONE);
                cameraItem.setVisibility(View.GONE);
                muteItem.setVisibility(View.GONE);
                selectedPhotosListView.setVisibility(View.GONE);
                selectedPhotosListView.setAlpha(0.0f);
                selectedPhotosListView.setTranslationY(-AndroidUtilities.dp(10));
                photosCounterView.setRotationX(0.0f);
                selectedPhotosListView.setEnabled(false);
                isPhotosListViewVisible = false;
                if (needCaptionLayout) {
                    captionTextViewSwitcher.setVisibility(View.INVISIBLE);
                }
                if (sendPhotoType == 0 || sendPhotoType == 4 || (sendPhotoType == 2 || sendPhotoType == 5) && imagesArrLocals.size() > 1) {
                    checkImageView.setVisibility(View.GONE);
                    photosCounterView.setVisibility(View.GONE);
                }
                final Bitmap bitmap = centerImage.getBitmap();
                if (bitmap != null || isCurrentVideo) {
                    photoCropView.setBitmap(bitmap, centerImage.getOrientation(), sendPhotoType != SELECT_TYPE_AVATAR, false, paintingOverlay, cropTransform, isCurrentVideo ? (VideoEditTextureView) videoTextureView : null, editState.cropState);
                    photoCropView.onDisappear();
                    int bitmapWidth = centerImage.getBitmapWidth();
                    int bitmapHeight = centerImage.getBitmapHeight();
                    if (editState.cropState != null) {
                        if (editState.cropState.transformRotation == 90 || editState.cropState.transformRotation == 270) {
                            int temp = bitmapWidth;
                            bitmapWidth = bitmapHeight;
                            bitmapHeight = temp;
                        }
                        bitmapWidth *= editState.cropState.cropPw;
                        bitmapHeight *= editState.cropState.cropPh;
                    }
                    float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
                    float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
                    float newScaleX = (float) getContainerViewWidth(1) / (float) bitmapWidth;
                    float newScaleY = (float) getContainerViewHeight(1) / (float) bitmapHeight;
                    float scale = Math.min(scaleX, scaleY);
                    float newScale = Math.min(newScaleX, newScaleY);
                    if (sendPhotoType == SELECT_TYPE_AVATAR) {
                        float minSide = Math.min(getContainerViewWidth(1), getContainerViewHeight(1));
                        newScaleX = minSide / (float) bitmapWidth;
                        newScaleY = minSide / (float) bitmapHeight;
                        newScale = Math.max(newScaleX, newScaleY);
                    }
                    animateToScale = newScale / scale;
                    animateToX = getLeftInset() / 2 - getRightInset() / 2;
                    animateToY = -AndroidUtilities.dp(24 + 32) + (isStatusBarVisible() ? AndroidUtilities.statusBarHeight / 2 : 0);
                    animationStartTime = System.currentTimeMillis();
                    zoomAnimation = true;
                }
                imageMoveAnimation = new AnimatorSet();
                imageMoveAnimation.playTogether(ObjectAnimator.ofFloat(editorDoneLayout, View.TRANSLATION_Y, AndroidUtilities.dp(48), 0), ObjectAnimator.ofFloat(PhotoViewer.this, AnimationProperties.PHOTO_VIEWER_ANIMATION_VALUE, 0, 1), ObjectAnimator.ofFloat(photoCropView, View.ALPHA, 0, 1));
                imageMoveAnimation.setDuration(200);
                imageMoveAnimation.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationStart(Animator animation) {
                        editorDoneLayout.setVisibility(View.VISIBLE);
                        photoCropView.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        photoCropView.onAppeared();
                        photoCropView.onShow();
                        imageMoveAnimation = null;
                        currentEditMode = mode;
                        switchingToMode = -1;
                        animateToScale = 1;
                        animateToX = 0;
                        animateToY = 0;
                        scale = 1;
                        updateMinMax(scale);
                        padImageForHorizontalInsets = true;
                        containerView.invalidate();
                    }
                });
                imageMoveAnimation.start();
            }
        });
        changeModeAnimation.start();
    } else if (mode == 2) {
        // filter
        startVideoPlayer();
        if (photoFilterView == null) {
            MediaController.SavedFilterState state = null;
            Bitmap bitmap;
            String originalPath = null;
            int orientation = 0;
            if (!imagesArrLocals.isEmpty()) {
                Object object = imagesArrLocals.get(currentIndex);
                if (object instanceof MediaController.PhotoEntry) {
                    MediaController.PhotoEntry entry = (MediaController.PhotoEntry) object;
                    orientation = entry.orientation;
                }
                MediaController.MediaEditState editState = (MediaController.MediaEditState) object;
                state = editState.savedFilterState;
                originalPath = editState.getPath();
            }
            if (videoTextureView != null) {
                bitmap = null;
            } else {
                if (state == null) {
                    bitmap = centerImage.getBitmap();
                    orientation = centerImage.getOrientation();
                } else {
                    bitmap = BitmapFactory.decodeFile(originalPath);
                }
            }
            int hasFaces;
            if (sendPhotoType == SELECT_TYPE_AVATAR) {
                hasFaces = 1;
            } else if (isCurrentVideo || currentImageHasFace == 2) {
                hasFaces = 2;
            } else {
                hasFaces = currentImageHasFace == 1 ? 1 : 0;
            }
            photoFilterView = new PhotoFilterView(parentActivity, videoTextureView != null ? (VideoEditTextureView) videoTextureView : null, bitmap, orientation, state, isCurrentVideo ? null : paintingOverlay, hasFaces, videoTextureView == null && (editState.cropState != null && editState.cropState.mirrored || cropTransform.isMirrored()), resourcesProvider);
            containerView.addView(photoFilterView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            photoFilterView.getDoneTextView().setOnClickListener(v -> {
                applyCurrentEditMode();
                switchToEditMode(0);
            });
            photoFilterView.getCancelTextView().setOnClickListener(v -> {
                if (photoFilterView.hasChanges()) {
                    if (parentActivity == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity, resourcesProvider);
                    builder.setMessage(LocaleController.getString("DiscardChanges", R.string.DiscardChanges));
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> switchToEditMode(0));
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    showAlertDialog(builder);
                } else {
                    switchToEditMode(0);
                }
            });
            photoFilterView.getToolsView().setTranslationY(AndroidUtilities.dp(186));
        }
        changeModeAnimation = new AnimatorSet();
        ArrayList<Animator> arrayList = new ArrayList<>();
        arrayList.add(ObjectAnimator.ofFloat(pickerView, View.TRANSLATION_Y, 0, AndroidUtilities.dp(isCurrentVideo ? 154 : 96)));
        arrayList.add(ObjectAnimator.ofFloat(pickerViewSendButton, View.TRANSLATION_Y, 0, AndroidUtilities.dp(isCurrentVideo ? 154 : 96)));
        arrayList.add(ObjectAnimator.ofFloat(actionBar, View.TRANSLATION_Y, 0, -actionBar.getHeight()));
        if (sendPhotoType == 0 || sendPhotoType == 4) {
            arrayList.add(ObjectAnimator.ofFloat(checkImageView, View.ALPHA, 1, 0));
            arrayList.add(ObjectAnimator.ofFloat(photosCounterView, View.ALPHA, 1, 0));
        } else if (sendPhotoType == SELECT_TYPE_AVATAR) {
            arrayList.add(ObjectAnimator.ofFloat(photoCropView, View.ALPHA, 1, 0));
        }
        if (selectedPhotosListView.getVisibility() == View.VISIBLE) {
            arrayList.add(ObjectAnimator.ofFloat(selectedPhotosListView, View.ALPHA, 1, 0));
        }
        if (cameraItem.getTag() != null) {
            arrayList.add(ObjectAnimator.ofFloat(cameraItem, View.ALPHA, 1, 0));
        }
        if (muteItem.getTag() != null) {
            arrayList.add(ObjectAnimator.ofFloat(muteItem, View.ALPHA, 1, 0));
        }
        changeModeAnimation.playTogether(arrayList);
        changeModeAnimation.setDuration(200);
        changeModeAnimation.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                changeModeAnimation = null;
                pickerView.setVisibility(View.GONE);
                pickerViewSendButton.setVisibility(View.GONE);
                actionBar.setVisibility(View.GONE);
                cameraItem.setVisibility(View.GONE);
                muteItem.setVisibility(View.GONE);
                if (photoCropView != null) {
                    photoCropView.setVisibility(View.INVISIBLE);
                }
                selectedPhotosListView.setVisibility(View.GONE);
                selectedPhotosListView.setAlpha(0.0f);
                selectedPhotosListView.setTranslationY(-AndroidUtilities.dp(10));
                photosCounterView.setRotationX(0.0f);
                selectedPhotosListView.setEnabled(false);
                isPhotosListViewVisible = false;
                if (needCaptionLayout) {
                    captionTextViewSwitcher.setVisibility(View.INVISIBLE);
                }
                if (sendPhotoType == 0 || sendPhotoType == 4 || (sendPhotoType == 2 || sendPhotoType == 5) && imagesArrLocals.size() > 1) {
                    checkImageView.setVisibility(View.GONE);
                    photosCounterView.setVisibility(View.GONE);
                }
                Bitmap bitmap = centerImage.getBitmap();
                if (bitmap != null) {
                    int bitmapWidth = centerImage.getBitmapWidth();
                    int bitmapHeight = centerImage.getBitmapHeight();
                    float oldScale;
                    float newScale = Math.min(getContainerViewWidth(2) / (float) bitmapWidth, getContainerViewHeight(2) / (float) bitmapHeight);
                    if (sendPhotoType == SELECT_TYPE_AVATAR) {
                        animateToY = -AndroidUtilities.dp(36);
                        oldScale = getCropFillScale(false);
                    } else {
                        animateToY = -AndroidUtilities.dp(93) + (isStatusBarVisible() ? AndroidUtilities.statusBarHeight / 2 : 0);
                        if (editState.cropState != null && (editState.cropState.transformRotation == 90 || editState.cropState.transformRotation == 270)) {
                            oldScale = Math.min(getContainerViewWidth() / (float) bitmapHeight, getContainerViewHeight() / (float) bitmapWidth);
                        } else {
                            oldScale = Math.min(getContainerViewWidth() / (float) bitmapWidth, getContainerViewHeight() / (float) bitmapHeight);
                        }
                    }
                    animateToScale = newScale / oldScale;
                    animateToX = getLeftInset() / 2 - getRightInset() / 2;
                    animationStartTime = System.currentTimeMillis();
                    zoomAnimation = true;
                }
                imageMoveAnimation = new AnimatorSet();
                imageMoveAnimation.playTogether(ObjectAnimator.ofFloat(PhotoViewer.this, AnimationProperties.PHOTO_VIEWER_ANIMATION_VALUE, 0, 1), ObjectAnimator.ofFloat(photoFilterView.getToolsView(), View.TRANSLATION_Y, AndroidUtilities.dp(186), 0));
                imageMoveAnimation.setDuration(200);
                imageMoveAnimation.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationStart(Animator animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        photoFilterView.init();
                        imageMoveAnimation = null;
                        currentEditMode = mode;
                        switchingToMode = -1;
                        animateToScale = 1;
                        animateToX = 0;
                        animateToY = 0;
                        scale = 1;
                        updateMinMax(scale);
                        padImageForHorizontalInsets = true;
                        containerView.invalidate();
                    }
                });
                imageMoveAnimation.start();
            }
        });
        changeModeAnimation.start();
    } else if (mode == 3) {
        startVideoPlayer();
        createPaintView();
        changeModeAnimation = new AnimatorSet();
        ArrayList<Animator> arrayList = new ArrayList<>();
        arrayList.add(ObjectAnimator.ofFloat(pickerView, View.TRANSLATION_Y, AndroidUtilities.dp(isCurrentVideo ? 154 : 96)));
        arrayList.add(ObjectAnimator.ofFloat(pickerViewSendButton, View.TRANSLATION_Y, AndroidUtilities.dp(isCurrentVideo ? 154 : 96)));
        arrayList.add(ObjectAnimator.ofFloat(actionBar, View.TRANSLATION_Y, -actionBar.getHeight()));
        if (needCaptionLayout) {
            arrayList.add(ObjectAnimator.ofFloat(captionTextViewSwitcher, View.TRANSLATION_Y, AndroidUtilities.dp(isCurrentVideo ? 154 : 96)));
        }
        if (sendPhotoType == 0 || sendPhotoType == 4) {
            arrayList.add(ObjectAnimator.ofFloat(checkImageView, View.ALPHA, 1, 0));
            arrayList.add(ObjectAnimator.ofFloat(photosCounterView, View.ALPHA, 1, 0));
        } else if (sendPhotoType == SELECT_TYPE_AVATAR) {
            arrayList.add(ObjectAnimator.ofFloat(photoCropView, View.ALPHA, 1, 0));
        }
        if (selectedPhotosListView.getVisibility() == View.VISIBLE) {
            arrayList.add(ObjectAnimator.ofFloat(selectedPhotosListView, View.ALPHA, 1, 0));
        }
        if (cameraItem.getTag() != null) {
            arrayList.add(ObjectAnimator.ofFloat(cameraItem, View.ALPHA, 1, 0));
        }
        if (muteItem.getTag() != null) {
            arrayList.add(ObjectAnimator.ofFloat(muteItem, View.ALPHA, 1, 0));
        }
        changeModeAnimation.playTogether(arrayList);
        changeModeAnimation.setDuration(200);
        changeModeAnimation.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                switchToPaintMode();
            }
        });
        changeModeAnimation.start();
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) MediaController(org.telegram.messenger.MediaController) VideoEditTextureView(org.telegram.ui.Components.VideoEditTextureView) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) SpannableString(android.text.SpannableString) PhotoFilterView(org.telegram.ui.Components.PhotoFilterView) Bitmap(android.graphics.Bitmap) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) Animator(android.animation.Animator) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) ViewPropertyAnimator(android.view.ViewPropertyAnimator) UserObject(org.telegram.messenger.UserObject) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) ChatObject(org.telegram.messenger.ChatObject)

Example 9 with VideoEditTextureView

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

the class PhotoViewer method applyCurrentEditMode.

private void applyCurrentEditMode() {
    if (currentIndex < 0 || currentIndex >= imagesArrLocals.size()) {
        return;
    }
    Object object = imagesArrLocals.get(currentIndex);
    if (!(object instanceof MediaController.MediaEditState)) {
        return;
    }
    Bitmap bitmap = null;
    Bitmap[] paintThumbBitmap = new Bitmap[1];
    ArrayList<TLRPC.InputDocument> stickers = null;
    MediaController.SavedFilterState savedFilterState = null;
    ArrayList<VideoEditedInfo.MediaEntity> entities = null;
    int[] orientation = null;
    boolean hasChanged = false;
    MediaController.MediaEditState entry = (MediaController.MediaEditState) imagesArrLocals.get(currentIndex);
    if (currentEditMode == 1 || currentEditMode == 0 && sendPhotoType == SELECT_TYPE_AVATAR) {
        photoCropView.makeCrop(entry);
        if (entry.cropState == null) {
            return;
        }
        if (isCurrentVideo) {
            if (!TextUtils.isEmpty(entry.filterPath)) {
                bitmap = ImageLoader.loadBitmap(entry.filterPath, null, thumbSize, thumbSize, true);
            } else {
                if (sendPhotoType == SELECT_TYPE_AVATAR) {
                    orientation = new int[1];
                    bitmap = SendMessagesHelper.createVideoThumbnailAtTime(entry.getPath(), avatarStartTime / 1000, orientation, true);
                } else {
                    bitmap = SendMessagesHelper.createVideoThumbnailAtTime(entry.getPath(), (long) (videoTimelineView.getLeftProgress() * videoPlayer.getDuration() * 1000L));
                }
            }
        } else {
            bitmap = centerImage.getBitmap();
            orientation = new int[] { centerImage.getOrientation() };
        }
    } else if (currentEditMode == 2) {
        bitmap = photoFilterView.getBitmap();
        savedFilterState = photoFilterView.getSavedFilterState();
    } else if (currentEditMode == 3) {
        if (Build.VERSION.SDK_INT >= 18 && (sendPhotoType == 0 || sendPhotoType == SELECT_TYPE_AVATAR || sendPhotoType == 2)) {
            entities = new ArrayList<>();
        }
        hasChanged = photoPaintView.hasChanges();
        bitmap = photoPaintView.getBitmap(entities, paintThumbBitmap);
        stickers = photoPaintView.getMasks();
    }
    if (bitmap == null) {
        return;
    }
    if (entry.thumbPath != null) {
        new File(entry.thumbPath).delete();
        entry.thumbPath = null;
    }
    if (entry.imagePath != null) {
        new File(entry.imagePath).delete();
        entry.imagePath = null;
    }
    if (currentEditMode == 1 || currentEditMode == 0 && sendPhotoType == SELECT_TYPE_AVATAR) {
        editState.cropState = entry.cropState;
        editState.croppedPaintPath = entry.croppedPaintPath;
        editState.croppedMediaEntities = entry.croppedMediaEntities;
        Bitmap croppedBitmap = createCroppedBitmap(bitmap, entry.cropState, orientation, true);
        if (entry.paintPath != null) {
            Bitmap paintBitmap = BitmapFactory.decodeFile(entry.fullPaintPath);
            Bitmap croppedPaintBitmap = createCroppedBitmap(paintBitmap, entry.cropState, null, false);
            if (!isCurrentVideo) {
                if (hasAnimatedMediaEntities()) {
                    TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(croppedBitmap, Bitmap.CompressFormat.JPEG, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 87, false, 101, 101);
                    entry.imagePath = currentImagePath = FileLoader.getPathToAttach(size, true).toString();
                } else {
                    File f = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), SharedConfig.getLastLocalId() + "_temp.jpg");
                    mergeImages(entry.imagePath = f.getAbsolutePath(), null, croppedPaintBitmap, croppedBitmap, AndroidUtilities.getPhotoSize(), true);
                }
            }
            File f = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), SharedConfig.getLastLocalId() + "_temp.jpg");
            mergeImages(entry.thumbPath = f.getAbsolutePath(), null, croppedPaintBitmap, croppedBitmap, thumbSize, true);
            if (croppedPaintBitmap != null) {
                croppedPaintBitmap.recycle();
            }
            if (paintBitmap != null) {
                paintBitmap.recycle();
            }
        } else {
            if (!isCurrentVideo) {
                TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(croppedBitmap, Bitmap.CompressFormat.JPEG, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 87, false, 101, 101);
                entry.imagePath = currentImagePath = FileLoader.getPathToAttach(size, true).toString();
            }
            TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(croppedBitmap, thumbSize, thumbSize, 70, false, 101, 101);
            entry.thumbPath = FileLoader.getPathToAttach(size, true).toString();
        }
        if (currentEditMode == 0 && isCurrentVideo) {
            bitmap.recycle();
            bitmap = croppedBitmap;
        }
    } else if (currentEditMode == 2) {
        if (entry.filterPath != null) {
            new File(entry.filterPath).delete();
        }
        TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(bitmap, Bitmap.CompressFormat.JPEG, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 87, false, 101, 101);
        entry.filterPath = FileLoader.getPathToAttach(size, true).toString();
        Bitmap b = entry.cropState != null ? createCroppedBitmap(bitmap, entry.cropState, null, true) : bitmap;
        if (entry.paintPath == null) {
            if (!isCurrentVideo) {
                size = ImageLoader.scaleAndSaveImage(b, Bitmap.CompressFormat.JPEG, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 87, false, 101, 101);
                entry.imagePath = currentImagePath = FileLoader.getPathToAttach(size, true).toString();
            }
            size = ImageLoader.scaleAndSaveImage(b, Bitmap.CompressFormat.JPEG, thumbSize, thumbSize, 83, false, 101, 101);
            entry.thumbPath = FileLoader.getPathToAttach(size, true).toString();
        } else {
            String path = entry.fullPaintPath;
            Bitmap fullPaintBitmap = entry.paintPath.equals(entry.fullPaintPath) ? paintingOverlay.getThumb() : null;
            Bitmap paintBitmap;
            boolean recyclePaint;
            if (entry.cropState != null) {
                if (fullPaintBitmap == null) {
                    Bitmap b2 = BitmapFactory.decodeFile(entry.fullPaintPath);
                    paintBitmap = createCroppedBitmap(b2, entry.cropState, null, false);
                    b2.recycle();
                } else {
                    paintBitmap = createCroppedBitmap(fullPaintBitmap, entry.cropState, null, false);
                }
                recyclePaint = true;
            } else {
                paintBitmap = fullPaintBitmap;
                recyclePaint = false;
            }
            if (!isCurrentVideo) {
                if (hasAnimatedMediaEntities()) {
                    size = ImageLoader.scaleAndSaveImage(b, Bitmap.CompressFormat.JPEG, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 87, false, 101, 101);
                    entry.imagePath = currentImagePath = FileLoader.getPathToAttach(size, true).toString();
                } else {
                    File f = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), SharedConfig.getLastLocalId() + "_temp.jpg");
                    mergeImages(entry.imagePath = f.getAbsolutePath(), path, paintBitmap, b, AndroidUtilities.getPhotoSize(), true);
                }
            }
            File f = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), SharedConfig.getLastLocalId() + "_temp.jpg");
            mergeImages(entry.thumbPath = f.getAbsolutePath(), path, paintBitmap, b, thumbSize, true);
            if (recyclePaint) {
                paintBitmap.recycle();
            }
        }
        if (entry.cropState != null) {
            b.recycle();
        }
    } else if (currentEditMode == 3) {
        if (entry.paintPath != null) {
            new File(entry.paintPath).delete();
            if (!entry.paintPath.equals(entry.fullPaintPath)) {
                new File(entry.fullPaintPath).delete();
            }
        }
        TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(bitmap, Bitmap.CompressFormat.PNG, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 87, false, 101, 101);
        entry.stickers = stickers;
        entry.paintPath = editState.paintPath = FileLoader.getPathToAttach(size, true).toString();
        paintingOverlay.setEntities(entry.mediaEntities = editState.mediaEntities = entities == null || entities.isEmpty() ? null : entities, isCurrentVideo, true);
        entry.averageDuration = editState.averageDuration = photoPaintView.getLcm();
        if (entry.mediaEntities != null && paintThumbBitmap[0] != null) {
            size = ImageLoader.scaleAndSaveImage(paintThumbBitmap[0], Bitmap.CompressFormat.PNG, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 87, false, 101, 101);
            entry.fullPaintPath = FileLoader.getPathToAttach(size, true).toString();
        } else {
            entry.fullPaintPath = entry.paintPath;
        }
        paintingOverlay.setBitmap(bitmap);
        if (entry.cropState != null && entry.cropState.initied) {
            String path = CropView.getCopy(editState.paintPath);
            if (editState.croppedPaintPath != null) {
                new File(editState.croppedPaintPath).delete();
                editState.croppedPaintPath = null;
            }
            editState.croppedPaintPath = path;
            if (editState.mediaEntities != null && !editState.mediaEntities.isEmpty()) {
                editState.croppedMediaEntities = new ArrayList<>(editState.mediaEntities.size());
                for (int a = 0, N = editState.mediaEntities.size(); a < N; a++) {
                    editState.croppedMediaEntities.add(editState.mediaEntities.get(a).copy());
                }
            } else {
                editState.croppedMediaEntities = null;
            }
            Bitmap resultBitmap = Bitmap.createBitmap(entry.cropState.width, entry.cropState.height, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(resultBitmap);
            int w, h;
            if (isCurrentVideo) {
                VideoEditTextureView videoEditTextureView = (VideoEditTextureView) videoTextureView;
                w = videoEditTextureView.getVideoWidth();
                h = videoEditTextureView.getVideoHeight();
            } else {
                w = centerImage.getBitmapWidth();
                h = centerImage.getBitmapHeight();
            }
            CropView.editBitmap(parentActivity, path, null, canvas, resultBitmap, Bitmap.CompressFormat.PNG, entry.cropState.matrix, w, h, entry.cropState.stateScale, entry.cropState.cropRotate, entry.cropState.transformRotation, entry.cropState.scale, false, editState.croppedMediaEntities, false);
            resultBitmap.recycle();
            entry.croppedPaintPath = editState.croppedPaintPath;
            entry.croppedMediaEntities = editState.croppedMediaEntities;
        }
        boolean recycle = false;
        Bitmap fullPaintBitmap = paintThumbBitmap[0] != null ? paintThumbBitmap[0] : bitmap;
        Bitmap paintBitmap = fullPaintBitmap;
        if (entry.cropState != null && entry.cropState.initied) {
            paintBitmap = createCroppedBitmap(fullPaintBitmap, entry.cropState, null, false);
            recycle = true;
        }
        boolean recycleCropped;
        Bitmap croppedBitmap;
        if (isCurrentVideo) {
            Bitmap originalBitmap;
            if (entry.filterPath == null) {
                originalBitmap = SendMessagesHelper.createVideoThumbnailAtTime(entry.getPath(), (long) (videoTimelineView.getLeftProgress() * videoPlayer.getDuration() * 1000L));
            } else {
                originalBitmap = ImageLoader.loadBitmap(entry.filterPath, null, thumbSize, thumbSize, true);
            }
            croppedBitmap = entry.cropState != null ? createCroppedBitmap(originalBitmap, entry.cropState, null, true) : originalBitmap;
            if (entry.cropState != null) {
                originalBitmap.recycle();
            }
            recycleCropped = true;
        } else {
            orientation = new int[] { centerImage.getOrientation() };
            if (entry.cropState != null) {
                croppedBitmap = createCroppedBitmap(centerImage.getBitmap(), entry.cropState, orientation, true);
                recycleCropped = true;
            } else {
                croppedBitmap = centerImage.getBitmap();
                if (orientation[0] != 0) {
                    Matrix matrix = new Matrix();
                    matrix.postRotate(orientation[0]);
                    croppedBitmap = Bitmaps.createBitmap(croppedBitmap, 0, 0, croppedBitmap.getWidth(), croppedBitmap.getHeight(), matrix, true);
                    recycleCropped = true;
                } else {
                    recycleCropped = false;
                }
            }
        }
        if (!isCurrentVideo) {
            if (hasAnimatedMediaEntities()) {
                size = ImageLoader.scaleAndSaveImage(croppedBitmap, Bitmap.CompressFormat.JPEG, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 87, false, 101, 101);
                entry.imagePath = currentImagePath = FileLoader.getPathToAttach(size, true).toString();
            } else {
                File f = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), SharedConfig.getLastLocalId() + "_temp.jpg");
                mergeImages(entry.imagePath = f.getAbsolutePath(), null, croppedBitmap, paintBitmap, AndroidUtilities.getPhotoSize(), false);
            }
        }
        File f = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), SharedConfig.getLastLocalId() + "_temp.jpg");
        mergeImages(entry.thumbPath = f.getAbsolutePath(), null, croppedBitmap, paintBitmap, thumbSize, false);
        if (recycle && paintBitmap != null) {
            paintBitmap.recycle();
        }
        if (recycleCropped && croppedBitmap != null) {
            croppedBitmap.recycle();
        }
        if (sendPhotoType == SELECT_TYPE_AVATAR && videoPlayer != null && isCurrentVideo && getAnimatedMediaEntitiesCount(false) == 1 && videoTimelineView.getLeftProgress() <= 0.0f && videoTimelineView.getRightProgress() >= 1.0f) {
            long duration = entry.averageDuration;
            long videoDuration = videoPlayer.getDuration();
            while (duration < 3000 && duration < videoDuration) {
                duration += entry.averageDuration;
            }
            videoTimelineView.setRightProgress(Math.min(1.0f, duration / (float) videoDuration));
        }
    }
    SharedConfig.saveConfig();
    if (savedFilterState != null) {
        entry.savedFilterState = editState.savedFilterState = savedFilterState;
    }
    if (currentEditMode == 1) {
        entry.isCropped = true;
        cropItem.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogFloatingButton), PorterDuff.Mode.MULTIPLY));
    } else if (currentEditMode == 2) {
        entry.isFiltered = true;
        tuneItem.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogFloatingButton), PorterDuff.Mode.MULTIPLY));
    } else if (currentEditMode == 3) {
        if (hasChanged) {
            entry.isPainted = true;
            paintItem.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogFloatingButton), PorterDuff.Mode.MULTIPLY));
        }
    }
    if ((sendPhotoType == 0 || sendPhotoType == 4) && placeProvider != null) {
        placeProvider.updatePhotoAtIndex(currentIndex);
        if (!placeProvider.isPhotoChecked(currentIndex)) {
            setPhotoChecked();
        }
    }
    if (currentEditMode == 1) {
        float scaleX = photoCropView.getRectSizeX() / (float) getContainerViewWidth();
        float scaleY = photoCropView.getRectSizeY() / (float) getContainerViewHeight();
        scale = Math.max(scaleX, scaleY);
        translationX = photoCropView.getRectX() + photoCropView.getRectSizeX() / 2 - getContainerViewWidth() / 2;
        translationY = photoCropView.getRectY() + photoCropView.getRectSizeY() / 2 - getContainerViewHeight() / 2;
        zoomAnimation = true;
        applying = true;
        photoCropView.onDisappear();
    }
    centerImage.setParentView(null);
    ignoreDidSetImage = true;
    boolean setImage;
    if (isCurrentVideo) {
        setImage = currentEditMode == 1 || currentEditMode == 0 && sendPhotoType == SELECT_TYPE_AVATAR;
    } else {
        setImage = currentEditMode == 2;
    }
    if (setImage) {
        centerImage.setImageBitmap(bitmap);
        centerImage.setOrientation(0, true);
        containerView.requestLayout();
    }
    ignoreDidSetImage = false;
    centerImage.setParentView(containerView);
}
Also used : MediaController(org.telegram.messenger.MediaController) VideoEditTextureView(org.telegram.ui.Components.VideoEditTextureView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) SpannableString(android.text.SpannableString) TLRPC(org.telegram.tgnet.TLRPC) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) UserObject(org.telegram.messenger.UserObject) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) ChatObject(org.telegram.messenger.ChatObject) WebFile(org.telegram.messenger.WebFile) File(java.io.File)

Aggregations

SuppressLint (android.annotation.SuppressLint)9 Paint (android.graphics.Paint)9 TextPaint (android.text.TextPaint)9 VideoEditTextureView (org.telegram.ui.Components.VideoEditTextureView)9 Bitmap (android.graphics.Bitmap)6 MediaController (org.telegram.messenger.MediaController)6 MessageObject (org.telegram.messenger.MessageObject)6 ChatObject (org.telegram.messenger.ChatObject)5 DialogObject (org.telegram.messenger.DialogObject)5 UserObject (org.telegram.messenger.UserObject)5 TLObject (org.telegram.tgnet.TLObject)5 Animator (android.animation.Animator)4 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)4 ObjectAnimator (android.animation.ObjectAnimator)4 ValueAnimator (android.animation.ValueAnimator)4 ViewPropertyAnimator (android.view.ViewPropertyAnimator)4 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)4 AspectRatioFrameLayout (com.google.android.exoplayer2.ui.AspectRatioFrameLayout)4 TLRPC (org.telegram.tgnet.TLRPC)4 PhotoFilterView (org.telegram.ui.Components.PhotoFilterView)4