diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 61a9130..fb7f4a8 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
new file mode 100644
index 0000000..4154a1c
--- /dev/null
+++ b/.idea/deploymentTargetDropDown.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 4351827..271d60b 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -14,7 +14,6 @@
-
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 81cb483..b8d0990 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -55,7 +55,7 @@
-
+
diff --git a/README.md b/README.md
index 6670c13..12be48d 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,17 @@
+
-
-
-Android Image Slide
+
+
+
+
+
+
+Android Image Slider
This is an android image slider library. Just add the images you want to view.
-You can use automatic scrolling for the time you set.
-You can also add the title you want to the images.
-You can set corner radius images.
-You can use with Java or Kotlin.
+You can use automatic scrolling for the time you set.
+You can also add the title you want to the images.
+You can set corner radius images.
+You can use with Java or Kotlin.
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ImageSlideshow-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/7587)
@@ -19,13 +24,14 @@
- Add ImageSlider to your **layout**
```xml
-
+
```
- You can change placeholder image.
@@ -87,17 +93,38 @@ imageSlider.setImageList(imageList, ScaleTypes.FIT) // for all images
//or
app:iss_title_background="@android:color/holo_red_light"
```
+- Also change text color on xml. It is default white.
-- You can use click listener.
+```xml
+ app:iss_text_color="#FFA0A0"
+```
+
+- Indicators can be remove.
+
+```xml
+ app:iss_no_dots="true"
+```
+
+- You can use click listener or double click listener.
```kt
-imageSlider.setItemClickListener(object : ItemClickListener {
- override fun onItemSelected(position: Int) {
- // You can listen here
- }
+imageSlider.setItemClickListener(object : ItemClickListener {
+ override fun onItemSelected(position: Int) {
+ // You can listen here.
+ }
+
+ override fun doubleClick(position: Int) {
+ // Do not use onItemSelected if you are using a double click listener at the same time.
+ // Its just added for specific cases.
+ // Listen for clicks under 250 milliseconds.
+ }
})
```
+- You can add animation like that, 14 Animations added. You can check in Animation List
+```kt
+imageSlider.setSlideAnimation(AnimationTypes.ZOOM_OUT)
+```
- You can add stop and start auto sliding again.
```kt
@@ -110,15 +137,15 @@ imageSlider.stopSliding()
```xml
allprojects {
- repositories {
+ repositories {
...
maven { url 'https://jitpack.io' }
- }
-}
+ }
+ }
-dependencies {
- implementation 'com.github.denzcoskun:ImageSlideshow:0.1.0'
-}
+ dependencies {
+ implementation 'com.github.denzcoskun:ImageSlideshow:0.1.1'
+ }
```
## 📄 License
diff --git a/app/src/main/java/com/denzcoskun/imageslideshow/MainActivity.kt b/app/src/main/java/com/denzcoskun/imageslideshow/MainActivity.kt
index 4b9bab3..0019322 100644
--- a/app/src/main/java/com/denzcoskun/imageslideshow/MainActivity.kt
+++ b/app/src/main/java/com/denzcoskun/imageslideshow/MainActivity.kt
@@ -26,12 +26,13 @@ class MainActivity : AppCompatActivity() {
val imageSlider = findViewById(R.id.image_slider) // init imageSlider
val imageList = ArrayList() // Create image list
- imageList.add(SlideModel("https://bit.ly/37Rn50u", "Baby Owl", ScaleTypes.CENTER_CROP))
- imageList.add(SlideModel("https://bit.ly/2BteuF2", "Elephants and tigers may become extinct."))
- imageList.add(SlideModel("https://bit.ly/3fLJf72", "The population of elephants is decreasing in the world."))
+ imageList.add(SlideModel("https://t.ly/aaa_", "The future is our hands."))
+ imageList.add(SlideModel("https://t.ly/sg91", "Climate change is moving very fast."))
+ imageList.add(SlideModel("https://t.ly/hqW3", "The population has decreased by 27 percent in the last 5 years."))
- imageSlider.setImageList(imageList)
- imageSlider.setSlideAnimation(AnimationTypes.GATE)
+ imageSlider.setImageList(imageList, ScaleTypes.CENTER_CROP)
+
+ imageSlider.setSlideAnimation(AnimationTypes.ZOOM_OUT)
imageSlider.setItemClickListener(object : ItemClickListener {
override fun onItemSelected(position: Int) {
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index c7f31d0..e3fb451 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -13,14 +13,10 @@
android:layout_width="wrap_content"
android:layout_height="300dp"
app:iss_auto_cycle="true"
- app:iss_period="2000"
+ app:iss_period="1000"
app:iss_delay="1000"
- app:iss_text_align="RIGHT"
- app:iss_title_background="@drawable/gradient"
- app:iss_error_image="@drawable/error"
- app:iss_selected_dot="@drawable/default_selected_dot"
- app:iss_unselected_dot="@drawable/default_unselected_dot"
- app:iss_text_color="#FFE69C"
+ app:iss_text_align="CENTER"
+ app:iss_text_color="#FFA0A0"
app:iss_no_dots="true"/>
\ No newline at end of file
diff --git a/imageslider/src/main/java/com/denzcoskun/imageslider/ImageSlider.kt b/imageslider/src/main/java/com/denzcoskun/imageslider/ImageSlider.kt
index 289ed83..d23234b 100644
--- a/imageslider/src/main/java/com/denzcoskun/imageslider/ImageSlider.kt
+++ b/imageslider/src/main/java/com/denzcoskun/imageslider/ImageSlider.kt
@@ -6,7 +6,6 @@ import android.os.Handler
import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
-import android.view.MotionEvent
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RelativeLayout
@@ -14,13 +13,13 @@ import androidx.core.content.ContextCompat
import androidx.viewpager.widget.ViewPager
import com.denzcoskun.imageslider.adapters.ViewPagerAdapter
import com.denzcoskun.imageslider.animations.*
-import com.denzcoskun.imageslider.constants.ActionTypes
import com.denzcoskun.imageslider.constants.AnimationTypes
import com.denzcoskun.imageslider.constants.ScaleTypes
import com.denzcoskun.imageslider.interfaces.ItemChangeListener
import com.denzcoskun.imageslider.interfaces.ItemClickListener
import com.denzcoskun.imageslider.interfaces.TouchListener
import com.denzcoskun.imageslider.models.SlideModel
+import java.lang.reflect.Field
import java.util.*
/**
@@ -81,11 +80,11 @@ class ImageSlider @JvmOverloads constructor(
period = typedArray.getInt(R.styleable.ImageSlider_iss_period, 1000).toLong()
delay = typedArray.getInt(R.styleable.ImageSlider_iss_delay, 1000).toLong()
autoCycle = typedArray.getBoolean(R.styleable.ImageSlider_iss_auto_cycle, false)
- placeholder = typedArray.getResourceId(R.styleable.ImageSlider_iss_placeholder, R.drawable.loading)
- errorImage = typedArray.getResourceId(R.styleable.ImageSlider_iss_error_image, R.drawable.error)
+ placeholder = typedArray.getResourceId(R.styleable.ImageSlider_iss_placeholder, R.drawable.default_loading)
+ errorImage = typedArray.getResourceId(R.styleable.ImageSlider_iss_error_image, R.drawable.default_error)
selectedDot = typedArray.getResourceId(R.styleable.ImageSlider_iss_selected_dot, R.drawable.default_selected_dot)
unselectedDot = typedArray.getResourceId(R.styleable.ImageSlider_iss_unselected_dot, R.drawable.default_unselected_dot)
- titleBackground = typedArray.getResourceId(R.styleable.ImageSlider_iss_title_background, R.drawable.gradient)
+ titleBackground = typedArray.getResourceId(R.styleable.ImageSlider_iss_title_background, R.drawable.default_gradient)
noDots = typedArray.getBoolean(R.styleable.ImageSlider_iss_no_dots, false)
if (typedArray.getString(R.styleable.ImageSlider_iss_text_align) != null){
@@ -184,7 +183,6 @@ class ImageSlider @JvmOverloads constructor(
}
private fun setupDots(size: Int) {
- println(indicatorAlign)
pagerDots!!.gravity = getGravityFromAlign(indicatorAlign)
pagerDots!!.removeAllViews()
dots = arrayOfNulls(size)
@@ -244,6 +242,9 @@ class ImageSlider @JvmOverloads constructor(
}
private fun scheduleTimer(period: Long) {
+
+ viewPager!!.setViewPageScroller(ViewPagerScroller(context))
+
val handler = Handler()
val update = Runnable {
if (currentPage == imageCount) {
@@ -260,6 +261,18 @@ class ImageSlider @JvmOverloads constructor(
}, delay, period)
}
+ fun ViewPager.setViewPageScroller(viewPageScroller: ViewPagerScroller) {
+ try {
+ val mScroller: Field = ViewPager::class.java.getDeclaredField("mScroller")
+ mScroller.isAccessible = true
+ mScroller.set(this, viewPageScroller)
+ } catch (_: NoSuchFieldException) {
+ } catch (_: IllegalArgumentException) {
+ } catch (_: IllegalAccessException) {
+ }
+
+ }
+
/**
* Set item click listener for listen to image click
*
diff --git a/imageslider/src/main/java/com/denzcoskun/imageslider/ViewPagerScroller.kt b/imageslider/src/main/java/com/denzcoskun/imageslider/ViewPagerScroller.kt
new file mode 100644
index 0000000..a0d460a
--- /dev/null
+++ b/imageslider/src/main/java/com/denzcoskun/imageslider/ViewPagerScroller.kt
@@ -0,0 +1,31 @@
+package com.denzcoskun.imageslider
+
+import android.content.Context
+import android.view.animation.Interpolator
+import android.widget.Scroller
+
+
+/**
+ * Created by Deniz Coşkun on 05/04/2023.
+ * denzcoskun@hotmail.com
+ * İstanbul
+ */
+class ViewPagerScroller : Scroller {
+
+ var fixedDuration = 1000 //time to scroll in milliseconds
+
+ constructor(context: Context) : super(context)
+
+ constructor(context: Context, interpolator: Interpolator) : super(context, interpolator)
+
+ constructor(context: Context, interpolator: Interpolator, flywheel: Boolean) : super(context, interpolator, flywheel)
+
+
+ override fun startScroll(startX: Int, startY: Int, dx: Int, dy: Int, duration: Int) {
+ super.startScroll(startX, startY, dx, dy, fixedDuration)
+ }
+
+ override fun startScroll(startX: Int, startY: Int, dx: Int, dy: Int) {
+ super.startScroll(startX, startY, dx, dy, fixedDuration)
+ }
+}
\ No newline at end of file
diff --git a/imageslider/src/main/res/drawable/error.png b/imageslider/src/main/res/drawable/default_error.png
similarity index 100%
rename from imageslider/src/main/res/drawable/error.png
rename to imageslider/src/main/res/drawable/default_error.png
diff --git a/imageslider/src/main/res/drawable/gradient.xml b/imageslider/src/main/res/drawable/default_gradient.xml
similarity index 100%
rename from imageslider/src/main/res/drawable/gradient.xml
rename to imageslider/src/main/res/drawable/default_gradient.xml
diff --git a/imageslider/src/main/res/drawable/loading.png b/imageslider/src/main/res/drawable/default_loading.png
similarity index 100%
rename from imageslider/src/main/res/drawable/loading.png
rename to imageslider/src/main/res/drawable/default_loading.png
diff --git a/imageslider/src/main/res/drawable/placeholder.jpg b/imageslider/src/main/res/drawable/default_placeholder.jpg
similarity index 100%
rename from imageslider/src/main/res/drawable/placeholder.jpg
rename to imageslider/src/main/res/drawable/default_placeholder.jpg
diff --git a/imageslider/src/main/res/layout/pager_row.xml b/imageslider/src/main/res/layout/pager_row.xml
index ed080aa..cbb3c9b 100644
--- a/imageslider/src/main/res/layout/pager_row.xml
+++ b/imageslider/src/main/res/layout/pager_row.xml
@@ -18,7 +18,7 @@
android:paddingBottom="40dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
- android:background="@drawable/gradient"
+ android:background="@drawable/default_gradient"
android:paddingTop="5dp">