├── .github └── ISSUE_TEMPLATE │ ├── another-type-of-issue.md │ ├── bug.md │ └── feature_request.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images ├── image_viewer_main_demo.gif ├── image_viewer_transition_demo.gif ├── misc │ ├── horizontal_colorful_1.jpg │ ├── horizontal_colorful_2.jpg │ ├── horizontal_colorful_3.jpg │ ├── square_colorful.jpg │ ├── vertical_colorful_1.jpg │ ├── vertical_colorful_2.jpg │ ├── vertical_colorful_3.jpg │ └── vertical_colorful_4.jpg └── posters │ ├── Daniel.jpg │ ├── Driver.jpg │ ├── Frank.jpg │ ├── Jules.jpg │ ├── Korben.jpg │ ├── Marty.jpg │ ├── Max.jpg │ ├── Toretto.jpg │ └── Vincent.jpg ├── imageviewer ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── stfalcon │ │ └── imageviewer │ │ ├── StfalconImageViewer.java │ │ ├── common │ │ ├── extensions │ │ │ ├── ImageView.kt │ │ │ ├── PhotoView.kt │ │ │ ├── SparseArray.kt │ │ │ ├── Transition.kt │ │ │ ├── View.kt │ │ │ ├── ViewPager.kt │ │ │ └── ViewPropertyAnimator.kt │ │ ├── gestures │ │ │ ├── detector │ │ │ │ └── SimpleOnGestureListener.kt │ │ │ ├── direction │ │ │ │ ├── SwipeDirection.kt │ │ │ │ └── SwipeDirectionDetector.kt │ │ │ └── dismiss │ │ │ │ └── SwipeToDismissHandler.kt │ │ └── pager │ │ │ ├── MultiTouchViewPager.kt │ │ │ └── RecyclingPagerAdapter.kt │ │ ├── listeners │ │ ├── OnDismissListener.java │ │ └── OnImageChangeListener.java │ │ ├── loader │ │ └── ImageLoader.java │ │ └── viewer │ │ ├── adapter │ │ └── ImagesPagerAdapter.kt │ │ ├── builder │ │ └── BuilderData.kt │ │ ├── dialog │ │ └── ImageViewerDialog.kt │ │ └── view │ │ ├── ImageViewerView.kt │ │ └── TransitionImageAnimator.kt │ └── res │ ├── layout │ └── view_image_viewer.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── sample ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── stfalcon │ │ └── sample │ │ ├── common │ │ ├── extensions │ │ │ ├── Context.kt │ │ │ └── ImageView.kt │ │ ├── models │ │ │ ├── Demo.kt │ │ │ └── Poster.kt │ │ └── ui │ │ │ ├── base │ │ │ └── BaseActivity.kt │ │ │ └── views │ │ │ ├── PosterOverlayView.kt │ │ │ └── PostersGridView.kt │ │ └── features │ │ ├── demo │ │ ├── grid │ │ │ └── PostersGridDemoActivity.kt │ │ ├── rotation │ │ │ └── RotationDemoActivity.kt │ │ ├── scroll │ │ │ └── ScrollingImagesDemoActivity.kt │ │ └── styled │ │ │ ├── StylingDemoActivity.kt │ │ │ └── options │ │ │ └── StylingOptions.kt │ │ └── main │ │ ├── MainActivity.kt │ │ ├── adapter │ │ └── MainActivityPagerAdapter.kt │ │ └── card │ │ └── DemoCardFragment.kt │ └── res │ ├── drawable-hdpi │ └── ic_placeholder.png │ ├── drawable-mdpi │ └── ic_placeholder.png │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable-xhdpi │ └── ic_placeholder.png │ ├── drawable-xxhdpi │ └── ic_placeholder.png │ ├── drawable-xxxhdpi │ └── ic_placeholder.png │ ├── drawable │ ├── ic_arrow_right.xml │ ├── ic_arrow_up.xml │ ├── ic_circle_accent.xml │ ├── ic_delete.xml │ ├── ic_launcher_background.xml │ ├── ic_settings.xml │ ├── ic_share.xml │ ├── ic_stfalcon_bird.xml │ └── shape_placeholder.xml │ ├── layout │ ├── activity_demo_posters_grid.xml │ ├── activity_demo_rotation.xml │ ├── activity_demo_scrolling_images.xml │ ├── activity_demo_styling.xml │ ├── activity_main.xml │ ├── fragment_demo_card.xml │ ├── view_poster_overlay.xml │ └── view_posters_grid.xml │ ├── menu │ └── styling_options_menu.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.github/ISSUE_TEMPLATE/another-type-of-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Another type of issue 3 | about: Ask a question about the project 4 | title: '' 5 | labels: question 6 | assignees: troy379 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: troy379 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Additional context** 27 | Add any other context about the problem here. 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: troy379 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | *.jar 5 | !gradle/wrapper/gradle-wrapper.jar 6 | 7 | # files for the dex VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # generated files 14 | android/bin/ 15 | android/gen/ 16 | 17 | # Local configuration file (sdk path, etc) 18 | local.properties 19 | 20 | # Eclipse project files 21 | .classpath 22 | .project 23 | .properties 24 | .settings/ 25 | libprojects/ 26 | 27 | # Proguard folder generated by Eclipse 28 | android/proguard/ 29 | 30 | # Intellij project files 31 | *.iml 32 | *.ipr 33 | *.iws 34 | .idea/ 35 | build/ 36 | .gradle -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at info@stfalcon.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![codebeat badge](https://codebeat.co/badges/91ce76f4-cba6-4971-aad7-070e635d11be)](https://codebeat.co/projects/github-com-stfalcon-studio-stfalconimageviewer-master) 2 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/23c4c8c6f44541a8bfdb0e385da2436a)](https://www.codacy.com/app/troy.carvill/StfalconImageViewer?utm_source=github.com&utm_medium=referral&utm_content=stfalcon-studio/StfalconImageViewer&utm_campaign=Badge_Grade) 3 | [![Download](https://api.bintray.com/packages/troy379/maven/StfalconImageViewer/images/download.svg) ](https://bintray.com/troy379/maven/StfalconImageViewer/_latestVersion) 4 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 5 | 6 | # Stfalcon ImageViewer 7 | A simple and customizable full-screen image viewer with shared image transition support, "pinch to zoom" and "swipe to dismiss" gestures. Compatible with all of the most popular image processing libraries such as `Picasso`, `Glide` etc. 8 | Based on [PhotoView](https://github.com/chrisbanes/PhotoView) by [chrisbanes](https://github.com/chrisbanes). 9 | 10 | ![alt tag](images/image_viewer_main_demo.gif) ![alt tag](images/image_viewer_transition_demo.gif) 11 | 12 | ### Who we are 13 | Need iOS and Android apps, MVP development or prototyping? Contact us via info@stfalcon.com. We develop software since 2009, and we're known experts in this field. Check out our [portfolio](https://stfalcon.com/en/portfolio) and see more libraries from [stfalcon-studio](https://stfalcon-studio.github.io/). 14 | 15 | ### Requirements 16 | * A project configured with the AndroidX 17 | * SDK 19 and and higher 18 | 19 | ### Demo Application 20 | [![Get it on Google Play](https://play.google.com/intl/en_us/badges/images/badge_new.png)](https://play.google.com/store/apps/details?id=com.stfalcon.stfalconimageviewersample) 21 | 22 | ### Install 23 | Download via **Gradle**: 24 | 25 | Add this to the **project `build.gradle`** file: 26 | ```gradle 27 | allprojects { 28 | repositories { 29 | ... 30 | maven { url "https://jitpack.io" } 31 | } 32 | } 33 | ``` 34 | 35 | And then add the dependency to the **module `build.gradle`** file: 36 | ```gradle 37 | implementation 'com.github.stfalcon-studio:StfalconImageViewer:v1.0.1' 38 | ``` 39 | 40 | Download via **Maven**: 41 | ``` 42 | 43 | com.github.stfalcon 44 | stfalcon-imageviewer 45 | latest_version 46 | pom 47 | 48 | ``` 49 | 50 | Where the `latest_version` is the value from `Download` badge. 51 | 52 | ### Usage 53 | #### Simple usage 54 | All you need to show the viewer is to pass the context, list or array of your image objects and the implementation of the `ImageLoader` and call the `show()` method: 55 | ```java 56 | StfalconImageViewer.Builder(context, images) { view, image -> 57 | Picasso.get().load(image.url).into(view) 58 | }.show() 59 | ``` 60 | Piece of cake! 61 | 62 | #### Transition animation 63 | To improve the UX of your app you would like to add a transition when a user opens the viewer. And this is simple as never before! Just tell the viewer which image should be used for animation using `withTransitionFrom(myImageView)` method and the library will do it for you! 64 | 65 | If you need more advanced behavior like updating transition target while changing images in the viewer please see the sample app for how to do this. 66 | 67 | #### Update images list on the fly 68 | There are a lot of common cases (such as pagination, deleting, editing etc.) where you need to update the existing images list while the viewer is running. To do this you can simply update the existing list (or even replace it with a new one) and then call `updateImages(images)`. 69 | 70 | #### Change current image 71 | Images are not always leafed through by the user. Maybe you want to implement some kind of preview list at the bottom of the viewer - `setCurrentPosition` is here for help. Change images programmatically wherever you want! 72 | 73 | #### Custom overlay view 74 | If you need to show some content over the image (e.g. sharing or download button, description, numeration etc.) you can set your own custom view using the `setOverlayView(customView)` and bind it with the viewer through the `ImageViewer.OnImageChangeListener`. 75 | 76 | #### Background 77 | Use the `setBackgroundColorRes(colorRes)` or `setBackgroundColor(colorInt)` to set a color of the fading background. 78 | 79 | #### Images margin 80 | Simply add margins between images using the `withImagesMargin(context, dimenRes)` method for dimensions, or use the `withImageMarginPixels(int)` for pixels size. 81 | 82 | #### Container padding 83 | Overlay image hides part of the images? Set container padding with dimens using `withContainerPadding(context, start, top, end, bottom)` or `withContainerPadding(context, dimen)` for all of the sides evenly. 84 | For setting a padding in pixels, just use the `withContainerPadding(...)` methods variant. 85 | 86 | #### Status bar visibility 87 | Control the status bar visibility of the opened viewer by using the `withHiddenStatusBar(boolean)` method (`true` by default) 88 | 89 | #### Gestures 90 | If you need to disable some of the gestures - you can use the `allowSwipeToDismiss(boolean)` and `allowZooming(boolean)` methods accordingly. 91 | 92 | #### Options overview 93 | Here is the example with all of the existing options applied: 94 | ```java 95 | StfalconImageViewer.Builder(this, images, ::loadImage) 96 | .withStartPosition(startPosition) 97 | .withBackgroundColor(color) 98 | //.withBackgroundColorResource(R.color.color) 99 | .withOverlayView(view) 100 | .withImagesMargin(R.dimen.margin) 101 | //.withImageMarginPixels(margin) 102 | .withContainerPadding(R.dimen.padding) 103 | //.withContainerPadding(R.dimen.paddingStart, R.dimen.paddingTop, R.dimen.paddingEnd, R.dimen.paddingBottom) 104 | //.withContainerPaddingPixels(padding) 105 | //.withContainerPaddingPixels(paddingStart, paddingTop, paddingEnd, paddingBottom) 106 | .withHiddenStatusBar(shouldHideStatusBar) 107 | .allowZooming(isZoomingAllowed) 108 | .allowSwipeToDismiss(isSwipeToDismissAllowed) 109 | .withTransitionFrom(targeImageView) 110 | .withImageChangeListener(::onImageChanged) 111 | .withDismissListener(::onViewerDismissed) 112 | .withDismissListener(::onViewerDismissed) 113 | ``` 114 | 115 | Also, you can take a look at the [sample project](https://github.com/stfalcon-studio/StfalconImageViewer/tree/master/sample) for more information. 116 | 117 | ### Usage with Fresco 118 | If you use the Fresco library - check out the [FrescoImageViewer](https://github.com/stfalcon-studio/FrescoImageViewer) which was also developed by our team. 119 | 120 | ### License 121 | ``` 122 | Copyright (C) 2018 stfalcon.com 123 | 124 | Licensed under the Apache License, Version 2.0 (the "License"); 125 | you may not use this file except in compliance with the License. 126 | You may obtain a copy of the License at 127 | 128 | http://www.apache.org/licenses/LICENSE-2.0 129 | 130 | Unless required by applicable law or agreed to in writing, software 131 | distributed under the License is distributed on an "AS IS" BASIS, 132 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133 | See the License for the specific language governing permissions and 134 | limitations under the License. 135 | 136 | ``` 137 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.3.50' 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:4.1.2' 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | plugins { 18 | id 'maven-publish' 19 | } 20 | 21 | allprojects { 22 | repositories { 23 | google() 24 | jcenter() 25 | maven { url "https://jitpack.io" } 26 | } 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | android.enableJetifier=true 10 | android.useAndroidX=true 11 | org.gradle.jvmargs=-Xmx1536m 12 | # When configured, Gradle will run in incubating parallel mode. 13 | # This option should only be used with decoupled projects. More details, visit 14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 15 | # org.gradle.parallel=true 16 | 17 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin, switch paths to Windows format before running java 129 | if $cygwin ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem http://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /images/image_viewer_main_demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/image_viewer_main_demo.gif -------------------------------------------------------------------------------- /images/image_viewer_transition_demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/image_viewer_transition_demo.gif -------------------------------------------------------------------------------- /images/misc/horizontal_colorful_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/misc/horizontal_colorful_1.jpg -------------------------------------------------------------------------------- /images/misc/horizontal_colorful_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/misc/horizontal_colorful_2.jpg -------------------------------------------------------------------------------- /images/misc/horizontal_colorful_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/misc/horizontal_colorful_3.jpg -------------------------------------------------------------------------------- /images/misc/square_colorful.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/misc/square_colorful.jpg -------------------------------------------------------------------------------- /images/misc/vertical_colorful_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/misc/vertical_colorful_1.jpg -------------------------------------------------------------------------------- /images/misc/vertical_colorful_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/misc/vertical_colorful_2.jpg -------------------------------------------------------------------------------- /images/misc/vertical_colorful_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/misc/vertical_colorful_3.jpg -------------------------------------------------------------------------------- /images/misc/vertical_colorful_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/misc/vertical_colorful_4.jpg -------------------------------------------------------------------------------- /images/posters/Daniel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/posters/Daniel.jpg -------------------------------------------------------------------------------- /images/posters/Driver.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/posters/Driver.jpg -------------------------------------------------------------------------------- /images/posters/Frank.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/posters/Frank.jpg -------------------------------------------------------------------------------- /images/posters/Jules.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/posters/Jules.jpg -------------------------------------------------------------------------------- /images/posters/Korben.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/posters/Korben.jpg -------------------------------------------------------------------------------- /images/posters/Marty.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/posters/Marty.jpg -------------------------------------------------------------------------------- /images/posters/Max.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/posters/Max.jpg -------------------------------------------------------------------------------- /images/posters/Toretto.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/posters/Toretto.jpg -------------------------------------------------------------------------------- /images/posters/Vincent.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/images/posters/Vincent.jpg -------------------------------------------------------------------------------- /imageviewer/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'maven-publish' 4 | 5 | android { 6 | compileSdkVersion 29 7 | 8 | defaultConfig { 9 | minSdkVersion 19 10 | targetSdkVersion 29 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | 22 | afterEvaluate { 23 | publishing { 24 | publications { 25 | // Creates a Maven publication called "release". 26 | release(MavenPublication) { 27 | // Applies the component for the release build variant. 28 | from components.release 29 | 30 | // You can then customize attributes of the publication as shown below. 31 | groupId = 'com.github.stfalcon' 32 | artifactId = 'stfalcon-imageviewer' 33 | version = '1.0.1' 34 | } 35 | } 36 | } 37 | } 38 | 39 | } 40 | 41 | dependencies { 42 | api 'androidx.appcompat:appcompat:1.1.0' 43 | api 'androidx.transition:transition:1.2.0' 44 | implementation 'com.github.chrisbanes:PhotoView:2.2.0' 45 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 46 | } 47 | 48 | repositories { 49 | maven { url "https://jitpack.io" } 50 | mavenCentral() 51 | google() 52 | } 53 | 54 | // Avoid Kotlin docs error 55 | tasks.withType(Javadoc) { 56 | enabled = false 57 | } 58 | 59 | // Remove javadoc related tasks 60 | task javadoc(type: Javadoc) { 61 | source = android.sourceSets.main.java.srcDirs 62 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 63 | } 64 | -------------------------------------------------------------------------------- /imageviewer/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /imageviewer/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/StfalconImageViewer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer; 18 | 19 | import android.content.Context; 20 | import android.util.Log; 21 | import android.view.View; 22 | import android.widget.ImageView; 23 | import androidx.annotation.*; 24 | import androidx.core.content.ContextCompat; 25 | import com.stfalcon.imageviewer.listeners.OnDismissListener; 26 | import com.stfalcon.imageviewer.listeners.OnImageChangeListener; 27 | import com.stfalcon.imageviewer.loader.ImageLoader; 28 | import com.stfalcon.imageviewer.viewer.builder.BuilderData; 29 | import com.stfalcon.imageviewer.viewer.dialog.ImageViewerDialog; 30 | 31 | import java.util.ArrayList; 32 | import java.util.Arrays; 33 | import java.util.List; 34 | 35 | //N.B.! This class is written in Java for convenient use of lambdas due to languages compatibility issues. 36 | @SuppressWarnings({"unused", "WeakerAccess"}) 37 | public class StfalconImageViewer { 38 | 39 | private Context context; 40 | private BuilderData builderData; 41 | private ImageViewerDialog dialog; 42 | 43 | protected StfalconImageViewer(@NonNull Context context, @NonNull BuilderData builderData) { 44 | this.context = context; 45 | this.builderData = builderData; 46 | this.dialog = new ImageViewerDialog<>(context, builderData); 47 | } 48 | 49 | /** 50 | * Displays the built viewer if passed list of images is not empty 51 | */ 52 | public void show() { 53 | show(true); 54 | } 55 | 56 | /** 57 | * Displays the built viewer if passed list of images is not empty 58 | * 59 | * @param animate whether the passed transition view should be animated on open. Useful for screen rotation handling. 60 | */ 61 | public void show(boolean animate) { 62 | if (!builderData.getImages().isEmpty()) { 63 | dialog.show(animate); 64 | } else { 65 | Log.w(context.getString(R.string.library_name), 66 | "Images list cannot be empty! Viewer ignored."); 67 | } 68 | } 69 | 70 | /** 71 | * Closes the viewer with suitable close animation 72 | */ 73 | public void close() { 74 | dialog.close(); 75 | } 76 | 77 | /** 78 | * Dismisses the dialog with no animation 79 | */ 80 | public void dismiss() { 81 | dialog.dismiss(); 82 | } 83 | 84 | /** 85 | * Updates an existing images list if a new list is not empty, otherwise closes the viewer 86 | */ 87 | public void updateImages(T[] images) { 88 | updateImages(new ArrayList<>(Arrays.asList(images))); 89 | } 90 | 91 | /** 92 | * Updates an existing images list if a new list is not empty, otherwise closes the viewer 93 | */ 94 | public void updateImages(List images) { 95 | if (!images.isEmpty()) { 96 | dialog.updateImages(images); 97 | } else { 98 | dialog.close(); 99 | } 100 | } 101 | 102 | public int currentPosition() { 103 | return dialog.getCurrentPosition(); 104 | } 105 | 106 | public int setCurrentPosition(int position){ 107 | return dialog.setCurrentPosition(position); 108 | } 109 | 110 | /** 111 | * Updates transition image view. 112 | * Useful for a case when image position has changed and you want to update the transition animation target. 113 | */ 114 | public void updateTransitionImage(ImageView imageView) { 115 | dialog.updateTransitionImage(imageView); 116 | } 117 | 118 | /** 119 | * Builder class for {@link StfalconImageViewer} 120 | */ 121 | public static class Builder { 122 | 123 | private Context context; 124 | private BuilderData data; 125 | 126 | public Builder(Context context, T[] images, ImageLoader imageLoader) { 127 | this(context, new ArrayList<>(Arrays.asList(images)), imageLoader); 128 | } 129 | 130 | public Builder(Context context, List images, ImageLoader imageLoader) { 131 | this.context = context; 132 | this.data = new BuilderData<>(images, imageLoader); 133 | } 134 | 135 | /** 136 | * Sets a position to start viewer from. 137 | * 138 | * @return This Builder object to allow calls chaining 139 | */ 140 | public Builder withStartPosition(int position) { 141 | this.data.setStartPosition(position); 142 | return this; 143 | } 144 | 145 | /** 146 | * Sets a background color value for the viewer 147 | * 148 | * @return This Builder object to allow calls chaining 149 | */ 150 | public Builder withBackgroundColor(@ColorInt int color) { 151 | this.data.setBackgroundColor(color); 152 | return this; 153 | } 154 | 155 | /** 156 | * Sets a background color resource for the viewer 157 | * 158 | * @return This Builder object to allow calls chaining 159 | */ 160 | public Builder withBackgroundColorResource(@ColorRes int color) { 161 | return this.withBackgroundColor(ContextCompat.getColor(context, color)); 162 | } 163 | 164 | /** 165 | * Sets custom overlay view to be shown over the viewer. 166 | * Commonly used for image description or counter displaying. 167 | * 168 | * @return This Builder object to allow calls chaining 169 | */ 170 | public Builder withOverlayView(View view) { 171 | this.data.setOverlayView(view); 172 | return this; 173 | } 174 | 175 | /** 176 | * Sets space between the images using dimension. 177 | * 178 | * @return This Builder object to allow calls chaining 179 | */ 180 | public Builder withImagesMargin(@DimenRes int dimen) { 181 | this.data.setImageMarginPixels(Math.round(context.getResources().getDimension(dimen))); 182 | return this; 183 | } 184 | 185 | /** 186 | * Sets space between the images in pixels. 187 | * 188 | * @return This Builder object to allow calls chaining 189 | */ 190 | public Builder withImageMarginPixels(int marginPixels) { 191 | this.data.setImageMarginPixels(marginPixels); 192 | return this; 193 | } 194 | 195 | /** 196 | * Sets overall padding for zooming and scrolling area using dimension. 197 | * 198 | * @return This Builder object to allow calls chaining 199 | */ 200 | public Builder withContainerPadding(@DimenRes int padding) { 201 | int paddingPx = Math.round(context.getResources().getDimension(padding)); 202 | return withContainerPaddingPixels(paddingPx, paddingPx, paddingPx, paddingPx); 203 | } 204 | 205 | /** 206 | * Sets `start`, `top`, `end` and `bottom` padding for zooming and scrolling area using dimension. 207 | * 208 | * @return This Builder object to allow calls chaining 209 | */ 210 | public Builder withContainerPadding(@DimenRes int start, @DimenRes int top, 211 | @DimenRes int end, @DimenRes int bottom 212 | ) { 213 | withContainerPaddingPixels( 214 | Math.round(context.getResources().getDimension(start)), 215 | Math.round(context.getResources().getDimension(top)), 216 | Math.round(context.getResources().getDimension(end)), 217 | Math.round(context.getResources().getDimension(bottom))); 218 | return this; 219 | } 220 | 221 | /** 222 | * Sets overall padding for zooming and scrolling area in pixels. 223 | * 224 | * @return This Builder object to allow calls chaining 225 | */ 226 | public Builder withContainerPaddingPixels(@Px int padding) { 227 | this.data.setContainerPaddingPixels(new int[]{padding, padding, padding, padding}); 228 | return this; 229 | } 230 | 231 | /** 232 | * Sets `start`, `top`, `end` and `bottom` padding for zooming and scrolling area in pixels. 233 | * 234 | * @return This Builder object to allow calls chaining 235 | */ 236 | public Builder withContainerPaddingPixels(int start, int top, int end, int bottom) { 237 | this.data.setContainerPaddingPixels(new int[]{start, top, end, bottom}); 238 | return this; 239 | } 240 | 241 | /** 242 | * Sets status bar visibility. True by default. 243 | * 244 | * @return This Builder object to allow calls chaining 245 | */ 246 | public Builder withHiddenStatusBar(boolean value) { 247 | this.data.setShouldStatusBarHide(value); 248 | return this; 249 | } 250 | 251 | /** 252 | * Enables or disables zooming. True by default. 253 | * 254 | * @return This Builder object to allow calls chaining 255 | */ 256 | public Builder allowZooming(boolean value) { 257 | this.data.setZoomingAllowed(value); 258 | return this; 259 | } 260 | 261 | /** 262 | * Enables or disables the "Swipe to Dismiss" gesture. True by default. 263 | * 264 | * @return This Builder object to allow calls chaining 265 | */ 266 | public Builder allowSwipeToDismiss(boolean value) { 267 | this.data.setSwipeToDismissAllowed(value); 268 | return this; 269 | } 270 | 271 | /** 272 | * Sets a target {@link ImageView} to be part of transition when opening or closing the viewer/ 273 | * 274 | * @return This Builder object to allow calls chaining 275 | */ 276 | public Builder withTransitionFrom(ImageView imageView) { 277 | this.data.setTransitionView(imageView); 278 | return this; 279 | } 280 | 281 | /** 282 | * Sets {@link OnImageChangeListener} for the viewer. 283 | * 284 | * @return This Builder object to allow calls chaining 285 | */ 286 | public Builder withImageChangeListener(OnImageChangeListener imageChangeListener) { 287 | this.data.setImageChangeListener(imageChangeListener); 288 | return this; 289 | } 290 | 291 | /** 292 | * Sets {@link OnDismissListener} for viewer. 293 | * 294 | * @return This Builder object to allow calls chaining 295 | */ 296 | public Builder withDismissListener(OnDismissListener onDismissListener) { 297 | this.data.setOnDismissListener(onDismissListener); 298 | return this; 299 | } 300 | 301 | /** 302 | * Creates a {@link StfalconImageViewer} with the arguments supplied to this builder. It does not 303 | * show the dialog. This allows the user to do any extra processing 304 | * before displaying the dialog. Use {@link #show()} if you don't have any other processing 305 | * to do and want this to be created and displayed. 306 | */ 307 | public StfalconImageViewer build() { 308 | return new StfalconImageViewer<>(context, data); 309 | } 310 | 311 | /** 312 | * Creates the {@link StfalconImageViewer} with the arguments supplied to this builder and 313 | * shows the dialog. 314 | */ 315 | public StfalconImageViewer show() { 316 | return show(true); 317 | } 318 | 319 | /** 320 | * Creates the {@link StfalconImageViewer} with the arguments supplied to this builder and 321 | * shows the dialog. 322 | * 323 | * @param animate whether the passed transition view should be animated on open. Useful for screen rotation handling. 324 | */ 325 | public StfalconImageViewer show(boolean animate) { 326 | StfalconImageViewer viewer = build(); 327 | viewer.show(animate); 328 | return viewer; 329 | } 330 | } 331 | } 332 | -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/extensions/ImageView.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.extensions 18 | 19 | import android.graphics.drawable.BitmapDrawable 20 | import android.widget.ImageView 21 | 22 | fun ImageView.copyBitmapFrom(target: ImageView?) { 23 | target?.drawable?.let { 24 | if (it is BitmapDrawable) { 25 | setImageBitmap(it.bitmap) 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/extensions/PhotoView.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.extensions 18 | 19 | import com.github.chrisbanes.photoview.PhotoView 20 | 21 | internal fun PhotoView.resetScale(animate: Boolean) { 22 | setScale(minimumScale, animate) 23 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/extensions/SparseArray.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.extensions 18 | 19 | import android.util.SparseArray 20 | import java.util.ConcurrentModificationException 21 | 22 | internal inline fun SparseArray.forEach(block: (Int, T) -> Unit) { 23 | val size = this.size() 24 | for (index in 0 until size) { 25 | if (size != this.size()) throw ConcurrentModificationException() 26 | block(this.keyAt(index), this.valueAt(index)) 27 | } 28 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/extensions/Transition.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.extensions 18 | 19 | import androidx.transition.Transition 20 | 21 | internal fun Transition.addListener( 22 | onTransitionEnd: ((Transition) -> Unit)? = null, 23 | onTransitionResume: ((Transition) -> Unit)? = null, 24 | onTransitionPause: ((Transition) -> Unit)? = null, 25 | onTransitionCancel: ((Transition) -> Unit)? = null, 26 | onTransitionStart: ((Transition) -> Unit)? = null 27 | ) = addListener( 28 | object : Transition.TransitionListener { 29 | override fun onTransitionEnd(transition: Transition) { 30 | onTransitionEnd?.invoke(transition) 31 | } 32 | 33 | override fun onTransitionResume(transition: Transition) { 34 | onTransitionResume?.invoke(transition) 35 | } 36 | 37 | override fun onTransitionPause(transition: Transition) { 38 | onTransitionPause?.invoke(transition) 39 | } 40 | 41 | override fun onTransitionCancel(transition: Transition) { 42 | onTransitionCancel?.invoke(transition) 43 | } 44 | 45 | override fun onTransitionStart(transition: Transition) { 46 | onTransitionStart?.invoke(transition) 47 | } 48 | }) -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/extensions/View.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.extensions 18 | 19 | import android.animation.Animator 20 | import android.animation.AnimatorListenerAdapter 21 | import android.animation.ObjectAnimator 22 | import android.graphics.Rect 23 | import android.view.View 24 | import android.view.ViewConfiguration 25 | import android.view.ViewGroup 26 | 27 | internal val View?.localVisibleRect: Rect 28 | get() = Rect().also { this?.getLocalVisibleRect(it) } 29 | 30 | internal val View?.globalVisibleRect: Rect 31 | get() = Rect().also { this?.getGlobalVisibleRect(it) } 32 | 33 | internal val View?.hitRect: Rect 34 | get() = Rect().also { this?.getHitRect(it) } 35 | 36 | internal val View?.isRectVisible: Boolean 37 | get() = this != null && globalVisibleRect != localVisibleRect 38 | 39 | internal val View?.isVisible: Boolean 40 | get() = this != null && visibility == View.VISIBLE 41 | 42 | internal fun View.makeVisible() { 43 | visibility = View.VISIBLE 44 | } 45 | 46 | internal fun View.makeInvisible() { 47 | visibility = View.INVISIBLE 48 | } 49 | 50 | internal fun View.makeGone() { 51 | visibility = View.GONE 52 | } 53 | 54 | internal inline fun T.postApply(crossinline block: T.() -> Unit) { 55 | post { apply(block) } 56 | } 57 | 58 | internal inline fun T.postDelayed(delayMillis: Long, crossinline block: T.() -> Unit) { 59 | postDelayed({ block() }, delayMillis) 60 | } 61 | 62 | internal fun View.applyMargin( 63 | start: Int? = null, 64 | top: Int? = null, 65 | end: Int? = null, 66 | bottom: Int? = null 67 | ) { 68 | if (layoutParams is ViewGroup.MarginLayoutParams) { 69 | layoutParams = (layoutParams as ViewGroup.MarginLayoutParams).apply { 70 | marginStart = start ?: marginStart 71 | topMargin = top ?: topMargin 72 | marginEnd = end ?: marginEnd 73 | bottomMargin = bottom ?: bottomMargin 74 | } 75 | } 76 | } 77 | 78 | internal fun View.requestNewSize( 79 | width: Int, height: Int) { 80 | layoutParams.width = width 81 | layoutParams.height = height 82 | layoutParams = layoutParams 83 | } 84 | 85 | internal fun View.makeViewMatchParent() { 86 | applyMargin(0, 0, 0, 0) 87 | requestNewSize( 88 | ViewGroup.LayoutParams.MATCH_PARENT, 89 | ViewGroup.LayoutParams.MATCH_PARENT) 90 | } 91 | 92 | internal fun View.animateAlpha(from: Float?, to: Float?, duration: Long) { 93 | alpha = from ?: 0f 94 | clearAnimation() 95 | animate() 96 | .alpha(to ?: 0f) 97 | .setDuration(duration) 98 | .start() 99 | } 100 | 101 | internal fun View.switchVisibilityWithAnimation() { 102 | val isVisible = visibility == View.VISIBLE 103 | val from = if (isVisible) 1.0f else 0.0f 104 | val to = if (isVisible) 0.0f else 1.0f 105 | 106 | ObjectAnimator.ofFloat(this, "alpha", from, to).apply { 107 | duration = ViewConfiguration.getDoubleTapTimeout().toLong() 108 | 109 | if (isVisible) { 110 | addListener(object : AnimatorListenerAdapter() { 111 | override fun onAnimationEnd(animation: Animator?) { 112 | makeGone() 113 | } 114 | }) 115 | } else { 116 | makeVisible() 117 | } 118 | 119 | start() 120 | } 121 | } 122 | 123 | -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/extensions/ViewPager.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.extensions 18 | 19 | import androidx.viewpager.widget.ViewPager 20 | 21 | internal fun ViewPager.addOnPageChangeListener( 22 | onPageScrolled: ((position: Int, offset: Float, offsetPixels: Int) -> Unit)? = null, 23 | onPageSelected: ((position: Int) -> Unit)? = null, 24 | onPageScrollStateChanged: ((state: Int) -> Unit)? = null 25 | ) = object : ViewPager.OnPageChangeListener { 26 | override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { 27 | onPageScrolled?.invoke(position, positionOffset, positionOffsetPixels) 28 | } 29 | 30 | override fun onPageSelected(position: Int) { 31 | onPageSelected?.invoke(position) 32 | } 33 | 34 | override fun onPageScrollStateChanged(state: Int) { 35 | onPageScrollStateChanged?.invoke(state) 36 | } 37 | }.also { addOnPageChangeListener(it) } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/extensions/ViewPropertyAnimator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.extensions 18 | 19 | import android.animation.Animator 20 | import android.animation.AnimatorListenerAdapter 21 | import android.view.ViewPropertyAnimator 22 | 23 | internal fun ViewPropertyAnimator.setAnimatorListener( 24 | onAnimationEnd: ((Animator?) -> Unit)? = null, 25 | onAnimationStart: ((Animator?) -> Unit)? = null 26 | ) = this.setListener( 27 | object : AnimatorListenerAdapter() { 28 | 29 | override fun onAnimationEnd(animation: Animator?) { 30 | onAnimationEnd?.invoke(animation) 31 | } 32 | 33 | override fun onAnimationStart(animation: Animator?) { 34 | onAnimationStart?.invoke(animation) 35 | } 36 | }) -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/gestures/detector/SimpleOnGestureListener.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.gestures.detector 18 | 19 | import android.view.GestureDetector 20 | import android.view.MotionEvent 21 | 22 | internal class SimpleOnGestureListener( 23 | private val onSingleTap: ((MotionEvent) -> Boolean)? = null, 24 | private val onDoubleTap: ((MotionEvent) -> Boolean)? = null 25 | ) : GestureDetector.SimpleOnGestureListener() { 26 | 27 | override fun onSingleTapConfirmed(event: MotionEvent): Boolean = 28 | onSingleTap?.invoke(event) ?: false 29 | 30 | override fun onDoubleTap(event: MotionEvent): Boolean = 31 | onDoubleTap?.invoke(event) ?: false 32 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/gestures/direction/SwipeDirection.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.gestures.direction 18 | 19 | internal enum class SwipeDirection { 20 | NOT_DETECTED, 21 | UP, 22 | DOWN, 23 | LEFT, 24 | RIGHT; 25 | 26 | companion object { 27 | fun fromAngle(angle: Double): SwipeDirection { 28 | return when (angle) { 29 | in 0.0..45.0 -> RIGHT 30 | in 45.0..135.0 -> UP 31 | in 135.0..225.0 -> LEFT 32 | in 225.0..315.0 -> DOWN 33 | in 315.0..360.0 -> RIGHT 34 | else -> NOT_DETECTED 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/gestures/direction/SwipeDirectionDetector.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.gestures.direction 18 | 19 | import android.content.Context 20 | import android.view.MotionEvent 21 | import android.view.ViewConfiguration 22 | 23 | internal class SwipeDirectionDetector( 24 | context: Context, 25 | private val onDirectionDetected: (SwipeDirection) -> Unit 26 | ) { 27 | 28 | private val touchSlop: Int = ViewConfiguration.get(context).scaledTouchSlop 29 | private var startX: Float = 0f 30 | private var startY: Float = 0f 31 | private var isDetected: Boolean = false 32 | 33 | fun handleTouchEvent(event: MotionEvent) { 34 | when (event.action) { 35 | MotionEvent.ACTION_DOWN -> { 36 | startX = event.x 37 | startY = event.y 38 | } 39 | MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_UP -> { 40 | if (!isDetected) { 41 | onDirectionDetected(SwipeDirection.NOT_DETECTED) 42 | } 43 | startY = 0.0f 44 | startX = startY 45 | isDetected = false 46 | } 47 | MotionEvent.ACTION_MOVE -> if (!isDetected && getEventDistance(event) > touchSlop) { 48 | isDetected = true 49 | onDirectionDetected(getDirection(startX, startY, event.x, event.y)) 50 | } 51 | } 52 | } 53 | 54 | /** 55 | * Given two points in the plane p1=(x1, x2) and p2=(y1, y1), this method 56 | * returns the direction that an arrow pointing from p1 to p2 would have. 57 | * 58 | * @param x1 the x position of the first point 59 | * @param y1 the y position of the first point 60 | * @param x2 the x position of the second point 61 | * @param y2 the y position of the second point 62 | * @return the direction 63 | */ 64 | private fun getDirection(x1: Float, y1: Float, x2: Float, y2: Float): SwipeDirection { 65 | val angle = getAngle(x1, y1, x2, y2) 66 | return SwipeDirection.fromAngle(angle) 67 | } 68 | 69 | /** 70 | * Finds the angle between two points in the plane (x1,y1) and (x2, y2) 71 | * The angle is measured with 0/360 being the X-axis to the right, angles 72 | * increase counter clockwise. 73 | * 74 | * @param x1 the x position of the first point 75 | * @param y1 the y position of the first point 76 | * @param x2 the x position of the second point 77 | * @param y2 the y position of the second point 78 | * @return the angle between two points 79 | */ 80 | private fun getAngle(x1: Float, y1: Float, x2: Float, y2: Float): Double { 81 | val rad = Math.atan2((y1 - y2).toDouble(), (x2 - x1).toDouble()) + Math.PI 82 | return (rad * 180 / Math.PI + 180) % 360 83 | } 84 | 85 | private fun getEventDistance(ev: MotionEvent): Float { 86 | val dx = ev.getX(0) - startX 87 | val dy = ev.getY(0) - startY 88 | return Math.sqrt((dx * dx + dy * dy).toDouble()).toFloat() 89 | } 90 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/gestures/dismiss/SwipeToDismissHandler.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.gestures.dismiss 18 | 19 | import android.annotation.SuppressLint 20 | import android.view.MotionEvent 21 | import android.view.View 22 | import android.view.animation.AccelerateInterpolator 23 | import com.stfalcon.imageviewer.common.extensions.hitRect 24 | import com.stfalcon.imageviewer.common.extensions.setAnimatorListener 25 | 26 | internal class SwipeToDismissHandler( 27 | private val swipeView: View, 28 | private val onDismiss: () -> Unit, 29 | private val onSwipeViewMove: (translationY: Float, translationLimit: Int) -> Unit, 30 | private val shouldAnimateDismiss: () -> Boolean 31 | ) : View.OnTouchListener { 32 | 33 | companion object { 34 | private const val ANIMATION_DURATION = 200L 35 | } 36 | 37 | private var translationLimit: Int = swipeView.height / 4 38 | private var isTracking = false 39 | private var startY: Float = 0f 40 | 41 | @SuppressLint("ClickableViewAccessibility") 42 | override fun onTouch(v: View, event: MotionEvent): Boolean { 43 | when (event.action) { 44 | MotionEvent.ACTION_DOWN -> { 45 | if (swipeView.hitRect.contains(event.x.toInt(), event.y.toInt())) { 46 | isTracking = true 47 | } 48 | startY = event.y 49 | return true 50 | } 51 | MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { 52 | if (isTracking) { 53 | isTracking = false 54 | onTrackingEnd(v.height) 55 | } 56 | return true 57 | } 58 | MotionEvent.ACTION_MOVE -> { 59 | if (isTracking) { 60 | val translationY = event.y - startY 61 | swipeView.translationY = translationY 62 | onSwipeViewMove(translationY, translationLimit) 63 | } 64 | return true 65 | } 66 | else -> { 67 | return false 68 | } 69 | } 70 | } 71 | 72 | internal fun initiateDismissToBottom() { 73 | animateTranslation(swipeView.height.toFloat()) 74 | } 75 | 76 | private fun onTrackingEnd(parentHeight: Int) { 77 | val animateTo = when { 78 | swipeView.translationY < -translationLimit -> -parentHeight.toFloat() 79 | swipeView.translationY > translationLimit -> parentHeight.toFloat() 80 | else -> 0f 81 | } 82 | 83 | if (animateTo != 0f && !shouldAnimateDismiss()) { 84 | onDismiss() 85 | } else { 86 | animateTranslation(animateTo) 87 | } 88 | } 89 | 90 | private fun animateTranslation(translationTo: Float) { 91 | swipeView.animate() 92 | .translationY(translationTo) 93 | .setDuration(ANIMATION_DURATION) 94 | .setInterpolator(AccelerateInterpolator()) 95 | .setUpdateListener { onSwipeViewMove(swipeView.translationY, translationLimit) } 96 | .setAnimatorListener(onAnimationEnd = { 97 | if (translationTo != 0f) { 98 | onDismiss() 99 | } 100 | 101 | //remove the update listener, otherwise it will be saved on the next animation execution: 102 | swipeView.animate().setUpdateListener(null) 103 | }) 104 | .start() 105 | } 106 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/pager/MultiTouchViewPager.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.common.pager 18 | 19 | import android.annotation.SuppressLint 20 | import android.content.Context 21 | import android.util.AttributeSet 22 | import android.view.MotionEvent 23 | import androidx.viewpager.widget.ViewPager 24 | import com.stfalcon.imageviewer.common.extensions.addOnPageChangeListener 25 | 26 | internal class MultiTouchViewPager @JvmOverloads constructor( 27 | context: Context, 28 | attrs: AttributeSet? = null 29 | ) : ViewPager(context, attrs) { 30 | 31 | internal var isIdle = true 32 | private set 33 | 34 | private var isInterceptionDisallowed: Boolean = false 35 | private var pageChangeListener: ViewPager.OnPageChangeListener? = null 36 | 37 | override fun onAttachedToWindow() { 38 | super.onAttachedToWindow() 39 | pageChangeListener = addOnPageChangeListener( 40 | onPageScrollStateChanged = ::onPageScrollStateChanged) 41 | } 42 | 43 | override fun onDetachedFromWindow() { 44 | super.onDetachedFromWindow() 45 | pageChangeListener?.let { removeOnPageChangeListener(it) } 46 | } 47 | 48 | override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) { 49 | isInterceptionDisallowed = disallowIntercept 50 | super.requestDisallowInterceptTouchEvent(disallowIntercept) 51 | } 52 | 53 | override fun dispatchTouchEvent(ev: MotionEvent): Boolean { 54 | return if (ev.pointerCount > 1 && isInterceptionDisallowed) { 55 | requestDisallowInterceptTouchEvent(false) 56 | val handled = super.dispatchTouchEvent(ev) 57 | requestDisallowInterceptTouchEvent(true) 58 | handled 59 | } else { 60 | super.dispatchTouchEvent(ev) 61 | } 62 | } 63 | 64 | override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { 65 | return if (ev.pointerCount > 1) { 66 | false 67 | } else { 68 | try { 69 | super.onInterceptTouchEvent(ev) 70 | } catch (ex: IllegalArgumentException) { 71 | false 72 | } 73 | } 74 | } 75 | 76 | @SuppressLint("ClickableViewAccessibility") 77 | override fun onTouchEvent(ev: MotionEvent): Boolean { 78 | return try { 79 | super.onTouchEvent(ev) 80 | } catch (ex: IllegalArgumentException) { 81 | false 82 | } 83 | } 84 | 85 | private fun onPageScrollStateChanged(state: Int) { 86 | isIdle = state == ViewPager.SCROLL_STATE_IDLE 87 | } 88 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/common/pager/RecyclingPagerAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.imageviewer.common.pager 2 | 3 | import android.os.Bundle 4 | import android.os.Parcelable 5 | import android.util.SparseArray 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.viewpager.widget.PagerAdapter 9 | import com.stfalcon.imageviewer.common.extensions.forEach 10 | 11 | internal abstract class RecyclingPagerAdapter 12 | : PagerAdapter() { 13 | 14 | companion object { 15 | private val STATE = RecyclingPagerAdapter::class.java.simpleName 16 | private const val VIEW_TYPE_IMAGE = 0 17 | } 18 | 19 | internal abstract fun getItemCount(): Int 20 | internal abstract fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH 21 | internal abstract fun onBindViewHolder(holder: VH, position: Int) 22 | 23 | private val typeCaches = SparseArray() 24 | private var savedStates = SparseArray() 25 | 26 | override fun destroyItem(parent: ViewGroup, position: Int, item: Any) { 27 | if (item is ViewHolder) { 28 | item.detach(parent) 29 | } 30 | } 31 | 32 | override fun getCount() = getItemCount() 33 | 34 | override fun getItemPosition(item: Any) = POSITION_NONE 35 | 36 | @Suppress("UNCHECKED_CAST") 37 | override fun instantiateItem(parent: ViewGroup, position: Int): Any { 38 | var cache = typeCaches.get(VIEW_TYPE_IMAGE) 39 | 40 | if (cache == null) { 41 | cache = RecycleCache(this) 42 | typeCaches.put(VIEW_TYPE_IMAGE, cache) 43 | } 44 | 45 | return cache.getFreeViewHolder(parent, VIEW_TYPE_IMAGE) 46 | .apply { 47 | attach(parent, position) 48 | onBindViewHolder(this as VH, position) 49 | onRestoreInstanceState(savedStates.get(getItemId(position))) 50 | } 51 | } 52 | 53 | override fun isViewFromObject(view: View, obj: Any): Boolean = 54 | obj is ViewHolder && obj.itemView === view 55 | 56 | override fun saveState(): Parcelable? { 57 | for (viewHolder in getAttachedViewHolders()) { 58 | savedStates.put(getItemId(viewHolder.position), viewHolder.onSaveInstanceState()) 59 | } 60 | return Bundle().apply { putSparseParcelableArray(STATE, savedStates) } 61 | } 62 | 63 | override fun restoreState(state: Parcelable?, loader: ClassLoader?) { 64 | if (state != null && state is Bundle) { 65 | state.classLoader = loader 66 | val sparseArray: SparseArray? = state.getSparseParcelableArray(STATE) 67 | savedStates = sparseArray ?: SparseArray() 68 | } 69 | super.restoreState(state, loader) 70 | } 71 | 72 | private fun getItemId(position: Int) = position 73 | 74 | private fun getAttachedViewHolders(): List { 75 | val attachedViewHolders = ArrayList() 76 | 77 | typeCaches.forEach { _, value -> 78 | value.caches.forEach { holder -> 79 | if (holder.isAttached) { 80 | attachedViewHolders.add(holder) 81 | } 82 | } 83 | } 84 | 85 | return attachedViewHolders 86 | } 87 | 88 | private class RecycleCache internal constructor( 89 | private val adapter: RecyclingPagerAdapter<*> 90 | ) { 91 | 92 | internal val caches = mutableListOf() 93 | 94 | internal fun getFreeViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 95 | var iterationsCount = 0 96 | var viewHolder: ViewHolder 97 | 98 | while (iterationsCount < caches.size) { 99 | viewHolder = caches[iterationsCount] 100 | if (!viewHolder.isAttached) { 101 | return viewHolder 102 | } 103 | iterationsCount++ 104 | } 105 | 106 | return adapter.onCreateViewHolder(parent, viewType).also { caches.add(it) } 107 | } 108 | } 109 | 110 | internal abstract class ViewHolder(internal val itemView: View) { 111 | 112 | companion object { 113 | private val STATE = ViewHolder::class.java.simpleName 114 | } 115 | 116 | internal var position: Int = 0 117 | internal var isAttached: Boolean = false 118 | 119 | internal fun attach(parent: ViewGroup, position: Int) { 120 | this.isAttached = true 121 | this.position = position 122 | parent.addView(itemView) 123 | } 124 | 125 | internal fun detach(parent: ViewGroup) { 126 | parent.removeView(itemView) 127 | isAttached = false 128 | } 129 | 130 | internal fun onRestoreInstanceState(state: Parcelable?) { 131 | getStateFromParcelable(state)?.let { itemView.restoreHierarchyState(it) } 132 | } 133 | 134 | internal fun onSaveInstanceState(): Parcelable { 135 | val state = SparseArray() 136 | itemView.saveHierarchyState(state) 137 | return Bundle().apply { putSparseParcelableArray(STATE, state) } 138 | } 139 | 140 | private fun getStateFromParcelable(state: Parcelable?): SparseArray? { 141 | if (state != null && state is Bundle && state.containsKey(STATE)) { 142 | return state.getSparseParcelableArray(STATE) 143 | } 144 | return null 145 | } 146 | } 147 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/listeners/OnDismissListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.listeners; 18 | 19 | /** 20 | * Interface definition for a callback to be invoked when 21 | * {@link com.stfalcon.imageviewer.StfalconImageViewer} was dismissed. 22 | * */ 23 | //N.B.! This class is written in Java for convenient use of lambdas due to languages compatibility issues. 24 | public interface OnDismissListener { 25 | 26 | void onDismiss(); 27 | } 28 | -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/listeners/OnImageChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.listeners; 18 | 19 | /** 20 | * Interface definition for a callback to be invoked when current image position was changed. 21 | */ 22 | //N.B.! This class is written in Java for convenient use of lambdas due to languages compatibility issues. 23 | public interface OnImageChangeListener { 24 | 25 | void onImageChange(int position); 26 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/loader/ImageLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.loader; 18 | 19 | import android.widget.ImageView; 20 | 21 | /** 22 | * Interface definition for a callback to be invoked when image should be loaded 23 | */ 24 | //N.B.! This class is written in Java for convenient use of lambdas due to languages compatibility issues. 25 | public interface ImageLoader { 26 | 27 | /** 28 | * Fires every time when image object should be displayed in a provided {@link ImageView} 29 | * 30 | * @param imageView an {@link ImageView} object where the image should be loaded 31 | * @param image image data from which image should be loaded 32 | */ 33 | void loadImage(ImageView imageView, T image); 34 | } 35 | -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/adapter/ImagesPagerAdapter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.viewer.adapter 18 | 19 | import android.content.Context 20 | import android.view.View 21 | import android.view.ViewGroup 22 | import com.github.chrisbanes.photoview.PhotoView 23 | import com.stfalcon.imageviewer.common.extensions.resetScale 24 | import com.stfalcon.imageviewer.common.pager.RecyclingPagerAdapter 25 | import com.stfalcon.imageviewer.loader.ImageLoader 26 | 27 | internal class ImagesPagerAdapter( 28 | private val context: Context, 29 | _images: List, 30 | private val imageLoader: ImageLoader, 31 | private val isZoomingAllowed: Boolean 32 | ) : RecyclingPagerAdapter.ViewHolder>() { 33 | 34 | private var images = _images 35 | private val holders = mutableListOf() 36 | 37 | fun isScaled(position: Int): Boolean = 38 | holders.firstOrNull { it.position == position }?.isScaled ?: false 39 | 40 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 41 | val photoView = PhotoView(context).apply { 42 | isEnabled = isZoomingAllowed 43 | setOnViewDragListener { _, _ -> setAllowParentInterceptOnEdge(scale == 1.0f) } 44 | } 45 | 46 | return ViewHolder(photoView).also { holders.add(it) } 47 | } 48 | 49 | override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(position) 50 | 51 | override fun getItemCount() = images.size 52 | 53 | internal fun updateImages(images: List) { 54 | this.images = images 55 | notifyDataSetChanged() 56 | } 57 | 58 | internal fun resetScale(position: Int) = 59 | holders.firstOrNull { it.position == position }?.resetScale() 60 | 61 | internal inner class ViewHolder(itemView: View) 62 | : RecyclingPagerAdapter.ViewHolder(itemView) { 63 | 64 | internal var isScaled: Boolean = false 65 | get() = photoView.scale > 1f 66 | 67 | private val photoView: PhotoView = itemView as PhotoView 68 | 69 | fun bind(position: Int) { 70 | this.position = position 71 | imageLoader.loadImage(photoView, images[position]) 72 | } 73 | 74 | fun resetScale() = photoView.resetScale(animate = true) 75 | } 76 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/builder/BuilderData.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.viewer.builder 18 | 19 | import android.graphics.Color 20 | import android.view.View 21 | import android.widget.ImageView 22 | import com.stfalcon.imageviewer.listeners.OnDismissListener 23 | import com.stfalcon.imageviewer.listeners.OnImageChangeListener 24 | import com.stfalcon.imageviewer.loader.ImageLoader 25 | 26 | internal class BuilderData( 27 | val images: List, 28 | val imageLoader: ImageLoader 29 | ) { 30 | var backgroundColor = Color.BLACK 31 | var startPosition: Int = 0 32 | var imageChangeListener: OnImageChangeListener? = null 33 | var onDismissListener: OnDismissListener? = null 34 | var overlayView: View? = null 35 | var imageMarginPixels: Int = 0 36 | var containerPaddingPixels = IntArray(4) 37 | var shouldStatusBarHide = true 38 | var isZoomingAllowed = true 39 | var isSwipeToDismissAllowed = true 40 | var transitionView: ImageView? = null 41 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/dialog/ImageViewerDialog.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.viewer.dialog 18 | 19 | import android.content.Context 20 | import android.view.KeyEvent 21 | import android.widget.ImageView 22 | import androidx.appcompat.app.AlertDialog 23 | import com.stfalcon.imageviewer.R 24 | import com.stfalcon.imageviewer.viewer.builder.BuilderData 25 | import com.stfalcon.imageviewer.viewer.view.ImageViewerView 26 | 27 | internal class ImageViewerDialog( 28 | context: Context, 29 | private val builderData: BuilderData 30 | ) { 31 | 32 | private val dialog: AlertDialog 33 | private val viewerView: ImageViewerView = ImageViewerView(context) 34 | private var animateOpen = true 35 | 36 | private val dialogStyle: Int 37 | get() = if (builderData.shouldStatusBarHide) 38 | R.style.ImageViewerDialog_NoStatusBar 39 | else 40 | R.style.ImageViewerDialog_Default 41 | 42 | init { 43 | setupViewerView() 44 | dialog = AlertDialog 45 | .Builder(context, dialogStyle) 46 | .setView(viewerView) 47 | .setOnKeyListener { _, keyCode, event -> onDialogKeyEvent(keyCode, event) } 48 | .create() 49 | .apply { 50 | setOnShowListener { viewerView.open(builderData.transitionView, animateOpen) } 51 | setOnDismissListener { builderData.onDismissListener?.onDismiss() } 52 | } 53 | } 54 | 55 | fun show(animate: Boolean) { 56 | animateOpen = animate 57 | dialog.show() 58 | } 59 | 60 | fun close() { 61 | viewerView.close() 62 | } 63 | 64 | fun dismiss() { 65 | dialog.dismiss() 66 | } 67 | 68 | fun updateImages(images: List) { 69 | viewerView.updateImages(images) 70 | } 71 | 72 | fun getCurrentPosition(): Int = 73 | viewerView.currentPosition 74 | 75 | fun setCurrentPosition(position: Int): Int { 76 | viewerView.currentPosition = position 77 | return viewerView.currentPosition 78 | } 79 | 80 | fun updateTransitionImage(imageView: ImageView?) { 81 | viewerView.updateTransitionImage(imageView) 82 | } 83 | 84 | private fun onDialogKeyEvent(keyCode: Int, event: KeyEvent): Boolean { 85 | if (keyCode == KeyEvent.KEYCODE_BACK && 86 | event.action == KeyEvent.ACTION_UP && 87 | !event.isCanceled 88 | ) { 89 | if (viewerView.isScaled) { 90 | viewerView.resetScale() 91 | } else { 92 | viewerView.close() 93 | } 94 | return true 95 | } 96 | return false 97 | } 98 | 99 | private fun setupViewerView() { 100 | viewerView.apply { 101 | isZoomingAllowed = builderData.isZoomingAllowed 102 | isSwipeToDismissAllowed = builderData.isSwipeToDismissAllowed 103 | 104 | containerPadding = builderData.containerPaddingPixels 105 | imagesMargin = builderData.imageMarginPixels 106 | overlayView = builderData.overlayView 107 | 108 | setBackgroundColor(builderData.backgroundColor) 109 | setImages(builderData.images, builderData.startPosition, builderData.imageLoader) 110 | 111 | onPageChange = { position -> builderData.imageChangeListener?.onImageChange(position) } 112 | onDismiss = { dialog.dismiss() } 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/view/ImageViewerView.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.viewer.view 18 | 19 | import android.content.Context 20 | import android.util.AttributeSet 21 | import android.view.MotionEvent 22 | import android.view.ScaleGestureDetector 23 | import android.view.View 24 | import android.view.ViewGroup 25 | import android.widget.FrameLayout 26 | import android.widget.ImageView 27 | import android.widget.RelativeLayout 28 | import androidx.core.view.GestureDetectorCompat 29 | import com.stfalcon.imageviewer.R 30 | import com.stfalcon.imageviewer.common.extensions.addOnPageChangeListener 31 | import com.stfalcon.imageviewer.common.extensions.animateAlpha 32 | import com.stfalcon.imageviewer.common.extensions.applyMargin 33 | import com.stfalcon.imageviewer.common.extensions.copyBitmapFrom 34 | import com.stfalcon.imageviewer.common.extensions.isRectVisible 35 | import com.stfalcon.imageviewer.common.extensions.isVisible 36 | import com.stfalcon.imageviewer.common.extensions.makeGone 37 | import com.stfalcon.imageviewer.common.extensions.makeInvisible 38 | import com.stfalcon.imageviewer.common.extensions.makeVisible 39 | import com.stfalcon.imageviewer.common.extensions.switchVisibilityWithAnimation 40 | import com.stfalcon.imageviewer.common.gestures.detector.SimpleOnGestureListener 41 | import com.stfalcon.imageviewer.common.gestures.direction.SwipeDirection 42 | import com.stfalcon.imageviewer.common.gestures.direction.SwipeDirection.DOWN 43 | import com.stfalcon.imageviewer.common.gestures.direction.SwipeDirection.LEFT 44 | import com.stfalcon.imageviewer.common.gestures.direction.SwipeDirection.RIGHT 45 | import com.stfalcon.imageviewer.common.gestures.direction.SwipeDirection.UP 46 | import com.stfalcon.imageviewer.common.gestures.direction.SwipeDirectionDetector 47 | import com.stfalcon.imageviewer.common.gestures.dismiss.SwipeToDismissHandler 48 | import com.stfalcon.imageviewer.common.pager.MultiTouchViewPager 49 | import com.stfalcon.imageviewer.loader.ImageLoader 50 | import com.stfalcon.imageviewer.viewer.adapter.ImagesPagerAdapter 51 | 52 | internal class ImageViewerView @JvmOverloads constructor( 53 | context: Context, 54 | attrs: AttributeSet? = null, 55 | defStyleAttr: Int = 0 56 | ) : RelativeLayout(context, attrs, defStyleAttr) { 57 | 58 | internal var isZoomingAllowed = true 59 | internal var isSwipeToDismissAllowed = true 60 | 61 | internal var currentPosition: Int 62 | get() = imagesPager.currentItem 63 | set(value) { 64 | imagesPager.currentItem = value 65 | } 66 | 67 | internal var onDismiss: (() -> Unit)? = null 68 | internal var onPageChange: ((position: Int) -> Unit)? = null 69 | 70 | internal val isScaled 71 | get() = imagesAdapter?.isScaled(currentPosition) ?: false 72 | 73 | internal var containerPadding = intArrayOf(0, 0, 0, 0) 74 | 75 | internal var imagesMargin 76 | get() = imagesPager.pageMargin 77 | set(value) { 78 | imagesPager.pageMargin = value 79 | } 80 | 81 | internal var overlayView: View? = null 82 | set(value) { 83 | field = value 84 | value?.let { rootContainer.addView(it) } 85 | } 86 | 87 | private var rootContainer: ViewGroup 88 | private var backgroundView: View 89 | private var dismissContainer: ViewGroup 90 | 91 | private val transitionImageContainer: FrameLayout 92 | private val transitionImageView: ImageView 93 | private var externalTransitionImageView: ImageView? = null 94 | 95 | private var imagesPager: MultiTouchViewPager 96 | private var imagesAdapter: ImagesPagerAdapter? = null 97 | 98 | private var directionDetector: SwipeDirectionDetector 99 | private var gestureDetector: GestureDetectorCompat 100 | private var scaleDetector: ScaleGestureDetector 101 | private lateinit var swipeDismissHandler: SwipeToDismissHandler 102 | 103 | private var wasScaled: Boolean = false 104 | private var wasDoubleTapped = false 105 | private var isOverlayWasClicked: Boolean = false 106 | private var swipeDirection: SwipeDirection? = null 107 | 108 | private var images: List = listOf() 109 | private var imageLoader: ImageLoader? = null 110 | private lateinit var transitionImageAnimator: TransitionImageAnimator 111 | 112 | private var startPosition: Int = 0 113 | set(value) { 114 | field = value 115 | currentPosition = value 116 | } 117 | 118 | private val shouldDismissToBottom: Boolean 119 | get() = externalTransitionImageView == null 120 | || !externalTransitionImageView.isRectVisible 121 | || !isAtStartPosition 122 | 123 | private val isAtStartPosition: Boolean 124 | get() = currentPosition == startPosition 125 | 126 | init { 127 | View.inflate(context, R.layout.view_image_viewer, this) 128 | 129 | rootContainer = findViewById(R.id.rootContainer) 130 | backgroundView = findViewById(R.id.backgroundView) 131 | dismissContainer = findViewById(R.id.dismissContainer) 132 | 133 | transitionImageContainer = findViewById(R.id.transitionImageContainer) 134 | transitionImageView = findViewById(R.id.transitionImageView) 135 | 136 | imagesPager = findViewById(R.id.imagesPager) 137 | imagesPager.addOnPageChangeListener( 138 | onPageSelected = { 139 | externalTransitionImageView?.apply { 140 | if (isAtStartPosition) makeInvisible() else makeVisible() 141 | } 142 | onPageChange?.invoke(it) 143 | }) 144 | 145 | directionDetector = createSwipeDirectionDetector() 146 | gestureDetector = createGestureDetector() 147 | scaleDetector = createScaleGestureDetector() 148 | } 149 | 150 | override fun dispatchTouchEvent(event: MotionEvent): Boolean { 151 | if (overlayView.isVisible && overlayView?.dispatchTouchEvent(event) == true) { 152 | return true 153 | } 154 | 155 | if (!this::transitionImageAnimator.isInitialized || transitionImageAnimator.isAnimating) { 156 | return true 157 | } 158 | 159 | //one more tiny kludge to prevent single tap a one-finger zoom which is broken by the SDK 160 | if (wasDoubleTapped && 161 | event.action == MotionEvent.ACTION_MOVE && 162 | event.pointerCount == 1) { 163 | return true 164 | } 165 | 166 | handleUpDownEvent(event) 167 | 168 | if (swipeDirection == null && (scaleDetector.isInProgress || event.pointerCount > 1 || wasScaled)) { 169 | wasScaled = true 170 | return imagesPager.dispatchTouchEvent(event) 171 | } 172 | 173 | return if (isScaled) super.dispatchTouchEvent(event) else handleTouchIfNotScaled(event) 174 | } 175 | 176 | override fun setBackgroundColor(color: Int) { 177 | findViewById(R.id.backgroundView).setBackgroundColor(color) 178 | } 179 | 180 | internal fun setImages(images: List, startPosition: Int, imageLoader: ImageLoader) { 181 | this.images = images 182 | this.imageLoader = imageLoader 183 | this.imagesAdapter = ImagesPagerAdapter(context, images, imageLoader, isZoomingAllowed) 184 | this.imagesPager.adapter = imagesAdapter 185 | this.startPosition = startPosition 186 | } 187 | 188 | internal fun open(transitionImageView: ImageView?, animate: Boolean) { 189 | prepareViewsForTransition() 190 | 191 | externalTransitionImageView = transitionImageView 192 | 193 | imageLoader?.loadImage(this.transitionImageView, images[startPosition]) 194 | this.transitionImageView.copyBitmapFrom(transitionImageView) 195 | 196 | transitionImageAnimator = createTransitionImageAnimator(transitionImageView) 197 | swipeDismissHandler = createSwipeToDismissHandler() 198 | rootContainer.setOnTouchListener(swipeDismissHandler) 199 | 200 | if (animate) animateOpen() else prepareViewsForViewer() 201 | } 202 | 203 | internal fun close() { 204 | if (shouldDismissToBottom) { 205 | swipeDismissHandler.initiateDismissToBottom() 206 | } else { 207 | animateClose() 208 | } 209 | } 210 | 211 | internal fun updateImages(images: List) { 212 | this.images = images 213 | imagesAdapter?.updateImages(images) 214 | } 215 | 216 | internal fun updateTransitionImage(imageView: ImageView?) { 217 | externalTransitionImageView?.makeVisible() 218 | imageView?.makeInvisible() 219 | 220 | externalTransitionImageView = imageView 221 | startPosition = currentPosition 222 | transitionImageAnimator = createTransitionImageAnimator(imageView) 223 | imageLoader?.loadImage(transitionImageView, images[startPosition]) 224 | } 225 | 226 | internal fun resetScale() { 227 | imagesAdapter?.resetScale(currentPosition) 228 | } 229 | 230 | private fun animateOpen() { 231 | transitionImageAnimator.animateOpen( 232 | containerPadding = containerPadding, 233 | onTransitionStart = { duration -> 234 | backgroundView.animateAlpha(0f, 1f, duration) 235 | overlayView?.animateAlpha(0f, 1f, duration) 236 | }, 237 | onTransitionEnd = { prepareViewsForViewer() }) 238 | } 239 | 240 | private fun animateClose() { 241 | prepareViewsForTransition() 242 | dismissContainer.applyMargin(0, 0, 0, 0) 243 | 244 | transitionImageAnimator.animateClose( 245 | shouldDismissToBottom = shouldDismissToBottom, 246 | onTransitionStart = { duration -> 247 | backgroundView.animateAlpha(backgroundView.alpha, 0f, duration) 248 | overlayView?.animateAlpha(overlayView?.alpha, 0f, duration) 249 | }, 250 | onTransitionEnd = { onDismiss?.invoke() }) 251 | } 252 | 253 | private fun prepareViewsForTransition() { 254 | transitionImageContainer.makeVisible() 255 | imagesPager.makeGone() 256 | } 257 | 258 | private fun prepareViewsForViewer() { 259 | backgroundView.alpha = 1f 260 | transitionImageContainer.makeGone() 261 | imagesPager.makeVisible() 262 | } 263 | 264 | private fun handleTouchIfNotScaled(event: MotionEvent): Boolean { 265 | directionDetector.handleTouchEvent(event) 266 | 267 | return when (swipeDirection) { 268 | UP, DOWN -> { 269 | if (isSwipeToDismissAllowed && !wasScaled && imagesPager.isIdle) { 270 | swipeDismissHandler.onTouch(rootContainer, event) 271 | } else true 272 | } 273 | LEFT, RIGHT -> { 274 | imagesPager.dispatchTouchEvent(event) 275 | } 276 | else -> true 277 | } 278 | } 279 | 280 | private fun handleUpDownEvent(event: MotionEvent) { 281 | if (event.action == MotionEvent.ACTION_UP) { 282 | handleEventActionUp(event) 283 | } 284 | 285 | if (event.action == MotionEvent.ACTION_DOWN) { 286 | handleEventActionDown(event) 287 | } 288 | 289 | scaleDetector.onTouchEvent(event) 290 | gestureDetector.onTouchEvent(event) 291 | } 292 | 293 | private fun handleEventActionDown(event: MotionEvent) { 294 | swipeDirection = null 295 | wasScaled = false 296 | imagesPager.dispatchTouchEvent(event) 297 | 298 | swipeDismissHandler.onTouch(rootContainer, event) 299 | isOverlayWasClicked = dispatchOverlayTouch(event) 300 | } 301 | 302 | private fun handleEventActionUp(event: MotionEvent) { 303 | wasDoubleTapped = false 304 | swipeDismissHandler.onTouch(rootContainer, event) 305 | imagesPager.dispatchTouchEvent(event) 306 | isOverlayWasClicked = dispatchOverlayTouch(event) 307 | } 308 | 309 | private fun handleSingleTap(event: MotionEvent, isOverlayWasClicked: Boolean) { 310 | if (overlayView != null && !isOverlayWasClicked) { 311 | overlayView?.switchVisibilityWithAnimation() 312 | super.dispatchTouchEvent(event) 313 | } 314 | } 315 | 316 | private fun handleSwipeViewMove(translationY: Float, translationLimit: Int) { 317 | val alpha = calculateTranslationAlpha(translationY, translationLimit) 318 | backgroundView.alpha = alpha 319 | overlayView?.alpha = alpha 320 | } 321 | 322 | private fun dispatchOverlayTouch(event: MotionEvent): Boolean = 323 | overlayView 324 | ?.let { it.isVisible && it.dispatchTouchEvent(event) } 325 | ?: false 326 | 327 | private fun calculateTranslationAlpha(translationY: Float, translationLimit: Int): Float = 328 | 1.0f - 1.0f / translationLimit.toFloat() / 4f * Math.abs(translationY) 329 | 330 | private fun createSwipeDirectionDetector() = 331 | SwipeDirectionDetector(context) { swipeDirection = it } 332 | 333 | private fun createGestureDetector() = 334 | GestureDetectorCompat(context, SimpleOnGestureListener( 335 | onSingleTap = { 336 | if (imagesPager.isIdle) { 337 | handleSingleTap(it, isOverlayWasClicked) 338 | } 339 | false 340 | }, 341 | onDoubleTap = { 342 | wasDoubleTapped = !isScaled 343 | false 344 | } 345 | )) 346 | 347 | private fun createScaleGestureDetector() = 348 | ScaleGestureDetector(context, ScaleGestureDetector.SimpleOnScaleGestureListener()) 349 | 350 | private fun createSwipeToDismissHandler() 351 | : SwipeToDismissHandler = SwipeToDismissHandler( 352 | swipeView = dismissContainer, 353 | shouldAnimateDismiss = { shouldDismissToBottom }, 354 | onDismiss = { animateClose() }, 355 | onSwipeViewMove = ::handleSwipeViewMove) 356 | 357 | private fun createTransitionImageAnimator(transitionImageView: ImageView?) = 358 | TransitionImageAnimator( 359 | externalImage = transitionImageView, 360 | internalImage = this.transitionImageView, 361 | internalImageContainer = this.transitionImageContainer) 362 | } -------------------------------------------------------------------------------- /imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/view/TransitionImageAnimator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 stfalcon.com 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.stfalcon.imageviewer.viewer.view 18 | 19 | import android.view.View 20 | import android.view.ViewGroup 21 | import android.view.animation.DecelerateInterpolator 22 | import android.widget.FrameLayout 23 | import android.widget.ImageView 24 | import androidx.transition.AutoTransition 25 | import androidx.transition.Transition 26 | import androidx.transition.TransitionManager 27 | import com.stfalcon.imageviewer.common.extensions.* 28 | 29 | internal class TransitionImageAnimator( 30 | private val externalImage: ImageView?, 31 | private val internalImage: ImageView, 32 | private val internalImageContainer: FrameLayout 33 | ) { 34 | 35 | companion object { 36 | private const val TRANSITION_DURATION_OPEN = 200L 37 | private const val TRANSITION_DURATION_CLOSE = 250L 38 | } 39 | 40 | internal var isAnimating = false 41 | 42 | private var isClosing = false 43 | 44 | private val transitionDuration: Long 45 | get() = if (isClosing) TRANSITION_DURATION_CLOSE else TRANSITION_DURATION_OPEN 46 | 47 | private val internalRoot: ViewGroup 48 | get() = internalImageContainer.parent as ViewGroup 49 | 50 | internal fun animateOpen( 51 | containerPadding: IntArray, 52 | onTransitionStart: (Long) -> Unit, 53 | onTransitionEnd: () -> Unit 54 | ) { 55 | if (externalImage.isRectVisible) { 56 | onTransitionStart(TRANSITION_DURATION_OPEN) 57 | doOpenTransition(containerPadding, onTransitionEnd) 58 | } else { 59 | onTransitionEnd() 60 | } 61 | } 62 | 63 | internal fun animateClose( 64 | shouldDismissToBottom: Boolean, 65 | onTransitionStart: (Long) -> Unit, 66 | onTransitionEnd: () -> Unit 67 | ) { 68 | if (externalImage.isRectVisible && !shouldDismissToBottom) { 69 | onTransitionStart(TRANSITION_DURATION_CLOSE) 70 | doCloseTransition(onTransitionEnd) 71 | } else { 72 | externalImage?.visibility = View.VISIBLE 73 | onTransitionEnd() 74 | } 75 | } 76 | 77 | private fun doOpenTransition(containerPadding: IntArray, onTransitionEnd: () -> Unit) { 78 | isAnimating = true 79 | prepareTransitionLayout() 80 | 81 | internalRoot.postApply { 82 | //ain't nothing but a kludge to prevent blinking when transition is starting 83 | externalImage?.postDelayed(50) { visibility = View.INVISIBLE } 84 | 85 | TransitionManager.beginDelayedTransition(internalRoot, createTransition { 86 | if (!isClosing) { 87 | isAnimating = false 88 | onTransitionEnd() 89 | } 90 | }) 91 | 92 | internalImageContainer.makeViewMatchParent() 93 | internalImage.makeViewMatchParent() 94 | 95 | internalRoot.applyMargin( 96 | containerPadding[0], 97 | containerPadding[1], 98 | containerPadding[2], 99 | containerPadding[3]) 100 | 101 | internalImageContainer.requestLayout() 102 | } 103 | } 104 | 105 | private fun doCloseTransition(onTransitionEnd: () -> Unit) { 106 | isAnimating = true 107 | isClosing = true 108 | 109 | TransitionManager.beginDelayedTransition( 110 | internalRoot, createTransition { handleCloseTransitionEnd(onTransitionEnd) }) 111 | 112 | prepareTransitionLayout() 113 | internalImageContainer.requestLayout() 114 | } 115 | 116 | private fun prepareTransitionLayout() { 117 | externalImage?.let { 118 | if (externalImage.isRectVisible) { 119 | with(externalImage.localVisibleRect) { 120 | internalImage.requestNewSize(it.width, it.height) 121 | internalImage.applyMargin(top = -top, start = -left) 122 | } 123 | with(externalImage.globalVisibleRect) { 124 | internalImageContainer.requestNewSize(width(), height()) 125 | internalImageContainer.applyMargin(left, top, right, bottom) 126 | } 127 | } 128 | 129 | resetRootTranslation() 130 | } 131 | } 132 | 133 | private fun handleCloseTransitionEnd(onTransitionEnd: () -> Unit) { 134 | externalImage?.visibility = View.VISIBLE 135 | internalImage.post { onTransitionEnd() } 136 | isAnimating = false 137 | } 138 | 139 | private fun resetRootTranslation() { 140 | internalRoot 141 | .animate() 142 | .translationY(0f) 143 | .setDuration(transitionDuration) 144 | .start() 145 | } 146 | 147 | private fun createTransition(onTransitionEnd: (() -> Unit)? = null): Transition = 148 | AutoTransition() 149 | .setDuration(transitionDuration) 150 | .setInterpolator(DecelerateInterpolator()) 151 | .addListener(onTransitionEnd = { onTransitionEnd?.invoke() }) 152 | } -------------------------------------------------------------------------------- /imageviewer/src/main/res/layout/view_image_viewer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 24 | 25 | 30 | 31 | 35 | 36 | 41 | 42 | 47 | 48 | 49 | 50 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /imageviewer/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | StfalconImageViewer 4 | 5 | -------------------------------------------------------------------------------- /imageviewer/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 29 7 | defaultConfig { 8 | applicationId "com.stfalcon.stfalconimageviewersample" 9 | minSdkVersion 19 10 | targetSdkVersion 29 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | vectorDrawables.useSupportLibrary = true 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | implementation project(':imageviewer') 26 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 27 | implementation 'androidx.appcompat:appcompat:1.1.0' 28 | implementation 'androidx.cardview:cardview:1.0.0' 29 | implementation 'androidx.transition:transition:1.2.0' 30 | implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3' 31 | implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0-rc01' 32 | 33 | //UI 34 | implementation 'com.squareup.picasso:picasso:2.71828' 35 | implementation 'me.relex:circleindicator:2.1.0' 36 | } 37 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 15 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 30 | 31 | 35 | 36 | 40 | 41 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/common/extensions/Context.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.common.extensions 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.graphics.drawable.Drawable 6 | import android.widget.Toast 7 | import androidx.annotation.DrawableRes 8 | import androidx.appcompat.content.res.AppCompatResources 9 | 10 | fun Context.showShortToast(textRes: Int) { 11 | showShortToast(getString(textRes)) 12 | } 13 | 14 | fun Context.showShortToast(text: String?) { 15 | Toast.makeText(this, text, Toast.LENGTH_SHORT).show() 16 | } 17 | 18 | 19 | fun Context.getDrawableCompat(@DrawableRes drawableRes: Int): Drawable? { 20 | return AppCompatResources.getDrawable(this, drawableRes) 21 | } 22 | 23 | fun Context.sendShareIntent(text: String) { 24 | startActivity(Intent().apply { 25 | action = Intent.ACTION_SEND 26 | putExtra(Intent.EXTRA_TEXT, text) 27 | type = "text/plain" 28 | }) 29 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/common/extensions/ImageView.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.common.extensions 2 | 3 | import android.widget.ImageView 4 | import com.squareup.picasso.Picasso 5 | 6 | fun ImageView.loadImage(url: String?) = 7 | Picasso.get().load(url).into(this) 8 | // GlideApp.with(context) 9 | // .load(url ?: "") 10 | // .into(this) -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/common/models/Demo.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.common.models 2 | 3 | object Demo { 4 | 5 | private const val POSTERS_PATH = "https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/master/images/posters" 6 | private const val MISC_PATH = "https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/master/images/misc" 7 | 8 | val posters = listOf( 9 | Poster(url = "$POSTERS_PATH/Vincent.jpg", description = "Vincent Vega is a hitman and associate of Marsellus Wallace. He had a brother named Vic Vega who was shot and killed by an undercover cop while on a job. He worked in Amsterdam for over three years and recently returned to Los Angeles, where he has been partnered with Jules Winnfield."), 10 | Poster(url = "$POSTERS_PATH/Jules.jpg", description = "Jules Winnfield - initially he is a Hitman working alongside Vincent Vega but after revelation, or as he refers to it \"a moment of clarity\" he decides to leave to \"Walk the Earth.\" During the film he is stated to be from Inglewood, California"), 11 | Poster(url = "$POSTERS_PATH/Korben.jpg", description = "Korben Dallas. A post-America taxi driver in New York City with a grand military background simply lives his life day to day, that is, before he meets Leeloo. Leeloo captures his heart soon after crashing into his taxi cab one day after escaping from a government-run laboratory. Korben soon finds himself running from the authorities in order to protect Leeloo, as well as becoming the center of a desperate ploy to save the world from an unknown evil."), 12 | Poster(url = "$POSTERS_PATH/Toretto.jpg", description = "Dominic \"Dom\" Toretto is the brother of Mia Toretto, uncle to Jack and husband to Letty Ortiz. The protagonist in The Fast and the Furious franchise, Dominic is an elite street racer and auto mechanic."), 13 | Poster(url = "$POSTERS_PATH/Marty.jpg", description = "Martin Seamus \"Marty\" McFly Sr. - he is the world's second time traveler, the first to travel backwards in time and the first human to travel though time. He was also a high school student at Hill Valley High School in 1985. He is best friends with Dr. Emmett Brown, who unveiled his first working invention to him."), 14 | Poster(url = "$POSTERS_PATH/Driver.jpg", description = "The Driver - real name unknown - is a quiet man who has made a career out of stealing fast cars and using them as getaway vehicles in big-time robberies all over Los Angeles. Hot on the Driver's trail is the Detective (Bruce Dern), a conceited (and similarly nameless) cop who refers to the Driver as \"Cowboy\"."), 15 | Poster(url = "$POSTERS_PATH/Frank.jpg", description = "Frank Martin (Transporter) - he initially serves as a reluctant hero. He is portrayed as a former Special Forces operative who was a team leader of a search and destroy unit. His military background includes operations \"in and out of\" Lebanon, Syria and Sudan. He retires from this after becoming fatigued and disenchanted with his superior officers."), 16 | Poster(url = "$POSTERS_PATH/Max.jpg", description = "Maximillian \"Max\" Rockatansky started his apocalyptic adventure as a Main Force Patrol officer who fought for peace on the decaying roads of Australian civilization. Max served as the last line of defense against the reckless marauders terrorizing the roadways, driving a V8 Interceptor."), 17 | Poster(url = "$POSTERS_PATH/Daniel.jpg", description = "Daniel Morales - the fastest delivery man for the local pizza parlor Pizza Joe in Marseille, France. On the last day of work, he sets a new speed record, then leaves the job to pursue a new career as a taxi driver with the blessings of his boss and co-workers. Daniel's vehicle is a white 1997 Peugeot 406...")) 18 | 19 | val horizontalImages = listOf( 20 | "$MISC_PATH/horizontal_colorful_1.jpg", 21 | "$MISC_PATH/square_colorful.jpg", 22 | "$MISC_PATH/horizontal_colorful_2.jpg", 23 | "$MISC_PATH/horizontal_colorful_3.jpg" 24 | ) 25 | 26 | val verticalImages = listOf( 27 | "$MISC_PATH/vertical_colorful_1.jpg", 28 | "$MISC_PATH/vertical_colorful_2.jpg", 29 | "$MISC_PATH/vertical_colorful_3.jpg", 30 | "$MISC_PATH/vertical_colorful_4.jpg" 31 | ) 32 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/common/models/Poster.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.common.models 2 | 3 | data class Poster( 4 | val url: String, 5 | val description: String 6 | ) -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/common/ui/base/BaseActivity.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.common.ui.base 2 | 3 | import android.widget.ImageView 4 | import androidx.appcompat.app.AppCompatActivity 5 | import com.stfalcon.sample.R 6 | import com.stfalcon.sample.common.extensions.getDrawableCompat 7 | import com.stfalcon.sample.common.extensions.loadImage 8 | import com.stfalcon.sample.common.models.Poster 9 | 10 | abstract class BaseActivity : AppCompatActivity() { 11 | 12 | protected fun loadPosterImage(imageView: ImageView, poster: Poster?) { 13 | loadImage(imageView, poster?.url) 14 | } 15 | 16 | protected fun loadImage(imageView: ImageView, url: String?) { 17 | imageView.apply { 18 | background = getDrawableCompat(R.drawable.shape_placeholder) 19 | loadImage(url) 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/common/ui/views/PosterOverlayView.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.common.ui.views 2 | 3 | import android.content.Context 4 | import android.graphics.Color 5 | import android.util.AttributeSet 6 | import android.view.View 7 | import androidx.constraintlayout.widget.ConstraintLayout 8 | import com.stfalcon.sample.R 9 | import com.stfalcon.sample.common.extensions.sendShareIntent 10 | import com.stfalcon.sample.common.models.Poster 11 | import kotlinx.android.synthetic.main.view_poster_overlay.view.* 12 | 13 | class PosterOverlayView @JvmOverloads constructor( 14 | context: Context, 15 | attrs: AttributeSet? = null, 16 | defStyleAttr: Int = 0 17 | ) : ConstraintLayout(context, attrs, defStyleAttr) { 18 | 19 | var onDeleteClick: (Poster) -> Unit = {} 20 | 21 | init { 22 | View.inflate(context, R.layout.view_poster_overlay, this) 23 | setBackgroundColor(Color.TRANSPARENT) 24 | } 25 | 26 | fun update(poster: Poster) { 27 | posterOverlayDescriptionText.text = poster.description 28 | posterOverlayShareButton.setOnClickListener { context.sendShareIntent(poster.url) } 29 | posterOverlayDeleteButton.setOnClickListener { onDeleteClick(poster) } 30 | } 31 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/common/ui/views/PostersGridView.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.common.ui.views 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import android.view.View 6 | import android.widget.ImageView 7 | import androidx.constraintlayout.widget.ConstraintLayout 8 | import com.stfalcon.sample.R 9 | import com.stfalcon.sample.common.models.Demo 10 | import com.stfalcon.sample.common.models.Poster 11 | import kotlinx.android.synthetic.main.view_posters_grid.view.* 12 | 13 | class PostersGridView @JvmOverloads constructor( 14 | context: Context, 15 | attrs: AttributeSet? = null, 16 | defStyleAttr: Int = 0 17 | ) : ConstraintLayout(context, attrs, defStyleAttr) { 18 | 19 | var imageLoader: ((ImageView, Poster?) -> Unit)? = null 20 | var onPosterClick: ((Int, ImageView) -> Unit)? = null 21 | 22 | val imageViews by lazy { 23 | mapOf( 24 | 0 to postersFirstImage, 25 | 1 to postersSecondImage, 26 | 2 to postersThirdImage, 27 | 3 to postersFourthImage, 28 | 4 to postersFifthImage, 29 | 5 to postersSixthImage, 30 | 6 to postersSeventhImage, 31 | 7 to postersEighthImage, 32 | 8 to postersNinthImage) 33 | } 34 | 35 | init { 36 | View.inflate(context, R.layout.view_posters_grid, this) 37 | } 38 | 39 | override fun onAttachedToWindow() { 40 | super.onAttachedToWindow() 41 | 42 | imageViews.values.forEachIndexed { index, imageView -> 43 | imageLoader?.invoke(imageView, Demo.posters.getOrNull(index)) 44 | imageView.setOnClickListener { onPosterClick?.invoke(index, imageView) } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/features/demo/grid/PostersGridDemoActivity.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.features.demo.grid 2 | 3 | import android.os.Bundle 4 | import android.widget.ImageView 5 | import androidx.appcompat.app.AppCompatActivity 6 | import com.stfalcon.imageviewer.StfalconImageViewer 7 | import com.stfalcon.sample.R 8 | import com.stfalcon.sample.common.extensions.getDrawableCompat 9 | import com.stfalcon.sample.common.extensions.loadImage 10 | import com.stfalcon.sample.common.models.Demo 11 | import com.stfalcon.sample.common.models.Poster 12 | import kotlinx.android.synthetic.main.activity_demo_posters_grid.* 13 | 14 | class PostersGridDemoActivity : AppCompatActivity() { 15 | 16 | private lateinit var viewer: StfalconImageViewer 17 | 18 | override fun onCreate(savedInstanceState: Bundle?) { 19 | super.onCreate(savedInstanceState) 20 | setContentView(R.layout.activity_demo_posters_grid) 21 | 22 | postersGridView.apply { 23 | imageLoader = ::loadPosterImage 24 | onPosterClick = ::openViewer 25 | } 26 | } 27 | 28 | private fun openViewer(startPosition: Int, target: ImageView) { 29 | viewer = StfalconImageViewer.Builder(this, Demo.posters, ::loadPosterImage) 30 | .withStartPosition(startPosition) 31 | .withTransitionFrom(target) 32 | .withImageChangeListener { 33 | viewer.updateTransitionImage(postersGridView.imageViews[it]) 34 | } 35 | .show() 36 | } 37 | 38 | private fun loadPosterImage(imageView: ImageView, poster: Poster?) { 39 | imageView.apply { 40 | background = getDrawableCompat(R.drawable.shape_placeholder) 41 | loadImage(poster?.url) 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/features/demo/rotation/RotationDemoActivity.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.features.demo.rotation 2 | 3 | import android.os.Bundle 4 | import android.widget.ImageView 5 | import androidx.appcompat.app.AppCompatActivity 6 | import com.stfalcon.imageviewer.StfalconImageViewer 7 | import com.stfalcon.sample.R 8 | import com.stfalcon.sample.common.extensions.getDrawableCompat 9 | import com.stfalcon.sample.common.extensions.loadImage 10 | import com.stfalcon.sample.common.models.Demo 11 | import com.stfalcon.sample.common.models.Poster 12 | import kotlinx.android.synthetic.main.activity_demo_rotation.* 13 | 14 | class RotationDemoActivity : AppCompatActivity() { 15 | 16 | companion object { 17 | private const val KEY_IS_DIALOG_SHOWN = "IS_DIALOG_SHOWN" 18 | private const val KEY_CURRENT_POSITION = "CURRENT_POSITION" 19 | } 20 | 21 | private var isDialogShown = false 22 | private var currentPosition: Int = 0 23 | 24 | private lateinit var viewer: StfalconImageViewer 25 | 26 | override fun onCreate(savedInstanceState: Bundle?) { 27 | super.onCreate(savedInstanceState) 28 | setContentView(R.layout.activity_demo_rotation) 29 | 30 | rotationDemoImage.setOnClickListener { openViewer(0) } 31 | loadPosterImage(rotationDemoImage, Demo.posters[0]) 32 | } 33 | 34 | override fun onPause() { 35 | super.onPause() 36 | viewer.dismiss() 37 | } 38 | 39 | override fun onRestoreInstanceState(savedInstanceState: Bundle?) { 40 | super.onRestoreInstanceState(savedInstanceState) 41 | if (savedInstanceState != null) { 42 | isDialogShown = savedInstanceState.getBoolean(KEY_IS_DIALOG_SHOWN) 43 | currentPosition = savedInstanceState.getInt(KEY_CURRENT_POSITION) 44 | } 45 | 46 | if (isDialogShown) { 47 | openViewer(currentPosition) 48 | } 49 | } 50 | 51 | override fun onSaveInstanceState(outState: Bundle) { 52 | outState.putBoolean(KEY_IS_DIALOG_SHOWN, isDialogShown) 53 | outState.putInt(KEY_CURRENT_POSITION, currentPosition) 54 | super.onSaveInstanceState(outState) 55 | } 56 | 57 | private fun openViewer(startPosition: Int) { 58 | viewer = StfalconImageViewer.Builder(this, Demo.posters, ::loadPosterImage) 59 | .withTransitionFrom(getTransitionTarget(startPosition)) 60 | .withStartPosition(startPosition) 61 | .withImageChangeListener { 62 | currentPosition = it 63 | viewer.updateTransitionImage(getTransitionTarget(it)) 64 | } 65 | .withDismissListener { isDialogShown = false } 66 | .show(!isDialogShown) 67 | 68 | currentPosition = startPosition 69 | isDialogShown = true 70 | } 71 | 72 | private fun loadPosterImage(imageView: ImageView, poster: Poster?) { 73 | imageView.apply { 74 | background = getDrawableCompat(R.drawable.shape_placeholder) 75 | loadImage(poster?.url) 76 | } 77 | } 78 | 79 | private fun getTransitionTarget(position: Int) = 80 | if (position == 0) rotationDemoImage else null 81 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/features/demo/scroll/ScrollingImagesDemoActivity.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.features.demo.scroll 2 | 3 | import android.os.Bundle 4 | import android.widget.ImageView 5 | import androidx.appcompat.app.AppCompatActivity 6 | import com.stfalcon.imageviewer.StfalconImageViewer 7 | import com.stfalcon.sample.R 8 | import com.stfalcon.sample.common.extensions.getDrawableCompat 9 | import com.stfalcon.sample.common.extensions.loadImage 10 | import com.stfalcon.sample.common.models.Demo 11 | import kotlinx.android.synthetic.main.activity_demo_scrolling_images.* 12 | 13 | class ScrollingImagesDemoActivity : AppCompatActivity() { 14 | 15 | private val horizontalImageViews by lazy { 16 | listOf( 17 | scrollingHorizontalFirstImage, 18 | scrollingHorizontalSecondImage, 19 | scrollingHorizontalThirdImage, 20 | scrollingHorizontalFourthImage) 21 | } 22 | 23 | private val verticalImageViews by lazy { 24 | listOf( 25 | scrollingVerticalFirstImage, 26 | scrollingVerticalSecondImage, 27 | scrollingVerticalThirdImage, 28 | scrollingVerticalFourthImage) 29 | } 30 | 31 | private lateinit var viewer: StfalconImageViewer 32 | 33 | override fun onCreate(savedInstanceState: Bundle?) { 34 | super.onCreate(savedInstanceState) 35 | setContentView(R.layout.activity_demo_scrolling_images) 36 | 37 | horizontalImageViews.forEachIndexed { index, imageView -> 38 | loadImage(imageView, Demo.horizontalImages.getOrNull(index)) 39 | imageView.setOnClickListener { 40 | openViewer(index, imageView, Demo.horizontalImages, horizontalImageViews) 41 | } 42 | } 43 | 44 | verticalImageViews.forEachIndexed { index, imageView -> 45 | loadImage(imageView, Demo.verticalImages.getOrNull(index)) 46 | imageView.setOnClickListener { 47 | openViewer(index, imageView, Demo.verticalImages, verticalImageViews) 48 | } 49 | } 50 | } 51 | 52 | private fun openViewer( 53 | startPosition: Int, 54 | target: ImageView, 55 | images: List, 56 | imageViews: List) { 57 | viewer = StfalconImageViewer.Builder(this, images, ::loadImage) 58 | .withStartPosition(startPosition) 59 | .withTransitionFrom(target) 60 | .withImageChangeListener { viewer.updateTransitionImage(imageViews.getOrNull(it)) } 61 | .show() 62 | } 63 | 64 | private fun loadImage(imageView: ImageView, url: String?) { 65 | imageView.apply { 66 | background = getDrawableCompat(R.drawable.shape_placeholder) 67 | loadImage(url) 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/features/demo/styled/StylingDemoActivity.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.features.demo.styled 2 | 3 | import android.os.Bundle 4 | import android.view.Menu 5 | import android.view.MenuItem 6 | import android.widget.ImageView 7 | import com.stfalcon.imageviewer.StfalconImageViewer 8 | import com.stfalcon.sample.R 9 | import com.stfalcon.sample.common.extensions.showShortToast 10 | import com.stfalcon.sample.common.models.Demo 11 | import com.stfalcon.sample.common.models.Poster 12 | import com.stfalcon.sample.common.ui.base.BaseActivity 13 | import com.stfalcon.sample.common.ui.views.PosterOverlayView 14 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions 15 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.CONTAINER_PADDING 16 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.HIDE_STATUS_BAR 17 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.IMAGES_MARGIN 18 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.RANDOM_BACKGROUND 19 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.SHOW_OVERLAY 20 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.SHOW_TRANSITION 21 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.SWIPE_TO_DISMISS 22 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.ZOOMING 23 | import kotlinx.android.synthetic.main.activity_demo_styling.* 24 | 25 | class StylingDemoActivity : BaseActivity() { 26 | 27 | private var options = StylingOptions() 28 | private var overlayView: PosterOverlayView? = null 29 | private var viewer: StfalconImageViewer? = null 30 | 31 | override fun onCreate(savedInstanceState: Bundle?) { 32 | super.onCreate(savedInstanceState) 33 | setContentView(R.layout.activity_demo_styling) 34 | 35 | stylingPostersGridView.apply { 36 | imageLoader = ::loadPosterImage 37 | onPosterClick = ::openViewer 38 | } 39 | } 40 | 41 | override fun onCreateOptionsMenu(menu: Menu): Boolean { 42 | menuInflater.inflate(R.menu.styling_options_menu, menu) 43 | return super.onCreateOptionsMenu(menu) 44 | } 45 | 46 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 47 | options.showDialog(this) 48 | return super.onOptionsItemSelected(item) 49 | } 50 | 51 | private fun openViewer(startPosition: Int, imageView: ImageView) { 52 | val posters = Demo.posters.toMutableList() 53 | 54 | val builder = StfalconImageViewer.Builder(this, posters, ::loadPosterImage) 55 | .withStartPosition(startPosition) 56 | .withImageChangeListener { position -> 57 | if (options.isPropertyEnabled(SHOW_TRANSITION)) { 58 | viewer?.updateTransitionImage(stylingPostersGridView.imageViews[position]) 59 | } 60 | 61 | overlayView?.update(posters[position]) 62 | } 63 | .withDismissListener { showShortToast(R.string.message_on_dismiss) } 64 | 65 | builder.withHiddenStatusBar(options.isPropertyEnabled(HIDE_STATUS_BAR)) 66 | 67 | if (options.isPropertyEnabled(IMAGES_MARGIN)) { 68 | builder.withImagesMargin(R.dimen.image_margin) 69 | } 70 | 71 | if (options.isPropertyEnabled(CONTAINER_PADDING)) { 72 | builder.withContainerPadding(R.dimen.image_margin) 73 | } 74 | 75 | if (options.isPropertyEnabled(SHOW_TRANSITION)) { 76 | builder.withTransitionFrom(imageView) 77 | } 78 | 79 | builder.allowSwipeToDismiss(options.isPropertyEnabled(SWIPE_TO_DISMISS)) 80 | builder.allowZooming(options.isPropertyEnabled(ZOOMING)) 81 | 82 | if (options.isPropertyEnabled(SHOW_OVERLAY)) { 83 | setupOverlayView(posters, startPosition) 84 | builder.withOverlayView(overlayView) 85 | } 86 | 87 | if (options.isPropertyEnabled(RANDOM_BACKGROUND)) { 88 | builder.withBackgroundColor(getRandomColor()) 89 | } 90 | 91 | viewer = builder.show() 92 | } 93 | 94 | private fun setupOverlayView(posters: MutableList, startPosition: Int) { 95 | overlayView = PosterOverlayView(this).apply { 96 | update(posters[startPosition]) 97 | 98 | onDeleteClick = { 99 | val currentPosition = viewer?.currentPosition() ?: 0 100 | 101 | posters.removeAt(currentPosition) 102 | viewer?.updateImages(posters) 103 | 104 | posters.getOrNull(currentPosition) 105 | ?.let { poster -> update(poster) } 106 | } 107 | } 108 | } 109 | 110 | private fun getRandomColor(): Int { 111 | val random = java.util.Random() 112 | return android.graphics.Color.argb(255, random.nextInt(156), random.nextInt(156), random.nextInt(156)) 113 | } 114 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/features/demo/styled/options/StylingOptions.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.features.demo.styled.options 2 | 3 | import android.content.Context 4 | import androidx.appcompat.app.AlertDialog 5 | import com.stfalcon.sample.R 6 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.CONTAINER_PADDING 7 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.HIDE_STATUS_BAR 8 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.IMAGES_MARGIN 9 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.RANDOM_BACKGROUND 10 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.SHOW_OVERLAY 11 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.SHOW_TRANSITION 12 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.SWIPE_TO_DISMISS 13 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.ZOOMING 14 | import com.stfalcon.sample.features.demo.styled.options.StylingOptions.Property.values 15 | 16 | class StylingOptions { 17 | 18 | private val options = sortedMapOf( 19 | HIDE_STATUS_BAR to true, 20 | IMAGES_MARGIN to true, 21 | CONTAINER_PADDING to false, 22 | SHOW_TRANSITION to true, 23 | SWIPE_TO_DISMISS to true, 24 | ZOOMING to true, 25 | SHOW_OVERLAY to true, 26 | RANDOM_BACKGROUND to false) 27 | 28 | fun isPropertyEnabled(property: Property): Boolean { 29 | return options[property] == true 30 | } 31 | 32 | fun showDialog(context: Context) { 33 | AlertDialog.Builder(context) 34 | .setMultiChoiceItems( 35 | context.resources.getStringArray(R.array.styling_options), 36 | options.values.toBooleanArray() 37 | ) { _, indexSelected, isChecked -> 38 | options[values()[indexSelected]] = isChecked 39 | }.show() 40 | } 41 | 42 | enum class Property { 43 | HIDE_STATUS_BAR, 44 | IMAGES_MARGIN, 45 | CONTAINER_PADDING, 46 | SHOW_TRANSITION, 47 | SWIPE_TO_DISMISS, 48 | ZOOMING, 49 | SHOW_OVERLAY, 50 | RANDOM_BACKGROUND 51 | } 52 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/features/main/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.features.main 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import androidx.appcompat.app.AppCompatActivity 6 | import com.stfalcon.sample.R 7 | import com.stfalcon.sample.features.demo.grid.PostersGridDemoActivity 8 | import com.stfalcon.sample.features.demo.rotation.RotationDemoActivity 9 | import com.stfalcon.sample.features.demo.scroll.ScrollingImagesDemoActivity 10 | import com.stfalcon.sample.features.demo.styled.StylingDemoActivity 11 | import com.stfalcon.sample.features.main.adapter.MainActivityPagerAdapter 12 | import com.stfalcon.sample.features.main.adapter.MainActivityPagerAdapter.Companion.ID_IMAGES_GRID 13 | import com.stfalcon.sample.features.main.adapter.MainActivityPagerAdapter.Companion.ID_ROTATION 14 | import com.stfalcon.sample.features.main.adapter.MainActivityPagerAdapter.Companion.ID_SCROLL 15 | import com.stfalcon.sample.features.main.adapter.MainActivityPagerAdapter.Companion.ID_STYLING 16 | import com.stfalcon.sample.features.main.card.DemoCardFragment 17 | import kotlinx.android.synthetic.main.activity_main.* 18 | 19 | class MainActivity : AppCompatActivity(), 20 | DemoCardFragment.OnCardActionListener { 21 | 22 | override fun onCreate(savedInstanceState: Bundle?) { 23 | super.onCreate(savedInstanceState) 24 | setContentView(R.layout.activity_main) 25 | 26 | mainCardsViewPager.apply { 27 | adapter = MainActivityPagerAdapter(this@MainActivity, supportFragmentManager) 28 | pageMargin = resources.getDimension(R.dimen.card_padding).toInt() / 4 29 | offscreenPageLimit = 3 30 | } 31 | mainCardsPagerIndicator.setViewPager(mainCardsViewPager) 32 | } 33 | 34 | override fun onCardAction(actionId: Int) { 35 | when (actionId) { 36 | ID_IMAGES_GRID -> { 37 | startActivity(Intent(this, PostersGridDemoActivity::class.java)) 38 | } 39 | ID_SCROLL -> { 40 | startActivity(Intent(this, ScrollingImagesDemoActivity::class.java)) 41 | } 42 | ID_STYLING -> { 43 | startActivity(Intent(this, StylingDemoActivity::class.java)) 44 | } 45 | ID_ROTATION -> { 46 | startActivity(Intent(this, RotationDemoActivity::class.java)) 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/features/main/adapter/MainActivityPagerAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.features.main.adapter 2 | 3 | import android.content.Context 4 | import androidx.fragment.app.Fragment 5 | import androidx.fragment.app.FragmentManager 6 | import androidx.fragment.app.FragmentStatePagerAdapter 7 | import com.stfalcon.sample.R 8 | import com.stfalcon.sample.features.main.card.DemoCardFragment 9 | 10 | class MainActivityPagerAdapter( 11 | private val context: Context, 12 | fragmentManager: FragmentManager 13 | ) : FragmentStatePagerAdapter(fragmentManager) { 14 | 15 | companion object { 16 | const val ID_IMAGES_GRID = 0 17 | const val ID_SCROLL = 1 18 | const val ID_STYLING = 2 19 | const val ID_ROTATION = 3 20 | } 21 | 22 | override fun getItem(position: Int): Fragment { 23 | var title = "" 24 | var description = "" 25 | when (position) { 26 | ID_IMAGES_GRID -> { 27 | title = context.getString(R.string.action_images_grid) 28 | description = context.getString(R.string.description_images_grid) 29 | } 30 | ID_SCROLL -> { 31 | title = context.getString(R.string.action_scroll) 32 | description = context.getString(R.string.description_scroll) 33 | } 34 | ID_STYLING -> { 35 | title = context.getString(R.string.action_style) 36 | description = context.getString(R.string.action_description_styled_view) 37 | } 38 | ID_ROTATION -> { 39 | title = context.getString(R.string.action_rotation) 40 | description = context.getString(R.string.description_rotation_support) 41 | } 42 | } 43 | return DemoCardFragment.newInstance(position, title, description) 44 | } 45 | 46 | override fun getCount() = 4 47 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/stfalcon/sample/features/main/card/DemoCardFragment.kt: -------------------------------------------------------------------------------- 1 | package com.stfalcon.sample.features.main.card 2 | 3 | import android.content.Context 4 | import android.os.Bundle 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.Fragment 9 | import com.stfalcon.sample.R 10 | import kotlinx.android.synthetic.main.fragment_demo_card.* 11 | 12 | class DemoCardFragment : Fragment() { 13 | 14 | companion object { 15 | private const val ARG_ACTION_ID = "ARG_ACTION_ID" 16 | private const val ARG_TITLE = "ARG_TITLE" 17 | private const val ARG_DESCRIPTION = "ARG_DESCRIPTION" 18 | 19 | fun newInstance(actionId: Int, title: String, description: String) = 20 | DemoCardFragment().apply { 21 | arguments = Bundle().apply { 22 | putInt(ARG_ACTION_ID, actionId) 23 | putString(ARG_TITLE, title) 24 | putString(ARG_DESCRIPTION, description) 25 | } 26 | } 27 | } 28 | 29 | private val actionId: Int 30 | get() = arguments?.getInt(ARG_ACTION_ID) ?: -1 31 | 32 | private val title: String 33 | get() = arguments?.getString(ARG_TITLE) ?: "" 34 | 35 | private val description: String 36 | get() = arguments?.getString(ARG_DESCRIPTION) ?: "" 37 | 38 | private var cardActionListener: OnCardActionListener? = null 39 | 40 | override fun onCreateView( 41 | inflater: LayoutInflater, 42 | container: ViewGroup?, 43 | savedInstanceState: Bundle? 44 | ): View? = inflater.inflate(R.layout.fragment_demo_card, container, false) 45 | 46 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 47 | super.onViewCreated(view, savedInstanceState) 48 | 49 | demoCardTitleText.text = title 50 | demoCardDescriptionText.text = description 51 | demoCardActionButton.setOnClickListener { cardActionListener?.onCardAction(actionId) } 52 | } 53 | 54 | override fun onAttach(context: Context) { 55 | super.onAttach(context) 56 | if (context is OnCardActionListener) { 57 | cardActionListener = context 58 | } else { 59 | throw RuntimeException(context.toString() + " must to implement the OnCardActionListener") 60 | } 61 | } 62 | 63 | override fun onDetach() { 64 | super.onDetach() 65 | cardActionListener = null 66 | } 67 | 68 | interface OnCardActionListener { 69 | fun onCardAction(actionId: Int) 70 | } 71 | } -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/ic_placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/sample/src/main/res/drawable-hdpi/ic_placeholder.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/ic_placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/sample/src/main/res/drawable-mdpi/ic_placeholder.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/ic_placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/sample/src/main/res/drawable-xhdpi/ic_placeholder.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/sample/src/main/res/drawable-xxhdpi/ic_placeholder.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxxhdpi/ic_placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/4828487fc046913ca4dae40afa38efb492f4c909/sample/src/main/res/drawable-xxxhdpi/ic_placeholder.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_arrow_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_arrow_up.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_circle_accent.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_delete.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_share.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_stfalcon_bird.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/shape_placeholder.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_demo_posters_grid.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_demo_rotation.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_demo_scrolling_images.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 18 | 22 | 23 | 26 | 27 | 35 | 36 | 40 | 41 | 52 | 53 | 58 | 59 | 65 | 66 | 72 | 73 | 79 | 80 | 81 | 82 | 83 | 84 | 99 | 100 | 109 | 110 | 120 | 121 | 131 | 132 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_demo_styling.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 24 | 25 | 43 | 44 | 57 | 58 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/fragment_demo_card.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 13 | 14 | 28 | 29 | 42 | 43 |