Skip to content

Commit

Permalink
Project updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
denzcoskun committed Apr 4, 2023
1 parent f07c737 commit 6a2ef73
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 52 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<a href="https://github.com/denzcoskun/ImageSlideshow">
<img src="https://user-images.githubusercontent.com/15522554/54867096-7169d700-4d8d-11e9-8f9a-bee162a01427.png">
<a href="https://github.com/Ramotion/cardslider-android">
<img align="left" src="https://user-images.githubusercontent.com/15522554/85434507-d3b41780-b58e-11ea-9386-42741f0921ae.gif"/></a>
<p><h1 align="left">Android Image Slide</h1></p>
</a>
<p></p>
<a href="https://github.com/denzcoskun/ImageSlideshow">
<img align="left" src="https://user-images.githubusercontent.com/15522554/229931372-db70cfd5-2e37-4e45-a4e1-aae6e0654063.gif"/>
<img align="left" src="https://user-images.githubusercontent.com/15522554/229932076-43a6770d-b4a3-45ec-b473-f235c98b2d1b.png"/>
</a>
<h3 align="center">Android Image Slider</h3>
<p>This is an android image slider library. Just add the images you want to view. </p>
<p>You can use automatic scrolling for the time you set. </p>
<p>You can also add the title you want to the images.</p>
<p>You can set corner radius images.</p>
<p>You can use with Java or Kotlin.</p>
<li>You can use automatic scrolling for the time you set. </li>
<li>You can also add the title you want to the images.</li>
<li>You can set corner radius images.</li>
<li>You can use with Java or Kotlin.</p>
</br></br>

[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ImageSlideshow-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/7587)
Expand All @@ -19,13 +24,14 @@
- Add ImageSlider to your **layout**

```xml
<com.denzcoskun.imageslider.ImageSlider
android:id="@+id/image_slider"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:iss_auto_cycle="true"
app:iss_period="1000"
app:iss_delay="0"/>
<com.denzcoskun.imageslider.ImageSlider
android:id="@+id/image_slider"
android:layout_width="wrap_content"
android:layout_height="300dp"
app:iss_auto_cycle="true"
app:iss_period="1000"
app:iss_delay="1000"
app:iss_text_align="CENTER"/>
```

- You can change placeholder image.
Expand Down Expand Up @@ -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, <b>14 Animations added</b>. You can check in <a href="https://github.com/denzcoskun/ImageSlideshow/blob/master/imageslider/src/main/java/com/denzcoskun/imageslider/constants/AnimationTypes.kt"> Animation List </a>

```kt
imageSlider.setSlideAnimation(AnimationTypes.ZOOM_OUT)
```
- You can add stop and start auto sliding again.

```kt
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/com/denzcoskun/imageslideshow/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ class MainActivity : AppCompatActivity() {
val imageSlider = findViewById<ImageSlider>(R.id.image_slider) // init imageSlider

val imageList = ArrayList<SlideModel>() // 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) {
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ 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
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.*

/**
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -184,7 +183,6 @@ class ImageSlider @JvmOverloads constructor(
}

private fun setupDots(size: Int) {
println(indicatorAlign)
pagerDots!!.gravity = getGravityFromAlign(indicatorAlign)
pagerDots!!.removeAllViews()
dots = arrayOfNulls(size)
Expand Down Expand Up @@ -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) {
Expand All @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
2 changes: 1 addition & 1 deletion imageslider/src/main/res/layout/pager_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<TextView
android:id="@+id/text_view"
Expand Down

0 comments on commit 6a2ef73

Please sign in to comment.