Skip to main content

Android Customized-FloatSeekBar

A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.

SeekBar support only int values for progress:
void setMax(int max) Set the upper range of the progress bar max.
void setMin(int min) Set the lower range of the progress bar to min.
void setProgress(int progress) Sets the current progress to the specified value.
int getMax() Return the upper limit of this progress bar's range.
int getMin() Return the lower limit of this progress bar's range.
int getProgress() Get the progress bar's current level of progress.

In some scenario we would need floating point seekbar progress, which is not supported by default in android.

Here the floating seekbar which supports floating point value:

You can download the full sample and library from https://github.com/yuvaraj119/Customized-FloatSeekBar 

In layout:

<com.yuvaraj.floatseekbar.FloatSeekBar
        android:id="@+id/seekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" /> 

In Activity:

        
        FloatSeekBar seekBar= (FloatSeekBar) findViewById(R.id.seekBar);

        ImageButton add = (ImageButton) findViewById(R.id.add);
        add.setOnClickListener(this);
        ImageButton minus = (ImageButton) findViewById(R.id.minus);
        minus.setOnClickListener(this);
        TextView textView=(TextView) findViewById(R.id.textView);

        seekBar.setMaxFloat(10000.0f);
        seekBar.setMinFloat(0.50f);
        seekBar.setValue(5.0f);
        seekBar.setSeekValueFloat(5.0f);
        
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBars,
                              int progress, boolean fromUser) {
                if (clicked == 1) {//add
                    clicked = 0;
                } else if (clicked == 2) {//minus
                    clicked = 0;
                } else {
                    seekBar.setSeekValueFloat(seekBar.getValue());
                    clicked = 0;
                }
                textView.setText("" + seekBar.getSeekValueFloat());
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        
    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
        case R.id.add:
                clicked = 1;
                if (seekBar.getSeekValueFloat() < seekBar.getMaxFloat()) {
                    seekBar.setPlus(seekBar1.getSeekValueFloat());
                    textView.setText("" + seekBar.getSeekValueFloat());
                }
                break;
            case R.id.minus:
                clicked = 2;
                if (seekBar.getSeekValueFloat() > seekBar.getMinFloat()) {
                    seekBar.setMinus(seekBar.getSeekValueFloat());
                    textView.setText("" + seekBar.getSeekValueFloat());
                }
                break;
        }
    }

Comments

Popular posts from this blog

Vertical AutoScrolling TextView in Android

In android by default we can scroll the text in horizontal using marquee in layout, but if we want to scroll the text in vertical its not possible by default. So here we will learn to create a custom TextView which will auto-scroll in vertical direction. Source Code:  VerticalScrollingTextView-Android Create a AutoScrollingTextView.class which extends TextView: @SuppressLint ( "AppCompatCustomView" ) public class AutoScrollingTextView extends TextView { private static final float DEFAULT_SPEED = 65.0f ; public Scroller scroller ; public float speed = DEFAULT_SPEED ; public boolean continuousScrolling = true; public AutoScrollingTextView (Context context) { super (context) ; init( null, 0 ) ; scrollerInstance(context) ; } public AutoScrollingTextView (Context context , AttributeSet attrs) { super (context , attrs) ; init(attrs , 0 ) ; scr...

Flexbox inside the RecyclerView as a LayoutManager (FlexboxLayoutManager).

Currently google has release the Flexbox which can be used for building flexible layouts using FlexboxLayout, it can be interpreted as an advanced LinearLayout because both layouts align their child views sequentially. For more detail on this flexbox-layout But here we are gonna work on Flexbox with RecyclerView. Flexbox with a large number of items in a scrollable container! Let's first see what are the Supported attributes / features comparison Due to some characteristics of the RecyclerView, some Flexbox attributes are not available/not implemented to the FlexboxLayoutManager. Here is a quick overview of the attributes/features comparison between the two containers. Attribute / Feature FlexboxLayout                FlexboxLayoutManager (RecyclerView) flexDirection flexWrap (except wrap_reverse ) justifyContent alignItems alignContent - layout_order - layout_fle...

Support in-app updates

Keeping your app up-to-date on your users’ devices enables them to try new features, as well as benefit from performance improvements and bug fixes. Although some users enable background updates when their device is connected to an unmetered connection, other users may need to be reminded to update. In-app updates is a Play Core library feature that introduces a new request flow to prompt active users to update your app. Add this in dependencies{ implementation ' com.google.android.play:core: 1.6 . 4 ' } In-app updates work only with devices running Android 5.0 (API level 21) or higher, and requires you to use Play Core library 1.5.0 or higher. After meeting these requirements, your app can support the following UX for in-app updates: Flexible Immediate   Flexible A user experience that provides background download and installation with graceful state monitoring. This UX is appropriate when it’s acceptable for the user to use the app while downloading t...