Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom color to individual segmented colors and progress #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/src/main/java/com/carlosmuvi/sample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.carlosmuvi.sample;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Expand Down Expand Up @@ -69,6 +70,15 @@ private void initSegmentedProgressBar() {
//set filled segments directly
segmentedProgressBar.setCompletedSegments(1);

segmentedProgressBar.setSegmentCount(10);

segmentedProgressBar.setProgress(55);
segmentedProgressBar.setFillColor(Color.parseColor("#F56200"),0);
segmentedProgressBar.setFillColor(Color.parseColor("#F56200"),1);
segmentedProgressBar.setFillColor(Color.parseColor("#F5C300"),2);
segmentedProgressBar.setFillColor(Color.parseColor("#F5C300"),3);
segmentedProgressBar.setFillColor(Color.parseColor("#8AF400"),4);

segmentedProgressBar.setCompletedSegmentListener(new CompletedSegmentListener() {
@Override
public void onSegmentCompleted(int segmentCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@ package com.carlosmuvi.segmentedprogressbar
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.util.Log
import java.math.BigDecimal

class PropertiesModel(context: Context, attrs: AttributeSet?) {
class PropertiesModel(context: Context, attrs: AttributeSet?)
{

var segmentCount: Int = DEFAULT_SEGMENT_COUNT
var containerColor: Int = Color.LTGRAY
var fillColor: Int = Color.BLUE
var segmentGapWidth: Int = context.dp(DEFAULT_SEGMENT_GAP_DP)
var cornerRadius: Int = context.dp(DEFAULT_CORNER_RADIUS_DP)
var progressValuePerContainer: Int = 50;
var progressFilledContainers: BigDecimal = BigDecimal("0.0")
var progressValue: Float = 0f
var segmentedContainerColors: HashMap<Int, Int> = HashMap<Int, Int>()
init
{


if (attrs != null)
{


init {
if (attrs != null) {
val styledAttrs =
context.theme.obtainStyledAttributes(attrs, R.styleable.SegmentedProgressBar, 0, 0)
segmentCount =
Expand All @@ -26,10 +38,29 @@ class PropertiesModel(context: Context, attrs: AttributeSet?) {
styledAttrs.getDimensionPixelSize(R.styleable.SegmentedProgressBar_gap_size, segmentGapWidth)
cornerRadius =
styledAttrs.getDimensionPixelSize(R.styleable.SegmentedProgressBar_corner_radius, cornerRadius)
val totalProgress: Int = styledAttrs.getInt(R.styleable.SegmentedProgressBar_total_progress, 100)


progressValue = styledAttrs.getFloat(R.styleable.SegmentedProgressBar_progress, 0f)

calculateContainerValue(totalProgress)


}

}

fun calculateContainerValue(totalProgress: Int = 100)
{

progressValuePerContainer = totalProgress / segmentCount;

if (progressValue != 0f)
progressFilledContainers = BigDecimal((progressValue / progressValuePerContainer).toString())
}

companion object {
companion object
{
const val DEFAULT_SEGMENT_COUNT = 5
const val DEFAULT_CORNER_RADIUS_DP = 6
const val DEFAULT_SEGMENT_GAP_DP = 1
Expand Down
Loading