Search in sources :

Example 1 with VideoEditedInfo

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

the class ImageUpdater method openPhotoForEdit.

public void openPhotoForEdit(String path, String thumb, int orientation, boolean isVideo) {
    final ArrayList<Object> arrayList = new ArrayList<>();
    MediaController.PhotoEntry photoEntry = new MediaController.PhotoEntry(0, 0, 0, path, orientation, false, 0, 0, 0);
    photoEntry.isVideo = isVideo;
    photoEntry.thumbPath = thumb;
    arrayList.add(photoEntry);
    PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity());
    PhotoViewer.getInstance().openPhotoForSelect(arrayList, 0, PhotoViewer.SELECT_TYPE_AVATAR, false, new PhotoViewer.EmptyPhotoViewerProvider() {

        @Override
        public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
            String path = null;
            MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) arrayList.get(0);
            if (photoEntry.imagePath != null) {
                path = photoEntry.imagePath;
            } else if (photoEntry.path != null) {
                path = photoEntry.path;
            }
            MessageObject avatarObject = null;
            Bitmap bitmap;
            if (photoEntry.isVideo || photoEntry.editedInfo != 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 = 0;
                avatarObject = new MessageObject(UserConfig.selectedAccount, message, false, false);
                avatarObject.messageOwner.attachPath = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), SharedConfig.getLastLocalId() + "_avatar.mp4").getAbsolutePath();
                avatarObject.videoEditedInfo = photoEntry.editedInfo;
                bitmap = ImageLoader.loadBitmap(photoEntry.thumbPath, null, 800, 800, true);
            } else {
                bitmap = ImageLoader.loadBitmap(path, null, 800, 800, true);
            }
            processBitmap(bitmap, avatarObject);
        }

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

        @Override
        public boolean canScrollAway() {
            return false;
        }
    }, null);
}
Also used : MediaController(org.telegram.messenger.MediaController) ArrayList(java.util.ArrayList) PhotoViewer(org.telegram.ui.PhotoViewer) TLRPC(org.telegram.tgnet.TLRPC) Bitmap(android.graphics.Bitmap) MessageObject(org.telegram.messenger.MessageObject) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) MessageObject(org.telegram.messenger.MessageObject) File(java.io.File)

Example 2 with VideoEditedInfo

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

the class PhotoViewer method openCurrentPhotoInPaintModeForSelect.

