diff --git a/README.md b/README.md index 83236edd..b47d0755 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,9 @@ For setting a padding in pixels, just use the `withContainerPadding(...)` method #### Status bar visibility Control the status bar visibility of the opened viewer by using the `withHiddenStatusBar(boolean)` method (`true` by default) +#### Image full focus +Hide everything but the image when interacting with the image by using the `withImageFullFocusEnabled(boolean)` method (`false` by default) + #### Gestures If you need to disable some of the gestures - you can use the `allowSwipeToDismiss(boolean)` and `allowZooming(boolean)` methods accordingly. @@ -107,6 +110,7 @@ StfalconImageViewer.Builder(this, images, ::loadImage) .allowZooming(isZoomingAllowed) .allowSwipeToDismiss(isSwipeToDismissAllowed) .withTransitionFrom(targeImageView) + .withImageFullFocusEnabled(true) .withImageChangeListener(::onImageChanged) .withDismissListener(::onViewerDismissed) .withDismissListener(::onViewerDismissed) diff --git a/imageviewer/src/main/java/com/stfalcon/imageviewer/StfalconImageViewer.java b/imageviewer/src/main/java/com/stfalcon/imageviewer/StfalconImageViewer.java index 61d8179a..9ee45e08 100644 --- a/imageviewer/src/main/java/com/stfalcon/imageviewer/StfalconImageViewer.java +++ b/imageviewer/src/main/java/com/stfalcon/imageviewer/StfalconImageViewer.java @@ -161,6 +161,18 @@ public Builder withBackgroundColorResource(@ColorRes int color) { return this.withBackgroundColor(ContextCompat.getColor(context, color)); } + /** + * Sets image full focus enabled or disabled. When full focus is enabled, tapping to hide + * the overlay, zooming or double tapping will also hide the status bar, navigation bar + * and set the background to black so the only thing visible is the image. + * + * @return This Builder object to allow calls chaining + */ + public Builder withImageFullFocusEnabled(boolean enabled) { + this.data.setImageFullFocusEnabled(enabled); + return this; + } + /** * Sets custom overlay view to be shown over the viewer. * Commonly used for image description or counter displaying. diff --git a/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/builder/BuilderData.kt b/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/builder/BuilderData.kt index 7153a95a..a76d272d 100644 --- a/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/builder/BuilderData.kt +++ b/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/builder/BuilderData.kt @@ -38,4 +38,5 @@ internal class BuilderData( var isZoomingAllowed = true var isSwipeToDismissAllowed = true var transitionView: ImageView? = null + var imageFullFocusEnabled = false } \ No newline at end of file diff --git a/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/dialog/ImageViewerDialog.kt b/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/dialog/ImageViewerDialog.kt index bfb14f57..dc755faf 100644 --- a/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/dialog/ImageViewerDialog.kt +++ b/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/dialog/ImageViewerDialog.kt @@ -104,6 +104,7 @@ internal class ImageViewerDialog( containerPadding = builderData.containerPaddingPixels imagesMargin = builderData.imageMarginPixels overlayView = builderData.overlayView + imageFullFocusEnabled = builderData.imageFullFocusEnabled setBackgroundColor(builderData.backgroundColor) setImages(builderData.images, builderData.startPosition, builderData.imageLoader) diff --git a/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/view/ImageViewerView.kt b/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/view/ImageViewerView.kt index 7b7447e5..d0181f12 100644 --- a/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/view/ImageViewerView.kt +++ b/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/view/ImageViewerView.kt @@ -17,6 +17,7 @@ package com.stfalcon.imageviewer.viewer.view import android.content.Context +import android.graphics.Color import android.util.AttributeSet import android.view.MotionEvent import android.view.ScaleGestureDetector @@ -83,6 +84,7 @@ internal class ImageViewerView @JvmOverloads constructor( field = value value?.let { rootContainer.addView(it) } } + internal var imageFullFocusEnabled = false private var rootContainer: ViewGroup private var backgroundView: View @@ -104,6 +106,7 @@ internal class ImageViewerView @JvmOverloads constructor( private var wasDoubleTapped = false private var isOverlayWasClicked: Boolean = false private var swipeDirection: SwipeDirection? = null + private var setBackgroundColor: Int? = null private var images: List = listOf() private var imageLoader: ImageLoader? = null @@ -166,6 +169,9 @@ internal class ImageViewerView @JvmOverloads constructor( handleUpDownEvent(event) if (swipeDirection == null && (scaleDetector.isInProgress || event.pointerCount > 1 || wasScaled)) { + if (!wasScaled) { + setImageFullFocus(true) + } wasScaled = true return imagesPager.dispatchTouchEvent(event) } @@ -175,6 +181,7 @@ internal class ImageViewerView @JvmOverloads constructor( override fun setBackgroundColor(color: Int) { findViewById(R.id.backgroundView).setBackgroundColor(color) + setBackgroundColor = color } internal fun setImages(images: List, startPosition: Int, imageLoader: ImageLoader) { @@ -307,11 +314,32 @@ internal class ImageViewerView @JvmOverloads constructor( private fun handleSingleTap(event: MotionEvent, isOverlayWasClicked: Boolean) { if (overlayView != null && !isOverlayWasClicked) { - overlayView?.switchVisibilityWithAnimation() + setImageFullFocus(overlayView.isVisible) + if (!imageFullFocusEnabled) { + overlayView?.switchVisibilityWithAnimation() + } super.dispatchTouchEvent(event) } } + private fun setImageFullFocus(fullFocus: Boolean) { + if (imageFullFocusEnabled) { + if (fullFocus) { + systemUiVisibility = + View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE + backgroundView.setBackgroundColor(Color.BLACK) + } else { + systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE + setBackgroundColor?.let { + backgroundView.setBackgroundColor(it) + } + } + if (overlayView?.isVisible == fullFocus) { + overlayView?.switchVisibilityWithAnimation() + } + } + } + private fun handleSwipeViewMove(translationY: Float, translationLimit: Int) { val alpha = calculateTranslationAlpha(translationY, translationLimit) backgroundView.alpha = alpha @@ -338,6 +366,7 @@ internal class ImageViewerView @JvmOverloads constructor( false }, onDoubleTap = { + setImageFullFocus(true) wasDoubleTapped = !isScaled false }