Hello I'm very new to android programming. I'd like to calculate the sleep cycle of a person in Android. I found a java code from the net but I don't know how to apply it in Android.
Here's the code I found:
/**
* Get times to wake. We add 14 minutes to fall asleep, and calculate the
* sleep cycles.
*
* @return list of times when to get up
*/
public static Set<Date> getWakingTimes() {
return getWakingTime(new Date());
}
/**
* Get times to wake. We add 14 minutes to fall asleep, and calculate the
* sleep cycles.
*
* @param sleepTime
* bed time
*
* @return list of times when to get up
*/
public static Set<Date> getWakingTime(Date sleepTime) {
Calendar fallAsleep = Calendar.getInstance();
fallAsleep.setTime(sleepTime);
fallAsleep.add(Calendar.MINUTE, 14);
Set<Date> result = new TreeSet<Date>();
for (int i = 1; i <= 6; i++) {
fallAsleep.add(Calendar.MINUTE, 90);
result.add(fallAsleep.getTime());
}
return result;
}
/**
* Get sleeping times corresponding to a local time
*
* @param wakingTime
* time to wake up !
* @return list of times one should go to bed to
*/
public static Set<Date> getSleepingTimes(Date wakingTime) {
Set<Date> result = new TreeSet<Date>();
Calendar calendar = Calendar.getInstance();
calendar.setTime(wakingTime);
calendar.add(Calendar.MINUTE, -14);
calendar.add(Calendar.MINUTE, -(2 * 90));
for (int i = 3; i <= 6; i++) {
calendar.add(Calendar.MINUTE, -90);
result.add(calendar.getTime());
}
return result;
} // end of getSleepingTimes method
private void resetSpinnerValues()
{
spHour.setSelection(0);
spMinute.setSelection(0);
spTime.setSelection(0);
} // end of resetSpinnerValues method
I'd like to try this: Click Here(null)
If anyone knows please help. Thanks.