private void openCurrentPhotoInPaintModeForSelect() {
    if (!canSendMediaToParentChatActivity()) {
        return;
    }
    File file = null;
    boolean isVideo = false;
    boolean capReplace = false;
    MessageObject messageObject = null;
    if (currentMessageObject != null) {
        messageObject = currentMessageObject;
        capReplace = currentMessageObject.canEditMedia() && !currentMessageObject.isDocument();
        isVideo = currentMessageObject.isVideo();
        if (!TextUtils.isEmpty(currentMessageObject.messageOwner.attachPath)) {
            file = new File(currentMessageObject.messageOwner.attachPath);
            if (!file.exists()) {
                file = null;
            }
        }
        if (file == null) {
            file = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
        }
    }
    if (file != null && file.exists()) {
        savedState = new SavedState(currentIndex, new ArrayList<>(imagesArr), placeProvider);
        final ActionBarToggleParams toggleParams = new ActionBarToggleParams().enableStatusBarAnimation(false);
        toggleActionBar(false, true, toggleParams);
        File finalFile = file;
        boolean finalIsVideo = isVideo;
        boolean finalCanReplace = capReplace;
        MessageObject finalMessageObject = messageObject;
        AndroidUtilities.runOnUIThread(() -> {
            int orientation = 0;
            try {
                ExifInterface ei = new ExifInterface(finalFile.getAbsolutePath());
                int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
                switch(exif) {
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        orientation = 90;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        orientation = 180;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        orientation = 270;
                        break;
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            final MediaController.PhotoEntry photoEntry = new MediaController.PhotoEntry(0, lastImageId--, 0, finalFile.getAbsolutePath(), orientation, finalIsVideo, 0, 0, 0);
            sendPhotoType = 2;
            doneButtonPressed = false;
            final PhotoViewerProvider chatPhotoProvider = placeProvider;
            placeProvider = new EmptyPhotoViewerProvider() {

                private final ImageReceiver.BitmapHolder thumbHolder = centerImage.getBitmapSafe();

                @Override
                public PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index, boolean needPreview) {
                    return chatPhotoProvider != null ? chatPhotoProvider.getPlaceForPhoto(finalMessageObject, null, 0, needPreview) : null;
                }

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

                @Override
                public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
                    sendMedia(videoEditedInfo, notify, scheduleDate, false, forceDocument);
                }

                @Override
                public void replaceButtonPressed(int index, VideoEditedInfo videoEditedInfo) {
                    if (photoEntry.isCropped || photoEntry.isPainted || photoEntry.isFiltered || videoEditedInfo != null || !TextUtils.isEmpty(photoEntry.caption)) {
                        sendMedia(videoEditedInfo, false, 0, true, false);
                    }
                }

                @Override
                public boolean canReplace(int index) {
                    return chatPhotoProvider != null && finalCanReplace;
                }

                @Override
                public MessageObject getEditingMessageObject() {
                    return finalMessageObject;
                }

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

                private void sendMedia(VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean replace, boolean forceDocument) {
                    if (parentChatActivity != null) {
                        final MessageObject editingMessageObject = replace ? finalMessageObject : null;
                        if (editingMessageObject != null && !TextUtils.isEmpty(photoEntry.caption)) {
                            editingMessageObject.editingMessage = photoEntry.caption;
                            editingMessageObject.editingMessageEntities = photoEntry.entities;
                        }
                        if (photoEntry.isVideo) {
                            if (videoEditedInfo != null) {
                                SendMessagesHelper.prepareSendingVideo(parentChatActivity.getAccountInstance(), photoEntry.path, videoEditedInfo, parentChatActivity.getDialogId(), parentChatActivity.getReplyMessage(), parentChatActivity.getThreadMessage(), photoEntry.caption, photoEntry.entities, photoEntry.ttl, editingMessageObject, notify, scheduleDate, forceDocument);
                            } else {
                                SendMessagesHelper.prepareSendingVideo(parentChatActivity.getAccountInstance(), photoEntry.path, null, parentChatActivity.getDialogId(), parentChatActivity.getReplyMessage(), parentChatActivity.getThreadMessage(), photoEntry.caption, photoEntry.entities, photoEntry.ttl, editingMessageObject, notify, scheduleDate, forceDocument);
                            }
                        } else {
                            if (photoEntry.imagePath != null) {
                                SendMessagesHelper.prepareSendingPhoto(parentChatActivity.getAccountInstance(), photoEntry.imagePath, photoEntry.thumbPath, null, parentChatActivity.getDialogId(), parentChatActivity.getReplyMessage(), parentChatActivity.getThreadMessage(), photoEntry.caption, photoEntry.entities, photoEntry.stickers, null, photoEntry.ttl, editingMessageObject, videoEditedInfo, notify, scheduleDate, forceDocument);
                            } else if (photoEntry.path != null) {
                                SendMessagesHelper.prepareSendingPhoto(parentChatActivity.getAccountInstance(), photoEntry.path, photoEntry.thumbPath, null, parentChatActivity.getDialogId(), parentChatActivity.getReplyMessage(), parentChatActivity.getThreadMessage(), photoEntry.caption, photoEntry.entities, photoEntry.stickers, null, photoEntry.ttl, editingMessageObject, videoEditedInfo, notify, scheduleDate, forceDocument);
                            }
                        }
                    }
                }
            };
            selectedPhotosAdapter.notifyDataSetChanged();
            if (velocityTracker == null) {
                velocityTracker = VelocityTracker.obtain();
            }
            togglePhotosListView(false, false);
            toggleActionBar(true, false);
            if (parentChatActivity != null && parentChatActivity.getChatActivityEnterView() != null && parentChatActivity.isKeyboardVisible()) {
                parentChatActivity.getChatActivityEnterView().closeKeyboard();
            } else {
                makeFocusable();
            }
            backgroundDrawable.setAlpha(255);
            containerView.setAlpha(1.0f);
            onPhotoShow(null, null, null, null, null, null, Collections.singletonList(photoEntry), 0, null);
            pickerView.setTranslationY(AndroidUtilities.dp(isCurrentVideo ? 154 : 96));
            pickerViewSendButton.setTranslationY(AndroidUtilities.dp(isCurrentVideo ? 154 : 96));
            actionBar.setTranslationY(-actionBar.getHeight());
            captionTextViewSwitcher.setTranslationY(AndroidUtilities.dp(isCurrentVideo ? 154 : 96));
            createPaintView();
            switchToPaintMode();
        }, toggleParams.animationDuration);
    } else {
        showDownloadAlert();
    }
}
Also used : MediaController(org.telegram.messenger.MediaController) ExifInterface(androidx.exifinterface.media.ExifInterface) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) ImageReceiver(org.telegram.messenger.ImageReceiver) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) WebFile(org.telegram.messenger.WebFile) File(java.io.File) MessageObject(org.telegram.messenger.MessageObject)

