From a805fa37829c6ff4cd88acfa272e449c3fb54a8e Mon Sep 17 00:00:00 2001 From: Minjae Seon Date: Sun, 26 Dec 2021 14:20:04 +0900 Subject: [PATCH 01/10] Fixed Null Type Exception --- .../dev/aftermoon/slideactionlayout/fragment/ImageFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/fragment/ImageFragment.kt b/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/fragment/ImageFragment.kt index b3c8425..a16b36e 100644 --- a/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/fragment/ImageFragment.kt +++ b/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/fragment/ImageFragment.kt @@ -69,7 +69,7 @@ class ImageFragment: Fragment() { super.onViewCreated(view, savedInstanceState) arguments?.let { bitmap = it.getParcelable("image") - scaleType = it.getSerializable("scaleType") as ImageView.ScaleType + scaleType = it.getSerializable("scaleType") as ImageView.ScaleType? if(bitmap != null) { Log.d(this.javaClass.simpleName, "Image Success") From 51e355c6905e2bb99a831b6f7a485f8a693c4024 Mon Sep 17 00:00:00 2001 From: Minjae Seon Date: Sun, 26 Dec 2021 14:20:19 +0900 Subject: [PATCH 02/10] Fixed Auto Slide Bug --- .../java/dev/aftermoon/slideactionlayout/SlideActionLayout.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/SlideActionLayout.kt b/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/SlideActionLayout.kt index 8da066d..6668aae 100644 --- a/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/SlideActionLayout.kt +++ b/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/SlideActionLayout.kt @@ -275,7 +275,7 @@ class SlideActionLayout @JvmOverloads constructor(context: Context, attrs: Attri autoSlideHandler!!.postDelayed(object : Runnable { override fun run() { if(slideActionAdapter != null && autoSlideEnabled) { - if(viewPager.currentItem < slideActionAdapter!!.itemCount) { + if(viewPager.currentItem < slideActionAdapter!!.itemCount - 1) { viewPager.currentItem = viewPager.currentItem + 1 } else { From c153da0059568a14a3a4a1738d10122cbbc2ebec Mon Sep 17 00:00:00 2001 From: Minjae Seon Date: Sun, 26 Dec 2021 14:33:38 +0900 Subject: [PATCH 03/10] Added Set Scale Type at Add Image Fragment Methods --- .../slideactionlayout/SlideActionLayout.kt | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/SlideActionLayout.kt b/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/SlideActionLayout.kt index 6668aae..5ce92c0 100644 --- a/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/SlideActionLayout.kt +++ b/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/SlideActionLayout.kt @@ -27,6 +27,7 @@ import android.view.Gravity import android.view.LayoutInflater import android.view.ViewGroup import android.widget.FrameLayout +import android.widget.ImageView import androidx.core.view.ViewCompat import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity @@ -111,6 +112,7 @@ class SlideActionLayout @JvmOverloads constructor(context: Context, attrs: Attri } } + /** * Add Image Fragment * @param drawable Drawable Type Image @@ -122,7 +124,18 @@ class SlideActionLayout @JvmOverloads constructor(context: Context, attrs: Attri } /** - * Add Fragment Fragments + * Add Image Fragment with Image Scale Type + * @param drawable Drawable Type Image + * @param scaleType ImageView ScaleType + */ + fun addImageFragment(drawable: Drawable, scaleType: ImageView.ScaleType) { + checkInitial() + val imageFragment = ImageFragment.newInstance(drawable, scaleType) + slideActionAdapter!!.addFragment(imageFragment) + } + + /** + * Add Image Fragments * @param drawables Drawables ArrayList */ fun addDrawableFragments(drawables: ArrayList) { @@ -133,6 +146,20 @@ class SlideActionLayout @JvmOverloads constructor(context: Context, attrs: Attri } } + + /** + * Add Image Fragments with Image Scale Type + * @param drawables Drawables ArrayList + * @param scaleType ImageView ScaleType + */ + fun addDrawableFragments(drawables: ArrayList, scaleType: ImageView.ScaleType) { + checkInitial() + + for (i in 0..drawables.size) { + slideActionAdapter!!.addFragment(ImageFragment.newInstance(drawables[i], scaleType)) + } + } + /** * Add Image Fragment * @param bitmap Bitmap Type Image @@ -143,6 +170,17 @@ class SlideActionLayout @JvmOverloads constructor(context: Context, attrs: Attri slideActionAdapter!!.addFragment(imageFragment) } + /** + * Add Image Fragment with Image Scale Type + * @param bitmap Bitmap Type Image + * @param scaleType ImageView ScaleType + */ + fun addImageFragment(bitmap: Bitmap, scaleType: ImageView.ScaleType) { + checkInitial() + val imageFragment = ImageFragment.newInstance(bitmap, scaleType) + slideActionAdapter!!.addFragment(imageFragment) + } + /** * Add Bitmap Fragments * @param bitmaps Bitmap ArrayList @@ -155,6 +193,19 @@ class SlideActionLayout @JvmOverloads constructor(context: Context, attrs: Attri } } + /** + * Add Bitmap Fragments with Scale Type + * @param bitmaps Bitmap ArrayList + * @param scaleType ImageView ScaleType + */ + fun addBitmapFragments(bitmaps: ArrayList, scaleType: ImageView.ScaleType) { + checkInitial() + + for (i in 0..bitmaps.size) { + slideActionAdapter!!.addFragment(ImageFragment.newInstance(bitmaps[i], scaleType)) + } + } + /** * Add Fragment * @param fragment New Fragment @@ -290,7 +341,6 @@ class SlideActionLayout @JvmOverloads constructor(context: Context, attrs: Attri else { if (autoSlideHandler != null) { autoSlideHandler!!.removeCallbacksAndMessages(null) - autoSlideHandler = null } } } @@ -299,7 +349,7 @@ class SlideActionLayout @JvmOverloads constructor(context: Context, attrs: Attri * Get Current State of Auto Slide * @return Enabled or Disabled Auto Slide */ - fun getEnableAutoSlide(): Boolean = autoSlideEnabled + fun isEnableAutoSlide(): Boolean = autoSlideEnabled /** * Check Initial From 0cccc1f7f09d29d8657239a9572cb689bef3abb4 Mon Sep 17 00:00:00 2001 From: Minjae Seon Date: Sun, 26 Dec 2021 14:34:28 +0900 Subject: [PATCH 04/10] Added Annotation at Indicator Color --- .../slideactionlayout/createindicator/CreateIndicator.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/createindicator/CreateIndicator.kt b/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/createindicator/CreateIndicator.kt index 2bf1570..3b3f900 100644 --- a/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/createindicator/CreateIndicator.kt +++ b/SlideActionLayout/src/main/java/dev/aftermoon/slideactionlayout/createindicator/CreateIndicator.kt @@ -22,6 +22,7 @@ import android.graphics.Color import android.graphics.drawable.GradientDrawable import android.graphics.drawable.LayerDrawable import android.graphics.drawable.StateListDrawable +import androidx.annotation.ColorInt import androidx.core.content.ContextCompat import androidx.core.content.res.ResourcesCompat import androidx.core.graphics.BlendModeColorFilterCompat @@ -36,7 +37,7 @@ class CreateIndicator { * @param selectedColor Selected Circle Fill Color Value (argb) * @param unselectedColor Unselected Circle Fill Color Value (argb) */ - fun createCircleIndicator(context: Context, selectedColor: Int, unselectedColor: Int): StateListDrawable { + fun createCircleIndicator(context: Context, @ColorInt selectedColor: Int, @ColorInt unselectedColor: Int): StateListDrawable { val stateListDrawable = StateListDrawable() val dotLayout = ResourcesCompat.getDrawable(context.resources, R.drawable.selected_dot, null) as LayerDrawable From dd22ad9a66f9f4be22420a40bda41c5bc9ff5c93 Mon Sep 17 00:00:00 2001 From: Minjae Seon Date: Sun, 26 Dec 2021 14:35:31 +0900 Subject: [PATCH 05/10] Added AutoSlide in Demo --- .idea/misc.xml | 2 ++ .../slideaction_demo/MainActivity.kt | 19 ++++++++++++++++--- app/src/main/res/layout/activity_main.xml | 9 ++++++++- app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index c6c8d0d..b6838a3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,6 +5,8 @@ + + diff --git a/app/src/main/java/dev/aftermoon/slideaction_demo/MainActivity.kt b/app/src/main/java/dev/aftermoon/slideaction_demo/MainActivity.kt index 5e70433..eaf9528 100644 --- a/app/src/main/java/dev/aftermoon/slideaction_demo/MainActivity.kt +++ b/app/src/main/java/dev/aftermoon/slideaction_demo/MainActivity.kt @@ -16,12 +16,10 @@ package dev.aftermoon.slideaction_demo -import android.graphics.Color import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.os.Handler -import android.os.Looper import android.view.Gravity +import android.widget.Button import androidx.core.content.ContextCompat import androidx.viewpager2.widget.ViewPager2 import dev.aftermoon.slideactionlayout.SlideActionLayout @@ -42,5 +40,20 @@ class MainActivity : AppCompatActivity() { ContextCompat.getDrawable(this, R.drawable.second)?.let { layout.addImageFragment(it) } ContextCompat.getDrawable(this, R.drawable.third)?.let { layout.addImageFragment(it) } layout.addFragment(TestFragment()) + + layout.setAutoSlide(3000, true) + + val btn = findViewById