diff --git a/README.md b/README.md
index ba30d42..16fff9b 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# 🌈 SSArcSeekBar
#### Choose your way to flaunt the progress.
[](https://developer.android.com/studio/)
-[](https://jitpack.io/#SimformSolutionsPvtLtd/SSArcSeekBar)
+[](https://jitpack.io/#SimformSolutionsPvtLtd/SSArcSeekBar)

[](https://kotlinlang.org)
[](https://android-arsenal.com/api?level=21)
@@ -56,7 +56,7 @@ Different type of arc seekbar. Easy to use and configure your own seekbar using
```groovy
dependencies {
- implementation 'com.github.SimformSolutionsPvtLtd:SSArcSeekBar:1.0.0'
+ implementation 'com.github.SimformSolutionsPvtLtd:SSArcSeekBar:1.0.2'
}
```
@@ -64,15 +64,15 @@ Different type of arc seekbar. Easy to use and configure your own seekbar using
```kotlin
+ android:id="@+id/progress"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ app:layout_constraintDimensionRatio="1"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:thumbRadius="18dp"
+ app:trackWidth="18dp" />
```
* Now get the progress
@@ -87,29 +87,29 @@ Different type of arc seekbar. Easy to use and configure your own seekbar using
```kotlin
+ android:id="@+id/progress"
+ ...
+ app:startAngleDegrees="90"
+ app:thumbColor="@color/colorPrimary"
+ app:thumbDrawable="@drawable/custom_thumb"
+ app:trackGradient="@array/progressRainbow"
+ app:trackWidth="13dp" />
```
* Segmented arc seekbar
```kotlin
+ android:id="@+id/segmentedArc"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:max="40"
+ app:progress_primary_circle_size="20"
+ app:progress_primary_color="@color/color_progress"
+ app:progress_radius="380"
+ app:progress_secondary_circle_size="15"
+ app:progress_secondary_color="@color/colorPrimaryDark"
+ app:start_offset="40" />
```
* Add animation for the progress, show animation when it is first time loaded on screen
@@ -126,7 +126,7 @@ Different type of arc seekbar. Easy to use and configure your own seekbar using
}
// Add delay before starting the animation
- GlobalScope.launch(Dispatchers.Main) {
+ lifecycleScope.launch(Dispatchers.Main) {
delay(1000)
valueAnimator(view.segmentedArcSeekbar.getMax(), oldProgressValue)
}
diff --git a/sampleapp/build.gradle b/sampleapp/build.gradle
index 2386d66..b1b9088 100755
--- a/sampleapp/build.gradle
+++ b/sampleapp/build.gradle
@@ -9,11 +9,11 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
- compileSdkVersion 31
+ compileSdkVersion 32
defaultConfig {
applicationId "com.tenclouds.gaugeprogressbar"
minSdkVersion 21
- targetSdkVersion 31
+ targetSdkVersion 32
versionCode 1
versionName "1.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
@@ -29,10 +29,13 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
- implementation 'androidx.appcompat:appcompat:1.4.0'
- implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
+ implementation 'androidx.appcompat:appcompat:1.4.1'
+ implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
+ implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation project(':ssarcseekbar')
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"
+ implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.1"
}
diff --git a/sampleapp/src/main/java/com/ssarcseekbar/presentation/FragmentAnimatedSegmentedProgress.kt b/sampleapp/src/main/java/com/ssarcseekbar/presentation/FragmentAnimatedSegmentedProgress.kt
new file mode 100644
index 0000000..a5efefc
--- /dev/null
+++ b/sampleapp/src/main/java/com/ssarcseekbar/presentation/FragmentAnimatedSegmentedProgress.kt
@@ -0,0 +1,69 @@
+package com.ssarcseekbar.presentation
+
+import android.animation.ValueAnimator
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.Toast
+import androidx.lifecycle.lifecycleScope
+import com.ssarcseekbar.app.segmented.SegmentedArc
+import kotlinx.android.synthetic.main.fragment_animated_segmented_progress.animatedProgressText
+import kotlinx.android.synthetic.main.fragment_animated_segmented_progress.view.animateSegmentedArc
+import kotlinx.android.synthetic.main.fragment_animated_segmented_progress.view.btnAnimate
+import kotlinx.android.synthetic.main.fragment_animated_segmented_progress.view.edtProgressValue
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
+
+class FragmentAnimatedSegmentedProgress : Fragment() {
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ val view = inflater.inflate(R.layout.fragment_animated_segmented_progress, container, false)
+ var oldProgress = 1
+
+ // Animate progress when it is first time visible on screen
+ animateProgress(oldProgress, view.animateSegmentedArc.getMax())
+ lifecycleScope.launch(Dispatchers.Main) {
+ delay(1000)
+ animateProgress(view.animateSegmentedArc.getMax(), oldProgress)
+ }
+
+ view.btnAnimate.setOnClickListener {
+ oldProgress = view.animateSegmentedArc.getSegmentedProgress()
+ val newProgress: Int
+ if (view.edtProgressValue.text?.isNotEmpty() == true) {
+ newProgress = view.edtProgressValue.text.toString().toInt()
+ if (newProgress > 0 && newProgress <= view.animateSegmentedArc.getMax()) {
+ animateProgress(oldProgress, newProgress)
+ } else {
+ Toast.makeText(requireContext(), "Please enter value in range 1 to ${view.animateSegmentedArc.getMax()}", Toast.LENGTH_SHORT).show()
+ }
+ } else {
+ Toast.makeText(requireContext(), "Please enter value", Toast.LENGTH_SHORT).show()
+ }
+ }
+
+ view.animateSegmentedArc.setOnProgressChangedListener(object : SegmentedArc.onProgressChangedListener {
+ override fun onProgressChanged(progress: Int) {
+ if (progress > 0 && progress <= view.animateSegmentedArc.getMax()) {
+ animatedProgressText.text = progress.toString()
+ }
+ }
+ })
+ return view
+ }
+
+ private fun animateProgress(oldProgress: Int, newProgress: Int) {
+ val valueAnimator = ValueAnimator.ofInt(oldProgress, newProgress)
+ valueAnimator.duration = 1000
+ valueAnimator.addUpdateListener {
+ view?.animateSegmentedArc?.setSegmentedProgress(it.animatedValue as Int)
+ }
+ valueAnimator.start()
+ }
+}
\ No newline at end of file
diff --git a/sampleapp/src/main/java/com/ssarcseekbar/presentation/MainActivity.kt b/sampleapp/src/main/java/com/ssarcseekbar/presentation/MainActivity.kt
index eaf9e40..983902f 100755
--- a/sampleapp/src/main/java/com/ssarcseekbar/presentation/MainActivity.kt
+++ b/sampleapp/src/main/java/com/ssarcseekbar/presentation/MainActivity.kt
@@ -42,7 +42,7 @@ class MainActivity : AppCompatActivity() {
supportFragmentManager.beginTransaction().replace(R.id.content_frame, FragmentUnstyledSeekbar()).commit()
navigationAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1)
- navigationAdapter.addAll(getString(R.string.unstyled_seekbar), getString(R.string.animated_progress), getString(R.string.custom_thumb), getString(R.string.seekbar_with_section))
+ navigationAdapter.addAll(getString(R.string.unstyled_seekbar), getString(R.string.animated_progress), getString(R.string.custom_thumb), getString(R.string.seekbar_with_section), getString(R.string.animated_segmented_progress))
navigationDrawer.apply {
adapter = navigationAdapter
@@ -52,6 +52,7 @@ class MainActivity : AppCompatActivity() {
1 -> supportFragmentManager.beginTransaction().replace(R.id.content_frame, FragmentAnimatedProgress()).commit()
2 -> supportFragmentManager.beginTransaction().replace(R.id.content_frame, FragmentCustomThumb()).commit()
3 -> supportFragmentManager.beginTransaction().replace(R.id.content_frame, FragmentSeekbarWithSection()).commit()
+ 4 -> supportFragmentManager.beginTransaction().replace(R.id.content_frame, FragmentAnimatedSegmentedProgress()).commit()
}
drawerLayout.closeDrawers()
}
diff --git a/sampleapp/src/main/res/layout/fragment_animated_segmented_progress.xml b/sampleapp/src/main/res/layout/fragment_animated_segmented_progress.xml
new file mode 100644
index 0000000..7ab91ce
--- /dev/null
+++ b/sampleapp/src/main/res/layout/fragment_animated_segmented_progress.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sampleapp/src/main/res/values/strings.xml b/sampleapp/src/main/res/values/strings.xml
index 4403c63..99ded55 100755
--- a/sampleapp/src/main/res/values/strings.xml
+++ b/sampleapp/src/main/res/values/strings.xml
@@ -7,5 +7,8 @@
Animated progress
Segmented seekbar
Custom Thumb
+ Animated Segmented Progress
+ Animate Progress
+ Enter progress value
1
diff --git a/ssarcseekbar/build.gradle b/ssarcseekbar/build.gradle
index ec9429a..4b1340e 100755
--- a/ssarcseekbar/build.gradle
+++ b/ssarcseekbar/build.gradle
@@ -6,10 +6,10 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
- compileSdkVersion 31
+ compileSdkVersion 32
defaultConfig {
minSdkVersion 21
- targetSdkVersion 31
+ targetSdkVersion 32
versionCode 1
versionName "1.0"
@@ -28,7 +28,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
- implementation 'androidx.appcompat:appcompat:1.4.0'
+ implementation 'androidx.appcompat:appcompat:1.4.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
diff --git a/ssarcseekbar/src/main/java/com/ssarcseekbar/app/segmented/SegmentedArc.kt b/ssarcseekbar/src/main/java/com/ssarcseekbar/app/segmented/SegmentedArc.kt
index 337e661..c656c6f 100644
--- a/ssarcseekbar/src/main/java/com/ssarcseekbar/app/segmented/SegmentedArc.kt
+++ b/ssarcseekbar/src/main/java/com/ssarcseekbar/app/segmented/SegmentedArc.kt
@@ -90,7 +90,7 @@ class SegmentedArc : View {
private fun initXMLAttrs(context: Context, attrs: AttributeSet?) {
val a = context.obtainStyledAttributes(attrs, R.styleable.SegmentedArc)
- progress = a.getInt(R.styleable.SegmentedArc_start_progress, 1)
+ setSegmentedProgress(a.getInt(R.styleable.SegmentedArc_start_progress, 1))
setProgressPrimaryColor(
a.getColor(
R.styleable.SegmentedArc_progress_primary_color,
@@ -131,7 +131,6 @@ class SegmentedArc : View {
setStartOffset(a.getInt(R.styleable.SegmentedArc_start_offset, 30))
setMax(a.getInt(R.styleable.SegmentedArc_max, 25))
setMin(a.getInt(R.styleable.SegmentedArc_min, 1))
- deg = (min + 2).toFloat()
setProgressRadius(a.getFloat(R.styleable.SegmentedArc_progress_radius, -1f))
a.recycle()
}
@@ -297,12 +296,14 @@ class SegmentedArc : View {
return super.dispatchTouchEvent(event)
}
- var progress: Int
- get() = (deg - 2).toInt()
- set(x) {
- deg = (x + 2).toFloat()
- invalidate()
- }
+ fun getSegmentedProgress(): Int {
+ return (deg - 2).toInt()
+ }
+
+ fun setSegmentedProgress(progress: Int) {
+ deg = (progress + 2).toFloat()
+ invalidate()
+ }
fun getProgressPrimaryColor(): Int {
return progressPrimaryColor