Skip to content

Allow users to apply a custom theme to the ImageViewer dialog #68

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

Open
wants to merge 1 commit 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
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,39 @@ builder.setCustomImageRequestBuilder(
.setPostprocessor(new GrayscalePostprocessor()));
```

#### Custom theme
You can also apply your own theme to the viewer:
```java
builder.setCustomTheme(R.style.MyCustomTheme);
```
You could, for example, provide an exit/enter animation to the viewer by declaring `MyCustomTheme` like this:
```xml
<style name="MyCustomTheme" parent="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
<item name="android:windowAnimationStyle">@style/MyAnimation.Window</item>
</style>

<style name="MyAnimation.Window" parent="@android:style/Animation.Activity">
<item name="android:windowEnterAnimation">@anim/fade_in</item>
<item name="android:windowExitAnimation">@anim/fade_out</item>
</style>
```
**fade_in.xml:**
```xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="300" />
```
**fade_out.xml:**
```xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="300" />
```

#### Image margin
Simply add margins between images with dimens with setImageMargin(context, dimen) or in `px` using `setImageMarginPx(marginPx)`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void onPageSelected(int position) {
}
});

dialog = new AlertDialog.Builder(builder.context, getDialogStyle())
dialog = new AlertDialog.Builder(builder.context, builder.customTheme == 0 ? getDialogStyle() : builder.customTheme)
.setView(viewer)
.setOnKeyListener(this)
.create();
Expand Down Expand Up @@ -211,6 +211,7 @@ public static class Builder<T> {
private boolean shouldStatusBarHide = true;
private boolean isZoomingAllowed = true;
private boolean isSwipeToDismissAllowed = true;
private @StyleRes int customTheme;

/**
* Constructor using a context and images urls array for this builder and the {@link ImageViewer} it creates.
Expand Down Expand Up @@ -354,7 +355,8 @@ public Builder setContainerPadding(Context context, @DimenRes int padding) {
}

/**
* Set status bar visibility. By default is true.
* Set status bar visibility. By default is true.<br>
* It is ignored if {@link #setCustomTheme(int)} was used.
*
* @return This Builder object to allow for chaining of calls to set methods
*/
Expand Down Expand Up @@ -416,6 +418,18 @@ public Builder setCustomDraweeHierarchyBuilder(GenericDraweeHierarchyBuilder cus
return this;
}

/**
* Set a custom theme for the viewer.
* Using a custom theme will make the viewer ignore the value set with {@link #hideStatusBar(boolean)}.
* You can still have it hidden by extending your custom theme from {@code Theme.Translucent.NoTitleBar.Fullscreen}.
*
* @return This Builder object to allow for chaining of calls to set methods
*/
public Builder setCustomTheme(@StyleRes int theme) {
this.customTheme = theme;
return this;
}

/**
* Creates a {@link ImageViewer} with the arguments supplied to this builder. It does not
* {@link ImageViewer#show()} the dialog. This allows the user to do any extra processing
Expand Down