Example 3 with VideoEditedInfo

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

the class PhotoViewer method sendPressed.

private void sendPressed(boolean notify, int scheduleDate, boolean replace, boolean forceDocument) {
    if (captionEditText.getTag() != null) {
        return;
    }
    if (placeProvider != null && !doneButtonPressed) {
        if (sendPhotoType == SELECT_TYPE_AVATAR) {
            applyCurrentEditMode();
        }
        if (!replace && parentChatActivity != null) {
            TLRPC.Chat chat = parentChatActivity.getCurrentChat();
            TLRPC.User user = parentChatActivity.getCurrentUser();
            if (user != null || ChatObject.isChannel(chat) && chat.megagroup || !ChatObject.isChannel(chat)) {
                MessagesController.getNotificationsSettings(currentAccount).edit().putBoolean("silent_" + parentChatActivity.getDialogId(), !notify).commit();
            }
        }
        VideoEditedInfo videoEditedInfo = getCurrentVideoEditedInfo();
        if (!imagesArrLocals.isEmpty() && currentIndex >= 0 && currentIndex < imagesArrLocals.size()) {
            Object entry = imagesArrLocals.get(currentIndex);
            if (entry instanceof MediaController.MediaEditState) {
                ((MediaController.MediaEditState) entry).editedInfo = videoEditedInfo;
            }
        }
        doneButtonPressed = true;
        if (!replace) {
            placeProvider.sendButtonPressed(currentIndex, videoEditedInfo, notify, scheduleDate, forceDocument);
        } else {
            placeProvider.replaceButtonPressed(currentIndex, videoEditedInfo);
        }
        closePhoto(false, false);
    }
}
Also used : MediaController(org.telegram.messenger.MediaController) 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) TLRPC(org.telegram.tgnet.TLRPC)

Example 4 with VideoEditedInfo

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

the class ChatActivity method openPhotosEditor.

