Search in sources :

Example 6 with VideoEditedInfo

use of org.telegram.messenger.VideoEditedInfo in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatActivityEnterView method didReceivedNotification.

@SuppressWarnings("unchecked")
@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.emojiLoaded) {
        if (emojiView != null) {
            emojiView.invalidateViews();
        }
        if (botKeyboardView != null) {
            botKeyboardView.invalidateViews();
        }
        if (messageEditText != null) {
            messageEditText.postInvalidate();
        }
    } else if (id == NotificationCenter.recordProgressChanged) {
        int guid = (Integer) args[0];
        if (guid != recordingGuid) {
            return;
        }
        if (recordInterfaceState != 0 && !wasSendTyping && !isInScheduleMode()) {
            wasSendTyping = true;
            accountInstance.getMessagesController().sendTyping(dialog_id, getThreadMessageId(), videoSendButton != null && videoSendButton.getTag() != null ? 7 : 1, 0);
        }
        if (recordCircle != null) {
            recordCircle.setAmplitude((Double) args[1]);
        }
    } else if (id == NotificationCenter.closeChats) {
        if (messageEditText != null && messageEditText.isFocused()) {
            AndroidUtilities.hideKeyboard(messageEditText);
        }
    } else if (id == NotificationCenter.recordStartError || id == NotificationCenter.recordStopped) {
        int guid = (Integer) args[0];
        if (guid != recordingGuid) {
            return;
        }
        if (recordingAudioVideo) {
            recordingAudioVideo = false;
            if (id == NotificationCenter.recordStopped) {
                Integer reason = (Integer) args[1];
                int state;
                if (reason == 4) {
                    state = RECORD_STATE_CANCEL_BY_TIME;
                } else if (isInVideoMode() && reason == 5) {
                    state = RECORD_STATE_SENDING;
                } else {
                    if (reason == 0) {
                        state = RECORD_STATE_CANCEL_BY_GESTURE;
                    } else if (reason == 6) {
                        state = RECORD_STATE_CANCEL;
                    } else {
                        state = RECORD_STATE_PREPARING;
                    }
                }
                if (state != RECORD_STATE_PREPARING) {
                    updateRecordIntefrace(state);
                }
            } else {
                updateRecordIntefrace(RECORD_STATE_CANCEL);
            }
        }
        if (id == NotificationCenter.recordStopped) {
            Integer reason = (Integer) args[1];
        }
    } else if (id == NotificationCenter.recordStarted) {
        int guid = (Integer) args[0];
        if (guid != recordingGuid) {
            return;
        }
        boolean audio = (Boolean) args[1];
        if (videoSendButton != null) {
            videoSendButton.setTag(audio ? null : 1);
            videoSendButton.setVisibility(audio ? View.GONE : View.VISIBLE);
            videoSendButton.setVisibility(audio ? View.VISIBLE : View.GONE);
        }
        if (!recordingAudioVideo) {
            recordingAudioVideo = true;
            updateRecordIntefrace(RECORD_STATE_ENTER);
        } else {
            recordCircle.showWaves(true, true);
        }
        recordTimerView.start();
        recordDot.enterAnimation = false;
    } else if (id == NotificationCenter.audioDidSent) {
        int guid = (Integer) args[0];
        if (guid != recordingGuid) {
            return;
        }
        Object audio = args[1];
        if (audio instanceof VideoEditedInfo) {
            videoToSendMessageObject = (VideoEditedInfo) audio;
            audioToSendPath = (String) args[2];
            ArrayList<Bitmap> keyframes = (ArrayList<Bitmap>) args[3];
            videoTimelineView.setVideoPath(audioToSendPath);
            videoTimelineView.setKeyframes(keyframes);
            videoTimelineView.setVisibility(VISIBLE);
            videoTimelineView.setMinProgressDiff(1000.0f / videoToSendMessageObject.estimatedDuration);
            updateRecordIntefrace(RECORD_STATE_PREPARING);
            checkSendButton(false);
        } else {
            audioToSend = (TLRPC.TL_document) args[1];
            audioToSendPath = (String) args[2];
            if (audioToSend != null) {
                if (recordedAudioPanel == null) {
                    return;
                }
                TLRPC.TL_message message = new TLRPC.TL_message();
                message.out = true;
                message.id = 0;
                message.peer_id = new TLRPC.TL_peerUser();
                message.from_id = new TLRPC.TL_peerUser();
                message.peer_id.user_id = message.from_id.user_id = UserConfig.getInstance(currentAccount).getClientUserId();
                message.date = (int) (System.currentTimeMillis() / 1000);
                message.message = "";
                message.attachPath = audioToSendPath;
                message.media = new TLRPC.TL_messageMediaDocument();
                message.media.flags |= 3;
                message.media.document = audioToSend;
                message.flags |= TLRPC.MESSAGE_FLAG_HAS_MEDIA | TLRPC.MESSAGE_FLAG_HAS_FROM_ID;
                audioToSendMessageObject = new MessageObject(UserConfig.selectedAccount, message, false, true);
                recordedAudioPanel.setAlpha(1.0f);
                recordedAudioPanel.setVisibility(VISIBLE);
                recordDeleteImageView.setVisibility(VISIBLE);
                recordDeleteImageView.setAlpha(0f);
                recordDeleteImageView.setScaleY(0f);
                recordDeleteImageView.setScaleX(0f);
                int duration = 0;
                for (int a = 0; a < audioToSend.attributes.size(); a++) {
                    TLRPC.DocumentAttribute attribute = audioToSend.attributes.get(a);
                    if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                        duration = attribute.duration;
                        break;
                    }
                }
                for (int a = 0; a < audioToSend.attributes.size(); a++) {
                    TLRPC.DocumentAttribute attribute = audioToSend.attributes.get(a);
                    if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                        if (attribute.waveform == null || attribute.waveform.length == 0) {
                            attribute.waveform = MediaController.getInstance().getWaveform(audioToSendPath);
                        }
                        recordedAudioSeekBar.setWaveform(attribute.waveform);
                        break;
                    }
                }
                recordedAudioTimeTextView.setText(AndroidUtilities.formatShortDuration(duration));
                checkSendButton(false);
                updateRecordIntefrace(RECORD_STATE_PREPARING);
            } else {
                if (delegate != null) {
                    delegate.onMessageSend(null, true, 0);
                }
            }
        }
    } else if (id == NotificationCenter.audioRouteChanged) {
        if (parentActivity != null) {
            boolean frontSpeaker = (Boolean) args[0];
            parentActivity.setVolumeControlStream(frontSpeaker ? AudioManager.STREAM_VOICE_CALL : AudioManager.USE_DEFAULT_STREAM_TYPE);
        }
    } else if (id == NotificationCenter.messagePlayingDidReset) {
        if (audioToSendMessageObject != null && !MediaController.getInstance().isPlayingMessage(audioToSendMessageObject)) {
            playPauseDrawable.setIcon(MediaActionDrawable.ICON_PLAY, true);
            recordedAudioPlayButton.setContentDescription(LocaleController.getString("AccActionPlay", R.string.AccActionPlay));
            recordedAudioSeekBar.setProgress(0);
        }
    } else if (id == NotificationCenter.messagePlayingProgressDidChanged) {
        Integer mid = (Integer) args[0];
        if (audioToSendMessageObject != null && MediaController.getInstance().isPlayingMessage(audioToSendMessageObject)) {
            MessageObject player = MediaController.getInstance().getPlayingMessageObject();
            audioToSendMessageObject.audioProgress = player.audioProgress;
            audioToSendMessageObject.audioProgressSec = player.audioProgressSec;
            if (!recordedAudioSeekBar.isDragging()) {
                recordedAudioSeekBar.setProgress(audioToSendMessageObject.audioProgress);
            }
        }
    } else if (id == NotificationCenter.featuredStickersDidLoad) {
        if (emojiButton != null) {
            for (int a = 0; a < emojiButton.length; a++) {
                emojiButton[a].invalidate();
            }
        }
    } else if (id == NotificationCenter.messageReceivedByServer) {
        Boolean scheduled = (Boolean) args[6];
        if (scheduled) {
            return;
        }
        long did = (Long) args[3];
        if (did == dialog_id && info != null && info.slowmode_seconds != 0) {
            TLRPC.Chat chat = accountInstance.getMessagesController().getChat(info.id);
            if (chat != null && !ChatObject.hasAdminRights(chat)) {
                info.slowmode_next_send_date = ConnectionsManager.getInstance(currentAccount).getCurrentTime() + info.slowmode_seconds;
                info.flags |= 262144;
                setSlowModeTimer(info.slowmode_next_send_date);
            }
        }
    } else if (id == NotificationCenter.sendingMessagesChanged) {
        if (info != null) {
            updateSlowModeText();
        }
    } else if (id == NotificationCenter.audioRecordTooShort) {
        updateRecordIntefrace(RECORD_STATE_CANCEL_BY_TIME);
    }
}
Also used : ArrayList(java.util.ArrayList) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) Bitmap(android.graphics.Bitmap) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) MessageObject(org.telegram.messenger.MessageObject)

