Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

countdown timer with seekbar

public class MainActivity extends AppCompatActivity {
    private int seconds = 120; // two min
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        circularSeekbar = (SeekBar) findViewById(R.id.circularSeekbar);
        mTvTime = (TextView) findViewById(R.id.mTvTime);


        circularSeekbar.setMax(seconds);
        circularSeekbar.setProgress(seconds);
        circularSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if(fromUser) {
                  seconds = progress;
                }

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                startTimer(seconds * 1000);
            }
        });

        startTimer(seconds * 1000);
    }


    private void startTimer(final long milisecods) {
        if (countDownTimer != null) {
            countDownTimer.cancel();
        }
        countDownTimer = new CountDownTimer(milisecods, 500) {

            // 500 means, onTick function will be called at every 500
            // milliseconds

            @Override
            public void onTick(long leftTimeInMilliseconds) {

                int barVal = (int) leftTimeInMilliseconds / 1000;
                circularSeekbar.setProgress(barVal);
                mTvTime.setText(String.format("%02d:%02d",
                        TimeUnit.MILLISECONDS.toMinutes(leftTimeInMilliseconds),
                        TimeUnit.MILLISECONDS.toSeconds(leftTimeInMilliseconds) -
                                TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(leftTimeInMilliseconds))
                ));
            }

            @Override
            public void onFinish() {

            }
        }.start();

    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: split by asterisk java 
Java :: close current file android studio shortct 
Java :: java stream list order lambda 
Java :: thread dump 
Java :: longest subarray with equal 0 and 1 
Java :: destroy fragent after navigating 
Java :: bloomreach clone session 
Java :: java 8 lambda delete from list 
Java :: java try-with-resources nested streams 
Java :: assigning value with for each 
Java :: viewresolver in spring boot 
Java :: using addition to multiply in java 
Java :: configuration reader java 
Java :: unparseable date android 
Java :: java t point c# 
Java :: HOW TO CODE WORKING PLUGIN IN MINECRAFT 
Java :: java.lang.String cannot be cast to java.util.Map 
Java :: java Color on Enum call 
Java :: while(++i<5)f*=i;System.out.println(f); 
Java :: matrix program 
Java :: Java Throwing checked exception 
Java :: final java 
Java :: create and populate list one line java 
Java :: online java http request demo 
Java :: math ceil java 
Java :: java program to print hexadecimal to decimal number conversion 
Java :: get number value of an output to another script java 
Java :: HQL . getFirstResult() 
Java :: java lexographic 
Java :: java kommazahl abschneiden 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =