Search in sources :

Example 6 with CameraView

use of org.telegram.messenger.camera.CameraView 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

Paint (android.graphics.Paint)6 View (android.view.View)6 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 CameraView (org.telegram.messenger.camera.CameraView)6 TextureView (android.view.TextureView)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 PhotoAttachCameraCell (org.telegram.ui.Cells.PhotoAttachCameraCell)4 Animator (android.animation.Animator)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 AnimatorSet (android.animation.AnimatorSet)2 ObjectAnimator (android.animation.ObjectAnimator)2 Canvas (android.graphics.Canvas)2 Camera (android.hardware.Camera)2 ChatActivity (org.telegram.ui.ChatActivity)2 ValueAnimator (android.animation.ValueAnimator)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Outline (android.graphics.Outline)1 Path (android.graphics.Path)1