about time

You must Login before you can answer or comment on any questions.

i have an difficulty in timer , problem is that i have an match of 10 minutes and if any problem is come that timer is stopped that after restarting that timer match should star from that time only like my match stop at 4th min and when its starts again it should start at 3:59 min , pls help me in solving this problem

— asked 10 months ago by Sagar Patel
2 Comments
  • var matchLiveWindow = Ti.UI.createView({ top : 0 * hFactor, height : 460 * hFactor, width : 320 * wFactor, visible : false, backgroundColor : 'white', active : false, title : 'matchLiveWindow', backgroundImage : '../images/backgrondImage.png' });

        var timer;
        var second = 0;
        var minute = 00;
        var hour = 0;
        var zeroSecond = 0;
        //totalminutes":"90
        dataContext.wholeMinutes = 00;
        Ti.API.info('hr  ' + hour);
        Ti.API.info('min ' + minute);
        Ti.API.info('sec ' + second);
        var vibrateLengthArray = [0, 500, 100, 500, 100, 500];
    
        Ti.App.addEventListener('minute', function(data) {
            minute = data.m 
        });
    
        function timerFunction(e) {
    
            if (Ti.App.Properties.getBool('timerReset')) {
                minute = matchLiveScreen.child.minute;
                second = matchLiveScreen.child.second;
    
                Ti.App.Properties.setBool('timerReset', false);
                Ti.API.info('Enter in to Timer Reset Loop');
            }
    
            if (Ti.App.Properties.getBool('timerIntervalReset')) {
                clearInterval(timer);
                Ti.App.Properties.setBool('timerIntervalReset', false);
            }
    
            if (e.source.cause == 'start') {
                currentWindow.keepScreenOn = true;
                //Ti.App.idleTimerDisabled = true;
                Ti.App.Properties.setBool('matchStarted', false);
                var sec, min, hr;
                Ti.API.info('hr  ' + hour);
                Ti.API.info('min ' + minute);
                Ti.API.info('sec ' + second);
                startBtn.visible = false;
                pauseBtn.visible = true;
                timerDoneButton.visible = false;
    
                timer = setInterval(function(e) {
                    second++;
    
                    if (second > 59) {
                        minute++;
                        second = 0;
                    }
                    if (second <= 9) {
                        sec = '0' + second;
    
                    } else {
                        sec = second;
                    }
                    if (minute <= 9) {
                        min = '0' + minute;
                    } else {
                        min = minute;
                    }
    
                    timerlabel.text = min + ':' + sec;
    
                    dataContext.minutes = min;
    
                    dataContext.second = sec;
    
                    if (min != '') {
                        dataContext.wholeMinutes = min;
                        //dataContext. serverMatchMinutes;
                        //  dataContext.wholeMinutes = minutes;
                        // this is orignal
                        Ti.API.info('wholeMinutes if ' + dataContext.wholeMinutes)
                        Ti.API.info('dataContext.second if ' + dataContext.second)
                    } else {
                        dataContext.wholeMinutes = 00;
                        Ti.API.info('wholeMinutes else ' + dataContext.wholeMinutes)
                        Ti.API.info('dataContext.second else ' + dataContext.second)
    
                    }
                    Ti.API.info('dataContext.second ' + dataContext.second);
                    Ti.API.info('dataContext.wholeMinutes ' + dataContext.wholeMinutes);
                    if (dataContext.wholeMinutes == 00 && zeroSecond == 0) {
                        zeroSecond++;
                        zeroTimeUpdate();
                    } else if ((dataContext.wholeMinutes * 60 ) == dataContext.halfSecond && zeroSecond == 2) {
                        zeroSecond++;
                        halfTimeStartUpdate();
    
                    }
    
                    if (dataContext.second == 00) {
                        everyTimeUpdate();
                    }
    
                    //if (dataContext.wholeMinutes == 45 && dataContext.second == 00) {
                    Ti.API.info('dataContext.halfSecond ' + dataContext.halfSecond)
                    if ((dataContext.wholeMinutes * 60 ) == dataContext.halfSecond && dataContext.second == 00) {
    
                        Ti.App.idleTimerDisabled = false;
                        currentWindow.keepScreenOn = false;
                        clearInterval(timer);
                        rustButton.visible = true;
                        pauseBtn.visible = false;
                        timerDoneButton.visible = false;
                        Ti.Media.vibrate(vibrateLengthArray);
    
                    }// else if (dataContext.wholeMinutes == 90 && dataContext.second == 00) {
                    else if ((dataContext.wholeMinutes * 60 ) == dataContext.wholeSecond && dataContext.second == 00) {
    
                        currentWindow.keepScreenOn = false;
                        clearInterval(timer);
                        Ti.App.Properties.setBool('matchStarted', true);
                        pauseBtn.visible = false;
                        Ti.API.info('pauseBtn.visible = false');
                        afgelopenButton.visible = true;
                        Ti.API.info('timerButton')
                        Ti.Media.vibrate(vibrateLengthArray);
                        Ti.API.info('welcome')
                    }
                }, 1000);
    
            } else if (e.source.cause == 'pause') {
                //timer.clearInterval();
                currentWindow.keepScreenOn = false;
                Ti.API.info('hr  ' + hour);
                Ti.API.info('min ' + minute);
                Ti.API.info('sec ' + second);
                clearInterval(timer);
                timer = null;
                startBtn.visible = true;
                pauseBtn.visible = false;
                timerDoneButton.visible = false;
                Ti.API.info('wholeMinutes else ' + dataContext.wholeMinutes)
    
            } else if (e.source.cause == 'timerDoneButton') {
                Ti.API.info('Enter in to timerDoneButton')
                startBtn.visible = true;
                pauseBtn.visible = false;
                timerDoneButton.visible = false;
                closeWindow();
                closeWindow();
                closeWindow();
                Ti.App.Properties.setBool('timerIntervalReset', true);
    
            } else if (e.source.cause == 'Rust') {
                zeroSecond++;
                HalfTimeUpdate();
                currentWindow.keepScreenOn = false;
                startBtn.visible = true;
                pauseBtn.visible = false;
                timerDoneButton.visible = false;
                rustButton.visible = false;
                Ti.API.info('wholeMinutes else ' + dataContext.wholeMinutes)
    
            } else if (e.source.cause == 'Afgelopen') {
                fullTimeUpdate();
                currentWindow.keepScreenOn = false;
                Ti.API.info('Enter in to timerDoneButton')
                //  closeWindow();
                startBtn.visible = true;
                afgelopenButton.visible = false;
                Ti.App.Properties.setBool('timerIntervalReset', true);
                second = 0;
                minute = 00;
                hour = 0;
                zeroSecond = 0;
                timerlabel.text = '00:00';
            }
        }
    
        var scoreBoardImage = Ti.UI.createView({
            backgroundImage : '../images/timerboard.png',
            top : 25 * hFactor,
            width : 298 * wFactor,
            height : 90 * hFactor
        });
    
        matchLiveWindow.add(scoreBoardImage);
    
        var timerlabel = Ti.UI.createLabel({
            text : "00:00",
            top : 35 * hFactor,
            //left: 10,
            width : 200 * wFactor,
            // height: 80,
            font : {
                fontSize : hFactor * 50,
                fontWeight : 'bold',
                fontFamily : 'phagspa'
            },
            color : 'white',
            textAlign : 'center'
        });
    
        matchLiveWindow.add(timerlabel);
    
        var startBtn = Ti.UI.createButton({
            width : 236 * wFactor,
            height : (63 * hFactor) - (63 * optV),
            top : 120 * hFactor + (63 / 2 * optV),
            //title : 'start',
            cause : 'start',
            backgroundImage : '../images/startButton.png',
            backgroundSelectedImage : '../images/startButton_focus.png',
            visible : true ,
        })
    
        matchLiveWindow.add(startBtn);
    
        startBtn.addEventListener('click', timerFunction)
    
        var pauseBtn = Ti.UI.createButton({
            width : 236 * wFactor,
            height : (63 * hFactor) - (63 * optV),
            top : 120 * hFactor + (63 / 2 * optV),
            //title : 'pause',
            cause : 'pause',
            visible : false,
            backgroundImage : '../images/pauseButton.png',
            backgroundSelectedImage : '../images/pauseButton_focus.png',
        })
    
        matchLiveWindow.add(pauseBtn);
    
        pauseBtn.addEventListener('click', timerFunction)
    
        var timerDoneButton = Ti.UI.createButton({
            width : 236 * wFactor,
            height : (63 * hFactor) - (63 * optV),
            top : 120 * hFactor + (63 / 2 * optV),
            title : 'done',
            cause : 'timerDoneButton',
            visible : false,
            backgroundImage : '../images/button.png'
        })
    
        matchLiveWindow.add(timerDoneButton);
    
        timerDoneButton.addEventListener('click', timerFunction)
    
        var rustButton = Ti.UI.createButton({
            width : 236 * wFactor,
            height : (63 * hFactor) - (63 * optV),
            top : 120 * hFactor + (63 / 2 * optV),
            //title : 'Rust',
            cause : 'Rust',
            visible : false,
            backgroundImage : '../images/rustButton.png',
            backgroundSelectedImage : '../images/rustButton_focus.png',
        })
    
        matchLiveWindow.add(rustButton);
    
        rustButton.addEventListener('click', timerFunction)
    
        var afgelopenButton = Ti.UI.createButton({
            width : 236 * wFactor,
            height : (63 * hFactor) - (63 * optV),
            top : 120 * hFactor + (63 / 2 * optV),
            //title : 'Afgelopen',
            cause : 'Afgelopen',
            visible : false,
            backgroundImage : '../images/afgelopenButton.png',
            backgroundSelectedImage : '../images/afgelopenButton_focus.png',
        })
    
        matchLiveWindow.add(afgelopenButton);
    
        afgelopenButton.addEventListener('click', timerFunction)
    
        var homeScoreBoard = Ti.UI.createView({
    
            backgroundImage : '../images/scoreBoard.png',
            top : 190 * hFactor + (126 / 2 * optV),
            height : 126 * hFactor - (126 * optV),
            width : 126 * wFactor,
            left : 20 * wFactor,
            cause : 'homeScoreBoard'
    
        });
        matchLiveWindow.add(homeScoreBoard);
    
        var homeGoalLabel = Ti.UI.createLabel({
            text : '0',
            height : 'auto',
            width : 'auto',
            color : 'white',
            font : {
                fontSize : 50 * hFactor,
                weight : 'bold',
                fontFamily : 'phagspa'
            },
            left : 50 * wFactor
        });
    
        homeScoreBoard.add(homeGoalLabel)
    
        var awayScoreBoard = Ti.UI.createView({
            backgroundImage : '../images/scoreBoard.png',
            top : 190 * hFactor + (126 / 2 * optV),
            height : 126 * hFactor - (126 * optV),
            width : 126 * wFactor,
            right : 20 * wFactor,
            cause : 'awayScoreBoard'
        });
    
        matchLiveWindow.add(awayScoreBoard);
    
        var awayGoalLabel = Ti.UI.createLabel({
            text : '0',
            height : 'auto',
            width : 'auto',
            color : 'white',
            font : {
                fontSize : 50 * hFactor,
                weight : 'bold',
                fontFamily : 'phagspa'
            },
            left : 50 * wFactor
        });
    
        awayScoreBoard.add(awayGoalLabel)
    
        var goalButton = Ti.UI.createView({
            backgroundImage : '../images/goalButton.png',
            top : 330 * hFactor + (100 / 2 * optV),
            height : 100 * hFactor - (100 * optV),
            width : 100 * wFactor,
            left : 10 * wFactor,
            cause : 'goal'
        });
    
        matchLiveWindow.add(goalButton);
    
        var penaltyButton = Ti.UI.createView({
            backgroundImage : '../images/penalityButton.png',
            top : 330 * hFactor + (100 / 2 * optV),
            height : 100 * hFactor - (100 * optV),
            width : 100 * wFactor,
            backgroundColor : 'black',
            left : 113 * wFactor,
            cause : 'penalty'
        });
    
        matchLiveWindow.add(penaltyButton);
    
        var substituteButton = Ti.UI.createView({
            backgroundImage : '../images/substitueButton.png',
            top : 330 * hFactor + (100 / 2 * optV),
            height : 100 * hFactor - (100 * optV),
            width : 100 * wFactor,
            backgroundColor : 'black',
            left : 215 * wFactor,
            cause : 'substitute'
        });
    
        matchLiveWindow.add(substituteButton);
    
        var child = {
            'awayGoalLabel' : awayGoalLabel,
            'homeGoalLabel' : homeGoalLabel,
            'second' : second,
            'minute' : minute,
            'hour' : hour,
            'timerlabel' : timerlabel,
            'timer' : timer,
            'startBtn' : startBtn,
            'pauseBtn' : pauseBtn,
            'timerDoneButton' : timerDoneButton
        }
    
        matchLiveWindow.child = child;
    
        return matchLiveWindow;
    
    }
    

    })();

    — commented 10 months ago by Sagar Patel

  • function runningMatchTime(e) {

    Ti.API.info('running match time' + '{"tmapp": {  "value": "match_running_get_info",  "details": {   "matchid":"' + dataContext.matchid + '",    "userid": "' + dataContext.userid + '", "sid":"' + dataContext.sid + '" }}}')
    requestServer({
        success : function(e) {
    
            Ti.API.info('running match time Response Data ' + this.responseText);
            var json = JSON.parse(this.responseText);
            Ti.API.info(' time Response Data ' + json.tmappresult.results.minute);
    
            dataContext.runningMinute = json.tmappresult.results.minute;
    
            Ti.API.info('-------  getting minute into time file from  server ------' + dataContext.runningMinute);
    
            Ti.App.fireEvent("minute", {
                m : dataContext.runningMinute
            })
    
            progress.hide();
    
        },
        method : 'POST',
        param : {
            "data" : '{"tmapp": {  "value": "match_running_get_info",  "details": {   "matchid": "' + dataContext.matchid + '",   "userid": "' + dataContext.userid + '", "sid":"' + dataContext.sid + '" }}}'
        },
    
        failed : function(e) {
            progress.hide();
            Ti.Analytics.featureEvent('PaultrainersMagazineApp.Log', this.responseText);
            Ti.API.info('Error Response:' + this.responseText);
        }
    });
    

    }

    — commented 10 months ago by Sagar Patel

2 Answers

please show us your code.. or else no 1 can help you

Your Answer

Think you can help? Login to answer this question!