Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to change dialog style to allow alert dialog customizations #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.stfalcon.imageviewer;

import android.content.Context;
import android.os.*;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
Expand Down Expand Up @@ -248,6 +249,28 @@ public Builder<T> withHiddenStatusBar(boolean value) {
return this;
}

/**
* Sets alert dialog style. ImageViewerDialog.Default by default.
*
* @return This Builder object to allow calls chaining
*/
public Builder<T> withDialogStyle(int value) {
this.data.setDialogStyle(value);
return this;
}

/**
* Sets status bar transparency to allow drawing underneath it. False by default.
* Works only on API 21 and above.
*
* @return This Builder object to allow calls chaining
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public Builder<T> shouldStatusBarTransparent(boolean value) {
this.data.setShouldStatusBarTransparent(value);
return this;
}

/**
* Enables or disables zooming. True by default.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.stfalcon.imageviewer.viewer.builder
import android.graphics.Color
import android.view.View
import android.widget.ImageView
import com.stfalcon.imageviewer.R
import com.stfalcon.imageviewer.listeners.OnDismissListener
import com.stfalcon.imageviewer.listeners.OnImageChangeListener
import com.stfalcon.imageviewer.loader.ImageLoader
Expand All @@ -35,7 +36,9 @@ internal class BuilderData<T>(
var imageMarginPixels: Int = 0
var containerPaddingPixels = IntArray(4)
var shouldStatusBarHide = true
var shouldStatusBarTransparent = false
var isZoomingAllowed = true
var isSwipeToDismissAllowed = true
var transitionView: ImageView? = null
}
var dialogStyle: Int = R.style.ImageViewerDialog_Default
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package com.stfalcon.imageviewer.viewer.dialog

import android.content.Context
import android.os.Build
import android.view.KeyEvent
import android.view.WindowManager
import android.widget.ImageView
import androidx.appcompat.app.AlertDialog
import com.stfalcon.imageviewer.R
Expand All @@ -37,7 +39,7 @@ internal class ImageViewerDialog<T>(
get() = if (builderData.shouldStatusBarHide)
R.style.ImageViewerDialog_NoStatusBar
else
R.style.ImageViewerDialog_Default
builderData.dialogStyle

init {
setupViewerView()
Expand All @@ -50,6 +52,11 @@ internal class ImageViewerDialog<T>(
setOnShowListener { viewerView.open(builderData.transitionView, animateOpen) }
setOnDismissListener { builderData.onDismissListener?.onDismiss() }
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (builderData.shouldStatusBarTransparent) {
dialog.window?.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
}
}
}

fun show(animate: Boolean) {
Expand Down