In my Android application I use the follow function. But I found out that when time is greater than 16777215 (0xFFFFFF) the calculation takes to much time and is incremented every 2 seconds instead of 1.
Is there a way to optimize the code below so it can handle numbers larger than 0xFFFFFF in time?
/**
* Sets the time wheels to the right time.
* @param time in seconds
* @param animation for enableing and disabling animation
*/
private void setTime(float time, boolean animation) {
int days;
int hours;
int mins;
int secs;
days = (int) (time / (3600*24));
hours = (int)(time / 3600);
time = time % 3600;
mins = (int) (time / 60);
time = time % 60;
secs = (int) time;
if(days >= 1){
getWheel(R.id.time4).setCurrentItem(days, animation);
} else {
getWheel(R.id.time4).setCurrentItem(0, animation);
}
if(hours >= 1){
getWheel(R.id.time3).setCurrentItem(hours, animation);
} else {
getWheel(R.id.time3).setCurrentItem(0, animation);
}
if(mins >= 1){
getWheel(R.id.time2).setCurrentItem(mins, animation);
} else {
getWheel(R.id.time2).setCurrentItem(0, animation);
}
if(secs >= 1){
getWheel(R.id.time1).setCurrentItem(secs, animation);
} else {
getWheel(R.id.time1).setCurrentItem(0, animation);
}
}
http://developer.android.com/reference/android/text/format/Time.html
A
Timeobject maybe do the trick?You may are exceeding the
floatdatatype, you should uselongin this case.This http://developer.android.com/reference/java/sql/Time.html#Time%28long%29 constructor is using
long.