我有8张图片。这里的图像将根据用户设置的时间进行翻转,并且默认唤醒时间为上午7:00。如果用户在晚上10:10设置时间并且唤醒时间是早上7:00。现在,图像需要翻转,图像的翻转是百分比的,即; 0%20%40%60%80%90%95%100%的总时间。现在,当我从上午10:00到下午7:00,上午9:00到上午11:00,下午7:00到晚上8:30设置时间时,图像会翻转。但是当我从晚上10点开始设置时到上午7点,图像没有翻转。
c = Calendar.getInstance();
SimpleDateFormat displayFormat = new SimpleDateFormat("HH:mm");
SimpleDateFormat testhrFormat = new SimpleDateFormat("HH");
SimpleDateFormat testminFormat = new SimpleDateFormat("mm");
String formattedDate = testhrFormat.format(c.getTime());
int minDate = Integer.parseInt(testminFormat.format(c.getTime()));
long hrlong = TimeUnit.HOURS.toMinutes(Long.parseLong(formattedDate));
addedmin = hrlong + minDate;
twwntyhrformat = displayFormat.format(c.getTime());
SimpleDateFormat parseFormat = new SimpleDateFormat("HH:mm a");
SharedPreferences timegot = getSharedPreferences("CHILDTIME", MODE_PRIVATE);
String time = timegot.getString("savedwakeuptime", "");
try {
Date date = parseFormat.parse(time);
String gottime = displayFormat.format(date);
String[] timedivided = gottime.split(":");
String gothr = timedivided[0];
long gotlong = TimeUnit.HOURS.toMinutes(Long.parseLong(gothr));
String gotmin = timedivided[1];
int gotintmin = Integer.parseInt(gotmin);
addgottime = gotlong + gotintmin;
long subtime = addgottime - addedmin;
String submilli = String.valueOf(subtime);
long submillitimeunit = TimeUnit.MINUTES.toMillis(Long.parseLong(submilli));
final int gotflippingtime = (int) submillitimeunit;
handler = new Handler();
run = new Runnable() {
@Override
public void run() {
String number = String.valueOf(fliper.getDisplayedChild());
if (number.equals("7")) {
handler.removeCallbacks(run);
back_home.setEnabled(true);
} else {
fliper.showNext();
handler.postDelayed(run, gotflippingtime);
}
}
};
for (int gotinterval : gotintervals) {
handler.postDelayed(run, gotinterval);
}
handler.postDelayed(run, gotflippingtime);
} catch (ParseException e) {
e.printStackTrace();
}
} else {
c = Calendar.getInstance();
SimpleDateFormat testhrFormat = new SimpleDateFormat("HH");
SimpleDateFormat testminFormat = new SimpleDateFormat("mm");
String formattedDate = testhrFormat.format(c.getTime());
int minDate = Integer.parseInt(testminFormat.format(c.getTime()));
long hrlong = TimeUnit.HOURS.toMinutes(Long.parseLong(formattedDate));
addedmin = hrlong + minDate;
SharedPreferences timegot = getSharedPreferences("CHILDTIME", MODE_PRIVATE);
long numberlong = timegot.getLong("savedwakeuptime",0);
long millicurrenttime=TimeUnit.MINUTES.toMillis(addedmin);
long subtime = numberlong-millicurrenttime;
Log.d("Calc", String.valueOf(subtime)+" "+String.valueOf(numberlong)+" "+String.valueOf(millicurrenttime));
flippingtime = (int) subtime;
intervals = new ArrayList<Integer>();
intervals.add((int) (flippingtime * 0.20f));
intervals.add((int) (flippingtime * 0.40f));
intervals.add((int) (flippingtime * 0.60f));
intervals.add((int) (flippingtime * 0.80f));
intervals.add((int) (flippingtime * 0.90f));
intervals.add((int) (flippingtime * 0.95f));
intervals.add((int) (flippingtime * 1.00f));
intervals.add(flippingtime);
handler = new Handler();
run = new Runnable() {
@Override
public void run() {
String number = String.valueOf(fliper.getDisplayedChild());
if (number.equals("7")) {
handler.removeCallbacks(run);
} else {
fliper.showNext();
handler.postDelayed(run, flippingtime);
}
}
};
for (int interval : intervals) {
handler.postDelayed(run, interval);
}
handler.postDelayed(run, flippingtime);