Search in sources :

Example 1 with PhotoFilterView

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

the class PhotoViewer method updateColors.

public void updateColors() {
    int color = getThemedColor(Theme.key_dialogFloatingButton);
    if (pickerViewSendButton != null) {
        Drawable drawable = pickerViewSendButton.getBackground();
        Theme.setSelectorDrawableColor(drawable, color, false);
        Theme.setSelectorDrawableColor(drawable, getThemedColor(Build.VERSION.SDK_INT >= 21 ? Theme.key_dialogFloatingButtonPressed : Theme.key_dialogFloatingButton), true);
        pickerViewSendButton.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogFloatingIcon), PorterDuff.Mode.MULTIPLY));
    }
    if (checkImageView != null) {
        checkImageView.setColor(getThemedColor(Theme.key_dialogFloatingButton), 0xffffffff);
    }
    PorterDuffColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY);
    if (timeItem != null && timeItem.getColorFilter() != null) {
        timeItem.setColorFilter(filter);
    }
    if (paintItem != null && paintItem.getColorFilter() != null) {
        paintItem.setColorFilter(filter);
    }
    if (cropItem != null && cropItem.getColorFilter() != null) {
        cropItem.setColorFilter(filter);
    }
    if (tuneItem != null && tuneItem.getColorFilter() != null) {
        tuneItem.setColorFilter(filter);
    }
    if (rotateItem != null && rotateItem.getColorFilter() != null) {
        rotateItem.setColorFilter(filter);
    }
    if (mirrorItem != null && mirrorItem.getColorFilter() != null) {
        mirrorItem.setColorFilter(filter);
    }
    if (editorDoneLayout != null) {
        editorDoneLayout.doneButton.setTextColor(color);
    }
    if (qualityPicker != null) {
        qualityPicker.doneButton.setTextColor(color);
    }
    if (photoPaintView != null) {
        photoPaintView.updateColors();
    }
    if (photoFilterView != null) {
        photoFilterView.updateColors();
    }
    if (captionEditText != null) {
        captionEditText.updateColors();
    }
    if (videoTimelineView != null) {
        videoTimelineView.invalidate();
    }
    if (selectedPhotosListView != null) {
        int count = selectedPhotosListView.getChildCount();
        for (int a = 0; a < count; a++) {
            View view = selectedPhotosListView.getChildAt(a);
            if (view instanceof PhotoPickerPhotoCell) {
                ((PhotoPickerPhotoCell) view).updateColors();
            }
        }
    }
    if (masksAlert != null) {
        masksAlert.updateColors(true);
    }
}
Also used : PhotoPickerPhotoCell(org.telegram.ui.Cells.PhotoPickerPhotoCell) AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) VideoForwardDrawable(org.telegram.ui.Components.VideoForwardDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) OtherDocumentPlaceholderDrawable(org.telegram.ui.Components.OtherDocumentPlaceholderDrawable) PlayPauseDrawable(org.telegram.ui.Components.PlayPauseDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) PhotoCropView(org.telegram.ui.Components.PhotoCropView) PhotoViewerWebView(org.telegram.ui.Components.PhotoViewerWebView) CropView(org.telegram.ui.Components.Crop.CropView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) SpoilersTextView(org.telegram.ui.Components.spoilers.SpoilersTextView) NestedScrollView(androidx.core.widget.NestedScrollView) RecyclerView(androidx.recyclerview.widget.RecyclerView) PipVideoView(org.telegram.ui.Components.PipVideoView) BackupImageView(org.telegram.ui.Components.BackupImageView) TextureView(android.view.TextureView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) PhotoViewerCaptionEnterView(org.telegram.ui.Components.PhotoViewerCaptionEnterView) UndoView(org.telegram.ui.Components.UndoView) VideoEditTextureView(org.telegram.ui.Components.VideoEditTextureView) GroupedPhotosListView(org.telegram.ui.Components.GroupedPhotosListView) PhotoPaintView(org.telegram.ui.Components.PhotoPaintView) ClippingImageView(org.telegram.ui.Components.ClippingImageView) View(android.view.View) TextView(android.widget.TextView) VideoTimelinePlayView(org.telegram.ui.Components.VideoTimelinePlayView) PhotoFilterView(org.telegram.ui.Components.PhotoFilterView) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Example 2 with PhotoFilterView

use of org.telegram.ui.Components.PhotoFilterView 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)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 Paint (android.graphics.Paint)2 TextPaint (android.text.TextPaint)2 PhotoFilterView (org.telegram.ui.Components.PhotoFilterView)2 VideoEditTextureView (org.telegram.ui.Components.VideoEditTextureView)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 Bitmap (android.graphics.Bitmap)1 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextureView (android.view.TextureView)1 View (android.view.View)1