Search in sources :

Example 1 with FloatSeekBarAccessibilityDelegate

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

the class PhotoViewer method createVideoControlsInterface.

private void createVideoControlsInterface() {
    videoPlayerControlFrameLayout = new VideoPlayerControlFrameLayout(containerView.getContext());
    containerView.addView(videoPlayerControlFrameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
    final VideoPlayerSeekBar.SeekBarDelegate seekBarDelegate = new VideoPlayerSeekBar.SeekBarDelegate() {

        @Override
        public void onSeekBarDrag(float progress) {
            if (videoPlayer != null) {
                if (!inPreview && videoTimelineView.getVisibility() == View.VISIBLE) {
                    progress = videoTimelineView.getLeftProgress() + (videoTimelineView.getRightProgress() - videoTimelineView.getLeftProgress()) * progress;
                }
                long duration = videoPlayer.getDuration();
                if (duration == C.TIME_UNSET) {
                    seekToProgressPending = progress;
                } else {
                    videoPlayer.seekTo((int) (progress * duration));
                }
                showVideoSeekPreviewPosition(false);
                needShowOnReady = false;
            }
        }

        @Override
        public void onSeekBarContinuousDrag(float progress) {
            if (videoPlayer != null && videoPreviewFrame != null) {
                videoPreviewFrame.setProgress(progress, videoPlayerSeekbar.getWidth());
            }
            showVideoSeekPreviewPosition(true);
            updateVideoSeekPreviewPosition();
        }
    };
    final FloatSeekBarAccessibilityDelegate accessibilityDelegate = new FloatSeekBarAccessibilityDelegate() {

        @Override
        public float getProgress() {
            return videoPlayerSeekbar.getProgress();
        }

        @Override
        public void setProgress(float progress) {
            seekBarDelegate.onSeekBarDrag(progress);
            videoPlayerSeekbar.setProgress(progress);
            videoPlayerSeekbarView.invalidate();
        }

        @Override
        public String getContentDescription(View host) {
            final String time = LocaleController.formatPluralString("Minutes", videoPlayerCurrentTime[0]) + ' ' + LocaleController.formatPluralString("Seconds", videoPlayerCurrentTime[1]);
            final String totalTime = LocaleController.formatPluralString("Minutes", videoPlayerTotalTime[0]) + ' ' + LocaleController.formatPluralString("Seconds", videoPlayerTotalTime[1]);
            return LocaleController.formatString("AccDescrPlayerDuration", R.string.AccDescrPlayerDuration, time, totalTime);
        }
    };
    videoPlayerSeekbarView = new View(containerView.getContext()) {

        @Override
        protected void onDraw(Canvas canvas) {
            videoPlayerSeekbar.draw(canvas, this);
        }
    };
    videoPlayerSeekbarView.setAccessibilityDelegate(accessibilityDelegate);
    videoPlayerSeekbarView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
    videoPlayerControlFrameLayout.addView(videoPlayerSeekbarView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    videoPlayerSeekbar = new VideoPlayerSeekBar(videoPlayerSeekbarView);
    videoPlayerSeekbar.setHorizontalPadding(AndroidUtilities.dp(2));
    videoPlayerSeekbar.setColors(0x33ffffff, 0x33ffffff, Color.WHITE, Color.WHITE, Color.WHITE, 0x59ffffff);
    videoPlayerSeekbar.setDelegate(seekBarDelegate);
    videoPreviewFrame = new VideoSeekPreviewImage(containerView.getContext(), () -> {
        if (needShowOnReady) {
            showVideoSeekPreviewPosition(true);
        }
    }) {

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            updateVideoSeekPreviewPosition();
        }

        @Override
        public void setVisibility(int visibility) {
            super.setVisibility(visibility);
            if (visibility == VISIBLE) {
                updateVideoSeekPreviewPosition();
            }
        }
    };
    videoPreviewFrame.setAlpha(0.0f);
    containerView.addView(videoPreviewFrame, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48 + 10));
    videoPlayerTime = new SimpleTextView(containerView.getContext());
    videoPlayerTime.setTextColor(0xffffffff);
    videoPlayerTime.setGravity(Gravity.RIGHT | Gravity.TOP);
    videoPlayerTime.setTextSize(14);
    videoPlayerTime.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    videoPlayerControlFrameLayout.addView(videoPlayerTime, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT | Gravity.TOP, 0, 15, 12, 0));
    exitFullscreenButton = new ImageView(containerView.getContext());
    exitFullscreenButton.setImageResource(R.drawable.msg_minvideo);
    exitFullscreenButton.setContentDescription(LocaleController.getString("AccExitFullscreen", R.string.AccExitFullscreen));
    exitFullscreenButton.setScaleType(ImageView.ScaleType.CENTER);
    exitFullscreenButton.setBackground(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    exitFullscreenButton.setVisibility(View.INVISIBLE);
    videoPlayerControlFrameLayout.addView(exitFullscreenButton, LayoutHelper.createFrame(48, 48, Gravity.TOP | Gravity.RIGHT));
    exitFullscreenButton.setOnClickListener(v -> {
        if (parentActivity == null) {
            return;
        }
        wasRotated = false;
        fullscreenedByButton = 2;
        if (prevOrientation == -10) {
            prevOrientation = parentActivity.getRequestedOrientation();
        }
        parentActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    });
}
Also used : VideoSeekPreviewImage(org.telegram.ui.Components.VideoSeekPreviewImage) Canvas(android.graphics.Canvas) SpannableString(android.text.SpannableString) 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) FloatSeekBarAccessibilityDelegate(org.telegram.ui.Components.FloatSeekBarAccessibilityDelegate) VideoPlayerSeekBar(org.telegram.ui.Components.VideoPlayerSeekBar) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) BackupImageView(org.telegram.ui.Components.BackupImageView) ImageView(android.widget.ImageView) ClippingImageView(org.telegram.ui.Components.ClippingImageView)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 SpannableString (android.text.SpannableString)1 TextPaint (android.text.TextPaint)1 TextureView (android.view.TextureView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 NestedScrollView (androidx.core.widget.NestedScrollView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 SimpleTextView (org.telegram.ui.ActionBar.SimpleTextView)1 BackupImageView (org.telegram.ui.Components.BackupImageView)1 ClippingImageView (org.telegram.ui.Components.ClippingImageView)1 CropView (org.telegram.ui.Components.Crop.CropView)1 FloatSeekBarAccessibilityDelegate (org.telegram.ui.Components.FloatSeekBarAccessibilityDelegate)1 GroupedPhotosListView (org.telegram.ui.Components.GroupedPhotosListView)1 PhotoCropView (org.telegram.ui.Components.PhotoCropView)1 PhotoFilterView (org.telegram.ui.Components.PhotoFilterView)1 PhotoPaintView (org.telegram.ui.Components.PhotoPaintView)1