Skip to content

Commit

Permalink
Merge pull request #12 from SimformSolutionsPvtLtd/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
shwetachauhan-simform authored Mar 25, 2022
2 parents 6a003f7 + 0d3addb commit ccd8236
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 45 deletions.
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -56,23 +56,23 @@ 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'
}
```

* Use this code in xml file (Basic arc seekbar)

```kotlin
<com.ssarcseekbar.app.GaugeSeekBar
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" />
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
Expand All @@ -87,29 +87,29 @@ Different type of arc seekbar. Easy to use and configure your own seekbar using

```kotlin
<com.ssarcseekbar.app.GaugeSeekBar
android:id="@+id/progress"
...
app:startAngleDegrees="90"
app:thumbColor="@color/colorPrimary"
app:thumbDrawable="@drawable/custom_thumb"
app:trackGradient="@array/progressRainbow"
app:trackWidth="13dp" />
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
<com.ssarcseekbar.app.segmented.SegmentedArc
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" />
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
Expand All @@ -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)
}
Expand Down
11 changes: 7 additions & 4 deletions sampleapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.ssarcseekbar.app.segmented.SegmentedArc
android:id="@+id/animateSegmentedArc"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginTop="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:progress_primary_circle_size="20"
app:progress_primary_color="@color/color_progress"
app:progress_secondary_circle_size="15"
app:progress_secondary_color="@color/colorPrimaryDark"
app:start_offset="40" />

<TextView
android:id="@+id/animatedProgressText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/one"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="@id/animateSegmentedArc"
app:layout_constraintEnd_toEndOf="@id/animateSegmentedArc"
app:layout_constraintStart_toStartOf="@id/animateSegmentedArc"
app:layout_constraintTop_toTopOf="@id/animateSegmentedArc" />

<TextView
android:id="@+id/enterValueTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter progress Value"
android:layout_marginTop="10dp"
android:textStyle="bold"
app:layout_constraintHorizontal_bias="0.4"
app:layout_constraintTop_toBottomOf="@id/animateSegmentedArc"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<EditText
android:id="@+id/edtProgressValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="2"
app:layout_constraintStart_toEndOf="@id/enterValueTextView"
app:layout_constraintTop_toBottomOf="@id/animateSegmentedArc"/>

<Button
android:id="@+id/btnAnimate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:inputType="number"
android:text="@string/animate_progress"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/enterValueTextView"/>


</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions sampleapp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
<string name="animated_progress">Animated progress</string>
<string name="seekbar_with_section">Segmented seekbar</string>
<string name="custom_thumb">Custom Thumb</string>
<string name="animated_segmented_progress">Animated Segmented Progress</string>
<string name="animate_progress">Animate Progress</string>
<string name="enter_progress_value">Enter progress value</string>
<string name="one">1</string>
</resources>
6 changes: 3 additions & 3 deletions ssarcseekbar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ccd8236

Please sign in to comment.