Example 7 with VideoEditedInfo

use of org.telegram.messenger.VideoEditedInfo in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatActivity method openEditingMessageInPhotoEditor.

private void openEditingMessageInPhotoEditor() {
    if (editingMessageObject == null || !editingMessageObject.canEditMedia() || editingMessageObjectReqId != 0) {
        return;
    }
    if (!editingMessageObject.isPhoto() && !editingMessageObject.isVideo()) {
        return;
    }
    final MessageObject object = editingMessageObject;
    File file = null;
    if (!TextUtils.isEmpty(object.messageOwner.attachPath)) {
        file = new File(object.messageOwner.attachPath);
        if (!file.exists()) {
            file = null;
        }
    }
    if (file == null) {
        file = FileLoader.getPathToMessage(object.messageOwner);
    }
    if (!file.exists()) {
        return;
    }
    PhotoViewer.getInstance().setParentActivity(getParentActivity(), themeDelegate);
    final ArrayList<Object> photos = new ArrayList<>();
    final MediaController.PhotoEntry entry = new MediaController.PhotoEntry(0, 0, 0, file.getAbsolutePath(), 0, object.isVideo(), 0, 0, 0);
    entry.caption = chatActivityEnterView.getFieldText();
    photos.add(entry);
    PhotoViewer.getInstance().openPhotoForSelect(photos, 0, 2, false, new PhotoViewer.EmptyPhotoViewerProvider() {

        @Override
        public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index, boolean needPreview) {
            return ChatActivity.this.getPlaceForPhoto(object, null, needPreview, true);
        }

        @Override
        public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
            if (editingMessageObject != object) {
                return;
            }
            if (entry.isCropped || entry.isPainted || entry.isFiltered || videoEditedInfo != null) {
                sendMedia(entry, videoEditedInfo, notify, scheduleDate, forceDocument);
            } else {
                chatActivityEnterView.doneEditingMessage();
            }
        }

        @Override
        public boolean canCaptureMorePhotos() {
            return false;
        }

        @Override
        public boolean allowSendingSubmenu() {
            return false;
        }

        @Override
        public MessageObject getEditingMessageObject() {
            return editingMessageObject == object ? object : null;
        }

        @Override
        public void onCaptionChanged(CharSequence caption) {
            if (editingMessageObject == object) {
                chatActivityEnterView.setFieldText(caption, true);
            }
        }

        @Override
        public boolean closeKeyboard() {
            if (chatActivityEnterView != null && isKeyboardVisible()) {
                chatActivityEnterView.closeKeyboard();
                return true;
            }
            return false;
        }
    }, this);
}
Also used : MediaController(org.telegram.messenger.MediaController) ArrayList(java.util.ArrayList) TLRPC(org.telegram.tgnet.TLRPC) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) 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) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) MessageObject(org.telegram.messenger.MessageObject) File(java.io.File)

