Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -107,6 +110,7 @@ StfalconImageViewer.Builder<String>(this, images, ::loadImage)
.allowZooming(isZoomingAllowed)
.allowSwipeToDismiss(isSwipeToDismissAllowed)
.withTransitionFrom(targeImageView)
.withImageFullFocusEnabled(true)
.withImageChangeListener(::onImageChanged)
.withDismissListener(::onViewerDismissed)
.withDismissListener(::onViewerDismissed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ public Builder<T> 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<T> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ internal class BuilderData<T>(
var isZoomingAllowed = true
var isSwipeToDismissAllowed = true
var transitionView: ImageView? = null
var imageFullFocusEnabled = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ internal class ImageViewerDialog<T>(
containerPadding = builderData.containerPaddingPixels
imagesMargin = builderData.imageMarginPixels
overlayView = builderData.overlayView
imageFullFocusEnabled = builderData.imageFullFocusEnabled

setBackgroundColor(builderData.backgroundColor)
setImages(builderData.images, builderData.startPosition, builderData.imageLoader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +84,7 @@ internal class ImageViewerView<T> @JvmOverloads constructor(
field = value
value?.let { rootContainer.addView(it) }
}
internal var imageFullFocusEnabled = false

private var rootContainer: ViewGroup
private var backgroundView: View
Expand All @@ -104,6 +106,7 @@ internal class ImageViewerView<T> @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<T> = listOf()
private var imageLoader: ImageLoader<T>? = null
Expand Down Expand Up @@ -166,6 +169,9 @@ internal class ImageViewerView<T> @JvmOverloads constructor(
handleUpDownEvent(event)

if (swipeDirection == null && (scaleDetector.isInProgress || event.pointerCount > 1 || wasScaled)) {
if (!wasScaled) {
setImageFullFocus(true)
}
wasScaled = true
return imagesPager.dispatchTouchEvent(event)
}
Expand All @@ -175,6 +181,7 @@ internal class ImageViewerView<T> @JvmOverloads constructor(

override fun setBackgroundColor(color: Int) {
findViewById<View>(R.id.backgroundView).setBackgroundColor(color)
setBackgroundColor = color
}

internal fun setImages(images: List<T>, startPosition: Int, imageLoader: ImageLoader<T>) {
Expand Down Expand Up @@ -307,11 +314,32 @@ internal class ImageViewerView<T> @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
Expand All @@ -338,6 +366,7 @@ internal class ImageViewerView<T> @JvmOverloads constructor(
false
},
onDoubleTap = {
setImageFullFocus(true)
wasDoubleTapped = !isScaled
false
}
Expand Down