├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── in │ │ └── myinnos │ │ └── imagesliderwithswipes │ │ ├── MainActivity.java │ │ └── application │ │ └── AppController.java │ └── res │ ├── layout │ └── activity_main.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-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gif └── image_slide_example.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── imagesliderwithswipeslibrary ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── fonts │ │ └── OpenSans-Regular.ttf │ ├── java │ └── in │ │ └── myinnos │ │ └── imagesliderwithswipeslibrary │ │ ├── Animations │ │ ├── BaseAnimationInterface.java │ │ └── DescriptionAnimation.java │ │ ├── Indicators │ │ └── PagerIndicator.java │ │ ├── SliderAdapter.java │ │ ├── SliderLayout.java │ │ ├── SliderTypes │ │ ├── BaseSliderView.java │ │ ├── DefaultSliderView.java │ │ └── TextSliderView.java │ │ ├── Transformers │ │ ├── AccordionTransformer.java │ │ ├── BackgroundToForegroundTransformer.java │ │ ├── BaseTransformer.java │ │ ├── CubeInTransformer.java │ │ ├── DefaultTransformer.java │ │ ├── DepthPageTransformer.java │ │ ├── FadeTransformer.java │ │ ├── FlipHorizontalTransformer.java │ │ ├── FlipPageViewTransformer.java │ │ ├── ForegroundToBackgroundTransformer.java │ │ ├── RotateDownTransformer.java │ │ ├── RotateUpTransformer.java │ │ ├── StackTransformer.java │ │ ├── TabletTransformer.java │ │ ├── ZoomInTransformer.java │ │ ├── ZoomOutSlideTransformer.java │ │ └── ZoomOutTransformer.java │ │ ├── Tricks │ │ ├── FixedSpeedScroller.java │ │ ├── InfinitePagerAdapter.java │ │ ├── InfiniteViewPager.java │ │ └── ViewPagerEx.java │ │ └── fonts │ │ └── TextViewCustomFont.java │ └── res │ ├── drawable │ ├── hunnibal.png │ └── indicator_corner_bg.xml │ ├── layout │ ├── indicator_layout.xml │ ├── render_type_default.xml │ ├── render_type_text.xml │ └── slider_layout.xml │ └── values │ ├── attrs.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | 10 | .idea/instapk.xml 11 | instapk.log* -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | ImageSliderWithSwipes -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /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 | # [ImageSliderWithSwipes](https://myinnos.github.io/ImageSliderWithSwipes/ "View Website - ImageSliderWithSwipes") 2 | 3 | This is an Image slider with swipes, Here we used Volley to load URL's from JSON! Here we make it very easy way to load images from Internet and We customized the description font(OpenSans). 4 | 5 | First of all thanks to [AndroidImageSlider](https://github.com/daimajia/AndroidImageSlider "AndroidImageSlider"), Here You can easily load images from an internet URL, drawable, or file. And there are many kinds of amazing animations you can choose. Happy Coding! 6 | 7 | [![Get it on Google Play](https://raw.github.com/repat/README-template/master/googleplay.png)](https://ff.app.link/gt_get_app) 8 | 9 | Kindly use the following links to use this library: 10 | 11 | In build.gradle (Project) 12 | ```java 13 | allprojects { 14 | repositories { 15 | ... 16 | maven { url "https://jitpack.io" } 17 | } 18 | } 19 | ``` 20 | And then in the other gradle file(may be your app gradle or your own module library gradle, but never add in both of them to avoid conflict.) 21 | ```java 22 | dependencies { 23 | implementation 'com.github.myinnos:ImageSliderWithSwipes:1.0.2' 24 | } 25 | ``` 26 | ## Example 27 | 28 | ![ImageSliderWithSwipes](https://raw.githubusercontent.com/myinnos/ImageSliderWithSwipes/master/gif/image_slide_example.gif) 29 | 30 | ##### Create Android Project (set name ImageSliderWithSwipes) 31 | 32 | ##### Add permissions to AndroidManifest.xml 33 | 34 | ```xml 35 | 36 | 37 | ``` 38 | 39 | ##### Add dependencies for Loading Images from URL's(Here we used Volley) 40 | 41 | ```java 42 | dependencies { 43 | implementation fileTree(dir: 'libs', include: ['*.jar']) 44 | implementation 'com.android.support:appcompat-v7:25.1.0' 45 | implementation 'com.github.myinnos:ImageSliderWithSwipes:1.0.1' 46 | implementation 'com.mcxiaoke.volley:library:1.0.+' 47 | } 48 | ``` 49 | 50 | ##### Copy this code in to activity_main.xml 51 | 52 | ```xml 53 | 57 | 58 | 66 | 67 | 68 | ``` 69 | ##### Copy this code in to MainActivity.java 70 | 71 | ```java 72 | public class MainActivity extends AppCompatActivity implements BaseSliderView.OnSliderClickListener { 73 | 74 | private SliderLayout mDemoSlider; 75 | 76 | // Billionaires json url 77 | private static final String getURL = "http://api.androidhive.info/json/movies.json"; 78 | HashMap url_maps; 79 | 80 | @Override 81 | protected void onCreate(Bundle savedInstanceState) { 82 | super.onCreate(savedInstanceState); 83 | setContentView(R.layout.activity_main); 84 | mDemoSlider = (SliderLayout) findViewById(R.id.slider); 85 | 86 | // Creating volley request obj 87 | JsonArrayRequest billionaireReq = new JsonArrayRequest(getURL, 88 | new Response.Listener() { 89 | @Override 90 | public void onResponse(JSONArray response) { 91 | url_maps = new HashMap(); 92 | // Parsing json 93 | for (int i = 0; i < response.length(); i++) { 94 | try { 95 | 96 | JSONObject obj = response.getJSONObject(i); 97 | url_maps.put(obj.getString("title") + " - " + obj.getString("releaseYear"), obj.getString("image")); 98 | 99 | } catch (JSONException e) { 100 | e.printStackTrace(); 101 | } 102 | } 103 | 104 | for (String name : url_maps.keySet()) { 105 | TextSliderView textSliderView = new TextSliderView(MainActivity.this); 106 | // initialize a SliderLayout 107 | textSliderView 108 | .description(name) 109 | .descriptionSize(20) 110 | .image(url_maps.get(name)) 111 | .setScaleType(BaseSliderView.ScaleType.CenterCrop) 112 | .setOnSliderClickListener(MainActivity.this); 113 | 114 | //add your extra information 115 | textSliderView.bundle(new Bundle()); 116 | textSliderView.getBundle().putString("extra", name); 117 | 118 | mDemoSlider.addSlider(textSliderView); 119 | } 120 | } 121 | }, new Response.ErrorListener() { 122 | @Override 123 | public void onErrorResponse(VolleyError error) { 124 | Toast.makeText(getApplicationContext(), "network issue: please enable wifi/mobile data", Toast.LENGTH_SHORT).show(); 125 | } 126 | }); 127 | 128 | // Adding request to request queue 129 | AppController.getInstance().addToRequestQueue(billionaireReq); 130 | 131 | mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Stack); 132 | mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Top); 133 | mDemoSlider.setCustomAnimation(new DescriptionAnimation()); 134 | mDemoSlider.setDuration(4000); 135 | 136 | mDemoSlider.setPresetTransformer("Stack"); 137 | 138 | } 139 | 140 | @Override 141 | protected void onStop() { 142 | // To prevent a memory leak on rotation, make sure to call stopAutoCycle() on the slider before activity or fragment is destroyed 143 | mDemoSlider.stopAutoCycle(); 144 | super.onStop(); 145 | } 146 | 147 | @Override 148 | public void onSliderClick(BaseSliderView slider) { 149 | Toast.makeText(this, slider.getBundle().get("extra") + "", Toast.LENGTH_SHORT).show(); 150 | } 151 | 152 | } 153 | 154 | ``` 155 | ## Apps using [ImageSliderWithSwipes](https://myinnos.github.io/ImageSliderWithSwipes/ "View Website - ImageSliderWithSwipes") 156 | If you are using ImageSliderWithSwipes in your app and would like to be listed here, please let us know by opening a [new issue](https://github.com/myinnos/ImageSliderWithSwipes/issues/new)! 157 | 158 | * [Pawan Kalyan : PSPK Fans Adda](https://play.google.com/store/apps/details?id=com.myinnos.pawankalyan "Pawan Kalyan : PSPK Fans Adda") 159 | 160 | * [Chiranjeevi : Fans Adda](https://play.google.com/store/apps/details?id=com.myinnos.chiru "Chiranjeevi : Fans Adda") 161 | 162 | * [Niharika Konidela](https://play.google.com/store/apps/details?id=com.fansfolio.niharika "Niharika Konidela") 163 | 164 | * [fans folio: Celebrity Lovers](https://play.google.com/store/apps/details?id=in.myinnos.fansfolio "fans folio: Celebrity Lovers") 165 | 166 | 167 | ## Thanks 168 | - [Volley](https://github.com/mcxiaoke/android-volley) 169 | - [Picasso](https://github.com/square/picasso) 170 | - [NineOldAndroids](https://github.com/JakeWharton/NineOldAndroids) 171 | - [ViewPagerTransforms](https://github.com/ToxicBakery/ViewPagerTransforms) 172 | - [AndroidImageSlider](https://github.com/daimajia/AndroidImageSlider) 173 | 174 | ## Contact 175 | #### Prabhakar Thota 176 | * :globe_with_meridians: Website: [myinnos.in](http://www.myinnos.in "Prabhakar Thota") 177 | * :email: e-mail: contact@myinnos.in 178 | * :mag_right: LinkedIn: [PrabhakarThota](https://www.linkedin.com/in/prabhakarthota "Prabhakar Thota on LinkedIn") 179 | * :thumbsup: Twitter: [@myinnos](https://twitter.com/myinnos "Prabhakar Thota on twitter") 180 | 181 | [![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=username&url=https://github.com/myinnos/ImageSliderWithSwipes&title=ImageSliderWithSwipes&language=&tags=github&category=software) 182 | 183 | License 184 | ------- 185 | 186 | Copyright 2017 MyInnos 187 | 188 | Licensed under the Apache License, Version 2.0 (the "License"); 189 | you may not use this file except in compliance with the License. 190 | You may obtain a copy of the License at 191 | 192 | http://www.apache.org/licenses/LICENSE-2.0 193 | 194 | Unless required by applicable law or agreed to in writing, software 195 | distributed under the License is distributed on an "AS IS" BASIS, 196 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 197 | See the License for the specific language governing permissions and 198 | limitations under the License. 199 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | applicationId "in.myinnos.imagesliderwithswipes" 9 | minSdkVersion 14 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:25.3.0' 25 | compile 'com.mcxiaoke.volley:library:1.0.+' 26 | compile project(':imagesliderwithswipeslibrary') 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Home\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/in/myinnos/imagesliderwithswipes/MainActivity.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipes; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.Toast; 6 | 7 | import com.android.volley.Response; 8 | import com.android.volley.VolleyError; 9 | import com.android.volley.toolbox.JsonArrayRequest; 10 | 11 | import org.json.JSONArray; 12 | import org.json.JSONException; 13 | import org.json.JSONObject; 14 | 15 | import java.util.HashMap; 16 | 17 | import in.myinnos.imagesliderwithswipes.application.AppController; 18 | import in.myinnos.imagesliderwithswipeslibrary.Animations.DescriptionAnimation; 19 | import in.myinnos.imagesliderwithswipeslibrary.SliderLayout; 20 | import in.myinnos.imagesliderwithswipeslibrary.SliderTypes.BaseSliderView; 21 | import in.myinnos.imagesliderwithswipeslibrary.SliderTypes.TextSliderView; 22 | 23 | 24 | public class MainActivity extends AppCompatActivity implements BaseSliderView.OnSliderClickListener { 25 | 26 | private SliderLayout mDemoSlider; 27 | 28 | // Billionaires json url 29 | private static final String getURL = "http://api.androidhive.info/json/movies.json"; 30 | HashMap url_maps; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | mDemoSlider = (SliderLayout) findViewById(R.id.slider); 37 | 38 | // Creating volley request obj 39 | JsonArrayRequest billionaireReq = new JsonArrayRequest(getURL, 40 | new Response.Listener() { 41 | @Override 42 | public void onResponse(JSONArray response) { 43 | url_maps = new HashMap(); 44 | // Parsing json 45 | for (int i = 0; i < response.length(); i++) { 46 | try { 47 | 48 | JSONObject obj = response.getJSONObject(i); 49 | url_maps.put(obj.getString("title") + " - " + obj.getString("releaseYear"), obj.getString("image")); 50 | 51 | } catch (JSONException e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | for (String name : url_maps.keySet()) { 57 | TextSliderView textSliderView = new TextSliderView(MainActivity.this); 58 | // initialize a SliderLayout 59 | textSliderView 60 | .description(name) 61 | .descriptionSize(12) 62 | .image(url_maps.get(name)) 63 | .setScaleType(BaseSliderView.ScaleType.CenterCrop) 64 | .setOnSliderClickListener(MainActivity.this); 65 | 66 | //add your extra information 67 | textSliderView.bundle(new Bundle()); 68 | textSliderView.getBundle().putString("extra", name); 69 | 70 | mDemoSlider.addSlider(textSliderView); 71 | } 72 | } 73 | }, new Response.ErrorListener() { 74 | @Override 75 | public void onErrorResponse(VolleyError error) { 76 | Toast.makeText(getApplicationContext(), "network issue: please enable wifi/mobile data + " + error, Toast.LENGTH_SHORT).show(); 77 | } 78 | }); 79 | 80 | // Adding request to request queue 81 | AppController.getInstance().addToRequestQueue(billionaireReq); 82 | 83 | mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Stack); 84 | mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Top); 85 | mDemoSlider.setCustomAnimation(new DescriptionAnimation()); 86 | mDemoSlider.setDuration(4000); 87 | 88 | mDemoSlider.setPresetTransformer("Stack"); 89 | 90 | } 91 | 92 | @Override 93 | protected void onStop() { 94 | // To prevent a memory leak on rotation, make sure to call stopAutoCycle() on the slider before activity or fragment is destroyed 95 | mDemoSlider.stopAutoCycle(); 96 | super.onStop(); 97 | } 98 | 99 | @Override 100 | public void onSliderClick(BaseSliderView slider) { 101 | Toast.makeText(this, slider.getBundle().get("extra") + "", Toast.LENGTH_SHORT).show(); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/in/myinnos/imagesliderwithswipes/application/AppController.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipes.application; 2 | 3 | import android.app.Application; 4 | import android.content.SharedPreferences; 5 | import android.text.TextUtils; 6 | 7 | import com.android.volley.Request; 8 | import com.android.volley.RequestQueue; 9 | import com.android.volley.toolbox.Volley; 10 | 11 | public class AppController extends Application { 12 | 13 | public static final String TAG = AppController.class.getSimpleName(); 14 | 15 | private RequestQueue mRequestQueue; 16 | private static AppController mInstance; 17 | SharedPreferences sharedPreferences; 18 | 19 | @Override 20 | public void onCreate() { 21 | super.onCreate(); 22 | mInstance = this; 23 | } 24 | 25 | public static synchronized AppController getInstance() { 26 | return mInstance; 27 | } 28 | 29 | public RequestQueue getRequestQueue() { 30 | if (mRequestQueue == null) { 31 | mRequestQueue = Volley.newRequestQueue(getApplicationContext()); 32 | } 33 | 34 | return mRequestQueue; 35 | } 36 | 37 | public void addToRequestQueue(Request req, String tag) { 38 | req.setTag(TextUtils.isEmpty(tag) ? TAG : tag); 39 | getRequestQueue().add(req); 40 | } 41 | 42 | public void addToRequestQueue(Request req) { 43 | addToRequestQueue(req, TAG); 44 | } 45 | 46 | public void cancelPendingRequests(Object tag) { 47 | if (mRequestQueue != null) { 48 | mRequestQueue.cancelAll(tag); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myinnos/ImageSliderWithSwipes/34e9210d5c2e6f089ac934100c69b32a2520a00a/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myinnos/ImageSliderWithSwipes/34e9210d5c2e6f089ac934100c69b32a2520a00a/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myinnos/ImageSliderWithSwipes/34e9210d5c2e6f089ac934100c69b32a2520a00a/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myinnos/ImageSliderWithSwipes/34e9210d5c2e6f089ac934100c69b32a2520a00a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myinnos/ImageSliderWithSwipes/34e9210d5c2e6f089ac934100c69b32a2520a00a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ImageSliderWithSwipes 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | maven { 7 | url 'https://maven.google.com/' 8 | name 'Google' 9 | } 10 | } 11 | dependencies { 12 | classpath 'com.android.tools.build:gradle:2.3.2' 13 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' 14 | 15 | // NOTE: Do not place your application dependencies here; they belong 16 | // in the individual module build.gradle files 17 | } 18 | } 19 | 20 | allprojects { 21 | repositories { 22 | jcenter() 23 | maven { 24 | url 'https://maven.google.com/' 25 | name 'Google' 26 | } 27 | } 28 | } 29 | 30 | task clean(type: Delete) { 31 | delete rootProject.buildDir 32 | } 33 | -------------------------------------------------------------------------------- /gif/image_slide_example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myinnos/ImageSliderWithSwipes/34e9210d5c2e6f089ac934100c69b32a2520a00a/gif/image_slide_example.gif -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myinnos/ImageSliderWithSwipes/34e9210d5c2e6f089ac934100c69b32a2520a00a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jun 13 17:41:04 IST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.jitpack' 5 | 6 | android { 7 | compileSdkVersion 25 8 | buildToolsVersion "25.0.2" 9 | 10 | defaultConfig { 11 | minSdkVersion 14 12 | targetSdkVersion 25 13 | versionCode 1 14 | versionName "1.0" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | compile 'com.android.support:appcompat-v7:25.3.0' 27 | compile 'com.android.support:support-v4:25.3.0' 28 | compile 'com.squareup.picasso:picasso:2.71828' 29 | compile 'com.nineoldandroids:library:2.4.0' 30 | } 31 | 32 | task sourcesJar(type: Jar) { 33 | from android.sourceSets.main.java.srcDirs 34 | classifier = 'sources' 35 | } 36 | 37 | task javadoc(type: Javadoc) { 38 | failOnError false 39 | source = android.sourceSets.main.java.sourceFiles 40 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 41 | } 42 | 43 | task javadocJar(type: Jar, dependsOn: javadoc) { 44 | classifier = 'javadoc' 45 | from javadoc.destinationDir 46 | } 47 | 48 | artifacts { 49 | archives sourcesJar 50 | archives javadocJar 51 | } -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Home\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/assets/fonts/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myinnos/ImageSliderWithSwipes/34e9210d5c2e6f089ac934100c69b32a2520a00a/imagesliderwithswipeslibrary/src/main/assets/fonts/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Animations/BaseAnimationInterface.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Animations; 2 | 3 | import android.view.View; 4 | 5 | 6 | public interface BaseAnimationInterface { 7 | 8 | /** 9 | * When the current item prepare to start leaving the screen. 10 | * @param current 11 | */ 12 | public void onPrepareCurrentItemLeaveScreen(View current); 13 | 14 | /** 15 | * The next item which will be shown in ViewPager/ 16 | * @param next 17 | */ 18 | public void onPrepareNextItemShowInScreen(View next); 19 | 20 | /** 21 | * Current item totally disappear from screen. 22 | * @param view 23 | */ 24 | public void onCurrentItemDisappear(View view); 25 | 26 | /** 27 | * Next item totally show in screen. 28 | * @param view 29 | */ 30 | public void onNextItemAppear(View view); 31 | } 32 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Animations/DescriptionAnimation.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Animations; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.animation.ObjectAnimator; 6 | import com.nineoldandroids.animation.ValueAnimator; 7 | import com.nineoldandroids.view.ViewHelper; 8 | 9 | import in.myinnos.imagesliderwithswipeslibrary.R; 10 | 11 | public class DescriptionAnimation implements BaseAnimationInterface { 12 | 13 | @Override 14 | public void onPrepareCurrentItemLeaveScreen(View current) { 15 | View descriptionLayout = current.findViewById(R.id.description_layout); 16 | if(descriptionLayout!=null){ 17 | current.findViewById(R.id.description_layout).setVisibility(View.INVISIBLE); 18 | } 19 | } 20 | 21 | /** 22 | * When next item is coming to show, let's hide the description layout. 23 | * @param next 24 | */ 25 | @Override 26 | public void onPrepareNextItemShowInScreen(View next) { 27 | View descriptionLayout = next.findViewById(R.id.description_layout); 28 | if(descriptionLayout!=null){ 29 | next.findViewById(R.id.description_layout).setVisibility(View.INVISIBLE); 30 | } 31 | } 32 | 33 | 34 | @Override 35 | public void onCurrentItemDisappear(View view) { 36 | 37 | } 38 | 39 | /** 40 | * When next item show in ViewPagerEx, let's make an animation to show the 41 | * description layout. 42 | * @param view 43 | */ 44 | @Override 45 | public void onNextItemAppear(View view) { 46 | 47 | View descriptionLayout = view.findViewById(R.id.description_layout); 48 | if(descriptionLayout!=null){ 49 | float layoutY = ViewHelper.getY(descriptionLayout); 50 | view.findViewById(R.id.description_layout).setVisibility(View.VISIBLE); 51 | ValueAnimator animator = ObjectAnimator.ofFloat( 52 | descriptionLayout,"y",layoutY + descriptionLayout.getHeight(), 53 | layoutY).setDuration(500); 54 | animator.start(); 55 | } 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Indicators/PagerIndicator.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Indicators; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.database.DataSetObserver; 6 | import android.graphics.Color; 7 | import android.graphics.drawable.Drawable; 8 | import android.graphics.drawable.GradientDrawable; 9 | import android.graphics.drawable.LayerDrawable; 10 | import android.support.v4.view.PagerAdapter; 11 | import android.util.AttributeSet; 12 | import android.view.View; 13 | import android.widget.ImageView; 14 | import android.widget.LinearLayout; 15 | 16 | import java.util.ArrayList; 17 | 18 | import in.myinnos.imagesliderwithswipeslibrary.R; 19 | import in.myinnos.imagesliderwithswipeslibrary.Tricks.InfinitePagerAdapter; 20 | import in.myinnos.imagesliderwithswipeslibrary.Tricks.ViewPagerEx; 21 | 22 | /** 23 | * Pager Indicator. 24 | */ 25 | public class PagerIndicator extends LinearLayout implements ViewPagerEx.OnPageChangeListener{ 26 | 27 | private Context mContext; 28 | 29 | 30 | private ViewPagerEx mPager; 31 | 32 | /** 33 | * Variable to remember the previous selected indicator. 34 | */ 35 | private ImageView mPreviousSelectedIndicator; 36 | 37 | /** 38 | * Previous selected indicator position. 39 | */ 40 | private int mPreviousSelectedPosition; 41 | 42 | /** 43 | * Custom selected indicator style resource id. 44 | */ 45 | private int mUserSetUnSelectedIndicatorResId; 46 | 47 | 48 | /** 49 | * Custom unselected indicator style resource id. 50 | */ 51 | private int mUserSetSelectedIndicatorResId; 52 | 53 | private Drawable mSelectedDrawable; 54 | private Drawable mUnselectedDrawable; 55 | 56 | private int mItemCount = 0; 57 | 58 | private Shape mIndicatorShape = Shape.Oval; 59 | 60 | private IndicatorVisibility mVisibility = IndicatorVisibility.Visible; 61 | 62 | private int mDefaultSelectedColor; 63 | private int mDefaultUnSelectedColor; 64 | 65 | private float mDefaultSelectedWidth; 66 | private float mDefaultSelectedHeight; 67 | 68 | private float mDefaultUnSelectedWidth; 69 | private float mDefaultUnSelectedHeight; 70 | 71 | public enum IndicatorVisibility{ 72 | Visible, 73 | Invisible; 74 | }; 75 | 76 | private GradientDrawable mUnSelectedGradientDrawable; 77 | private GradientDrawable mSelectedGradientDrawable; 78 | 79 | private LayerDrawable mSelectedLayerDrawable; 80 | private LayerDrawable mUnSelectedLayerDrawable; 81 | 82 | private float mPadding_left; 83 | private float mPadding_right; 84 | private float mPadding_top; 85 | private float mPadding_bottom; 86 | 87 | private float mSelectedPadding_Left; 88 | private float mSelectedPadding_Right; 89 | private float mSelectedPadding_Top; 90 | private float mSelectedPadding_Bottom; 91 | 92 | private float mUnSelectedPadding_Left; 93 | private float mUnSelectedPadding_Right; 94 | private float mUnSelectedPadding_Top; 95 | private float mUnSelectedPadding_Bottom; 96 | 97 | /** 98 | * Put all the indicators into a ArrayList, so we can remove them easily. 99 | */ 100 | private ArrayList mIndicators = new ArrayList(); 101 | 102 | 103 | public PagerIndicator(Context context) { 104 | this(context,null); 105 | } 106 | 107 | public PagerIndicator(Context context, AttributeSet attrs) { 108 | super(context, attrs); 109 | 110 | mContext = context; 111 | 112 | final TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.PagerIndicator,0,0); 113 | 114 | int visibility = attributes.getInt(R.styleable.PagerIndicator_visibility, IndicatorVisibility.Visible.ordinal()); 115 | 116 | for(IndicatorVisibility v : IndicatorVisibility.values()){ 117 | if(v.ordinal() == visibility){ 118 | mVisibility = v; 119 | break; 120 | } 121 | } 122 | 123 | int shape = attributes.getInt(R.styleable.PagerIndicator_shape, Shape.Oval.ordinal()); 124 | for(Shape s: Shape.values()){ 125 | if(s.ordinal() == shape){ 126 | mIndicatorShape = s; 127 | break; 128 | } 129 | } 130 | 131 | mUserSetSelectedIndicatorResId = attributes.getResourceId(R.styleable.PagerIndicator_selected_drawable, 132 | 0); 133 | mUserSetUnSelectedIndicatorResId = attributes.getResourceId(R.styleable.PagerIndicator_unselected_drawable, 134 | 0); 135 | 136 | mDefaultSelectedColor = attributes.getColor(R.styleable.PagerIndicator_selected_color, Color.rgb(255, 255, 255)); 137 | mDefaultUnSelectedColor = attributes.getColor(R.styleable.PagerIndicator_unselected_color, Color.argb(33,255,255,255)); 138 | 139 | mDefaultSelectedWidth = attributes.getDimension(R.styleable.PagerIndicator_selected_width,(int)pxFromDp(6)); 140 | mDefaultSelectedHeight = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_height,(int)pxFromDp(6)); 141 | 142 | mDefaultUnSelectedWidth = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_width,(int)pxFromDp(6)); 143 | mDefaultUnSelectedHeight = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_height,(int)pxFromDp(6)); 144 | 145 | mSelectedGradientDrawable = new GradientDrawable(); 146 | mUnSelectedGradientDrawable = new GradientDrawable(); 147 | 148 | mPadding_left = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_padding_left,(int)pxFromDp(3)); 149 | mPadding_right = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_padding_right,(int)pxFromDp(3)); 150 | mPadding_top = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_padding_top,(int)pxFromDp(0)); 151 | mPadding_bottom = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_padding_bottom,(int)pxFromDp(0)); 152 | 153 | mSelectedPadding_Left = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_left,(int)mPadding_left); 154 | mSelectedPadding_Right = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_right,(int)mPadding_right); 155 | mSelectedPadding_Top = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_top,(int)mPadding_top); 156 | mSelectedPadding_Bottom = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_bottom,(int)mPadding_bottom); 157 | 158 | mUnSelectedPadding_Left = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_left,(int)mPadding_left); 159 | mUnSelectedPadding_Right = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_right,(int)mPadding_right); 160 | mUnSelectedPadding_Top = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_top,(int)mPadding_top); 161 | mUnSelectedPadding_Bottom = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_bottom,(int)mPadding_bottom); 162 | 163 | mSelectedLayerDrawable = new LayerDrawable(new Drawable[]{mSelectedGradientDrawable}); 164 | mUnSelectedLayerDrawable = new LayerDrawable(new Drawable[]{mUnSelectedGradientDrawable}); 165 | 166 | 167 | setIndicatorStyleResource(mUserSetSelectedIndicatorResId,mUserSetUnSelectedIndicatorResId); 168 | setDefaultIndicatorShape(mIndicatorShape); 169 | setDefaultSelectedIndicatorSize(mDefaultSelectedWidth,mDefaultSelectedHeight, Unit.Px); 170 | setDefaultUnselectedIndicatorSize(mDefaultUnSelectedWidth,mDefaultUnSelectedHeight, Unit.Px); 171 | setDefaultIndicatorColor(mDefaultSelectedColor, mDefaultUnSelectedColor); 172 | setIndicatorVisibility(mVisibility); 173 | attributes.recycle(); 174 | } 175 | 176 | public enum Shape{ 177 | Oval,Rectangle 178 | } 179 | 180 | /** 181 | * if you are using the default indicator, this method will help you to set the shape of 182 | * indicator, there are two kind of shapes you can set, oval and rect. 183 | * @param shape 184 | */ 185 | public void setDefaultIndicatorShape(Shape shape){ 186 | if(mUserSetSelectedIndicatorResId == 0){ 187 | if(shape == Shape.Oval){ 188 | mSelectedGradientDrawable.setShape(GradientDrawable.OVAL); 189 | }else{ 190 | mSelectedGradientDrawable.setShape(GradientDrawable.RECTANGLE); 191 | } 192 | } 193 | if(mUserSetUnSelectedIndicatorResId == 0){ 194 | if(shape == Shape.Oval){ 195 | mUnSelectedGradientDrawable.setShape(GradientDrawable.OVAL); 196 | }else{ 197 | mUnSelectedGradientDrawable.setShape(GradientDrawable.RECTANGLE); 198 | } 199 | } 200 | resetDrawable(); 201 | } 202 | 203 | 204 | /** 205 | * Set Indicator style. 206 | * @param selected page selected drawable 207 | * @param unselected page unselected drawable 208 | */ 209 | public void setIndicatorStyleResource(int selected, int unselected){ 210 | mUserSetSelectedIndicatorResId = selected; 211 | mUserSetUnSelectedIndicatorResId = unselected; 212 | if(selected == 0){ 213 | mSelectedDrawable = mSelectedLayerDrawable; 214 | }else{ 215 | mSelectedDrawable = mContext.getResources().getDrawable(mUserSetSelectedIndicatorResId); 216 | } 217 | if(unselected == 0){ 218 | mUnselectedDrawable = mUnSelectedLayerDrawable; 219 | }else{ 220 | mUnselectedDrawable = mContext.getResources().getDrawable(mUserSetUnSelectedIndicatorResId); 221 | } 222 | 223 | resetDrawable(); 224 | } 225 | 226 | /** 227 | * if you are using the default indicator , this method will help you to set the selected status and 228 | * the unselected status color. 229 | * @param selectedColor 230 | * @param unselectedColor 231 | */ 232 | public void setDefaultIndicatorColor(int selectedColor,int unselectedColor){ 233 | if(mUserSetSelectedIndicatorResId == 0){ 234 | mSelectedGradientDrawable.setColor(selectedColor); 235 | } 236 | if(mUserSetUnSelectedIndicatorResId == 0){ 237 | mUnSelectedGradientDrawable.setColor(unselectedColor); 238 | } 239 | resetDrawable(); 240 | } 241 | 242 | public enum Unit{ 243 | DP,Px 244 | } 245 | 246 | public void setDefaultSelectedIndicatorSize(float width,float height,Unit unit){ 247 | if(mUserSetSelectedIndicatorResId == 0){ 248 | float w = width; 249 | float h = height; 250 | if(unit == Unit.DP){ 251 | w = pxFromDp(width); 252 | h = pxFromDp(height); 253 | } 254 | mSelectedGradientDrawable.setSize((int) w, (int) h); 255 | resetDrawable(); 256 | } 257 | } 258 | 259 | public void setDefaultUnselectedIndicatorSize(float width,float height,Unit unit){ 260 | if(mUserSetUnSelectedIndicatorResId == 0){ 261 | float w = width; 262 | float h = height; 263 | if(unit == Unit.DP){ 264 | w = pxFromDp(width); 265 | h = pxFromDp(height); 266 | } 267 | mUnSelectedGradientDrawable.setSize((int) w, (int) h); 268 | resetDrawable(); 269 | } 270 | } 271 | 272 | public void setDefaultIndicatorSize(float width, float height, Unit unit){ 273 | setDefaultSelectedIndicatorSize(width,height,unit); 274 | setDefaultUnselectedIndicatorSize(width,height,unit); 275 | } 276 | 277 | private float dpFromPx(float px) 278 | { 279 | return px / this.getContext().getResources().getDisplayMetrics().density; 280 | } 281 | 282 | private float pxFromDp(float dp) 283 | { 284 | return dp * this.getContext().getResources().getDisplayMetrics().density; 285 | } 286 | 287 | /** 288 | * set the visibility of indicator. 289 | * @param visibility 290 | */ 291 | public void setIndicatorVisibility(IndicatorVisibility visibility){ 292 | if(visibility == IndicatorVisibility.Visible){ 293 | setVisibility(View.VISIBLE); 294 | }else{ 295 | setVisibility(View.INVISIBLE); 296 | } 297 | resetDrawable(); 298 | } 299 | 300 | /** 301 | * clear self means unregister the dataset observer and remove all the child views(indicators). 302 | */ 303 | public void destroySelf(){ 304 | if(mPager == null || mPager.getAdapter() == null){ 305 | return; 306 | } 307 | InfinitePagerAdapter wrapper = (InfinitePagerAdapter)mPager.getAdapter(); 308 | PagerAdapter adapter = wrapper.getRealAdapter(); 309 | if(adapter!=null){ 310 | adapter.unregisterDataSetObserver(dataChangeObserver); 311 | } 312 | removeAllViews(); 313 | } 314 | 315 | /** 316 | * bind indicator with viewpagerEx. 317 | * @param pager 318 | */ 319 | public void setViewPager(ViewPagerEx pager){ 320 | if(pager.getAdapter() == null){ 321 | throw new IllegalStateException("Viewpager does not have adapter instance"); 322 | } 323 | mPager = pager; 324 | mPager.addOnPageChangeListener(this); 325 | ((InfinitePagerAdapter)mPager.getAdapter()).getRealAdapter().registerDataSetObserver(dataChangeObserver); 326 | } 327 | 328 | 329 | private void resetDrawable(){ 330 | for(View i : mIndicators){ 331 | if(mPreviousSelectedIndicator!= null && mPreviousSelectedIndicator.equals(i)){ 332 | ((ImageView)i).setImageDrawable(mSelectedDrawable); 333 | } 334 | else{ 335 | ((ImageView)i).setImageDrawable(mUnselectedDrawable); 336 | } 337 | } 338 | } 339 | 340 | /** 341 | * redraw the indicators. 342 | */ 343 | public void redraw(){ 344 | mItemCount = getShouldDrawCount(); 345 | mPreviousSelectedIndicator = null; 346 | for(View i:mIndicators){ 347 | removeView(i); 348 | } 349 | 350 | 351 | for(int i =0 ;i< mItemCount; i++){ 352 | ImageView indicator = new ImageView(mContext); 353 | indicator.setImageDrawable(mUnselectedDrawable); 354 | indicator.setPadding((int)mUnSelectedPadding_Left, 355 | (int)mUnSelectedPadding_Top, 356 | (int)mUnSelectedPadding_Right, 357 | (int)mUnSelectedPadding_Bottom); 358 | addView(indicator); 359 | mIndicators.add(indicator); 360 | } 361 | setItemAsSelected(mPreviousSelectedPosition); 362 | } 363 | 364 | /** 365 | * since we used a adapter wrapper, so we can't getCount directly from wrapper. 366 | * @return 367 | */ 368 | private int getShouldDrawCount(){ 369 | if(mPager.getAdapter() instanceof InfinitePagerAdapter){ 370 | return ((InfinitePagerAdapter)mPager.getAdapter()).getRealCount(); 371 | }else{ 372 | return mPager.getAdapter().getCount(); 373 | } 374 | } 375 | 376 | private DataSetObserver dataChangeObserver = new DataSetObserver() { 377 | @Override 378 | public void onChanged() { 379 | PagerAdapter adapter = mPager.getAdapter(); 380 | int count = 0; 381 | if(adapter instanceof InfinitePagerAdapter){ 382 | count = ((InfinitePagerAdapter)adapter).getRealCount(); 383 | }else{ 384 | count = adapter.getCount(); 385 | } 386 | if(count > mItemCount){ 387 | for(int i =0 ; i< count - mItemCount;i++){ 388 | ImageView indicator = new ImageView(mContext); 389 | indicator.setImageDrawable(mUnselectedDrawable); 390 | indicator.setPadding((int)mUnSelectedPadding_Left, 391 | (int)mUnSelectedPadding_Top, 392 | (int)mUnSelectedPadding_Right, 393 | (int)mUnSelectedPadding_Bottom); 394 | addView(indicator); 395 | mIndicators.add(indicator); 396 | } 397 | }else if(count < mItemCount){ 398 | for(int i = 0; i < mItemCount - count;i++){ 399 | removeView(mIndicators.get(0)); 400 | mIndicators.remove(0); 401 | } 402 | } 403 | mItemCount = count; 404 | mPager.setCurrentItem(mItemCount*20 + mPager.getCurrentItem()); 405 | } 406 | 407 | @Override 408 | public void onInvalidated() { 409 | super.onInvalidated(); 410 | redraw(); 411 | } 412 | }; 413 | 414 | private void setItemAsSelected(int position){ 415 | if(mPreviousSelectedIndicator != null){ 416 | mPreviousSelectedIndicator.setImageDrawable(mUnselectedDrawable); 417 | mPreviousSelectedIndicator.setPadding( 418 | (int)mUnSelectedPadding_Left, 419 | (int)mUnSelectedPadding_Top, 420 | (int)mUnSelectedPadding_Right, 421 | (int)mUnSelectedPadding_Bottom 422 | ); 423 | } 424 | ImageView currentSelected = (ImageView)getChildAt(position + 1); 425 | if(currentSelected != null){ 426 | currentSelected.setImageDrawable(mSelectedDrawable); 427 | currentSelected.setPadding( 428 | (int)mSelectedPadding_Left, 429 | (int)mSelectedPadding_Top, 430 | (int)mSelectedPadding_Right, 431 | (int)mSelectedPadding_Bottom 432 | ); 433 | mPreviousSelectedIndicator = currentSelected; 434 | } 435 | mPreviousSelectedPosition = position; 436 | } 437 | 438 | @Override 439 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 440 | } 441 | 442 | public IndicatorVisibility getIndicatorVisibility(){ 443 | return mVisibility; 444 | } 445 | 446 | @Override 447 | public void onPageSelected(int position) { 448 | if(mItemCount == 0){ 449 | return; 450 | } 451 | setItemAsSelected(position-1); 452 | } 453 | @Override 454 | public void onPageScrollStateChanged(int state) { 455 | } 456 | 457 | public int getSelectedIndicatorResId(){ 458 | return mUserSetSelectedIndicatorResId; 459 | } 460 | 461 | public int getUnSelectedIndicatorResId(){ 462 | return mUserSetUnSelectedIndicatorResId; 463 | } 464 | 465 | } 466 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/SliderAdapter.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import java.util.ArrayList; 9 | 10 | import in.myinnos.imagesliderwithswipeslibrary.SliderTypes.BaseSliderView; 11 | 12 | /** 13 | * A slider adapter 14 | */ 15 | public class SliderAdapter extends PagerAdapter implements BaseSliderView.ImageLoadListener{ 16 | 17 | private Context mContext; 18 | private ArrayList mImageContents; 19 | 20 | public SliderAdapter(Context context){ 21 | mContext = context; 22 | mImageContents = new ArrayList(); 23 | } 24 | 25 | public void addSlider(T slider){ 26 | slider.setOnImageLoadListener(this); 27 | mImageContents.add(slider); 28 | notifyDataSetChanged(); 29 | } 30 | 31 | public BaseSliderView getSliderView(int position){ 32 | if(position < 0 || position >= mImageContents.size()){ 33 | return null; 34 | }else{ 35 | return mImageContents.get(position); 36 | } 37 | } 38 | 39 | @Override 40 | public int getItemPosition(Object object) { 41 | return POSITION_NONE; 42 | } 43 | 44 | public void removeSlider(T slider){ 45 | if(mImageContents.contains(slider)){ 46 | mImageContents.remove(slider); 47 | notifyDataSetChanged(); 48 | } 49 | } 50 | 51 | public void removeSliderAt(int position){ 52 | if(mImageContents.size() > position){ 53 | mImageContents.remove(position); 54 | notifyDataSetChanged(); 55 | } 56 | } 57 | 58 | public void removeAllSliders(){ 59 | mImageContents.clear(); 60 | notifyDataSetChanged(); 61 | } 62 | 63 | @Override 64 | public int getCount() { 65 | return mImageContents.size(); 66 | } 67 | 68 | @Override 69 | public boolean isViewFromObject(View view, Object object) { 70 | return view==object; 71 | } 72 | 73 | @Override 74 | public void destroyItem(ViewGroup container, int position, Object object) { 75 | container.removeView((View) object); 76 | } 77 | 78 | @Override 79 | public Object instantiateItem(ViewGroup container, int position) { 80 | BaseSliderView b = mImageContents.get(position); 81 | View v = b.getView(); 82 | container.addView(v); 83 | return v; 84 | } 85 | 86 | @Override 87 | public void onStart(BaseSliderView target) { 88 | 89 | } 90 | 91 | /** 92 | * When image download error, then remove. 93 | * @param result 94 | * @param target 95 | */ 96 | @Override 97 | public void onEnd(boolean result, BaseSliderView target) { 98 | if(target.isErrorDisappear() == false || result == true){ 99 | return; 100 | } 101 | for (BaseSliderView slider: mImageContents){ 102 | if(slider.equals(target)){ 103 | removeSlider(target); 104 | break; 105 | } 106 | } 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/SliderLayout.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.os.Message; 6 | import android.support.v4.view.PagerAdapter; 7 | import android.util.AttributeSet; 8 | import android.view.LayoutInflater; 9 | import android.view.MotionEvent; 10 | import android.view.View; 11 | import android.view.animation.Interpolator; 12 | import android.widget.RelativeLayout; 13 | 14 | import java.lang.reflect.Field; 15 | import java.util.Timer; 16 | import java.util.TimerTask; 17 | 18 | import in.myinnos.imagesliderwithswipeslibrary.Animations.BaseAnimationInterface; 19 | import in.myinnos.imagesliderwithswipeslibrary.Indicators.PagerIndicator; 20 | import in.myinnos.imagesliderwithswipeslibrary.SliderTypes.BaseSliderView; 21 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.AccordionTransformer; 22 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.BackgroundToForegroundTransformer; 23 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.BaseTransformer; 24 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.CubeInTransformer; 25 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.DefaultTransformer; 26 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.DepthPageTransformer; 27 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.FadeTransformer; 28 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.FlipHorizontalTransformer; 29 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.FlipPageViewTransformer; 30 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.ForegroundToBackgroundTransformer; 31 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.RotateDownTransformer; 32 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.RotateUpTransformer; 33 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.StackTransformer; 34 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.TabletTransformer; 35 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.ZoomInTransformer; 36 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.ZoomOutSlideTransformer; 37 | import in.myinnos.imagesliderwithswipeslibrary.Transformers.ZoomOutTransformer; 38 | import in.myinnos.imagesliderwithswipeslibrary.Tricks.FixedSpeedScroller; 39 | import in.myinnos.imagesliderwithswipeslibrary.Tricks.InfinitePagerAdapter; 40 | import in.myinnos.imagesliderwithswipeslibrary.Tricks.InfiniteViewPager; 41 | import in.myinnos.imagesliderwithswipeslibrary.Tricks.ViewPagerEx; 42 | 43 | 44 | public class SliderLayout extends RelativeLayout { 45 | 46 | private Context mContext; 47 | /** 48 | * InfiniteViewPager is extended from ViewPagerEx. As the name says, it can scroll without bounder. 49 | */ 50 | private InfiniteViewPager mViewPager; 51 | 52 | /** 53 | * InfiniteViewPager adapter. 54 | */ 55 | private SliderAdapter mSliderAdapter; 56 | private PagerIndicator mIndicator; 57 | private Timer mCycleTimer; 58 | private TimerTask mCycleTask; 59 | private Timer mResumingTimer; 60 | private TimerTask mResumingTask; 61 | private boolean mCycling; 62 | private boolean mAutoRecover = true; 63 | 64 | private int mTransformerId; 65 | private int mTransformerSpan = 1100; 66 | 67 | private boolean mAutoCycle; 68 | 69 | /** 70 | * the duration between animation. 71 | */ 72 | private long mSliderDuration = 4000; 73 | private PagerIndicator.IndicatorVisibility mIndicatorVisibility = PagerIndicator.IndicatorVisibility.Visible; 74 | private BaseTransformer mViewPagerTransformer; 75 | 76 | private BaseAnimationInterface mCustomAnimation; 77 | 78 | public SliderLayout(Context context) { 79 | this(context, null); 80 | } 81 | 82 | public SliderLayout(Context context, AttributeSet attrs) { 83 | this(context, attrs, R.attr.SliderStyle); 84 | } 85 | 86 | public SliderLayout(Context context, AttributeSet attrs, int defStyle) { 87 | super(context, attrs, defStyle); 88 | mContext = context; 89 | LayoutInflater.from(context).inflate(R.layout.slider_layout, this, true); 90 | 91 | final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SliderLayout, 92 | defStyle, 0); 93 | 94 | mTransformerSpan = attributes.getInteger(R.styleable.SliderLayout_pager_animation_span, 1100); 95 | mTransformerId = attributes.getInt(R.styleable.SliderLayout_pager_animation, Transformer.Default.ordinal()); 96 | mAutoCycle = attributes.getBoolean(R.styleable.SliderLayout_auto_cycle, true); 97 | int visibility = attributes.getInt(R.styleable.SliderLayout_indicator_visibility, 0); 98 | for (PagerIndicator.IndicatorVisibility v : PagerIndicator.IndicatorVisibility.values()) { 99 | if (v.ordinal() == visibility) { 100 | mIndicatorVisibility = v; 101 | break; 102 | } 103 | } 104 | mSliderAdapter = new SliderAdapter(mContext); 105 | PagerAdapter wrappedAdapter = new InfinitePagerAdapter(mSliderAdapter); 106 | 107 | mViewPager = (InfiniteViewPager) findViewById(R.id.myinnos_slider_viewpager); 108 | mViewPager.setAdapter(wrappedAdapter); 109 | 110 | mViewPager.setOnTouchListener(new OnTouchListener() { 111 | @Override 112 | public boolean onTouch(View v, MotionEvent event) { 113 | int action = event.getAction(); 114 | switch (action) { 115 | case MotionEvent.ACTION_UP: 116 | recoverCycle(); 117 | break; 118 | } 119 | return false; 120 | } 121 | }); 122 | 123 | attributes.recycle(); 124 | setPresetIndicator(PresetIndicators.Center_Bottom); 125 | setPresetTransformer(mTransformerId); 126 | setSliderTransformDuration(mTransformerSpan, null); 127 | setIndicatorVisibility(mIndicatorVisibility); 128 | if (mAutoCycle) { 129 | startAutoCycle(); 130 | } 131 | } 132 | 133 | public void addOnPageChangeListener(ViewPagerEx.OnPageChangeListener onPageChangeListener) { 134 | if (onPageChangeListener != null) { 135 | mViewPager.addOnPageChangeListener(onPageChangeListener); 136 | } 137 | } 138 | 139 | public void removeOnPageChangeListener(ViewPagerEx.OnPageChangeListener onPageChangeListener) { 140 | mViewPager.removeOnPageChangeListener(onPageChangeListener); 141 | } 142 | 143 | public void setCustomIndicator(PagerIndicator indicator) { 144 | if (mIndicator != null) { 145 | mIndicator.destroySelf(); 146 | } 147 | mIndicator = indicator; 148 | mIndicator.setIndicatorVisibility(mIndicatorVisibility); 149 | mIndicator.setViewPager(mViewPager); 150 | mIndicator.redraw(); 151 | } 152 | 153 | public void addSlider(T imageContent) { 154 | mSliderAdapter.addSlider(imageContent); 155 | } 156 | 157 | private android.os.Handler mh = new android.os.Handler() { 158 | @Override 159 | public void handleMessage(Message msg) { 160 | super.handleMessage(msg); 161 | moveNextPosition(true); 162 | } 163 | }; 164 | 165 | public void startAutoCycle() { 166 | startAutoCycle(mSliderDuration, mSliderDuration, mAutoRecover); 167 | } 168 | 169 | /** 170 | * start auto cycle. 171 | * 172 | * @param delay delay time 173 | * @param duration animation duration time. 174 | * @param autoRecover if recover after user touches the slider. 175 | */ 176 | public void startAutoCycle(long delay, long duration, boolean autoRecover) { 177 | if (mCycleTimer != null) mCycleTimer.cancel(); 178 | if (mCycleTask != null) mCycleTask.cancel(); 179 | if (mResumingTask != null) mResumingTask.cancel(); 180 | if (mResumingTimer != null) mResumingTimer.cancel(); 181 | mSliderDuration = duration; 182 | mCycleTimer = new Timer(); 183 | mAutoRecover = autoRecover; 184 | mCycleTask = new TimerTask() { 185 | @Override 186 | public void run() { 187 | mh.sendEmptyMessage(0); 188 | } 189 | }; 190 | mCycleTimer.schedule(mCycleTask, delay, mSliderDuration); 191 | mCycling = true; 192 | mAutoCycle = true; 193 | } 194 | 195 | /** 196 | * pause auto cycle. 197 | */ 198 | private void pauseAutoCycle() { 199 | if (mCycling) { 200 | mCycleTimer.cancel(); 201 | mCycleTask.cancel(); 202 | mCycling = false; 203 | } else { 204 | if (mResumingTimer != null && mResumingTask != null) { 205 | recoverCycle(); 206 | } 207 | } 208 | } 209 | 210 | /** 211 | * set the duration between two slider changes. the duration value must >= 500 212 | * 213 | * @param duration 214 | */ 215 | public void setDuration(long duration) { 216 | if (duration >= 500) { 217 | mSliderDuration = duration; 218 | if (mAutoCycle && mCycling) { 219 | startAutoCycle(); 220 | } 221 | } 222 | } 223 | 224 | /** 225 | * stop the auto circle 226 | */ 227 | public void stopAutoCycle() { 228 | if (mCycleTask != null) { 229 | mCycleTask.cancel(); 230 | } 231 | if (mCycleTimer != null) { 232 | mCycleTimer.cancel(); 233 | } 234 | if (mResumingTimer != null) { 235 | mResumingTimer.cancel(); 236 | } 237 | if (mResumingTask != null) { 238 | mResumingTask.cancel(); 239 | } 240 | mAutoCycle = false; 241 | mCycling = false; 242 | } 243 | 244 | /** 245 | * when paused cycle, this method can weak it up. 246 | */ 247 | private void recoverCycle() { 248 | if (!mAutoRecover || !mAutoCycle) { 249 | return; 250 | } 251 | 252 | if (!mCycling) { 253 | if (mResumingTask != null && mResumingTimer != null) { 254 | mResumingTimer.cancel(); 255 | mResumingTask.cancel(); 256 | } 257 | mResumingTimer = new Timer(); 258 | mResumingTask = new TimerTask() { 259 | @Override 260 | public void run() { 261 | startAutoCycle(); 262 | } 263 | }; 264 | mResumingTimer.schedule(mResumingTask, 6000); 265 | } 266 | } 267 | 268 | 269 | @Override 270 | public boolean onInterceptTouchEvent(MotionEvent ev) { 271 | int action = ev.getAction(); 272 | switch (action) { 273 | case MotionEvent.ACTION_DOWN: 274 | pauseAutoCycle(); 275 | break; 276 | } 277 | return false; 278 | } 279 | 280 | /** 281 | * set ViewPager transformer. 282 | * 283 | * @param reverseDrawingOrder 284 | * @param transformer 285 | */ 286 | public void setPagerTransformer(boolean reverseDrawingOrder, BaseTransformer transformer) { 287 | mViewPagerTransformer = transformer; 288 | mViewPagerTransformer.setCustomAnimationInterface(mCustomAnimation); 289 | mViewPager.setPageTransformer(reverseDrawingOrder, mViewPagerTransformer); 290 | } 291 | 292 | 293 | /** 294 | * set the duration between two slider changes. 295 | * 296 | * @param period 297 | * @param interpolator 298 | */ 299 | public void setSliderTransformDuration(int period, Interpolator interpolator) { 300 | try { 301 | Field mScroller = ViewPagerEx.class.getDeclaredField("mScroller"); 302 | mScroller.setAccessible(true); 303 | FixedSpeedScroller scroller = new FixedSpeedScroller(mViewPager.getContext(), interpolator, period); 304 | mScroller.set(mViewPager, scroller); 305 | } catch (Exception e) { 306 | 307 | } 308 | } 309 | 310 | /** 311 | * preset transformers and their names 312 | */ 313 | public enum Transformer { 314 | Default("Default"), 315 | Accordion("Accordion"), 316 | Background2Foreground("Background2Foreground"), 317 | CubeIn("CubeIn"), 318 | DepthPage("DepthPage"), 319 | Fade("Fade"), 320 | FlipHorizontal("FlipHorizontal"), 321 | FlipPage("FlipPage"), 322 | Foreground2Background("Foreground2Background"), 323 | RotateDown("RotateDown"), 324 | RotateUp("RotateUp"), 325 | Stack("Stack"), 326 | Tablet("Tablet"), 327 | ZoomIn("ZoomIn"), 328 | ZoomOutSlide("ZoomOutSlide"), 329 | ZoomOut("ZoomOut"); 330 | 331 | private final String name; 332 | 333 | private Transformer(String s) { 334 | name = s; 335 | } 336 | 337 | public String toString() { 338 | return name; 339 | } 340 | 341 | public boolean equals(String other) { 342 | return (other == null) ? false : name.equals(other); 343 | } 344 | } 345 | 346 | ; 347 | 348 | /** 349 | * set a preset viewpager transformer by id. 350 | * 351 | * @param transformerId 352 | */ 353 | public void setPresetTransformer(int transformerId) { 354 | for (Transformer t : Transformer.values()) { 355 | if (t.ordinal() == transformerId) { 356 | setPresetTransformer(t); 357 | break; 358 | } 359 | } 360 | } 361 | 362 | /** 363 | * set preset PagerTransformer via the name of transforemer. 364 | * 365 | * @param transformerName 366 | */ 367 | public void setPresetTransformer(String transformerName) { 368 | for (Transformer t : Transformer.values()) { 369 | if (t.equals(transformerName)) { 370 | setPresetTransformer(t); 371 | return; 372 | } 373 | } 374 | } 375 | 376 | 377 | public void setCustomAnimation(BaseAnimationInterface animation) { 378 | mCustomAnimation = animation; 379 | if (mViewPagerTransformer != null) { 380 | mViewPagerTransformer.setCustomAnimationInterface(mCustomAnimation); 381 | } 382 | } 383 | 384 | /** 385 | * pretty much right? enjoy it. :-D 386 | * 387 | * @param ts 388 | */ 389 | public void setPresetTransformer(Transformer ts) { 390 | // 391 | // special thanks to https://github.com/ToxicBakery/ViewPagerTransforms 392 | // 393 | BaseTransformer t = null; 394 | switch (ts) { 395 | case Default: 396 | t = new DefaultTransformer(); 397 | break; 398 | case Accordion: 399 | t = new AccordionTransformer(); 400 | break; 401 | case Background2Foreground: 402 | t = new BackgroundToForegroundTransformer(); 403 | break; 404 | case CubeIn: 405 | t = new CubeInTransformer(); 406 | break; 407 | case DepthPage: 408 | t = new DepthPageTransformer(); 409 | break; 410 | case Fade: 411 | t = new FadeTransformer(); 412 | break; 413 | case FlipHorizontal: 414 | t = new FlipHorizontalTransformer(); 415 | break; 416 | case FlipPage: 417 | t = new FlipPageViewTransformer(); 418 | break; 419 | case Foreground2Background: 420 | t = new ForegroundToBackgroundTransformer(); 421 | break; 422 | case RotateDown: 423 | t = new RotateDownTransformer(); 424 | break; 425 | case RotateUp: 426 | t = new RotateUpTransformer(); 427 | break; 428 | case Stack: 429 | t = new StackTransformer(); 430 | break; 431 | case Tablet: 432 | t = new TabletTransformer(); 433 | break; 434 | case ZoomIn: 435 | t = new ZoomInTransformer(); 436 | break; 437 | case ZoomOutSlide: 438 | t = new ZoomOutSlideTransformer(); 439 | break; 440 | case ZoomOut: 441 | t = new ZoomOutTransformer(); 442 | break; 443 | } 444 | setPagerTransformer(true, t); 445 | } 446 | 447 | 448 | /** 449 | * Set the visibility of the indicators. 450 | * 451 | * @param visibility 452 | */ 453 | public void setIndicatorVisibility(PagerIndicator.IndicatorVisibility visibility) { 454 | if (mIndicator == null) { 455 | return; 456 | } 457 | 458 | mIndicator.setIndicatorVisibility(visibility); 459 | } 460 | 461 | public PagerIndicator.IndicatorVisibility getIndicatorVisibility() { 462 | if (mIndicator == null) { 463 | return mIndicator.getIndicatorVisibility(); 464 | } 465 | return PagerIndicator.IndicatorVisibility.Invisible; 466 | 467 | } 468 | 469 | 470 | public PagerIndicator getPagerIndicator() { 471 | return mIndicator; 472 | } 473 | 474 | public enum PresetIndicators { 475 | Right_Center("Right_Center", R.id.default_right_center_indicator), 476 | Center_Bottom("Center_Bottom", R.id.default_center_bottom_indicator), 477 | Right_Bottom("Right_Bottom", R.id.default_bottom_right_indicator), 478 | Left_Bottom("Left_Bottom", R.id.default_bottom_left_indicator), 479 | Center_Top("Center_Top", R.id.default_center_top_indicator), 480 | Right_Top("Right_Top", R.id.default_center_top_right_indicator), 481 | Left_Top("Left_Top", R.id.default_center_top_left_indicator); 482 | 483 | private final String name; 484 | private final int id; 485 | 486 | private PresetIndicators(String name, int id) { 487 | this.name = name; 488 | this.id = id; 489 | } 490 | 491 | public String toString() { 492 | return name; 493 | } 494 | 495 | public int getResourceId() { 496 | return id; 497 | } 498 | } 499 | 500 | public void setPresetIndicator(PresetIndicators presetIndicator) { 501 | PagerIndicator pagerIndicator = (PagerIndicator) findViewById(presetIndicator.getResourceId()); 502 | setCustomIndicator(pagerIndicator); 503 | } 504 | 505 | private InfinitePagerAdapter getWrapperAdapter() { 506 | PagerAdapter adapter = mViewPager.getAdapter(); 507 | if (adapter != null) { 508 | return (InfinitePagerAdapter) adapter; 509 | } else { 510 | return null; 511 | } 512 | } 513 | 514 | private SliderAdapter getRealAdapter() { 515 | PagerAdapter adapter = mViewPager.getAdapter(); 516 | if (adapter != null) { 517 | return (SliderAdapter) ((InfinitePagerAdapter) adapter).getRealAdapter(); 518 | } 519 | return null; 520 | } 521 | 522 | /** 523 | * get the current item position 524 | * 525 | * @return 526 | */ 527 | public int getCurrentPosition() { 528 | 529 | if (getRealAdapter() == null) 530 | throw new IllegalStateException("You did not set a slider adapter"); 531 | 532 | return mViewPager.getCurrentItem() % getRealAdapter().getCount(); 533 | 534 | } 535 | 536 | /** 537 | * get current slider. 538 | * 539 | * @return 540 | */ 541 | public BaseSliderView getCurrentSlider() { 542 | 543 | if (getRealAdapter() == null) 544 | throw new IllegalStateException("You did not set a slider adapter"); 545 | 546 | int count = getRealAdapter().getCount(); 547 | int realCount = mViewPager.getCurrentItem() % count; 548 | return getRealAdapter().getSliderView(realCount); 549 | } 550 | 551 | /** 552 | * remove the slider at the position. Notice: It's a not perfect method, a very small bug still exists. 553 | */ 554 | public void removeSliderAt(int position) { 555 | if (getRealAdapter() != null) { 556 | getRealAdapter().removeSliderAt(position); 557 | mViewPager.setCurrentItem(mViewPager.getCurrentItem(), false); 558 | } 559 | } 560 | 561 | /** 562 | * remove all the sliders. Notice: It's a not perfect method, a very small bug still exists. 563 | */ 564 | public void removeAllSliders() { 565 | if (getRealAdapter() != null) { 566 | int count = getRealAdapter().getCount(); 567 | getRealAdapter().removeAllSliders(); 568 | //a small bug, but fixed by this trick. 569 | //bug: when remove adapter's all the sliders.some caching slider still alive. 570 | mViewPager.setCurrentItem(mViewPager.getCurrentItem() + count, false); 571 | } 572 | } 573 | 574 | /** 575 | * set current slider 576 | * 577 | * @param position 578 | */ 579 | public void setCurrentPosition(int position, boolean smooth) { 580 | if (getRealAdapter() == null) 581 | throw new IllegalStateException("You did not set a slider adapter"); 582 | if (position >= getRealAdapter().getCount()) { 583 | throw new IllegalStateException("Item position is not exist"); 584 | } 585 | int p = mViewPager.getCurrentItem() % getRealAdapter().getCount(); 586 | int n = (position - p) + mViewPager.getCurrentItem(); 587 | mViewPager.setCurrentItem(n, smooth); 588 | } 589 | 590 | public void setCurrentPosition(int position) { 591 | setCurrentPosition(position, true); 592 | } 593 | 594 | /** 595 | * move to prev slide. 596 | */ 597 | public void movePrevPosition(boolean smooth) { 598 | 599 | if (getRealAdapter() == null) 600 | throw new IllegalStateException("You did not set a slider adapter"); 601 | 602 | mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1, smooth); 603 | } 604 | 605 | public void movePrevPosition() { 606 | movePrevPosition(true); 607 | } 608 | 609 | /** 610 | * move to next slide. 611 | */ 612 | public void moveNextPosition(boolean smooth) { 613 | 614 | if (getRealAdapter() == null) 615 | throw new IllegalStateException("You did not set a slider adapter"); 616 | 617 | mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, smooth); 618 | } 619 | 620 | public void moveNextPosition() { 621 | moveNextPosition(true); 622 | } 623 | } 624 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/SliderTypes/BaseSliderView.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.SliderTypes; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.ImageView; 7 | 8 | import com.squareup.picasso.Callback; 9 | import com.squareup.picasso.Picasso; 10 | import com.squareup.picasso.RequestCreator; 11 | 12 | import java.io.File; 13 | 14 | import in.myinnos.imagesliderwithswipeslibrary.R; 15 | 16 | public abstract class BaseSliderView { 17 | 18 | protected Context mContext; 19 | 20 | private Bundle mBundle; 21 | 22 | /** 23 | * Error place holder image. 24 | */ 25 | private int mErrorPlaceHolderRes; 26 | 27 | /** 28 | * Empty imageView placeholder. 29 | */ 30 | private int mEmptyPlaceHolderRes; 31 | 32 | private String mUrl; 33 | private File mFile; 34 | private int mRes; 35 | 36 | protected OnSliderClickListener mOnSliderClickListener; 37 | 38 | private boolean mErrorDisappear; 39 | 40 | private ImageLoadListener mLoadListener; 41 | 42 | private String mDescription; 43 | 44 | private int mDescriptionSize; 45 | 46 | private Picasso mPicasso; 47 | 48 | /** 49 | * Scale type of the image. 50 | */ 51 | private ScaleType mScaleType = ScaleType.Fit; 52 | 53 | public enum ScaleType{ 54 | CenterCrop, CenterInside, Fit, FitCenterCrop 55 | } 56 | 57 | protected BaseSliderView(Context context) { 58 | mContext = context; 59 | } 60 | 61 | /** 62 | * the placeholder image when loading image from url or file. 63 | * @param resId Image resource id 64 | * @return 65 | */ 66 | public BaseSliderView empty(int resId){ 67 | mEmptyPlaceHolderRes = resId; 68 | return this; 69 | } 70 | 71 | /** 72 | * determine whether remove the image which failed to download or load from file 73 | * @param disappear 74 | * @return 75 | */ 76 | public BaseSliderView errorDisappear(boolean disappear){ 77 | mErrorDisappear = disappear; 78 | return this; 79 | } 80 | 81 | /** 82 | * if you set errorDisappear false, this will set a error placeholder image. 83 | * @param resId image resource id 84 | * @return 85 | */ 86 | public BaseSliderView error(int resId){ 87 | mErrorPlaceHolderRes = resId; 88 | return this; 89 | } 90 | 91 | /** 92 | * the description of a slider image. 93 | * @param description 94 | * @return 95 | */ 96 | public BaseSliderView description(String description){ 97 | mDescription = description; 98 | return this; 99 | } 100 | 101 | /** 102 | * the description of a slider image. 103 | * @param descriptionSize 104 | * @return 105 | */ 106 | public BaseSliderView descriptionSize(int descriptionSize){ 107 | mDescriptionSize = descriptionSize; 108 | return this; 109 | } 110 | 111 | /** 112 | * set a url as a image that preparing to load 113 | * @param url 114 | * @return 115 | */ 116 | public BaseSliderView image(String url){ 117 | if(mFile != null || mRes != 0){ 118 | throw new IllegalStateException("Call multi image function," + 119 | "you only have permission to call it once"); 120 | } 121 | mUrl = url; 122 | return this; 123 | } 124 | 125 | /** 126 | * set a file as a image that will to load 127 | * @param file 128 | * @return 129 | */ 130 | public BaseSliderView image(File file){ 131 | if(mUrl != null || mRes != 0){ 132 | throw new IllegalStateException("Call multi image function," + 133 | "you only have permission to call it once"); 134 | } 135 | mFile = file; 136 | return this; 137 | } 138 | 139 | public BaseSliderView image(int res){ 140 | if(mUrl != null || mFile != null){ 141 | throw new IllegalStateException("Call multi image function," + 142 | "you only have permission to call it once"); 143 | } 144 | mRes = res; 145 | return this; 146 | } 147 | 148 | /** 149 | * lets users add a bundle of additional information 150 | * @param bundle 151 | * @return 152 | */ 153 | public BaseSliderView bundle(Bundle bundle){ 154 | mBundle = bundle; 155 | return this; 156 | } 157 | 158 | public String getUrl(){ 159 | return mUrl; 160 | } 161 | 162 | public boolean isErrorDisappear(){ 163 | return mErrorDisappear; 164 | } 165 | 166 | public int getEmpty(){ 167 | return mEmptyPlaceHolderRes; 168 | } 169 | 170 | public int getError(){ 171 | return mErrorPlaceHolderRes; 172 | } 173 | 174 | public String getDescription(){ 175 | return mDescription; 176 | } 177 | 178 | public int getDescriptionSize(){ 179 | return mDescriptionSize; 180 | } 181 | 182 | public Context getContext(){ 183 | return mContext; 184 | } 185 | 186 | /** 187 | * set a slider image click listener 188 | * @param l 189 | * @return 190 | */ 191 | public BaseSliderView setOnSliderClickListener(OnSliderClickListener l){ 192 | mOnSliderClickListener = l; 193 | return this; 194 | } 195 | 196 | /** 197 | * When you want to implement your own slider view, please call this method in the end in `getView()` method 198 | * @param v the whole view 199 | * @param targetImageView where to place image 200 | */ 201 | protected void bindEventAndShow(final View v, ImageView targetImageView){ 202 | final BaseSliderView me = this; 203 | 204 | v.setOnClickListener(new View.OnClickListener() { 205 | @Override 206 | public void onClick(View v) { 207 | if(mOnSliderClickListener != null){ 208 | mOnSliderClickListener.onSliderClick(me); 209 | } 210 | } 211 | }); 212 | 213 | if (targetImageView == null) 214 | return; 215 | 216 | if (mLoadListener != null) { 217 | mLoadListener.onStart(me); 218 | } 219 | 220 | Picasso p = (mPicasso != null) ? mPicasso : Picasso.get(); 221 | RequestCreator rq = null; 222 | if(mUrl!=null){ 223 | rq = p.load(mUrl); 224 | }else if(mFile != null){ 225 | rq = p.load(mFile); 226 | }else if(mRes != 0){ 227 | rq = p.load(mRes); 228 | }else{ 229 | return; 230 | } 231 | 232 | if(rq == null){ 233 | return; 234 | } 235 | 236 | if(getEmpty() != 0){ 237 | rq.placeholder(getEmpty()); 238 | } 239 | 240 | if(getError() != 0){ 241 | rq.error(getError()); 242 | } 243 | 244 | switch (mScaleType){ 245 | case Fit: 246 | rq.fit(); 247 | break; 248 | case CenterCrop: 249 | rq.fit().centerCrop(); 250 | break; 251 | case CenterInside: 252 | rq.fit().centerInside(); 253 | break; 254 | } 255 | 256 | rq.into(targetImageView,new Callback() { 257 | @Override 258 | public void onSuccess() { 259 | if(v.findViewById(R.id.loading_bar) != null){ 260 | v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE); 261 | } 262 | } 263 | 264 | @Override 265 | public void onError(Exception e) { 266 | if(mLoadListener != null){ 267 | mLoadListener.onEnd(false,me); 268 | } 269 | if(v.findViewById(R.id.loading_bar) != null){ 270 | v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE); 271 | } 272 | } 273 | 274 | /* @Override 275 | public void onError() { 276 | if(mLoadListener != null){ 277 | mLoadListener.onEnd(false,me); 278 | } 279 | if(v.findViewById(R.id.loading_bar) != null){ 280 | v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE); 281 | } 282 | }*/ 283 | }); 284 | } 285 | 286 | 287 | 288 | public BaseSliderView setScaleType(ScaleType type){ 289 | mScaleType = type; 290 | return this; 291 | } 292 | 293 | public ScaleType getScaleType(){ 294 | return mScaleType; 295 | } 296 | 297 | /** 298 | * the extended class have to implement getView(), which is called by the adapter, 299 | * every extended class response to render their own view. 300 | * @return 301 | */ 302 | public abstract View getView(); 303 | 304 | /** 305 | * set a listener to get a message , if load error. 306 | * @param l 307 | */ 308 | public void setOnImageLoadListener(ImageLoadListener l){ 309 | mLoadListener = l; 310 | } 311 | 312 | public interface OnSliderClickListener { 313 | public void onSliderClick(BaseSliderView slider); 314 | } 315 | 316 | /** 317 | * when you have some extra information, please put it in this bundle. 318 | * @return 319 | */ 320 | public Bundle getBundle(){ 321 | return mBundle; 322 | } 323 | 324 | public interface ImageLoadListener{ 325 | public void onStart(BaseSliderView target); 326 | public void onEnd(boolean result, BaseSliderView target); 327 | } 328 | 329 | /** 330 | * Get the last instance set via setPicasso(), or null if no user provided instance was set 331 | * 332 | * @return The current user-provided Picasso instance, or null if none 333 | */ 334 | public Picasso getPicasso() { 335 | return mPicasso; 336 | } 337 | 338 | /** 339 | * Provide a Picasso instance to use when loading pictures, this is useful if you have a 340 | * particular HTTP cache you would like to share. 341 | * 342 | * @param picasso The Picasso instance to use, may be null to let the system use the default 343 | * instance 344 | */ 345 | public void setPicasso(Picasso picasso) { 346 | mPicasso = picasso; 347 | } 348 | } 349 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/SliderTypes/DefaultSliderView.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.SliderTypes; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.ImageView; 7 | 8 | import in.myinnos.imagesliderwithswipeslibrary.R; 9 | 10 | /** 11 | * a simple slider view, which just show an image. If you want to make your own slider view, 12 | * 13 | * just extend BaseSliderView, and implement getView() method. 14 | */ 15 | public class DefaultSliderView extends BaseSliderView{ 16 | 17 | public DefaultSliderView(Context context) { 18 | super(context); 19 | } 20 | 21 | @Override 22 | public View getView() { 23 | View v = LayoutInflater.from(getContext()).inflate(R.layout.render_type_default,null); 24 | ImageView target = (ImageView)v.findViewById(R.id.myinnos_slider_image); 25 | bindEventAndShow(v, target); 26 | return v; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/SliderTypes/TextSliderView.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.SliderTypes; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | 9 | import in.myinnos.imagesliderwithswipeslibrary.R; 10 | 11 | /** 12 | * This is a slider with a description TextView. 13 | */ 14 | public class TextSliderView extends BaseSliderView { 15 | public TextSliderView(Context context) { 16 | super(context); 17 | } 18 | 19 | public static TextView description_textView; 20 | 21 | @Override 22 | public View getView() { 23 | View v = LayoutInflater.from(getContext()).inflate(R.layout.render_type_text, null); 24 | ImageView target = (ImageView) v.findViewById(R.id.myinnos_slider_image); 25 | description_textView = (TextView) v.findViewById(R.id.description); 26 | description_textView.setText(getDescription()); 27 | description_textView.setTextSize(getDescriptionSize()); 28 | bindEventAndShow(v, target); 29 | return v; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/AccordionTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | /** 4 | * Created by daimajia on 14-5-29. 5 | */ 6 | import android.view.View; 7 | 8 | import com.nineoldandroids.view.ViewHelper; 9 | 10 | public class AccordionTransformer extends BaseTransformer { 11 | 12 | @Override 13 | protected void onTransform(View view, float position) { 14 | ViewHelper.setPivotX(view,position < 0 ? 0 : view.getWidth()); 15 | ViewHelper.setScaleX(view,position < 0 ? 1f + position : 1f - position); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/BackgroundToForegroundTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | public class BackgroundToForegroundTransformer extends BaseTransformer { 8 | 9 | @Override 10 | protected void onTransform(View view, float position) { 11 | final float height = view.getHeight(); 12 | final float width = view.getWidth(); 13 | final float scale = min(position < 0 ? 1f : Math.abs(1f - position), 0.5f); 14 | 15 | ViewHelper.setScaleX(view,scale); 16 | ViewHelper.setScaleY(view,scale); 17 | ViewHelper.setPivotX(view,width*0.5f); 18 | ViewHelper.setPivotY(view,height*0.5f); 19 | ViewHelper.setTranslationX(view,position < 0 ? width * position : -width * position * 0.25f); 20 | } 21 | 22 | private static final float min(float val, float min) { 23 | return val < min ? min : val; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/BaseTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | 10 | import in.myinnos.imagesliderwithswipeslibrary.Animations.BaseAnimationInterface; 11 | import in.myinnos.imagesliderwithswipeslibrary.Tricks.ViewPagerEx; 12 | 13 | 14 | public abstract class BaseTransformer implements ViewPagerEx.PageTransformer { 15 | 16 | private BaseAnimationInterface mCustomAnimationInterface; 17 | 18 | /** 19 | * Called each {@link #transformPage(View, float)}. 20 | * 21 | * @param view 22 | * @param position 23 | */ 24 | protected abstract void onTransform(View view, float position); 25 | 26 | private HashMap> h = new HashMap>(); 27 | 28 | @Override 29 | public void transformPage(View view, float position) { 30 | onPreTransform(view, position); 31 | onTransform(view, position); 32 | onPostTransform(view, position); 33 | } 34 | 35 | /** 36 | * If the position offset of a fragment is less than negative one or greater than one, returning true will set the 37 | * visibility of the fragment to {@link View#GONE}. Returning false will force the fragment to {@link View#VISIBLE}. 38 | * 39 | * @return 40 | */ 41 | protected boolean hideOffscreenPages() { 42 | return true; 43 | } 44 | 45 | /** 46 | * Indicates if the default animations of the view pager should be used. 47 | * 48 | * @return 49 | */ 50 | protected boolean isPagingEnabled() { 51 | return false; 52 | } 53 | 54 | /** 55 | * Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)} is called. 56 | * 57 | * @param view 58 | * @param position 59 | */ 60 | protected void onPreTransform(View view, float position) { 61 | final float width = view.getWidth(); 62 | 63 | ViewHelper.setRotationX(view,0); 64 | ViewHelper.setRotationY(view,0); 65 | ViewHelper.setRotation(view,0); 66 | ViewHelper.setScaleX(view,1); 67 | ViewHelper.setScaleY(view,1); 68 | ViewHelper.setPivotX(view,0); 69 | ViewHelper.setPivotY(view,0); 70 | ViewHelper.setTranslationY(view,0); 71 | ViewHelper.setTranslationX(view,isPagingEnabled() ? 0f : -width * position); 72 | 73 | if (hideOffscreenPages()) { 74 | ViewHelper.setAlpha(view,position <= -1f || position >= 1f ? 0f : 1f); 75 | } else { 76 | ViewHelper.setAlpha(view,1f); 77 | } 78 | if(mCustomAnimationInterface != null){ 79 | if(h.containsKey(view) == false || h.get(view).size() == 1){ 80 | if(position > -1 && position < 1){ 81 | if(h.get(view) == null){ 82 | h.put(view,new ArrayList()); 83 | } 84 | h.get(view).add(position); 85 | if(h.get(view).size() == 2){ 86 | float zero = h.get(view).get(0); 87 | float cha = h.get(view).get(1) - h.get(view).get(0); 88 | if(zero > 0){ 89 | if(cha > -1 && cha < 0){ 90 | //in 91 | mCustomAnimationInterface.onPrepareNextItemShowInScreen(view); 92 | }else{ 93 | //out 94 | mCustomAnimationInterface.onPrepareCurrentItemLeaveScreen(view); 95 | } 96 | }else{ 97 | if(cha > -1 && cha < 0){ 98 | //out 99 | mCustomAnimationInterface.onPrepareCurrentItemLeaveScreen(view); 100 | }else{ 101 | //in 102 | mCustomAnimationInterface.onPrepareNextItemShowInScreen(view); 103 | } 104 | } 105 | } 106 | } 107 | } 108 | } 109 | } 110 | boolean isApp,isDis; 111 | /** 112 | * Called each {@link #transformPage(View, float)} call after {@link #onTransform(View, float)} is finished. 113 | * 114 | * @param view 115 | * @param position 116 | */ 117 | protected void onPostTransform(View view, float position) { 118 | if(mCustomAnimationInterface != null){ 119 | if(position == -1 || position == 1){ 120 | mCustomAnimationInterface.onCurrentItemDisappear(view); 121 | isApp = true; 122 | }else if(position == 0){ 123 | mCustomAnimationInterface.onNextItemAppear(view); 124 | isDis = true; 125 | } 126 | if(isApp && isDis){ 127 | h.clear(); 128 | isApp = false; 129 | isDis = false; 130 | } 131 | } 132 | } 133 | 134 | 135 | public void setCustomAnimationInterface(BaseAnimationInterface animationInterface){ 136 | mCustomAnimationInterface = animationInterface; 137 | } 138 | 139 | } -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/CubeInTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | public class CubeInTransformer extends BaseTransformer { 8 | 9 | @Override 10 | protected void onTransform(View view, float position) { 11 | // Rotate the fragment on the left or right edge 12 | ViewHelper.setPivotX(view,position > 0 ? 0 : view.getWidth()); 13 | ViewHelper.setPivotY(view,0); 14 | ViewHelper.setRotation(view,-90f * position); 15 | } 16 | 17 | @Override 18 | public boolean isPagingEnabled() { 19 | return true; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/DefaultTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | public class DefaultTransformer extends BaseTransformer { 6 | 7 | @Override 8 | protected void onTransform(View view, float position) { 9 | } 10 | 11 | @Override 12 | public boolean isPagingEnabled() { 13 | return true; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/DepthPageTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | public class DepthPageTransformer extends BaseTransformer { 8 | 9 | private static final float MIN_SCALE = 0.75f; 10 | 11 | @Override 12 | protected void onTransform(View view, float position) { 13 | if (position <= 0f) { 14 | ViewHelper.setTranslationX(view,0f); 15 | ViewHelper.setScaleX(view,1f); 16 | ViewHelper.setScaleY(view,1f); 17 | } else if (position <= 1f) { 18 | final float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position)); 19 | ViewHelper.setAlpha(view,1-position); 20 | ViewHelper.setPivotY(view,0.5f * view.getHeight()); 21 | ViewHelper.setTranslationX(view,view.getWidth() * - position); 22 | ViewHelper.setScaleX(view,scaleFactor); 23 | ViewHelper.setScaleY(view,scaleFactor); 24 | } 25 | } 26 | 27 | @Override 28 | protected boolean isPagingEnabled() { 29 | return true; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/FadeTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | /** 8 | * Created by realandylawton on 11/22/13. 9 | */ 10 | public class FadeTransformer extends BaseTransformer { 11 | 12 | @Override 13 | protected void onTransform(View view, float position) { 14 | 15 | // Page is not an immediate sibling, just make transparent 16 | if(position < -1 || position > 1) { 17 | ViewHelper.setAlpha(view,0.6f); 18 | } 19 | // Page is sibling to left or right 20 | else if (position <= 0 || position <= 1) { 21 | 22 | // Calculate alpha. Position is decimal in [-1,0] or [0,1] 23 | float alpha = (position <= 0) ? position + 1 : 1 - position; 24 | ViewHelper.setAlpha(view,alpha); 25 | 26 | } 27 | // Page is active, make fully visible 28 | else if (position == 0) { 29 | ViewHelper.setAlpha(view,1); 30 | } 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/FlipHorizontalTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | public class FlipHorizontalTransformer extends BaseTransformer { 8 | 9 | @Override 10 | protected void onTransform(View view, float position) { 11 | final float rotation = 180f * position; 12 | ViewHelper.setAlpha(view,rotation > 90f || rotation < -90f ? 0 : 1); 13 | ViewHelper.setPivotY(view,view.getHeight()*0.5f); 14 | ViewHelper.setPivotX(view,view.getWidth() * 0.5f); 15 | ViewHelper.setRotationY(view,rotation); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/FlipPageViewTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.os.Build; 4 | import android.view.View; 5 | 6 | import com.nineoldandroids.view.ViewHelper; 7 | 8 | import in.myinnos.imagesliderwithswipeslibrary.Tricks.ViewPagerEx; 9 | 10 | public class FlipPageViewTransformer extends BaseTransformer { 11 | 12 | @Override 13 | protected void onTransform(View view, float position) { 14 | float percentage = 1 - Math.abs(position); 15 | if(Build.VERSION.SDK_INT >= 13){ 16 | view.setCameraDistance(12000); 17 | } 18 | setVisibility(view, position); 19 | setTranslation(view); 20 | setSize(view, position, percentage); 21 | setRotation(view, position, percentage); 22 | } 23 | 24 | private void setVisibility(View page, float position) { 25 | if (position < 0.5 && position > -0.5) { 26 | page.setVisibility(View.VISIBLE); 27 | } else { 28 | page.setVisibility(View.INVISIBLE); 29 | } 30 | } 31 | 32 | private void setTranslation(View view) { 33 | ViewPagerEx viewPager = (ViewPagerEx) view.getParent(); 34 | int scroll = viewPager.getScrollX() - view.getLeft(); 35 | ViewHelper.setTranslationX(view,scroll); 36 | } 37 | 38 | private void setSize(View view, float position, float percentage) { 39 | ViewHelper.setScaleX(view,(position != 0 && position != 1) ? percentage : 1); 40 | ViewHelper.setScaleY(view,(position != 0 && position != 1) ? percentage : 1); 41 | } 42 | 43 | private void setRotation(View view, float position, float percentage) { 44 | if (position > 0) { 45 | ViewHelper.setRotationY(view,-180 * (percentage + 1)); 46 | } else { 47 | ViewHelper.setRotationY(view,180 * (percentage + 1)); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/ForegroundToBackgroundTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | public class ForegroundToBackgroundTransformer extends BaseTransformer { 8 | 9 | @Override 10 | protected void onTransform(View view, float position) { 11 | final float height = view.getHeight(); 12 | final float width = view.getWidth(); 13 | final float scale = min(position > 0 ? 1f : Math.abs(1f + position), 0.5f); 14 | 15 | ViewHelper.setScaleX(view,scale); 16 | ViewHelper.setScaleY(view,scale); 17 | ViewHelper.setPivotX(view,width * 0.5f); 18 | ViewHelper.setPivotY(view,height * 0.5f); 19 | ViewHelper.setTranslationX(view,position > 0 ? width * position : -width * position * 0.25f); 20 | } 21 | 22 | private static final float min(float val, float min) { 23 | return val < min ? min : val; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/RotateDownTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | public class RotateDownTransformer extends BaseTransformer { 8 | 9 | private static final float ROT_MOD = -15f; 10 | 11 | @Override 12 | protected void onTransform(View view, float position) { 13 | final float width = view.getWidth(); 14 | final float height = view.getHeight(); 15 | final float rotation = ROT_MOD * position * -1.25f; 16 | 17 | ViewHelper.setPivotX(view,width * 0.5f); 18 | ViewHelper.setPivotY(view,height); 19 | ViewHelper.setRotation(view,rotation); 20 | } 21 | 22 | @Override 23 | protected boolean isPagingEnabled() { 24 | return true; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/RotateUpTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | public class RotateUpTransformer extends BaseTransformer { 8 | 9 | private static final float ROT_MOD = -15f; 10 | 11 | @Override 12 | protected void onTransform(View view, float position) { 13 | final float width = view.getWidth(); 14 | final float rotation = ROT_MOD * position; 15 | 16 | ViewHelper.setPivotX(view,width * 0.5f); 17 | ViewHelper.setPivotY(view,0f); 18 | ViewHelper.setTranslationX(view,0f); 19 | ViewHelper.setRotation(view,rotation); 20 | } 21 | 22 | @Override 23 | protected boolean isPagingEnabled() { 24 | return true; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/StackTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | public class StackTransformer extends BaseTransformer { 8 | 9 | @Override 10 | protected void onTransform(View view, float position) { 11 | ViewHelper.setTranslationX(view,position < 0 ? 0f : -view.getWidth() * position); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/TabletTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.graphics.Camera; 4 | import android.graphics.Matrix; 5 | import android.view.View; 6 | 7 | import com.nineoldandroids.view.ViewHelper; 8 | 9 | public class TabletTransformer extends BaseTransformer { 10 | 11 | private static final Matrix OFFSET_MATRIX = new Matrix(); 12 | private static final Camera OFFSET_CAMERA = new Camera(); 13 | private static final float[] OFFSET_TEMP_FLOAT = new float[2]; 14 | 15 | @Override 16 | protected void onTransform(View view, float position) { 17 | final float rotation = (position < 0 ? 30f : -30f) * Math.abs(position); 18 | 19 | ViewHelper.setTranslationX(view,getOffsetXForRotation(rotation, view.getWidth(), view.getHeight())); 20 | ViewHelper.setPivotX(view,view.getWidth() * 0.5f); 21 | ViewHelper.setPivotY(view,0); 22 | ViewHelper.setRotationY(view,rotation); 23 | } 24 | 25 | protected static final float getOffsetXForRotation(float degrees, int width, int height) { 26 | OFFSET_MATRIX.reset(); 27 | OFFSET_CAMERA.save(); 28 | OFFSET_CAMERA.rotateY(Math.abs(degrees)); 29 | OFFSET_CAMERA.getMatrix(OFFSET_MATRIX); 30 | OFFSET_CAMERA.restore(); 31 | 32 | OFFSET_MATRIX.preTranslate(-width * 0.5f, -height * 0.5f); 33 | OFFSET_MATRIX.postTranslate(width * 0.5f, height * 0.5f); 34 | OFFSET_TEMP_FLOAT[0] = width; 35 | OFFSET_TEMP_FLOAT[1] = height; 36 | OFFSET_MATRIX.mapPoints(OFFSET_TEMP_FLOAT); 37 | return (width - OFFSET_TEMP_FLOAT[0]) * (degrees > 0.0f ? 1.0f : -1.0f); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/ZoomInTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | public class ZoomInTransformer extends BaseTransformer { 8 | 9 | @Override 10 | protected void onTransform(View view, float position) { 11 | final float scale = position < 0 ? position + 1f : Math.abs(1f - position); 12 | ViewHelper.setScaleX(view,scale); 13 | ViewHelper.setScaleY(view,scale); 14 | ViewHelper.setPivotX(view,view.getWidth() * 0.5f); 15 | ViewHelper.setPivotY(view,view.getHeight() * 0.5f); 16 | ViewHelper.setAlpha(view,position < -1f || position > 1f ? 0f : 1f - (scale - 1f)); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/ZoomOutSlideTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | public class ZoomOutSlideTransformer extends BaseTransformer { 8 | 9 | private static final float MIN_SCALE = 0.85f; 10 | private static final float MIN_ALPHA = 0.5f; 11 | 12 | @Override 13 | protected void onTransform(View view, float position) { 14 | if (position >= -1 || position <= 1) { 15 | // Modify the default slide transition to shrink the page as well 16 | final float height = view.getHeight(); 17 | final float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)); 18 | final float vertMargin = height * (1 - scaleFactor) / 2; 19 | final float horzMargin = view.getWidth() * (1 - scaleFactor) / 2; 20 | 21 | // Center vertically 22 | ViewHelper.setPivotY(view,0.5f * height); 23 | 24 | 25 | if (position < 0) { 26 | ViewHelper.setTranslationX(view,horzMargin - vertMargin / 2); 27 | } else { 28 | ViewHelper.setTranslationX(view,-horzMargin + vertMargin / 2); 29 | } 30 | 31 | // Scale the page down (between MIN_SCALE and 1) 32 | ViewHelper.setScaleX(view,scaleFactor); 33 | ViewHelper.setScaleY(view,scaleFactor); 34 | 35 | // Fade the page relative to its size. 36 | ViewHelper.setAlpha(view,MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA)); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Transformers/ZoomOutTransformer.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Transformers; 2 | 3 | import android.view.View; 4 | 5 | import com.nineoldandroids.view.ViewHelper; 6 | 7 | public class ZoomOutTransformer extends BaseTransformer { 8 | 9 | @Override 10 | protected void onTransform(View view, float position) { 11 | final float scale = 1f + Math.abs(position); 12 | ViewHelper.setScaleX(view,scale); 13 | ViewHelper.setScaleY(view,scale); 14 | ViewHelper.setPivotX(view,view.getWidth() * 0.5f); 15 | ViewHelper.setPivotY(view,view.getWidth() * 0.5f); 16 | ViewHelper.setAlpha(view,position < -1f || position > 1f ? 0f : 1f - (scale - 1f)); 17 | if(position < -0.9){ 18 | //-0.9 to prevent a small bug 19 | ViewHelper.setTranslationX(view,view.getWidth() * position); 20 | } 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Tricks/FixedSpeedScroller.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Tricks; 2 | 3 | import android.content.Context; 4 | import android.view.animation.Interpolator; 5 | import android.widget.Scroller; 6 | 7 | public class FixedSpeedScroller extends Scroller { 8 | 9 | private int mDuration = 1000; 10 | 11 | public FixedSpeedScroller(Context context) { 12 | super(context); 13 | } 14 | 15 | public FixedSpeedScroller(Context context, Interpolator interpolator) { 16 | super(context, interpolator); 17 | } 18 | 19 | public FixedSpeedScroller(Context context, Interpolator interpolator, int period){ 20 | this(context,interpolator); 21 | mDuration = period; 22 | } 23 | 24 | @Override 25 | public void startScroll(int startX, int startY, int dx, int dy, int duration) { 26 | // Ignore received duration, use fixed one instead 27 | super.startScroll(startX, startY, dx, dy, mDuration); 28 | } 29 | 30 | @Override 31 | public void startScroll(int startX, int startY, int dx, int dy) { 32 | // Ignore received duration, use fixed one instead 33 | super.startScroll(startX, startY, dx, dy, mDuration); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Tricks/InfinitePagerAdapter.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Tricks; 2 | 3 | import android.os.Parcelable; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.util.Log; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import in.myinnos.imagesliderwithswipeslibrary.SliderAdapter; 10 | 11 | /** 12 | * A PagerAdapter that wraps around another PagerAdapter to handle paging wrap-around. 13 | * Thanks to: https://github.com/antonyt/InfiniteViewPager 14 | */ 15 | public class InfinitePagerAdapter extends PagerAdapter { 16 | 17 | private static final String TAG = "InfinitePagerAdapter"; 18 | private static final boolean DEBUG = false; 19 | 20 | private SliderAdapter adapter; 21 | 22 | public InfinitePagerAdapter(SliderAdapter adapter) { 23 | this.adapter = adapter; 24 | } 25 | 26 | public PagerAdapter getRealAdapter(){ 27 | return this.adapter; 28 | } 29 | 30 | @Override 31 | public int getCount() { 32 | // warning: scrolling to very high values (1,000,000+) results in 33 | // strange drawing behaviour 34 | return Integer.MAX_VALUE; 35 | } 36 | 37 | /** 38 | * @return the {@link #getCount()} result of the wrapped adapter 39 | */ 40 | public int getRealCount() { 41 | return adapter.getCount(); 42 | } 43 | 44 | @Override 45 | public Object instantiateItem(ViewGroup container, int position) { 46 | if(getRealCount() == 0){ 47 | return null; 48 | } 49 | int virtualPosition = position % getRealCount(); 50 | debug("instantiateItem: real position: " + position); 51 | debug("instantiateItem: virtual position: " + virtualPosition); 52 | 53 | // only expose virtual position to the inner adapter 54 | return adapter.instantiateItem(container, virtualPosition); 55 | } 56 | 57 | @Override 58 | public void destroyItem(ViewGroup container, int position, Object object) { 59 | if(getRealCount() == 0){ 60 | return; 61 | } 62 | int virtualPosition = position % getRealCount(); 63 | debug("destroyItem: real position: " + position); 64 | debug("destroyItem: virtual position: " + virtualPosition); 65 | 66 | // only expose virtual position to the inner adapter 67 | adapter.destroyItem(container, virtualPosition, object); 68 | } 69 | 70 | /* 71 | * Delegate rest of methods directly to the inner adapter. 72 | */ 73 | 74 | @Override 75 | public void finishUpdate(ViewGroup container) { 76 | adapter.finishUpdate(container); 77 | } 78 | 79 | @Override 80 | public boolean isViewFromObject(View view, Object object) { 81 | return adapter.isViewFromObject(view, object); 82 | } 83 | 84 | @Override 85 | public void restoreState(Parcelable bundle, ClassLoader classLoader) { 86 | adapter.restoreState(bundle, classLoader); 87 | } 88 | 89 | @Override 90 | public Parcelable saveState() { 91 | return adapter.saveState(); 92 | } 93 | 94 | @Override 95 | public void startUpdate(ViewGroup container) { 96 | adapter.startUpdate(container); 97 | } 98 | 99 | /* 100 | * End delegation 101 | */ 102 | 103 | private void debug(String message) { 104 | if (DEBUG) { 105 | Log.d(TAG, message); 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/Tricks/InfiniteViewPager.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.Tricks; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.support.v4.view.ViewPager; 6 | import android.util.AttributeSet; 7 | 8 | /** 9 | * A {@link ViewPager} that allows pseudo-infinite paging with a wrap-around effect. Should be used with an {@link 10 | * InfinitePagerAdapter}. 11 | */ 12 | public class InfiniteViewPager extends ViewPagerEx { 13 | 14 | public InfiniteViewPager(Context context) { 15 | super(context); 16 | } 17 | 18 | public InfiniteViewPager(Context context, AttributeSet attrs) { 19 | super(context, attrs); 20 | } 21 | 22 | @Override 23 | public void setAdapter(PagerAdapter adapter) { 24 | super.setAdapter(adapter); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/java/in/myinnos/imagesliderwithswipeslibrary/fonts/TextViewCustomFont.java: -------------------------------------------------------------------------------- 1 | package in.myinnos.imagesliderwithswipeslibrary.fonts; 2 | 3 | import android.content.Context; 4 | import android.graphics.Typeface; 5 | import android.util.AttributeSet; 6 | import android.widget.TextView; 7 | 8 | /** 9 | * Created by Home on 13-07-2016. 10 | */ 11 | public class TextViewCustomFont extends TextView { 12 | 13 | public TextViewCustomFont(Context context, AttributeSet attrs, int defStyle) { 14 | super(context, attrs, defStyle); 15 | init(); 16 | } 17 | 18 | public TextViewCustomFont(Context context, AttributeSet attrs) { 19 | super(context, attrs); 20 | init(); 21 | } 22 | 23 | public TextViewCustomFont(Context context) { 24 | super(context); 25 | init(); 26 | } 27 | 28 | public void init() { 29 | Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/OpenSans-Regular.ttf"); 30 | setTypeface(tf ,1); 31 | 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/res/drawable/hunnibal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myinnos/ImageSliderWithSwipes/34e9210d5c2e6f089ac934100c69b32a2520a00a/imagesliderwithswipeslibrary/src/main/res/drawable/hunnibal.png -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/res/drawable/indicator_corner_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/res/layout/indicator_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/res/layout/render_type_default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 10 | 15 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/res/layout/render_type_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 11 | 12 | 17 | 18 | 27 | 28 | 35 | 36 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/res/layout/slider_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 12 | 13 | 22 | 23 | 32 | 33 | 42 | 43 | 51 | 52 | 61 | 62 | 71 | 72 | 81 | 82 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Default 16 | Accordion 17 | Background2Foreground 18 | CubeIn 19 | DepthPage 20 | Fade 21 | FlipHorizontal 22 | FlipPage 23 | Foreground2Background 24 | RotateDown 25 | RotateUp 26 | Stack 27 | Tablet 28 | ZoomIn 29 | ZoomOutSlide 30 | ZoomOut 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Slider 3 | 4 | -------------------------------------------------------------------------------- /imagesliderwithswipeslibrary/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 23 | 24 | 43 | 44 | 63 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':imagesliderwithswipeslibrary' 2 | --------------------------------------------------------------------------------