Example 8 with VideoEditedInfo

use of org.telegram.messenger.VideoEditedInfo in project Telegram-FOSS by Telegram-FOSS-Team.

the class PhotoViewer method requestVideoPreview.

private void requestVideoPreview(int request) {
    if (videoPreviewMessageObject != null) {
        MediaController.getInstance().cancelVideoConvert(videoPreviewMessageObject);
    }
    boolean wasRequestingPreview = requestingPreview && !tryStartRequestPreviewOnFinish;
    requestingPreview = false;
    loadInitialVideo = false;
    progressView.setVisibility(View.INVISIBLE);
    if (request == 1) {
        if (resultHeight == originalHeight && resultWidth == originalWidth) {
            tryStartRequestPreviewOnFinish = false;
            photoProgressViews[0].setProgress(0, photoProgressViews[0].backgroundState == 0 || photoProgressViews[0].previousBackgroundState == 0);
            photoProgressViews[0].setBackgroundState(PROGRESS_PLAY, false, true);
            if (!wasRequestingPreview) {
                preparePlayer(currentPlayingVideoFile, false, false, editState.savedFilterState);
                videoPlayer.seekTo((long) (videoTimelineView.getLeftProgress() * videoDuration));
            } else {
                loadInitialVideo = true;
            }
        } else {
            releasePlayer(false);
            if (videoPreviewMessageObject == null) {
                TLRPC.TL_message message = new TLRPC.TL_message();
                message.id = 0;
                message.message = "";
                message.media = new TLRPC.TL_messageMediaEmpty();
                message.action = new TLRPC.TL_messageActionEmpty();
                message.dialog_id = currentDialogId;
                videoPreviewMessageObject = new MessageObject(UserConfig.selectedAccount, message, false, false);
                videoPreviewMessageObject.messageOwner.attachPath = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), "video_preview.mp4").getAbsolutePath();
                videoPreviewMessageObject.videoEditedInfo = new VideoEditedInfo();
                videoPreviewMessageObject.videoEditedInfo.rotationValue = rotationValue;
                videoPreviewMessageObject.videoEditedInfo.originalWidth = originalWidth;
                videoPreviewMessageObject.videoEditedInfo.originalHeight = originalHeight;
                videoPreviewMessageObject.videoEditedInfo.framerate = videoFramerate;
                videoPreviewMessageObject.videoEditedInfo.originalPath = currentPlayingVideoFile.getPath();
            }
            long start = videoPreviewMessageObject.videoEditedInfo.startTime = startTime;
            long end = videoPreviewMessageObject.videoEditedInfo.endTime = endTime;
            if (start == -1) {
                start = 0;
            }
            if (end == -1) {
                end = (long) (videoDuration * 1000);
            }
            if (end - start > 5000000) {
                videoPreviewMessageObject.videoEditedInfo.endTime = start + 5000000;
            }
            videoPreviewMessageObject.videoEditedInfo.bitrate = bitrate;
            videoPreviewMessageObject.videoEditedInfo.resultWidth = resultWidth;
            videoPreviewMessageObject.videoEditedInfo.resultHeight = resultHeight;
            videoPreviewMessageObject.videoEditedInfo.needUpdateProgress = true;
            videoPreviewMessageObject.videoEditedInfo.originalDuration = (long) (videoDuration * 1000);
            if (!MediaController.getInstance().scheduleVideoConvert(videoPreviewMessageObject, true)) {
                tryStartRequestPreviewOnFinish = true;
            }
            requestingPreview = true;
            photoProgressViews[0].setProgress(0, photoProgressViews[0].backgroundState == 0 || photoProgressViews[0].previousBackgroundState == 0);
            photoProgressViews[0].setBackgroundState(PROGRESS_EMPTY, false, true);
        }
    } else {
        tryStartRequestPreviewOnFinish = false;
        photoProgressViews[0].setBackgroundState(PROGRESS_PLAY, false, true);
        if (request == 2) {
            preparePlayer(currentPlayingVideoFile, false, false, editState.savedFilterState);
            videoPlayer.seekTo((long) (videoTimelineView.getLeftProgress() * videoDuration));
        }
    }
    containerView.invalidate();
}
Also used : VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) MessageObject(org.telegram.messenger.MessageObject) WebFile(org.telegram.messenger.WebFile) File(java.io.File) TLRPC(org.telegram.tgnet.TLRPC)

