FrescoImageViewer


Source link: https://github.com/stfalcon-studio/FrescoImageViewer

FrescoImageViewer

Simple customizable full screen image viewer for Fresco library that includes "pinch to zoom" and "swipe to dismiss" gestures. Based on PhotoDraweeView by ongakuer.

Who we are

Need iOS and Android apps, MVP development or prototyping? Contact us via [email protected]. We develop software since 2009, and we're known experts in this field. Check out our portfolio and see more libraries from stfalcon-studio.

Requirements

  • Fresco v.0.12.0 and higher
  • SDK 14 and and higher

Demo Application

Usage

Simple usage

All you need to show a viewer is pass the context, start position and List or String[] into builder and call show().

new ImageViewer.Builder(context, list)

.setStartPosition(startPosition)

.show();

Custom objects

But what if in your application images are represented not only with urls? For example, you have object with url and description? You'll have to convert it to list of Strings and only then pass it to viewer, right? No, it's unnecessary! With ImageViewer.Formatter you can pass list of your custom images to viewer and simply write a rule for url extracting:

List<CustomImage> images = getImages();
 new ImageViewer.Builder<>(this, images)

.setFormatter(new ImageViewer.Formatter<CustomImage>() {

 @Override

 public String format(CustomImage customImage) {

  return customImage.getUrl();

 
}

}
)

.show();

If formatter isn't passed, Object.toString() will be used for image formatting as default behavior.

Piece of cake! 🍰 😉

Reminder

Don't forget to initialize Fresco in your Application class:

Fresco.initialize(this);

And if you expect to open really large images, use configuration below for better performance:

ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
  .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig())
  .setResizeAndRotateEnabledForNetwork(true)
  .setDownsampleEnabled(true)
  .build();
 Fresco.initialize(this, config);

Customizing

You can also customize a viewer to fit your needs.

Background

Use setBackgroundColorRes(colorRes) or setBackgroundColor(colorInt) to set color for fading background.

Custom overlay view

If you need some content over the image (e.g. sharing or download button, description, numeration etc.) you can set your custom view using setOverlayView(customView) and bind it with viewer through ImageViewer.OnImageChangeListener.

Custom drawee hierarchy

Of course, according to Fresco flexibility, you can use your custom GenericDraweeHierarchy. To do this you simply need to create GenericDraweeHierarchy Builder and pass it into builder:

GenericDraweeHierarchyBuilder hierarchyBuilder = GenericDraweeHierarchyBuilder.newInstance(getResources())

.setFailureImage(R.drawable.failureDrawable)

.setProgressBarImage(R.drawable.progressBarDrawable)

.setPlaceholderImage(R.drawable.placeholderDrawable);
  builder.setCustomDraweeHierarchyBuilder(hierarchyBuilder)

❗?But there is a limitation: default ScaleType in hierarchy is ScaleType.FIT_CENTER, so custom value will be ignored

Custom image requests

For rare cases like post-processing or bitmap resizing you need to use your custom ImageRequestBuilder. Create it with ImageViewer.createImageRequestBuilder() and after configuration pass it to viewer through setCustomImageRequestBuilder(ImageRequestBuilder).

builder.setCustomImageRequestBuilder(

 ImageViewer.createImageRequestBuilder()

.setPostprocessor(new GrayscalePostprocessor()));

Image margin

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

Container padding

Overlay image hides part of image? Set container padding with dimens using setContainerPadding(context, start, top, end, bottom) or setContainerPadding(context, dimean) for all sides at once. For setting padding in pixels, just use setContainerPaddingPx(...) method.

Status bar visibility

To show/hide status bar in view property you can set hideStatusBar(boolean) in builder. The default value is true.

Gestures disabling

If you need to disable some of gestures - do it using allowSwipeToDismiss(boolean) and allowZooming(boolean) accordingly.

Here is an example that sets all the possible options:

new ImageViewer.Builder<>(this, images)

.setStartPosition(startPosition)

.hideStatusBar(false)

.allowZooming(true)

.allowSwipeToDismiss(true)

.setBackgroundColorRes(colorRes)

//.setBackgroundColor(color)

.setImageMargin(margin)

//.setImageMarginPx(marginPx)

.setContainerPadding(this, dimen)

//.setContainerPadding(this, dimenStart, dimenTop, dimenEnd, dimenBottom)

//.setContainerPaddingPx(padding)

//.setContainerPaddingPx(start, top, end, bottom)

.setCustomImageRequestBuilder(imageRequestBuilder)

.setCustomDraweeHierarchyBuilder(draweeHierarchyBuilder)

.setImageChangeListener(imageChangeListener)

.setOnDismissListener(onDismissListener)

.setOverlayView(overlayView)

.show();
 

With this possibilities you can achieve something like this:

You can take a look at sample project for more information.

Install

Download via Gradle:

compile 'com.github.stfalcon:frescoimageviewer:0.5.0'

or Maven:

<dependency>
<groupId>com.github.stfalcon</groupId>
<artifactId>frescoimageviewer</artifactId>
<version>0.5.0</version>
<type>pom</type> </dependency>

Changelog

See the changelog to be aware of latest improvements and fixes.

License

Copyright (C) 2017 stfalcon.com  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.  

Resources

This is a repository with real-world useful examples of using RxJava with Android.

This is the DeployGate plugin for Apache Maven.

In-memory immutable 2D R-tree implementation in java using RxJava Observables for reactive processing of search results.

This library provides a means to access the content on the Web easily from AndroidWear.

Bash script to simplify adb command usage.

This is a helpful bash utility for working with multiple devices at the same time.

Wrapper for Android Preferences which provides a fluid syntax.

Example:

Prefs.with(context).save(key, value);

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes