Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.

Commit 966cf6c

Browse files
authored
Merge pull request #16 from jama5262/develop
Releasing v1.1.0
2 parents a83ce01 + 9b368e9 commit 966cf6c

File tree

9 files changed

+64
-8
lines changed

9 files changed

+64
-8
lines changed

.idea/codeStyles/Project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ allprojects {
3232

3333
```
3434
dependencies {
35-
implementation 'com.github.jama5262:CarouselView:1.0.0'
35+
implementation 'com.github.jama5262:CarouselView:1.1.0'
3636
}
3737
```
3838

@@ -51,7 +51,7 @@ dependencies {
5151
<dependency>
5252
<groupId>com.github.jama5262</groupId>
5353
<artifactId>CarouselView</artifactId>
54-
<version>1.0.0</version>
54+
<version>1.1.0</version>
5555
</dependency>
5656
```
5757

@@ -69,6 +69,8 @@ Below is all the XML attributes that the CarouselView has
6969
android:layout_height="wrap_content"
7070
app:enableSnapping="true"
7171
app:scaleOnScroll="false"
72+
app:setAutoPlay="true"
73+
app:setAutoPlayDelay="3000"
7274
app:carouselOffset="center"
7375
app:indicatorAnimationType="drop"
7476
app:indicatorRadius="5"
@@ -97,6 +99,7 @@ class CarouselActivity : AppCompatActivity() {
9799
carouselView.apply {
98100
size = images.size
99101
resource = R.layout.carousel_item
102+
autoPlay = true
100103
indicatorAnimationType = IndicatorAnimationType.THIN_WORM
101104
carouselOffset = OffsetType.CENTER
102105
setCarouselViewListener { view, position ->
@@ -128,6 +131,7 @@ class CenteredCarouselActivity extends AppCompatActivity {
128131

129132
carouselView.setSize(images.length);
130133
carouselView.setResource(R.layout.center_carousel_item);
134+
carouselView.setAutoPlay(true);
131135
carouselView.setIndicatorAnimationType(IndicatorAnimationType.THIN_WORM);
132136
carouselView.setCarouselOffset(OffsetType.CENTER);
133137
carouselView.setCarouselViewListener(new CarouselViewListener() {
@@ -151,6 +155,8 @@ Below are all the methods available
151155
| show | Show the carousel | | | No |
152156
| enableSnapping | Enables and disables snapping | true, false | true | Yes |
153157
| hideIndicator | Show and hide indicator | true, false | false | No |
158+
| setAutoPlay | Enable auto play | true, false | false | Yes |
159+
| setAutoPlayDelay | Set delay time for auto play | Takes in integers | 2500 (2.5 sec) | Yes |
154160
| setCarouselOffset | Sets the carousel item to display center or from start | OffsetType.CENTER, OffsetType.START | OffsetType.START | Yes |
155161
| setCurrentItem |This sets the item position | Takes item position | | No |
156162
| setIndicatorAnimationType | Sets the indicator animation type. This is thanks to [romandanylyk](https://github.com/romandanylyk/PageIndicatorView) | AnimationType.DROP, FILL, NONE, SWAP, WORM, COLOR, SCALE, SLIDE, THIN_WORM, SCALE_DOWN | AnimationType.NONE | Yes |

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: 'com.android.application'
2-
apply plugin: 'kotlin-android-extensions'
32
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
45

56
android {
67
compileSdkVersion 29

app/src/main/java/com/jama/carouselviewexample/examples/CenteredCarouselActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class CenteredCarouselActivity : AppCompatActivity() {
1818

1919
carouselView.apply {
2020
size = images.size
21+
autoPlay = true
22+
autoPlayDelay = 3000
2123
resource = R.layout.center_carousel_item
2224
indicatorAnimationType = IndicatorAnimationType.THIN_WORM
2325
carouselOffset = OffsetType.CENTER

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88

99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.5.0'
11+
classpath 'com.android.tools.build:gradle:3.5.3'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313

1414
// NOTE: Do not place your application dependencies here; they belong

carouselview/src/main/java/com/jama/carouselview/CarouselView.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import android.content.Context;
44
import android.content.res.TypedArray;
5+
import android.os.Handler;
56
import android.util.AttributeSet;
7+
import android.util.Log;
68
import android.view.LayoutInflater;
79
import android.view.View;
810
import android.widget.FrameLayout;
@@ -31,6 +33,9 @@ public class CarouselView extends FrameLayout {
3133
private OffsetType offsetType;
3234
private SnapHelper snapHelper;
3335
private boolean enableSnapping;
36+
private boolean enableAutoPlay;
37+
private int autoPlayDelay;
38+
private Handler autoPlayHandler;
3439
private boolean scaleOnScroll;
3540
private int resource;
3641
private int size;
@@ -55,6 +60,7 @@ private void init(AttributeSet attributeSet) {
5560
View carouselView = inflater.inflate(R.layout.view_carousel, this);
5661
this.carouselRecyclerView = carouselView.findViewById(R.id.carouselRecyclerView);
5762
this.pageIndicatorView = carouselView.findViewById(R.id.pageIndicatorView);
63+
this.autoPlayHandler = new Handler();
5864

5965
carouselRecyclerView.setHasFixedSize(false);
6066
this.initializeAttributes(attributeSet);
@@ -65,6 +71,8 @@ private void initializeAttributes(AttributeSet attributeSet) {
6571
TypedArray attributes = this.context.getTheme().obtainStyledAttributes(attributeSet, R.styleable.CarouselView, 0, 0);
6672
this.enableSnapping(attributes.getBoolean(R.styleable.CarouselView_enableSnapping, true));
6773
this.setScaleOnScroll(attributes.getBoolean(R.styleable.CarouselView_scaleOnScroll, false));
74+
this.setAutoPlay(attributes.getBoolean(R.styleable.CarouselView_setAutoPlay, false));
75+
this.setAutoPlayDelay(attributes.getInteger(R.styleable.CarouselView_setAutoPlayDelay, 2500));
6876
this.setCarouselOffset(this.getOffset(attributes.getInteger(R.styleable.CarouselView_carouselOffset, 0)));
6977
int resourceId = attributes.getResourceId(R.styleable.CarouselView_resource, 0);
7078
if (resourceId != 0) {
@@ -99,6 +107,12 @@ public void hideIndicator(boolean hide) {
99107
}
100108
}
101109

110+
@Override
111+
protected void onDetachedFromWindow() {
112+
super.onDetachedFromWindow();
113+
this.setAutoPlay(false);
114+
}
115+
102116
private void setAdapter() {
103117
this.layoutManager = new CarouselLinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
104118
this.layoutManager.isOffsetStart(this.getCarouselOffset() == OffsetType.START);
@@ -109,6 +123,7 @@ private void setAdapter() {
109123
this.snapHelper.attachToRecyclerView(this.carouselRecyclerView);
110124
}
111125
this.setScrollListener();
126+
this.enableAutoPlay();
112127
}
113128

114129
private void setScrollListener() {
@@ -137,6 +152,37 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
137152
});
138153
}
139154

155+
public void setAutoPlay(boolean enableAutoPlay) {
156+
this.enableAutoPlay = enableAutoPlay;
157+
}
158+
159+
public boolean getAutoPlay() {
160+
return this.enableAutoPlay;
161+
}
162+
163+
public void setAutoPlayDelay(int autoPlayDelay) {
164+
this.autoPlayDelay = autoPlayDelay;
165+
}
166+
167+
public int getAutoPlayDelay() {
168+
return this.autoPlayDelay;
169+
}
170+
171+
private void enableAutoPlay() {
172+
autoPlayHandler.postDelayed(new Runnable() {
173+
public void run() {
174+
if (getAutoPlay()) {
175+
if (getSize() - 1 == getCurrentItem()) {
176+
setCurrentItem(0);
177+
} else {
178+
setCurrentItem(getCurrentItem() + 1);
179+
}
180+
autoPlayHandler.postDelayed(this, getAutoPlayDelay());
181+
}
182+
}
183+
}, getAutoPlayDelay());
184+
}
185+
140186
public void setCarouselOffset(OffsetType offsetType) {
141187
this.offsetType = offsetType;
142188
switch (offsetType) {

carouselview/src/main/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
<attr name="enableSnapping" format="boolean" />
77
<attr name="scaleOnScroll" format="boolean" />
8+
<attr name="setAutoPlay" format="boolean" />
9+
<attr name="setAutoPlayDelay" format="integer" />
810
<attr name="carouselOffset" format="enum">
911
<enum name="start" value="0"/>
1012
<enum name="center" value="1"/>

0 commit comments

Comments
 (0)