在我的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);
}
}