Skip to content

Commit

Permalink
Merge pull request #103 from smarteist/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
smarteist authored Feb 16, 2020
2 parents 7df1704 + 512c637 commit b031aea
Show file tree
Hide file tree
Showing 34 changed files with 3,559 additions and 299 deletions.
134 changes: 77 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,34 @@ This is an amazing image slider for the Android .
You can easily load images with your custom layout, and there are many kinds of amazing animations you can choose.

```groovy
implementation 'com.github.smarteist:autoimageslider:1.3.3'
implementation 'com.github.smarteist:autoimageslider:1.3.4'
```
If you are using appcompat libraries
If you are using appcompat libraries use this one, but please migrate to androidx as soon as you can.
```groovy
implementation 'com.github.smarteist:autoimageslider:1.3.2-appcompat'
```

### New Feautures
* Bugs fixed.
* Ability to set an animation interpolator for slider.

# Demo
### New Feautures
* Infinite adapter implemented
* Auto cycle Bugs fixed.
* Slider API improvements.

### New Changes
* Circular handle completely replaced with infinite wrapper adapter.
because of that the following interface has been replaced with new one.
```CircularSliderHandle.CurrentPageListener```
changed to => `SliderView.OnSliderPageListener`.
* The slider permanently scrolls infinitely, so the following methods have also been deleted.
`sliderView.setCircularHandlerEnabled(boolean enable)`
& its attribute in xml side:
`app:sliderCircularHandlerEnabled="boolean"`
## Demo
![](https://github.com/smarteist/android-image-slider/blob/master/gif/0.gif)
![](https://github.com/smarteist/android-image-slider/blob/master/gif/8.gif)
![](https://github.com/smarteist/android-image-slider/blob/master/gif/4.gif)
![](https://github.com/smarteist/android-image-slider/blob/master/gif/7.gif)

# Integration guide
## Integration guide

First put the slider view in your layout xml :

Expand All @@ -39,7 +49,6 @@ First put the slider view in your layout xml :
app:sliderAnimationDuration="600"
app:sliderAutoCycleDirection="back_and_forth"
app:sliderAutoCycleEnabled="true"
app:sliderCircularHandlerEnabled="true"
app:sliderIndicatorAnimationDuration="600"
app:sliderIndicatorGravity="center_horizontal|bottom"
app:sliderIndicatorMargin="15dp"
Expand All @@ -51,24 +60,23 @@ First put the slider view in your layout xml :
app:sliderScrollTimeInSec="1"
app:sliderStartAutoCycle="true" />
```

Or you can put it inside the cardView to look more beautiful :

```xml
<androidx.cardview.widget.CardView
app:cardCornerRadius="6dp"
android:layout_margin="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.smarteist.autoimageslider.SliderView
android:id="@+id/imageSlider"
android:layout_width="match_parent"
android:layout_height="300dp"
app:sliderAnimationDuration="600"
app:sliderAutoCycleDirection="back_and_forth"
app:sliderAutoCycleEnabled="true"
app:sliderCircularHandlerEnabled="true"
app:sliderIndicatorAnimationDuration="600"
app:sliderIndicatorGravity="center_horizontal|bottom"
app:sliderIndicatorMargin="15dp"
Expand All @@ -79,88 +87,99 @@ Or you can put it inside the cardView to look more beautiful :
app:sliderIndicatorUnselectedColor="#FFF"
app:sliderScrollTimeInSec="1"
app:sliderStartAutoCycle="true" />

</androidx.cardview.widget.CardView>
```
# Next step

## Next step

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 :

```java
public class SliderAdapterExample extends SliderViewAdapter<SliderAdapterExample.SliderAdapterVH> {
```java
public class SliderAdapterExample extends
SliderViewAdapter<SliderAdapterExample.SliderAdapterVH> {

private Context context;
private List<SliderItem> mSliderItems = new ArrayList<>();

public SliderAdapterExample(Context context) {
this.context = context;
}

public void renewItems(List<SliderItem> sliderItems) {
this.mSliderItems = sliderItems;
notifyDataSetChanged();
}

public void deleteItem(int position) {
this.mSliderItems.remove(position);
notifyDataSetChanged();
}

public void addItem(SliderItem sliderItem) {
this.mSliderItems.add(sliderItem);
notifyDataSetChanged();
}

@Override
public SliderAdapterVH onCreateViewHolder(ViewGroup parent) {
View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.image_slider_layout_item, null);
return new SliderAdapterVH(inflate);
}

@Override
public void onBindViewHolder(SliderAdapterVH viewHolder, int position) {
viewHolder.textViewDescription.setText("This is slider item " + position);

switch (position) {
case 0:
Glide.with(viewHolder.itemView)
.load("https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.into(viewHolder.imageViewBackground);
break;
case 1:
Glide.with(viewHolder.itemView)
.load("https://images.pexels.com/photos/747964/pexels-photo-747964.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260")
.into(viewHolder.imageViewBackground);
break;
case 2:
Glide.with(viewHolder.itemView)
.load("https://images.pexels.com/photos/929778/pexels-photo-929778.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.into(viewHolder.imageViewBackground);
break;
default:
Glide.with(viewHolder.itemView)
.load("https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.into(viewHolder.imageViewBackground);
break;

}

public void onBindViewHolder(SliderAdapterVH viewHolder, final int position) {

SliderItem sliderItem = mSliderItems.get(position);

viewHolder.textViewDescription.setText(sliderItem.getDescription());
viewHolder.textViewDescription.setTextSize(16);
viewHolder.textViewDescription.setTextColor(Color.WHITE);
Glide.with(viewHolder.itemView)
.load(sliderItem.getImageUrl())
.fitCenter()
.into(viewHolder.imageViewBackground);

viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "This is item in position " + position, Toast.LENGTH_SHORT).show();
}
});
}

@Override
public int getCount() {
//slider view count could be dynamic size
return 4;
return mSliderItems.size();
}

class SliderAdapterVH extends SliderViewAdapter.ViewHolder {

View itemView;
ImageView imageViewBackground;
ImageView imageGifContainer;
TextView textViewDescription;

public SliderAdapterVH(View itemView) {
super(itemView);
imageViewBackground = itemView.findViewById(R.id.iv_auto_image_slider);
imageGifContainer = itemView.findViewById(R.id.iv_gif_container);
textViewDescription = itemView.findViewById(R.id.tv_auto_image_slider);
this.itemView = itemView;
}
}

}
```
# Set the adapter to the Sliderview
## Set the adapter to the Sliderview

After the instantiating of the sliderView (inside the activity or fragment with findViewById blah blah...), set the adapter to the slider.
After the instantiating of the sliderView (inside the activity or fragment with findViewById|BindView blah blah...), set the adapter to the slider.

```java
sliderView.setSliderAdapter(new SliderAdapterExample(context));
```

You can call this method if you want to start flipping automatically and you can also set up the slider animation :

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

# Elaborate more?
## Elaborate more?

Here is a more realistic and more complete example :

Expand All @@ -179,29 +198,30 @@ Here is a more realistic and more complete example :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

SliderView sliderView = findViewById(R.id.imageSlider);

SliderAdapterExample adapter = new SliderAdapterExample(this);

sliderView.setSliderAdapter(adapter);

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!!
sliderView.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
sliderView.setAutoCycleDirection(SliderView.AUTO_CYCLE_DIRECTION_BACK_AND_FORTH);
sliderView.setIndicatorSelectedColor(Color.WHITE);
sliderView.setIndicatorUnselectedColor(Color.GRAY);
sliderView.setScrollTimeInSec(4); //set scroll delay in seconds :
sliderView.startAutoCycle();

}
```

# Contribute
## Contribute

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

# Licence
## Licence

Copyright [2019] [Ali Hosseini]

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="com.smarteist.imageslider">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.smarteist.autoimageslider.IndicatorAnimations;
import com.smarteist.autoimageslider.SliderAnimations;
import com.smarteist.autoimageslider.SliderView;
import com.smarteist.imageslider.Model.SliderItem;

import java.util.ArrayList;
import java.util.List;

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

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!!
sliderView.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
sliderView.setAutoCycleDirection(SliderView.AUTO_CYCLE_DIRECTION_RIGHT);
sliderView.setAutoCycleDirection(SliderView.AUTO_CYCLE_DIRECTION_BACK_AND_FORTH);
sliderView.setIndicatorSelectedColor(Color.WHITE);
sliderView.setIndicatorUnselectedColor(Color.GRAY);
sliderView.setScrollTimeInSec(3);
sliderView.setAutoCycle(true);
sliderView.startAutoCycle();

}

Expand Down
11 changes: 4 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
android:layout_height="300dp"
app:sliderAnimationDuration="600"
app:sliderAutoCycleDirection="back_and_forth"
app:sliderAutoCycleEnabled="false"
app:sliderCircularHandlerEnabled="true"
app:sliderIndicatorAnimationDuration="600"
app:sliderIndicatorGravity="center_horizontal|bottom"
app:sliderIndicatorMargin="15dp"
Expand All @@ -30,8 +28,7 @@
app:sliderIndicatorRadius="2dp"
app:sliderIndicatorSelectedColor="#5A5A5A"
app:sliderIndicatorUnselectedColor="#FFF"
app:sliderScrollTimeInSec="1"
app:sliderStartAutoCycle="true" />
app:sliderScrollTimeInSec="1" />

</androidx.cardview.widget.CardView>

Expand All @@ -42,19 +39,19 @@
android:gravity="center"
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatButton
<Button
android:onClick="addNewItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add An Item" />

<androidx.appcompat.widget.AppCompatButton
<Button
android:onClick="removeLastItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rmove Last Item" />

<androidx.appcompat.widget.AppCompatButton
<Button
android:onClick="renewItems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion autoimageslider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ext {
siteUrl = 'https://github.com/smarteist'
gitUrl = 'https://github.com/smarteist/android-image-slider.git'

libraryVersion = '1.3.3'
libraryVersion = '1.3.4'
organization = 'smarteistbintray' // if you push to organization's repository.
developerId = 'smarteist'
developerName = 'Ali Hosseini'
Expand Down
Loading

0 comments on commit b031aea

Please sign in to comment.