-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from SimformSolutionsPvtLtd/develop
Develop
- Loading branch information
Showing
8 changed files
with
186 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
sampleapp/src/main/java/com/ssarcseekbar/presentation/FragmentAnimatedSegmentedProgress.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
sampleapp/src/main/res/layout/fragment_animated_segmented_progress.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters