Skip to main content

help required :java function for android App

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
syedrabab
Offline
Joined: 2014-06-12
Points: 0

can any one help me in changing the code i have a java script need to make a same function for android app.

in this function it passes the current time then the whole logic works

function knockout(rightnow) {
var r = ''; // return string
var hr = rightnow.getHours();
var dhr = 0; // separate variable to display because (24 hr clock)
var ap = '';

// it takes 14 minutes to fall asleep
var min = rightnow.getMinutes() + 14;
if(min > 60) {
min = min - 60;
hr = hr + 1;

if(hr >= 24) {
if(hr == 24) {
hr = 0; // midnight, must adjust!
}
else if(hr == 25) {
hr = 1;
}
}
}

r = '

It takes the average human fourteen minutes to fall asleep.

If you head to bed right now, you should try to wake up at one of the following times:

';
for(var ctr = 0; ctr < 6; ctr++) { // normal sleep schedule
// add an hour and a half
if(min < 30) {
min = min + 30;
}
else {
min = min - 30;
hr = hr + 1
}
hr = hr + 1;

if(hr == 24) {
hr = 0;
}
if(hr == 25) {
hr = 1;
}

if(hr < 12) {
ap = ' AM';
dhr = hr;
if(hr == 0) {
dhr = "12";
}
}
else {
ap = ' PM';
dhr = hr - 12;
}
if(dhr == 0) {
dhr = 12;
}
if(ctr == 0) {
if(min > 9) {
r = r + dhr + ':' + min + ap;
}
else {
r = r + dhr + ':0' + min + ap;
}
}
else if(ctr == 4 || ctr == 5) {
if(min > 9) {
r = r + ' or ' + dhr + ':' + min + ap + '';
}
else {
r = r + ' or ' + dhr + ':0' + min + ap;
}
}
else if(ctr == 3) {
if(min > 9) {
r = r + ' or ' + dhr + ':' + min + ap + '';
}
else {
r = r + ' or ' + dhr + ':0' + min + ap + '';
}
}
else {
if(min > 9) {
r = r + ' or ' + dhr + ':' + min + ap;
}
else {
r = r + ' or ' + dhr + ':0' + min + ap;
}
}
}
r = r + '

A good night\'s sleep consists of 5-6 complete sleep cycles.

';
return r;
}

// handle "sleep now" requests
// this currently fades out the #main id,
// and works in a totally separate div
$("#sleepnow").click(function() {
var st = '';
var answ = ''; // this is the text we return
var d = new Date();
answ = knockout(d); // knockout takes a Date() and returns a string of wake times
st = '';
$('#main').hide();
$('#instant').html(st);
$('#instant').show()
$('#bit').show(250);
putads()
});

i want to make a button in app on click of it it take the current time and then the same logic work.