Skip to content

Commit

Permalink
+ int getColor(int progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtugeek committed Oct 25, 2023
1 parent 3630720 commit c3837ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
Expand Up @@ -2,19 +2,17 @@ package com.rtugeek.android.colorseekbardemo.fragment

import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.SeekBar
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.rtugeek.android.colorseekbar.thumb.DefaultThumbDrawer
import com.rtugeek.android.colorseekbardemo.Utils
import com.rtugeek.android.colorseekbardemo.databinding.FragmentColorSeekBarBinding
import kotlinx.android.synthetic.main.fragment_color_seek_bar.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
* A placeholder fragment containing a simple view.
Expand Down Expand Up @@ -62,7 +60,6 @@ class ColorSeekBarFragment : Fragment() {
override fun onStopTrackingTouch(seekBar: SeekBar) {}
})


seek_thumb_size.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
val thumbDrawer = DefaultThumbDrawer(
Expand Down
Expand Up @@ -11,11 +11,9 @@
import android.graphics.RectF;
import android.graphics.Shader;
import android.os.Build;
import android.os.Parcelable;
import android.util.AttributeSet;

import androidx.annotation.ArrayRes;
import androidx.annotation.Nullable;

import com.rtugeek.android.colorseekbar.thumb.DefaultThumbDrawer;

Expand Down Expand Up @@ -73,7 +71,6 @@ public ColorSeekBar(Context context, AttributeSet attrs, int defStyleAttr, int d
applyStyle(context, attrs, defStyleAttr, defStyleRes);
}


private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
mContext = context;
//get attributes
Expand Down Expand Up @@ -231,10 +228,11 @@ protected void onDraw(Canvas canvas) {
}

/**
* get color by progress value
* @param progress
* @return color
* @return return Integer.MAX_VALUE if progress out of bounds
*/
private int pickColor(int progress) {
public int getColor(int progress) {
if (progress < 0) return Integer.MAX_VALUE;
if (progress > maxProgress) return Integer.MAX_VALUE;
if (progress >= getColors().size()) return Integer.MAX_VALUE;
Expand Down Expand Up @@ -264,7 +262,7 @@ private int pickColorFromBitmap(Bitmap bitmap, float percent) {
* @return
*/
public int getColor() {
return pickColor(progress);
return getColor(progress);
}


Expand Down

0 comments on commit c3837ad

Please sign in to comment.