Skip to content

Commit

Permalink
[4.0] Fixed and Improved.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumman04 committed Nov 26, 2023
1 parent 6c67318 commit 3b9c71e
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 107 deletions.
Binary file removed J-Slider-debug.aar
Binary file not shown.
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 @@ -42,7 +42,7 @@ afterEvaluate {
register<MavenPublication>("release") {
groupId = "com.github.Jumman04"
artifactId = "Jummania-Slider"
version = "2.9(alpha)"
version = "4.0"

afterEvaluate {
from(components["release"])
Expand Down
188 changes: 107 additions & 81 deletions J-Slider/src/main/java/com/jummania/JSlider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.graphics.Color
import android.os.Handler
import android.os.Looper
import android.util.AttributeSet
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -139,100 +140,125 @@ class JSlider @JvmOverloads constructor(
private lateinit var listener: OnSlideChangeListener

init {
// Obtain styled attributes from XML
val typedArray: TypedArray = context.theme.obtainStyledAttributes(
attrs, R.styleable.JSlider, defStyleAttr, defStyleAttr
)

// Set sliding duration based on the attribute, default to 1555 milliseconds
setSlidingDuration(
typedArray.getInt(R.styleable.JSlider_slidingDuration, 1555).toLong()
)

// Set indicator size based on the attribute, default to 30 pixels
setIndicatorSize(
typedArray.getDimensionPixelSize(
R.styleable.JSlider_indicatorSize, 30
try {
// Obtain styled attributes from XML
val typedArray: TypedArray = context.theme.obtainStyledAttributes(
attrs, R.styleable.JSlider, defStyleAttr, defStyleAttr
)
)

// Set padding for the slider based on left, top, right, and bottom attributes
setSliderPadding(
typedArray.getDimensionPixelSize(R.styleable.JSlider_sliderPaddingLeft, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_sliderPaddingTop, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_sliderPaddingRight, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_sliderPaddingBottom, 0)
)
try {

// Enable or disable auto-sliding based on the attribute, default to true
enableAutoSliding(typedArray.getBoolean(R.styleable.JSlider_enableAutoSliding, true))
// Set sliding duration based on the attribute, default to 1555 milliseconds
setSlidingDuration(
typedArray.getInt(R.styleable.JSlider_slidingDuration, 1555).toLong()
)

// Enable or disable the indicator based on the attribute, default to true
enableIndicator(typedArray.getBoolean(R.styleable.JSlider_enableIndicator, true))
// Set indicator size based on the attribute, default to 30 pixels
setIndicatorSize(
typedArray.getDimensionPixelSize(
R.styleable.JSlider_indicatorSize, 30
)
)

// Set indicator colors based on the attributes, default to semi-transparent white and white
setIndicatorColor(
typedArray.getColor(
R.styleable.JSlider_defaultIndicatorColor, Color.parseColor("#90ffffff")
), typedArray.getColor(R.styleable.JSlider_selectedIndicatorColor, Color.WHITE)
)
// Set padding for the slider based on left, top, right, and bottom attributes
setSliderPadding(
typedArray.getDimensionPixelSize(R.styleable.JSlider_sliderPaddingLeft, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_sliderPaddingTop, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_sliderPaddingRight, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_sliderPaddingBottom, 0)
)

// Set padding for the indicator based on left, top, right, and bottom attributes
setIndicatorPadding(
typedArray.getDimensionPixelSize(R.styleable.JSlider_indicatorPaddingLeft, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_indicatorPaddingTop, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_indicatorPaddingRight, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_indicatorPaddingBottom, 55)
)
// Enable or disable auto-sliding based on the attribute, default to true
enableAutoSliding(
typedArray.getBoolean(
R.styleable.JSlider_enableAutoSliding, true
)
)

// Set horizontal margin for the indicator dots, default to 6 pixels
setIndicatorMarginHorizontal(
typedArray.getDimensionPixelSize(
R.styleable.JSlider_indicatorMarginHorizontal, 6
)
)
// Enable or disable the indicator based on the attribute, default to true
enableIndicator(typedArray.getBoolean(R.styleable.JSlider_enableIndicator, true))

// Set slide animation based on the specified attribute
setSlideAnimation(
AnimationTypes.values()[typedArray.getInt(
R.styleable.JSlider_slideAnimation, AnimationTypes.DEFAULT.ordinal
)]
)
// Set indicator colors based on the attributes, default to semi-transparent white and white
setIndicatorColor(
typedArray.getColor(
R.styleable.JSlider_defaultIndicatorColor, Color.parseColor("#90ffffff")
), typedArray.getColor(R.styleable.JSlider_selectedIndicatorColor, Color.WHITE)
)

// Set indicator alignment based on the specified attribute
setIndicatorAlignment(
Alignment.values()[typedArray.getInt(
R.styleable.JSlider_indicatorAlignment, Alignment.BOTTOM.ordinal
)]
)
// Set indicator gravity based on the specified attribute
setIndicatorGravity(typedArray.getInt(R.styleable.JSlider_indicatorGravity, Gravity.CENTER))

// Set indicator update mode based on the specified attribute
setIndicatorUpdateTypes(
UpdateTypes.values()[typedArray.getInt(
R.styleable.JSlider_indicatorUpdateMode, UpdateTypes.SYNC.ordinal
)]
)
// Set padding for the indicator based on left, top, right, and bottom attributes
setIndicatorPadding(
typedArray.getDimensionPixelSize(R.styleable.JSlider_indicatorPaddingLeft, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_indicatorPaddingTop, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_indicatorPaddingRight, 0),
typedArray.getDimensionPixelSize(R.styleable.JSlider_indicatorPaddingBottom, 55)
)

// Setting the indicator shape type for a JSlider.
// This assumes that there is an enum called ShapeTypes defined
// in the JSlider class or its associated class, which represents the available shape types.

// Obtain a reference to the ShapeTypes enum and set the selected shape type based on the attributes
// specified in the XML layout using the R.styleable.JSlider_indicatorShapeTypes attribute.
// If the attribute is not defined, default to ShapeTypes.CIRCLE.
setIndicatorShapeTypes(
ShapeTypes.values()[typedArray.getInt(
R.styleable.JSlider_indicatorShapeTypes, ShapeTypes.CIRCLE.ordinal
)]
)
// Set horizontal margin for the indicator dots, default to 6 pixels
setIndicatorMarginHorizontal(
typedArray.getDimensionPixelSize(
R.styleable.JSlider_indicatorMarginHorizontal, 6
)
)

// Set slide animation based on the specified attribute
setSlideAnimation(
AnimationTypes.values()[typedArray.getInt(
R.styleable.JSlider_slideAnimation, AnimationTypes.DEFAULT.ordinal
)]
)

// Set indicator alignment based on the specified attribute
setIndicatorAlignment(
Alignment.values()[typedArray.getInt(
R.styleable.JSlider_indicatorAlignment, Alignment.BOTTOM.ordinal
)]
)
// Set indicator gravity based on the specified attribute
setIndicatorGravity(
typedArray.getInt(
R.styleable.JSlider_indicatorGravity, Gravity.CENTER
)
)

// Set indicator update mode based on the specified attribute
setIndicatorUpdateTypes(
UpdateTypes.values()[typedArray.getInt(
R.styleable.JSlider_indicatorUpdateMode, UpdateTypes.SYNC.ordinal
)]
)

// Setting the indicator shape type for a JSlider.
// This assumes that there is an enum called ShapeTypes defined
// in the JSlider class or its associated class, which represents the available shape types.

// Obtain a reference to the ShapeTypes enum and set the selected shape type based on the attributes
// specified in the XML layout using the R.styleable.JSlider_indicatorShapeTypes attribute.
// If the attribute is not defined, default to ShapeTypes.CIRCLE.
setIndicatorShapeTypes(
ShapeTypes.values()[typedArray.getInt(
R.styleable.JSlider_indicatorShapeTypes, ShapeTypes.CIRCLE.ordinal
)]
)

} finally {
// Recycle the TypedArray to avoid memory leaks
typedArray.recycle()
}

// Add the slider and indicator layout to the view
addView(jSlider)
addView(dotIndicatorLayout)
addView(selectedIndicatorLayout)

} catch (e: Resources.NotFoundException) {
Log.e("JSlider Initialization", "Resource not found: ${e.message}")
e.printStackTrace()
} catch (e: Exception) {
Log.e("JSlider Initialization", "An unexpected error occurred: ${e.message}")
e.printStackTrace()
}

// Add the slider and indicator layout to the view
addView(jSlider)
addView(dotIndicatorLayout)
addView(selectedIndicatorLayout)
}


Expand Down
3 changes: 1 addition & 2 deletions J-Slider/src/main/java/com/jummania/types/AnimationTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ import com.jummania.animations.ZoomOut
*/
enum class AnimationTypes(
internal val reverse: Boolean = false,
internal val onGetAnim: (ViewPager) -> PageTransformer?
) {
internal val onGetAnim: (ViewPager) -> PageTransformer?) {
ANTI_CLOCK_SPIN(false, { AntiClockSpin() }),
BACKGROUND_TO_FOREGROUND(false, { BackgroundToForeground() }),
CARD_STACK(false, { CardStack() }),
Expand Down
6 changes: 3 additions & 3 deletions J-Slider/src/main/java/com/jummania/widgets/Slider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ internal abstract class Slider(context: Context) : ViewPager(context) {
widthMeasureSpec,
MeasureSpec.makeMeasureSpec(child.measuredHeight, MeasureSpec.EXACTLY)
)
} else {
// If the height mode is EXACTLY or unspecified, use the original onMeasure
} else
// If the height mode is EXACTLY or unspecified, use the original onMeasure
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
}

}
}
9 changes: 3 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId = "com.jummania.jummaniaslider"
minSdk = 17
targetSdk = 34
versionCode = 3
versionName = "2.9(alpha)"
versionCode = 4
versionName = "4.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -21,8 +21,7 @@ android {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
)
}
}
Expand All @@ -42,7 +41,5 @@ dependencies {
implementation("com.google.android.material:material:1.10.0")
implementation(project(":J-Slider"))

implementation("com.squareup.picasso:picasso:2.8")

//./gradlew assembleRelease
}
12 changes: 5 additions & 7 deletions app/src/main/java/com/jummania/jummaniaslider/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.jummania.JSlider
import com.squareup.picasso.Picasso

