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. [![Android-Studio](https://img.shields.io/badge/Android%20Studio-ArcticFox-orange.svg?style=flat)](https://developer.android.com/studio/) -[![](https://jitpack.io/v/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton.svg)](https://jitpack.io/#SimformSolutionsPvtLtd/SSArcSeekBar) +[![](https://jitpack.io/v/SimformSolutionsPvtLtd/SSArcSeekBar.svg)](https://jitpack.io/#SimformSolutionsPvtLtd/SSArcSeekBar) ![Language](https://img.shields.io/badge/language-Kotlin-orange.svg) [![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.6.10-blue.svg)](https://kotlinlang.org) [![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](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 @@ + + + + + + + + + + + +