В моем приложении для Android я использую следующую функцию. Но я обнаружил, что когда time
больше 16777215 (0xFFFFFF), вычисление занимает много времени и увеличивается каждые 2 секунды вместо 1.
Есть ли способ оптимизировать приведенный ниже код, чтобы он мог обрабатывать числа больше 0xFFFFFF во времени?
/**
* 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);
}
}