Example 9 with VideoEditedInfo

use of org.telegram.messenger.VideoEditedInfo in project Telegram-FOSS by Telegram-FOSS-Team.

the class PhotoViewer method getCurrentVideoEditedInfo.

private VideoEditedInfo getCurrentVideoEditedInfo() {
    if (!isCurrentVideo && hasAnimatedMediaEntities() && centerImage.getBitmapWidth() > 0) {
        float maxSize = sendPhotoType == SELECT_TYPE_AVATAR ? 800 : 854;
        VideoEditedInfo videoEditedInfo = new VideoEditedInfo();
        videoEditedInfo.start = videoEditedInfo.startTime = 0;
        videoEditedInfo.endTime = Math.min(3000, editState.averageDuration);
        while (videoEditedInfo.endTime > 0 && videoEditedInfo.endTime < 1000) {
            videoEditedInfo.endTime *= 2;
        }
        videoEditedInfo.end = videoEditedInfo.endTime;
        videoEditedInfo.rotationValue = 0;
        videoEditedInfo.originalPath = currentImagePath;
        videoEditedInfo.estimatedSize = (int) (videoEditedInfo.endTime / 1000.0f * 115200);
        videoEditedInfo.estimatedDuration = videoEditedInfo.endTime;
        videoEditedInfo.framerate = 30;
        videoEditedInfo.originalDuration = videoEditedInfo.endTime;
        videoEditedInfo.filterState = editState.savedFilterState;
        if (editState.croppedPaintPath != null) {
            videoEditedInfo.paintPath = editState.croppedPaintPath;
            videoEditedInfo.mediaEntities = editState.croppedMediaEntities != null && !editState.croppedMediaEntities.isEmpty() ? editState.croppedMediaEntities : null;
        } else {
            videoEditedInfo.paintPath = editState.paintPath;
            videoEditedInfo.mediaEntities = editState.mediaEntities;
        }
        videoEditedInfo.isPhoto = true;
        int width = centerImage.getBitmapWidth();
        int height = centerImage.getBitmapHeight();
        if (editState.cropState != null) {
            if (editState.cropState.transformRotation == 90 || editState.cropState.transformRotation == 270) {
                int temp = width;
                width = height;
                height = temp;
            }
            width *= editState.cropState.cropPw;
            height *= editState.cropState.cropPh;
        }
        if (sendPhotoType == SELECT_TYPE_AVATAR) {
            width = height;
        }
        float scale = Math.max(width / maxSize, height / maxSize);
        if (scale < 1) {
            scale = 1;
        }
        width /= scale;
        height /= scale;
        if (width % 16 != 0) {
            width = Math.max(1, Math.round(width / 16.0f)) * 16;
        }
        if (height % 16 != 0) {
            height = Math.max(1, Math.round(height / 16.0f)) * 16;
        }
        videoEditedInfo.originalWidth = videoEditedInfo.resultWidth = width;
        videoEditedInfo.originalHeight = videoEditedInfo.resultHeight = height;
        videoEditedInfo.bitrate = -1;
        videoEditedInfo.muted = true;
        videoEditedInfo.avatarStartTime = 0;
        return videoEditedInfo;
    }
    if (!isCurrentVideo || currentPlayingVideoFile == null || compressionsCount == 0) {
        return null;
    }
    VideoEditedInfo videoEditedInfo = new VideoEditedInfo();
    videoEditedInfo.startTime = startTime;
    videoEditedInfo.endTime = endTime;
    videoEditedInfo.start = videoCutStart;
    videoEditedInfo.end = videoCutEnd;
    videoEditedInfo.rotationValue = rotationValue;
    videoEditedInfo.originalWidth = originalWidth;
    videoEditedInfo.originalHeight = originalHeight;
    videoEditedInfo.bitrate = bitrate;
    videoEditedInfo.originalPath = currentPathObject;
    videoEditedInfo.estimatedSize = estimatedSize != 0 ? estimatedSize : 1;
    videoEditedInfo.estimatedDuration = estimatedDuration;
    videoEditedInfo.framerate = videoFramerate;
    videoEditedInfo.originalDuration = (long) (videoDuration * 1000);
    videoEditedInfo.filterState = editState.savedFilterState;
    if (editState.croppedPaintPath != null) {
        videoEditedInfo.paintPath = editState.croppedPaintPath;
        videoEditedInfo.mediaEntities = editState.croppedMediaEntities != null && !editState.croppedMediaEntities.isEmpty() ? editState.croppedMediaEntities : null;
    } else {
        videoEditedInfo.paintPath = editState.paintPath;
        videoEditedInfo.mediaEntities = editState.mediaEntities != null && !editState.mediaEntities.isEmpty() ? editState.mediaEntities : null;
    }
    if (sendPhotoType != SELECT_TYPE_AVATAR && !muteVideo && (compressItem.getTag() == null || (videoEditedInfo.resultWidth == originalWidth && videoEditedInfo.resultHeight == originalHeight))) {
        videoEditedInfo.resultWidth = originalWidth;
        videoEditedInfo.resultHeight = originalHeight;
        videoEditedInfo.bitrate = muteVideo ? -1 : originalBitrate;
    } else {
        if (muteVideo || sendPhotoType == SELECT_TYPE_AVATAR) {
            selectedCompression = 1;
            updateWidthHeightBitrateForCompression();
        }
        videoEditedInfo.resultWidth = resultWidth;
        videoEditedInfo.resultHeight = resultHeight;
        videoEditedInfo.bitrate = muteVideo || sendPhotoType == SELECT_TYPE_AVATAR ? -1 : bitrate;
    }
    videoEditedInfo.cropState = editState.cropState;
    if (videoEditedInfo.cropState != null) {
        videoEditedInfo.rotationValue += videoEditedInfo.cropState.transformRotation;
        while (videoEditedInfo.rotationValue >= 360) {
            videoEditedInfo.rotationValue -= 360;
        }
        if (videoEditedInfo.rotationValue == 90 || videoEditedInfo.rotationValue == 270) {
            videoEditedInfo.cropState.transformWidth = (int) (videoEditedInfo.resultWidth * videoEditedInfo.cropState.cropPh);
            videoEditedInfo.cropState.transformHeight = (int) (videoEditedInfo.resultHeight * videoEditedInfo.cropState.cropPw);
        } else {
            videoEditedInfo.cropState.transformWidth = (int) (videoEditedInfo.resultWidth * videoEditedInfo.cropState.cropPw);
            videoEditedInfo.cropState.transformHeight = (int) (videoEditedInfo.resultHeight * videoEditedInfo.cropState.cropPh);
        }
        if (sendPhotoType == SELECT_TYPE_AVATAR) {
            if (videoEditedInfo.cropState.transformWidth > 800) {
                videoEditedInfo.cropState.transformWidth = 800;
            }
            if (videoEditedInfo.cropState.transformHeight > 800) {
                videoEditedInfo.cropState.transformHeight = 800;
            }
            videoEditedInfo.cropState.transformWidth = videoEditedInfo.cropState.transformHeight = Math.min(videoEditedInfo.cropState.transformWidth, videoEditedInfo.cropState.transformHeight);
        }
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("original transformed w = " + videoEditedInfo.cropState.transformWidth + " h = " + videoEditedInfo.cropState.transformHeight + " r = " + videoEditedInfo.rotationValue);
        }
        int[] fixedSize = fixVideoWidthHeight(videoEditedInfo.cropState.transformWidth, videoEditedInfo.cropState.transformHeight);
        videoEditedInfo.cropState.transformWidth = fixedSize[0];
        videoEditedInfo.cropState.transformHeight = fixedSize[1];
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("fixed transformed w = " + videoEditedInfo.cropState.transformWidth + " h = " + videoEditedInfo.cropState.transformHeight);
        }
    }
    if (sendPhotoType == SELECT_TYPE_AVATAR) {
        videoEditedInfo.avatarStartTime = avatarStartTime;
        videoEditedInfo.originalBitrate = originalBitrate;
    }
    videoEditedInfo.muted = muteVideo || sendPhotoType == SELECT_TYPE_AVATAR;
    return videoEditedInfo;
}
Also used : VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Example 10 with VideoEditedInfo

