Skip to content

Commit b031aea

Browse files
authored
Merge pull request #103 from smarteist/dev
Dev
2 parents 7df1704 + 512c637 commit b031aea

34 files changed

+3559
-299
lines changed

README.md

+77-57
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,34 @@ This is an amazing image slider for the Android .
1010
You can easily load images with your custom layout, and there are many kinds of amazing animations you can choose.
1111

1212
```groovy
13-
implementation 'com.github.smarteist:autoimageslider:1.3.3'
13+
implementation 'com.github.smarteist:autoimageslider:1.3.4'
1414
```
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.
1616
```groovy
1717
implementation 'com.github.smarteist:autoimageslider:1.3.2-appcompat'
1818
```
1919

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
2535
![](https://github.com/smarteist/android-image-slider/blob/master/gif/0.gif)
2636
![](https://github.com/smarteist/android-image-slider/blob/master/gif/8.gif)
2737
![](https://github.com/smarteist/android-image-slider/blob/master/gif/4.gif)
2838
![](https://github.com/smarteist/android-image-slider/blob/master/gif/7.gif)
2939

30-
# Integration guide
40+
## Integration guide
3141

3242
First put the slider view in your layout xml :
3343

@@ -39,7 +49,6 @@ First put the slider view in your layout xml :
3949
app:sliderAnimationDuration="600"
4050
app:sliderAutoCycleDirection="back_and_forth"
4151
app:sliderAutoCycleEnabled="true"
42-
app:sliderCircularHandlerEnabled="true"
4352
app:sliderIndicatorAnimationDuration="600"
4453
app:sliderIndicatorGravity="center_horizontal|bottom"
4554
app:sliderIndicatorMargin="15dp"
@@ -51,24 +60,23 @@ First put the slider view in your layout xml :
5160
app:sliderScrollTimeInSec="1"
5261
app:sliderStartAutoCycle="true" />
5362
```
54-
63+
5564
Or you can put it inside the cardView to look more beautiful :
56-
65+
5766
```xml
5867
<androidx.cardview.widget.CardView
5968
app:cardCornerRadius="6dp"
6069
android:layout_margin="16dp"
6170
android:layout_width="match_parent"
6271
android:layout_height="wrap_content">
63-
72+
6473
<com.smarteist.autoimageslider.SliderView
6574
android:id="@+id/imageSlider"
6675
android:layout_width="match_parent"
6776
android:layout_height="300dp"
6877
app:sliderAnimationDuration="600"
6978
app:sliderAutoCycleDirection="back_and_forth"
7079
app:sliderAutoCycleEnabled="true"
71-
app:sliderCircularHandlerEnabled="true"
7280
app:sliderIndicatorAnimationDuration="600"
7381
app:sliderIndicatorGravity="center_horizontal|bottom"
7482
app:sliderIndicatorMargin="15dp"
@@ -79,88 +87,99 @@ Or you can put it inside the cardView to look more beautiful :
7987
app:sliderIndicatorUnselectedColor="#FFF"
8088
app:sliderScrollTimeInSec="1"
8189
app:sliderStartAutoCycle="true" />
82-
90+
8391
</androidx.cardview.widget.CardView>
8492
```
85-
86-
# Next step
93+
94+
## Next step
8795

8896
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 :
8997

90-
```java
91-
public class SliderAdapterExample extends SliderViewAdapter<SliderAdapterExample.SliderAdapterVH> {
98+
```java
99+
public class SliderAdapterExample extends
100+
SliderViewAdapter<SliderAdapterExample.SliderAdapterVH> {
92101

93102
private Context context;
103+
private List<SliderItem> mSliderItems = new ArrayList<>();
94104

95105
public SliderAdapterExample(Context context) {
96106
this.context = context;
97107
}
98108

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+
99124
@Override
100125
public SliderAdapterVH onCreateViewHolder(ViewGroup parent) {
101126
View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.image_slider_layout_item, null);
102127
return new SliderAdapterVH(inflate);
103128
}
104129

105130
@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+
});
133149
}
134150

135151
@Override
136152
public int getCount() {
137153
//slider view count could be dynamic size
138-
return 4;
154+
return mSliderItems.size();
139155
}
140156

141157
class SliderAdapterVH extends SliderViewAdapter.ViewHolder {
142158

143159
View itemView;
144160
ImageView imageViewBackground;
161+
ImageView imageGifContainer;
145162
TextView textViewDescription;
146163

147164
public SliderAdapterVH(View itemView) {
148165
super(itemView);
149166
imageViewBackground = itemView.findViewById(R.id.iv_auto_image_slider);
167+
imageGifContainer = itemView.findViewById(R.id.iv_gif_container);
150168
textViewDescription = itemView.findViewById(R.id.tv_auto_image_slider);
151169
this.itemView = itemView;
152170
}
153171
}
172+
154173
}
155174
```
156-
# Set the adapter to the Sliderview
175+
## Set the adapter to the Sliderview
157176

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.
159178

160179
```java
161180
sliderView.setSliderAdapter(new SliderAdapterExample(context));
162181
```
163-
182+
164183
You can call this method if you want to start flipping automatically and you can also set up the slider animation :
165184

166185
```java
@@ -169,7 +188,7 @@ You can call this method if you want to start flipping automatically and you can
169188
sliderView.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
170189
```
171190

172-
# Elaborate more?
191+
## Elaborate more?
173192

174193
Here is a more realistic and more complete example :
175194

@@ -179,29 +198,30 @@ Here is a more realistic and more complete example :
179198
protected void onCreate(Bundle savedInstanceState) {
180199
super.onCreate(savedInstanceState);
181200
setContentView(R.layout.activity_main);
182-
201+
183202
SliderView sliderView = findViewById(R.id.imageSlider);
184-
203+
185204
SliderAdapterExample adapter = new SliderAdapterExample(this);
186-
205+
187206
sliderView.setSliderAdapter(adapter);
188-
207+
189208
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!!
190209
sliderView.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
191210
sliderView.setAutoCycleDirection(SliderView.AUTO_CYCLE_DIRECTION_BACK_AND_FORTH);
192211
sliderView.setIndicatorSelectedColor(Color.WHITE);
193212
sliderView.setIndicatorUnselectedColor(Color.GRAY);
194213
sliderView.setScrollTimeInSec(4); //set scroll delay in seconds :
195214
sliderView.startAutoCycle();
196-
215+
197216
}
198217
```
199218

200-
# Contribute
219+
## Contribute
201220

202221
Suggestions and pull requests are always welcome.
222+
Special Thanks [Roman Danylyk] (https://github.com/romandanylyk) for nice indicator!
203223

204-
# Licence
224+
## Licence
205225

206226
Copyright [2019] [Ali Hosseini]
207227

app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package="com.smarteist.imageslider">
44

55
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
67

78
<application
89
android:allowBackup="true"

app/src/main/java/com/smarteist/imageslider/MainActivity.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import android.graphics.Color;
44
import android.os.Bundle;
5+
import android.util.Log;
56
import android.view.View;
7+
68
import androidx.appcompat.app.AppCompatActivity;
9+
710
import com.smarteist.autoimageslider.IndicatorAnimations;
811
import com.smarteist.autoimageslider.SliderAnimations;
912
import com.smarteist.autoimageslider.SliderView;
1013
import com.smarteist.imageslider.Model.SliderItem;
14+
1115
import java.util.ArrayList;
1216
import java.util.List;
1317

@@ -29,10 +33,12 @@ protected void onCreate(Bundle savedInstanceState) {
2933

3034
sliderView.setIndicatorAnimation(IndicatorAnimations.SLIDE); //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!!
3135
sliderView.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
32-
sliderView.setAutoCycleDirection(SliderView.AUTO_CYCLE_DIRECTION_RIGHT);
36+
sliderView.setAutoCycleDirection(SliderView.AUTO_CYCLE_DIRECTION_BACK_AND_FORTH);
3337
sliderView.setIndicatorSelectedColor(Color.WHITE);
3438
sliderView.setIndicatorUnselectedColor(Color.GRAY);
3539
sliderView.setScrollTimeInSec(3);
40+
sliderView.setAutoCycle(true);
41+
sliderView.startAutoCycle();
3642

3743
}
3844

app/src/main/res/layout/activity_main.xml

+4-7
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
android:layout_height="300dp"
2121
app:sliderAnimationDuration="600"
2222
app:sliderAutoCycleDirection="back_and_forth"
23-
app:sliderAutoCycleEnabled="false"
24-
app:sliderCircularHandlerEnabled="true"
2523
app:sliderIndicatorAnimationDuration="600"
2624
app:sliderIndicatorGravity="center_horizontal|bottom"
2725
app:sliderIndicatorMargin="15dp"
@@ -30,8 +28,7 @@
3028
app:sliderIndicatorRadius="2dp"
3129
app:sliderIndicatorSelectedColor="#5A5A5A"
3230
app:sliderIndicatorUnselectedColor="#FFF"
33-
app:sliderScrollTimeInSec="1"
34-
app:sliderStartAutoCycle="true" />
31+
app:sliderScrollTimeInSec="1" />
3532

3633
</androidx.cardview.widget.CardView>
3734

@@ -42,19 +39,19 @@
4239
android:gravity="center"
4340
android:orientation="vertical">
4441

45-
<androidx.appcompat.widget.AppCompatButton
42+
<Button
4643
android:onClick="addNewItem"
4744
android:layout_width="wrap_content"
4845
android:layout_height="wrap_content"
4946
android:text="Add An Item" />
5047

51-
<androidx.appcompat.widget.AppCompatButton
48+
<Button
5249
android:onClick="removeLastItem"
5350
android:layout_width="wrap_content"
5451
android:layout_height="wrap_content"
5552
android:text="Rmove Last Item" />
5653

57-
<androidx.appcompat.widget.AppCompatButton
54+
<Button
5855
android:onClick="renewItems"
5956
android:layout_width="wrap_content"
6057
android:layout_height="wrap_content"

autoimageslider/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ext {
1515
siteUrl = 'https://github.com/smarteist'
1616
gitUrl = 'https://github.com/smarteist/android-image-slider.git'
1717

18-
libraryVersion = '1.3.3'
18+
libraryVersion = '1.3.4'
1919
organization = 'smarteistbintray' // if you push to organization's repository.
2020
developerId = 'smarteist'
2121
developerName = 'Ali Hosseini'

0 commit comments

Comments
 (0)