countdown timer with seekbar
Java
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();
}
}
Also in Java:
- Title
- java fx display simple rectangle
- Category
- Java
- Title
- waht does&& mean in java
- Category
- Java
- Title
- string to arraylist convert java
- Category
- Java
- Title
- create java windows application
- Category
- Java
- Title
- how to use spring in java
- Category
- Java
- Title
- properties java 8 maven in pom xml
- Category
- Java
- Title
- change number into array in java
- Category
- Java
- Title
- java script zip function
- Category
- Java
- Title
- java main method
- Category
- Java
- Title
- java how to initialize an array
- Category
- Java
- Title
- java read file from command line argument
- Category
- Java
- Title
- how to fill a 2d array in java
- Category
- Java
- Title
- java calendar add minutes
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- print values of bst java
- Category
- Java
- Title
- how to add to a file in java
- Category
- Java
- Title
- java max
- Category
- Java
- Title
- primitive and non primitive data types in java
- Category
- Java
- Title
- print in java
- Category
- Java
- Title
- java 8 seconds to days
- Category
- Java
- Title
- java array copy
- Category
- Java
- Title
- shortcut to find a class in java project eclipse
- Category
- Java
- Title
- java animated gif example
- Category
- Java
- Title
- how to exit a for loop in java
- Category
- Java
- Title
- java pass arraylist by value
- Category
- Java
- Title
- java http client eviction
- Category
- Java
- Title
- android get distance between two locations kotlin
- Category
- Java
- Title
- java count substring occurrences in string
- Category
- Java
- Title
- java split string
- Category
- Java
- Title
- add element to stack java
- Category
- Java
- Title
- raise number to power java
- Category
- Java
- Title
- Java.awt graphics tutorial
- Category
- Java
- Title
- how to separate no and text in java
- Category
- Java
- Title
- java concatenate arrays
- Category
- Java
- Title
- how to get the dimensions of a 2d array in java
- Category
- Java
- Title
- how to reverse a list in java
- Category
- Java
- Title
- parseints(str) java
- Category
- Java
- Title
- calculate days between two dates in java
- Category
- Java
- Title
- java mockito any string import
- Category
- Java
- Title
- compare list from db and list from request
- Category
- Java
- Title
- java remove duplicates
- Category
- Java
- Title
- java last element in array
- Category
- Java
- Title
- how to make array of objects in java and use it
- Category
- Java
- Title
- how to check the end of a string java
- Category
- Java
- Title
- create color object java
- Category
- Java
- Title
- @fortawesome/free-solid-svg-icons
- Category
- Java
- Title
- exponents java
- Category
- Java
- Title
- jframe border
- Category
- Java
- Title
- setting up javafx in eclipse
- Category
- Java
- Title
- java replace element in list
- Category
- Java
- Title
- processing sound library
- Category
- Java
- Title
- how to return the lower of two values in one line java
- Category
- Java
- Title
- processing sound android
- Category
- Java
- Title
- JavaFX mouse over effe
- Category
- Java
- Title
- java code to get all leaf nodes of a xml file
- Category
- Java
- Title
- Diamond Shape Pattern Program in Java
- Category
- Java
- Title
- how to create a hashmap in java
- Category
- Java
- Title
- how to create a linked list in java
- Category
- Java
- Title
- check if a string is a substring of another string java
- Category
- Java
- Title
- dataframe to dict without index
- Category
- Java
- Title
- how to import a scanner in java
- Category
- Java
- Title
- partial view tiles spring
- Category
- Java
- Title
- Enums injava
- Category
- Java
- Title
- How to make a class in Java?
- Category
- Java
- Title
- foreach java
- Category
- Java
- Title
- javafx datepicker
- Category
- Java
- Title
- run java classpath command line
- Category
- Java
- Title
- set java
- Category
- Java
- Title
- how to check if rs next is null
- Category
- Java
- Title
- android how to split string
- Category
- Java
- Title
- java djikstra's algorithm
- Category
- Java
- Title
- check if optional is empty java
- Category
- Java
- Title
- how to find substring in java
- Category
- Java
- Title
- java array to list
- Category
- Java
- Title
- number to char java
- Category
- Java
- Title
- read a mail and its content in java mail api
- Category
- Java
- Title
- login and logout react native and firebase
- Category
- Java
- Title
- java string to int
- Category
- Java
- Title
- cosinus-1 java
- Category
- Java
- Title
- convert string to array java
- Category
- Java
- Title
- override java
- Category
- Java
- Title
- android bottom navigation hiding views
- Category
- Java
- Title
- append to arraylist by index java
- Category
- Java
- Title
- how to append to a string in java
- Category
- Java
- Title
- java function without return
- Category
- Java
- Title
- convert string to mayus java
- Category
- Java
- Title
- arraylist with values java
- Category
- Java
- Title
- java create txt file
- Category
- Java
- Title
- leap year checker java
- Category
- Java
- Title
- how to copy all files and subdirectories in directory in java
- Category
- Java
- Title
- print a letter in java
- Category
- Java
- Title
- how to end a program in an if statement java
- Category
- Java
- Title
- how to write a perfect shuffle method in java
- Category
- Java
- Title
- java output array lists to file
- Category
- Java
- Title
- java 8 stream group by example
- Category
- Java
- Title
- java instantiate collection with values
- Category
- Java
- Title
- string replace java
- Category
- Java
- Title
- convert hashset to int array java
- Category
- Java
- Title
- how to test for legit email in java
- Category
- Java
- Title
- set color of text for jlabel
- Category
- Java