use of org.telegram.messenger.VideoEditedInfo in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatAttachAlertPhotoLayout method openPhotoViewer.

private void openPhotoViewer(MediaController.PhotoEntry entry, final boolean sameTakePictureOrientation, boolean external) {
    if (entry != null) {
        cameraPhotos.add(entry);
        selectedPhotos.put(entry.imageId, entry);
        selectedPhotosOrder.add(entry.imageId);
        parentAlert.updateCountButton(0);
        adapter.notifyDataSetChanged();
        cameraAttachAdapter.notifyDataSetChanged();
    }
    if (entry != null && !external && cameraPhotos.size() > 1) {
        updatePhotosCounter(false);
        if (cameraView != null) {
            zoomControlView.setZoom(0.0f, false);
            cameraZoom = 0.0f;
            cameraView.setZoom(0.0f);
            CameraController.getInstance().startPreview(cameraView.getCameraSession());
        }
        return;
    }
    if (cameraPhotos.isEmpty()) {
        return;
    }
    cancelTakingPhotos = true;
    PhotoViewer.getInstance().setParentActivity(parentAlert.baseFragment.getParentActivity(), resourcesProvider);
    PhotoViewer.getInstance().setParentAlert(parentAlert);
    PhotoViewer.getInstance().setMaxSelectedPhotos(parentAlert.maxSelectedPhotos, parentAlert.allowOrder);
    ChatActivity chatActivity;
    int type;
    if (parentAlert.avatarPicker != 0) {
        type = PhotoViewer.SELECT_TYPE_AVATAR;
        chatActivity = null;
    } else if (parentAlert.baseFragment instanceof ChatActivity) {
        chatActivity = (ChatActivity) parentAlert.baseFragment;
        type = 2;
    } else {
        chatActivity = null;
        type = 5;
    }
    ArrayList<Object> arrayList;
    int index;
    if (parentAlert.avatarPicker != 0) {
        arrayList = new ArrayList<>();
        arrayList.add(entry);
        index = 0;
    } else {
        arrayList = getAllPhotosArray();
        index = cameraPhotos.size() - 1;
    }
    PhotoViewer.getInstance().openPhotoForSelect(arrayList, index, type, false, new BasePhotoProvider() {

        @Override
        public ImageReceiver.BitmapHolder getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
            return null;
        }

        @Override
        public boolean cancelButtonPressed() {
            if (cameraOpened && cameraView != null) {
                AndroidUtilities.runOnUIThread(() -> {
                    if (cameraView != null && !parentAlert.isDismissed() && Build.VERSION.SDK_INT >= 21) {
                        cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN);
                    }
                }, 1000);
                zoomControlView.setZoom(0.0f, false);
                cameraZoom = 0.0f;
                cameraView.setZoom(0.0f);
                CameraController.getInstance().startPreview(cameraView.getCameraSession());
            }
            if (cancelTakingPhotos && cameraPhotos.size() == 1) {
                for (int a = 0, size = cameraPhotos.size(); a < size; a++) {
                    MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) cameraPhotos.get(a);
                    new File(photoEntry.path).delete();
                    if (photoEntry.imagePath != null) {
                        new File(photoEntry.imagePath).delete();
                    }
                    if (photoEntry.thumbPath != null) {
                        new File(photoEntry.thumbPath).delete();
                    }
                }
                cameraPhotos.clear();
                selectedPhotosOrder.clear();
                selectedPhotos.clear();
                counterTextView.setVisibility(View.INVISIBLE);
                cameraPhotoRecyclerView.setVisibility(View.GONE);
                adapter.notifyDataSetChanged();
                cameraAttachAdapter.notifyDataSetChanged();
                parentAlert.updateCountButton(0);
            }
            return true;
        }

        @Override
        public void needAddMorePhotos() {
            cancelTakingPhotos = false;
            if (mediaFromExternalCamera) {
                parentAlert.delegate.didPressedButton(0, true, true, 0, false);
                return;
            }
            if (!cameraOpened) {
                openCamera(false);
            }
            counterTextView.setVisibility(View.VISIBLE);
            cameraPhotoRecyclerView.setVisibility(View.VISIBLE);
            counterTextView.setAlpha(1.0f);
            updatePhotosCounter(false);
        }

        @Override
        public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
            if (cameraPhotos.isEmpty() || parentAlert.baseFragment == null) {
                return;
            }
            if (videoEditedInfo != null && index >= 0 && index < cameraPhotos.size()) {
                MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) cameraPhotos.get(index);
                photoEntry.editedInfo = videoEditedInfo;
            }
            if (!(parentAlert.baseFragment instanceof ChatActivity) || !((ChatActivity) parentAlert.baseFragment).isSecretChat()) {
                for (int a = 0, size = cameraPhotos.size(); a < size; a++) {
                    AndroidUtilities.addMediaToGallery(((MediaController.PhotoEntry) cameraPhotos.get(a)).path);
                }
            }
            parentAlert.applyCaption();
            closeCamera(false);
            parentAlert.delegate.didPressedButton(forceDocument ? 4 : 8, true, notify, scheduleDate, forceDocument);
            cameraPhotos.clear();
            selectedPhotosOrder.clear();
            selectedPhotos.clear();
            adapter.notifyDataSetChanged();
            cameraAttachAdapter.notifyDataSetChanged();
            parentAlert.dismiss();
        }

        @Override
        public boolean scaleToFill() {
            if (parentAlert.baseFragment == null || parentAlert.baseFragment.getParentActivity() == null) {
                return false;
            }
            int locked = Settings.System.getInt(parentAlert.baseFragment.getParentActivity().getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
            return sameTakePictureOrientation || locked == 1;
        }

        @Override
        public void willHidePhotoViewer() {
            int count = gridView.getChildCount();
            for (int a = 0; a < count; a++) {
                View view = gridView.getChildAt(a);
                if (view instanceof PhotoAttachPhotoCell) {
                    PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
                    cell.showImage();
                    cell.showCheck(true);
                }
            }
        }

        @Override
        public boolean canScrollAway() {
            return false;
        }

        @Override
        public boolean canCaptureMorePhotos() {
            return parentAlert.maxSelectedPhotos != 1;
        }
    }, chatActivity);
}
Also used : MediaController(org.telegram.messenger.MediaController) ChatActivity(org.telegram.ui.ChatActivity) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) TextureView(android.view.TextureView) CameraView(org.telegram.messenger.camera.CameraView) Paint(android.graphics.Paint) TLRPC(org.telegram.tgnet.TLRPC) PhotoAttachPhotoCell(org.telegram.ui.Cells.PhotoAttachPhotoCell) MessageObject(org.telegram.messenger.MessageObject) ChatObject(org.telegram.messenger.ChatObject) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) MessageObject(org.telegram.messenger.MessageObject) File(java.io.File)

Aggregations

VideoEditedInfo (org.telegram.messenger.VideoEditedInfo)10 MessageObject (org.telegram.messenger.MessageObject)9 TLRPC (org.telegram.tgnet.TLRPC)9 Paint (android.graphics.Paint)7 MediaController (org.telegram.messenger.MediaController)7 SuppressLint (android.annotation.SuppressLint)6 TextPaint (android.text.TextPaint)6 File (java.io.File)6 ArrayList (java.util.ArrayList)6 ChatObject (org.telegram.messenger.ChatObject)5 Bitmap (android.graphics.Bitmap)4 DialogObject (org.telegram.messenger.DialogObject)4 UserObject (org.telegram.messenger.UserObject)4 TLObject (org.telegram.tgnet.TLObject)3 TextSelectionHint (org.telegram.ui.Components.TextSelectionHint)3 ExifInterface (androidx.exifinterface.media.ExifInterface)2 ImageReceiver (org.telegram.messenger.ImageReceiver)2 WebFile (org.telegram.messenger.WebFile)2 BitmapFactory (android.graphics.BitmapFactory)1 SpannableString (android.text.SpannableString)1