@@ -10,24 +10,34 @@ This is an amazing image slider for the Android .
10
10
You can easily load images with your custom layout, and there are many kinds of amazing animations you can choose.
11
11
12
12
``` groovy
13
- implementation 'com.github.smarteist:autoimageslider:1.3.3 '
13
+ implementation 'com.github.smarteist:autoimageslider:1.3.4 '
14
14
```
15
- If you are using appcompat libraries
15
+ If you are using appcompat libraries use this one, but please migrate to androidx as soon as you can.
16
16
``` groovy
17
17
implementation 'com.github.smarteist:autoimageslider:1.3.2-appcompat'
18
18
```
19
19
20
- ### New Feautures
21
- * Bugs fixed.
22
- * Ability to set an animation interpolator for slider.
23
-
24
- # Demo
20
+ ### New Feautures
21
+ * Infinite adapter implemented
22
+ * Auto cycle Bugs fixed.
23
+ * Slider API improvements.
24
+
25
+ ### New Changes
26
+ * Circular handle completely replaced with infinite wrapper adapter.
27
+ because of that the following interface has been replaced with new one.
28
+ ``` CircularSliderHandle.CurrentPageListener ```
29
+ changed to => ` SliderView.OnSliderPageListener ` .
30
+ * The slider permanently scrolls infinitely, so the following methods have also been deleted.
31
+ ` sliderView.setCircularHandlerEnabled(boolean enable) `
32
+ & its attribute in xml side:
33
+ ` app:sliderCircularHandlerEnabled="boolean" `
34
+ ## Demo
25
35
![ ] ( https://github.com/smarteist/android-image-slider/blob/master/gif/0.gif )
26
36
![ ] ( https://github.com/smarteist/android-image-slider/blob/master/gif/8.gif )
27
37
![ ] ( https://github.com/smarteist/android-image-slider/blob/master/gif/4.gif )
28
38
![ ] ( https://github.com/smarteist/android-image-slider/blob/master/gif/7.gif )
29
39
30
- # Integration guide
40
+ ## Integration guide
31
41
32
42
First put the slider view in your layout xml :
33
43
@@ -39,7 +49,6 @@ First put the slider view in your layout xml :
39
49
app : sliderAnimationDuration =" 600"
40
50
app : sliderAutoCycleDirection =" back_and_forth"
41
51
app : sliderAutoCycleEnabled =" true"
42
- app : sliderCircularHandlerEnabled =" true"
43
52
app : sliderIndicatorAnimationDuration =" 600"
44
53
app : sliderIndicatorGravity =" center_horizontal|bottom"
45
54
app : sliderIndicatorMargin =" 15dp"
@@ -51,24 +60,23 @@ First put the slider view in your layout xml :
51
60
app : sliderScrollTimeInSec =" 1"
52
61
app : sliderStartAutoCycle =" true" />
53
62
```
54
-
63
+
55
64
Or you can put it inside the cardView to look more beautiful :
56
-
65
+
57
66
``` xml
58
67
<androidx .cardview.widget.CardView
59
68
app : cardCornerRadius =" 6dp"
60
69
android : layout_margin =" 16dp"
61
70
android : layout_width =" match_parent"
62
71
android : layout_height =" wrap_content" >
63
-
72
+
64
73
<com .smarteist.autoimageslider.SliderView
65
74
android : id =" @+id/imageSlider"
66
75
android : layout_width =" match_parent"
67
76
android : layout_height =" 300dp"
68
77
app : sliderAnimationDuration =" 600"
69
78
app : sliderAutoCycleDirection =" back_and_forth"
70
79
app : sliderAutoCycleEnabled =" true"
71
- app : sliderCircularHandlerEnabled =" true"
72
80
app : sliderIndicatorAnimationDuration =" 600"
73
81
app : sliderIndicatorGravity =" center_horizontal|bottom"
74
82
app : sliderIndicatorMargin =" 15dp"
@@ -79,88 +87,99 @@ Or you can put it inside the cardView to look more beautiful :
79
87
app : sliderIndicatorUnselectedColor =" #FFF"
80
88
app : sliderScrollTimeInSec =" 1"
81
89
app : sliderStartAutoCycle =" true" />
82
-
90
+
83
91
</androidx .cardview.widget.CardView>
84
92
```
85
-
86
- # Next step
93
+
94
+ ## Next step
87
95
88
96
The new version requires an slider adapter plus your custom layout for slider items, Although its very similar to RecyclerView & RecyclerAdapter, and it's familiar and easy to implement this adapter... here is an example for adapter implementation :
89
97
90
- ``` java
91
- public class SliderAdapterExample extends SliderViewAdapter<SliderAdapterExample .SliderAdapterVH > {
98
+ ``` java
99
+ public class SliderAdapterExample extends
100
+ SliderViewAdapter<SliderAdapterExample .SliderAdapterVH > {
92
101
93
102
private Context context;
103
+ private List<SliderItem > mSliderItems = new ArrayList<> ();
94
104
95
105
public SliderAdapterExample (Context context ) {
96
106
this . context = context;
97
107
}
98
108
109
+ public void renewItems (List<SliderItem > sliderItems ) {
110
+ this . mSliderItems = sliderItems;
111
+ notifyDataSetChanged();
112
+ }
113
+
114
+ public void deleteItem (int position ) {
115
+ this . mSliderItems. remove(position);
116
+ notifyDataSetChanged();
117
+ }
118
+
119
+ public void addItem (SliderItem sliderItem ) {
120
+ this . mSliderItems. add(sliderItem);
121
+ notifyDataSetChanged();
122
+ }
123
+
99
124
@Override
100
125
public SliderAdapterVH onCreateViewHolder (ViewGroup parent ) {
101
126
View inflate = LayoutInflater . from(parent. getContext()). inflate(R . layout. image_slider_layout_item, null );
102
127
return new SliderAdapterVH (inflate);
103
128
}
104
129
105
130
@Override
106
- public void onBindViewHolder (SliderAdapterVH viewHolder , int position ) {
107
- viewHolder. textViewDescription. setText(" This is slider item " + position);
108
-
109
- switch (position) {
110
- case 0 :
111
- Glide . with(viewHolder. itemView)
112
- .load(" https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" )
113
- .into(viewHolder. imageViewBackground);
114
- break ;
115
- case 1 :
116
- Glide . with(viewHolder. itemView)
117
- .load(" https://images.pexels.com/photos/747964/pexels-photo-747964.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" )
118
- .into(viewHolder. imageViewBackground);
119
- break ;
120
- case 2 :
121
- Glide . with(viewHolder. itemView)
122
- .load(" https://images.pexels.com/photos/929778/pexels-photo-929778.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" )
123
- .into(viewHolder. imageViewBackground);
124
- break ;
125
- default :
126
- Glide . with(viewHolder. itemView)
127
- .load(" https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" )
128
- .into(viewHolder. imageViewBackground);
129
- break ;
130
-
131
- }
132
-
131
+ public void onBindViewHolder (SliderAdapterVH viewHolder , final int position ) {
132
+
133
+ SliderItem sliderItem = mSliderItems. get(position);
134
+
135
+ viewHolder. textViewDescription. setText(sliderItem. getDescription());
136
+ viewHolder. textViewDescription. setTextSize(16 );
137
+ viewHolder. textViewDescription. setTextColor(Color . WHITE );
138
+ Glide . with(viewHolder. itemView)
139
+ .load(sliderItem. getImageUrl())
140
+ .fitCenter()
141
+ .into(viewHolder. imageViewBackground);
142
+
143
+ viewHolder. itemView. setOnClickListener(new View .OnClickListener () {
144
+ @Override
145
+ public void onClick (View v ) {
146
+ Toast . makeText(context, " This is item in position " + position, Toast . LENGTH_SHORT ). show();
147
+ }
148
+ });
133
149
}
134
150
135
151
@Override
136
152
public int getCount () {
137
153
// slider view count could be dynamic size
138
- return 4 ;
154
+ return mSliderItems . size() ;
139
155
}
140
156
141
157
class SliderAdapterVH extends SliderViewAdapter .ViewHolder {
142
158
143
159
View itemView;
144
160
ImageView imageViewBackground;
161
+ ImageView imageGifContainer;
145
162
TextView textViewDescription;
146
163
147
164
public SliderAdapterVH (View itemView ) {
148
165
super (itemView);
149
166
imageViewBackground = itemView. findViewById(R . id. iv_auto_image_slider);
167
+ imageGifContainer = itemView. findViewById(R . id. iv_gif_container);
150
168
textViewDescription = itemView. findViewById(R . id. tv_auto_image_slider);
151
169
this . itemView = itemView;
152
170
}
153
171
}
172
+
154
173
}
155
174
```
156
- # Set the adapter to the Sliderview
175
+ ## Set the adapter to the Sliderview
157
176
158
- After the instantiating of the sliderView (inside the activity or fragment with findViewById blah blah...), set the adapter to the slider.
177
+ After the instantiating of the sliderView (inside the activity or fragment with findViewById|BindView blah blah...), set the adapter to the slider.
159
178
160
179
``` java
161
180
sliderView. setSliderAdapter(new SliderAdapterExample (context));
162
181
```
163
-
182
+
164
183
You can call this method if you want to start flipping automatically and you can also set up the slider animation :
165
184
166
185
``` java
@@ -169,7 +188,7 @@ You can call this method if you want to start flipping automatically and you can
169
188
sliderView. setSliderTransformAnimation(SliderAnimations . SIMPLETRANSFORMATION );
170
189
```
171
190
172
- # Elaborate more?
191
+ ## Elaborate more?
173
192
174
193
Here is a more realistic and more complete example :
175
194
@@ -179,29 +198,30 @@ Here is a more realistic and more complete example :
179
198
protected void onCreate(Bundle savedInstanceState) {
180
199
super . onCreate(savedInstanceState);
181
200
setContentView(R . layout. activity_main);
182
-
201
+
183
202
SliderView sliderView = findViewById(R . id. imageSlider);
184
-
203
+
185
204
SliderAdapterExample adapter = new SliderAdapterExample (this );
186
-
205
+
187
206
sliderView. setSliderAdapter(adapter);
188
-
207
+
189
208
sliderView. setIndicatorAnimation(IndicatorAnimations . WORM ); // set indicator animation by using SliderLayout.IndicatorAnimations. :WORM or THIN_WORM or COLOR or DROP or FILL or NONE or SCALE or SCALE_DOWN or SLIDE and SWAP!!
190
209
sliderView. setSliderTransformAnimation(SliderAnimations . SIMPLETRANSFORMATION );
191
210
sliderView. setAutoCycleDirection(SliderView . AUTO_CYCLE_DIRECTION_BACK_AND_FORTH );
192
211
sliderView. setIndicatorSelectedColor(Color . WHITE );
193
212
sliderView. setIndicatorUnselectedColor(Color . GRAY );
194
213
sliderView. setScrollTimeInSec(4 ); // set scroll delay in seconds :
195
214
sliderView. startAutoCycle();
196
-
215
+
197
216
}
198
217
```
199
218
200
- # Contribute
219
+ ## Contribute
201
220
202
221
Suggestions and pull requests are always welcome.
222
+ Special Thanks [ Roman Danylyk] (https://github.com/romandanylyk ) for nice indicator!
203
223
204
- # Licence
224
+ ## Licence
205
225
206
226
Copyright [ 2019] [ Ali Hosseini]
207
227
0 commit comments