public boolean openPhotosEditor(ArrayList<SendMessagesHelper.SendingMediaInfo> photoPathes, CharSequence caption) {
    final ArrayList<MediaController.PhotoEntry> entries = new ArrayList<>();
    for (int a = 0; a < photoPathes.size(); ++a) {
        SendMessagesHelper.SendingMediaInfo photoInfo = photoPathes.get(a);
        String path;
        if (photoInfo.path != null) {
            path = photoInfo.path;
        } else if (photoInfo.uri != null) {
            path = AndroidUtilities.getPath(photoInfo.uri);
            if (path == null) {
                try {
                    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
                    InputStream inputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(photoInfo.uri);
                    Bitmap b = BitmapFactory.decodeStream(inputStream, null, bmOptions);
                    String fileName = Integer.MIN_VALUE + "_" + SharedConfig.getLastLocalId() + ".webp";
                    File fileDir = FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
                    final File cacheFile = new File(fileDir, fileName);
                    FileOutputStream stream = new FileOutputStream(cacheFile);
                    b.compress(Bitmap.CompressFormat.WEBP, 100, stream);
                    SharedConfig.saveConfig();
                    path = cacheFile.getPath();
                // path = Uri.fromFile(cacheFile);
                } catch (Exception e) {
                    continue;
                }
            }
        } else {
            continue;
        }
        int orientation = 0;
        try {
            ExifInterface ei = new ExifInterface(path);
            int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
            switch(exif) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    orientation = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    orientation = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    orientation = 270;
                    break;
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
        MediaController.PhotoEntry entry = new MediaController.PhotoEntry(0, 0, 0, path, orientation, photoInfo.isVideo, 0, 0, 0);
        if (a == photoPathes.size() - 1 && caption != null) {
            entry.caption = caption;
        }
        entries.add(entry);
    }
    if (entries.isEmpty()) {
        return false;
    }
    if (getParentActivity() != null) {
        final boolean[] checked = new boolean[entries.size()];
        Arrays.fill(checked, true);
        PhotoViewer.getInstance().setParentActivity(getParentActivity(), themeDelegate);
        PhotoViewer.getInstance().openPhotoForSelect(new ArrayList<>(entries), entries.size() - 1, 2, false, new PhotoViewer.EmptyPhotoViewerProvider() {

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

            @Override
            public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
                for (int i = entries.size() - 1; i >= 0; --i) {
                    if (!checked[i]) {
                        entries.remove(i);
                    }
                }
                sendPhotosGroup(entries, notify, scheduleDate, forceDocument);
            }

            @Override
            public int setPhotoChecked(int index, VideoEditedInfo videoEditedInfo) {
                return index;
            }

            @Override
            public boolean isPhotoChecked(int index) {
                return checked[index];
            }

            @Override
            public boolean canScrollAway() {
                return false;
            }
        }, this);
    } else {
        fillEditingMediaWithCaption(caption, null);
        sendPhotosGroup(entries, false, 0, false);
        afterMessageSend();
    }
    return true;
}
Also used : SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) MediaController(org.telegram.messenger.MediaController) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) TLRPC(org.telegram.tgnet.TLRPC) Bitmap(android.graphics.Bitmap) BitmapFactory(android.graphics.BitmapFactory) InputStream(java.io.InputStream) ExifInterface(androidx.exifinterface.media.ExifInterface) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) FileOutputStream(java.io.FileOutputStream) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) File(java.io.File) MessageObject(org.telegram.messenger.MessageObject)

Example 5 with VideoEditedInfo

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

the class ChatActivity method openVideoEditor.

public void openVideoEditor(String videoPath, String caption) {
    if (getParentActivity() != null) {
        final Bitmap thumb = SendMessagesHelper.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND);
        PhotoViewer.getInstance().setParentActivity(getParentActivity(), themeDelegate);
        final ArrayList<Object> cameraPhoto = new ArrayList<>();
        MediaController.PhotoEntry entry = new MediaController.PhotoEntry(0, 0, 0, videoPath, 0, true, 0, 0, 0);
        entry.caption = caption;
        cameraPhoto.add(entry);
        PhotoViewer.getInstance().openPhotoForSelect(cameraPhoto, 0, 0, false, new PhotoViewer.EmptyPhotoViewerProvider() {

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

            @Override
            public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
                sendMedia((MediaController.PhotoEntry) cameraPhoto.get(0), videoEditedInfo, notify, scheduleDate, forceDocument);
            }

            @Override
            public boolean canScrollAway() {
                return false;
            }
        }, this);
    } else {
        fillEditingMediaWithCaption(caption, null);
        SendMessagesHelper.prepareSendingVideo(getAccountInstance(), videoPath, null, dialog_id, replyingMessageObject, getThreadMessage(), null, null, 0, editingMessageObject, true, 0, false);
        afterMessageSend();
    }
}
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) ImageReceiver(org.telegram.messenger.ImageReceiver) Bitmap(android.graphics.Bitmap) 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)

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