Skip to content

Commit

Permalink
Fixed minor bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumman04 committed Dec 8, 2023
1 parent 7656b3b commit cef5808
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 83 deletions.
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/compiler.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/gradle.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/kotlinScripting.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/kotlinc.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/misc.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

Binary file modified J-Slider-release.aar
Binary file not shown.
2 changes: 1 addition & 1 deletion J-Slider/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ afterEvaluate {
register<MavenPublication>("release") {
groupId = "com.github.Jumman04"
artifactId = "Jummania-Slider"
version = "4.3"
version = "4.4"

afterEvaluate {
from(components["release"])
Expand Down
53 changes: 37 additions & 16 deletions J-Slider/src/main/java/com/jummania/JSlider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class JSlider @JvmOverloads constructor(
// Object to store integer values related to the slider configuration
private object IntObject {
var slidingDuration: Long = 1555 // Sliding duration in milliseconds
var size = 30 // Size of the dot indicator
var indicatorMarginHorizontal = 6 // Horizontal margin between dot indicators
var size = 33 // Size of the dot indicator
var indicatorMarginHorizontal = 4 // Horizontal margin between dot indicators
var selectedIndicatorColor = Color.WHITE // Color of the selected dot indicator
var defaultIndicatorColor =
Color.parseColor("#80ffffff") // Default color of the dot indicators
Expand Down Expand Up @@ -156,7 +156,7 @@ class JSlider @JvmOverloads constructor(
// Set indicator size based on the attribute, default to 30 pixels
setIndicatorSize(
typedArray.getDimensionPixelSize(
R.styleable.JSlider_indicatorSize, 30
R.styleable.JSlider_indicatorSize, 33
)
)

Expand Down Expand Up @@ -196,7 +196,7 @@ class JSlider @JvmOverloads constructor(
// Set horizontal margin for the indicator dots, default to 6 pixels
setIndicatorMarginHorizontal(
typedArray.getDimensionPixelSize(
R.styleable.JSlider_indicatorMarginHorizontal, 6
R.styleable.JSlider_indicatorMarginHorizontal, 4
)
)

Expand Down Expand Up @@ -280,14 +280,15 @@ class JSlider @JvmOverloads constructor(

onSliderSet(sliders)

// Set up the auto-sliding update runnable
update = Runnable {
if (!isDragging && autoSlidingBoolean) setCurrentItem(
if (currentItem == sliders - 1) 0 else currentItem + 1, true
)
}

// Handle auto-sliding
if (autoSlidingBoolean) {
// Set up the auto-sliding update runnable
update = Runnable {
if (!isDragging && autoSlidingBoolean) setCurrentItem(
if (currentItem == sliders - 1) 0 else currentItem + 1, true
)
}

updateHandler.removeCallbacks(update)
updateHandler.postDelayed(update, slidingDuration)
Expand Down Expand Up @@ -321,23 +322,41 @@ class JSlider @JvmOverloads constructor(
}

// Set up dot for the current position if indicator is enabled
// Check if indicator dots should be displayed
if (indicatorBoolean) {

// Create layout parameters for the indicator dots
val dotLayoutParams = LinearLayout.LayoutParams(size, size)
dotLayoutParams.marginStart = indicatorMarginHorizontal
dotLayoutParams.marginEnd = indicatorMarginHorizontal

// Calculate the maximum number of dots that can fit on the screen
val max =
(Resources.getSystem().displayMetrics.widthPixels / (size + indicatorMarginHorizontal * 2)) - 1

// Create indicator dots and add them to the layout
for (i in 0 until sliders) {
if (i == max) break

// Create a new JIndicator instance for the indicator dot
val dot = JIndicator(context, shapeTypes)

// Set layout parameters for the indicator dot
dot.layoutParams = dotLayoutParams

// Set a background resource for the indicator dot (if needed)
dot.setBackgroundResource(R.drawable.indicator)

// Set the default color for the indicator dot
dot.setColor(defaultIndicatorColor)

// Set padding for the indicator dot
dot.addPadding()

// Add the indicator dot to the dotIndicatorLayout
dotIndicatorLayout.addView(dot)

// Add the indicator dot to the list for future reference
dots.add(dot)
}

Expand All @@ -351,6 +370,7 @@ class JSlider @JvmOverloads constructor(
}
}


val max = dots.size - 1
var position: Int
var targetX: Float
Expand Down Expand Up @@ -459,14 +479,15 @@ class JSlider @JvmOverloads constructor(

onSliderSet(sliders)

// Set up the auto-sliding update runnable
update = Runnable {
if (!isDragging && autoSlidingBoolean) setCurrentItem(
(currentItem % slider.count) + 1, true
)
}

// Handle auto-sliding
if (autoSlidingBoolean) {
// Set up the auto-sliding update runnable
update = Runnable {
if (!isDragging && autoSlidingBoolean) setCurrentItem(
(currentItem % slider.count) + 1, true
)
}

updateHandler.removeCallbacks(update)
updateHandler.postDelayed(update, slidingDuration)
Expand Down
33 changes: 27 additions & 6 deletions J-Slider/src/main/java/com/jummania/widgets/JIndicator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import com.jummania.types.ShapeTypes
/**
* Abstract class representing a custom layout with a colored shape indicator.
*
* * Created by MD Abdulla and edited by Jummania on 20,November,2023.
* * Email: sharifuddinjumman@gmail.com
* * Dhaka, Bangladesh.
* This class serves as a base for creating custom indicator views with various shapes.
* Subclasses must implement the [ShapeTypes] interface to define the shape of the indicator.
*
* Created by MD Abdulla and edited by Jummania on 20, November, 2023.
* Email: sharifuddinjumman@gmail.com
* Dhaka, Bangladesh.
*
* @param context The context in which the layout is created.
* @param shapeTypes The shape type for the indicator.
Expand All @@ -32,15 +35,24 @@ internal abstract class JIndicator(
// Path object used for drawing shapes
private val path by lazy { Path() }

private var padding: Int = 0

/**
* Override the onDraw method to draw a colored shape in the center of the layout.
*
* This method is responsible for drawing the indicator shape on the canvas.
* It translates the canvas to account for padding and delegates the shape drawing
* to the [ShapeTypes.onDraw] method implemented by subclasses.
*
* @param canvas The canvas on which to draw the shape.
*/
override fun onDraw(canvas: Canvas) {
// Translate the canvas to handle padding
canvas.translate(padding.toFloat(), padding.toFloat())

// Draw the specified shape indicator with the given color
// Draw a colored circle in the center of the layout
shapeTypes.onDraw(width, height, paint, canvas, path)
// Adjust the width and height by subtracting padding
shapeTypes.onDraw(width - 2 * padding, height - 2 * padding, paint, canvas, path)
}

/**
Expand All @@ -52,5 +64,14 @@ internal abstract class JIndicator(
// Set the color of the paint object
paint.color = color
}
}

/**
* Set padding for the custom view.
*
* Padding is applied to create space around the indicator shape.
*
*/
fun addPadding() {
padding = 3
}
}
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdk = 17
targetSdk = 34
versionCode = 4
versionName = "4.3"
versionName = "4.4"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down

0 comments on commit cef5808

Please sign in to comment.