class MainActivity : AppCompatActivity() {

Expand Down Expand Up @@ -122,21 +119,22 @@ class MainActivity : AppCompatActivity() {

override fun onSliderCreate(view: View, position: Int) {

/*
val textView: TextView = view.findViewById(R.id.text_view) //find your child
val imageView: ImageView = view.findViewById(R.id.image_view)

Picasso.get()
.load("https://jummania.com/App/BanglaNatokSamahar/Images/Cover%20Photo.jpg")
.error(R.drawable.default_error).placeholder(R.drawable.default_loading)
.into(imageView)
textView.text = getString(R.string.Developer_Name)
textView.text = getString(R.string.Developer_Name)
view.setOnClickListener {
*/

view.setOnClickListener {
Toast.makeText(
this@MainActivity,
getString(R.string.Developer_Name) + "\nItem Position: $position",
"Developer Name: ${getString(R.string.Developer_Name)}\nItem Position: $position",
Toast.LENGTH_SHORT
).show()
}
Expand Down
Binary file added app/src/main/res/drawable/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion app/src/main/res/layout/item_slider2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="180dp"
android:scaleType="centerCrop" />
android:scaleType="centerCrop"
android:src="@drawable/img" />

<TextView
android:id="@+id/text_view"
Expand All @@ -27,6 +28,7 @@
android:paddingTop="6dp"
android:paddingBottom="44dp"
android:singleLine="true"
android:text="@string/Developer_Name"
android:textSize="18sp"
android:textStyle="bold" />

Expand Down
4 changes: 2 additions & 2 deletions jitpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ jdk:
before_install:
- ./scripts/prepareJitpackEnvironment.sh
install:
- FILE="-Dfile=J-Slider-debug.aar"
- mvn install:install-file $FILE -DgroupId=com.github.Jumman04 -DartifactId=Jummania-Slider -Dversion=2.9(alpha) -Dpackaging=aar -DgeneratePom=true
- FILE="-Dfile=J-Slider-release.aar"
- mvn install:install-file $FILE -DgroupId=com.github.Jumman04 -DartifactId=Jummania-Slider -Dversion=4.0 -Dpackaging=aar -DgeneratePom=true
11 changes: 7 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.Jumman04</groupId>
<artifactId>Jummania-Slider</artifactId>
<version>2.9(alpha)</version>
<version>4.0</version>
<packaging>pom</packaging>
<description>Empower Your UI with Seamless Slides: Introducing JSlider, the Universal Slider Library</description>
<description>Empower Your UI with Seamless Slides: Introducing JSlider, the Universal Slider
Library
</description>
</project>

0 comments on commit 3b9c71e

Please sign in to comment.