Created
May 21, 2012 17:15
-
-
Save pec1985/2763369 to your computer and use it in GitHub Desktop.
Android pause and resume events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var DEBUG = true; | |
/** | |
* Print log in cosole in "< INFO >" modude if DEBUG if true | |
* @param { String } _text console log text | |
*/ | |
exports.Info = function(_text){ | |
if(DEBUG){ | |
Ti.API.info('< INFO > '+_text); | |
} else { | |
return; | |
} | |
} | |
/** | |
* Print log in cosole in "< DEBUG >" modude if DEBUG if true | |
* @param { String } _text console log text | |
*/ | |
exports.Debug = function(_text){ | |
if(DEBUG){ | |
Ti.API.debug('< DEBUG > '+_text); | |
} else { | |
return; | |
} | |
} | |
/** | |
* Print log in cosole in "< ERROR >" modude if DEBUG if true | |
* @param { String } _text console log text | |
*/ | |
exports.Error = function(_text){ | |
if(DEBUG){ | |
Ti.API.error('< ERROR > '+_text); | |
} else { | |
return; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Use this to create every window | |
* @param { Object } _params Ti.UI.Window parameters | |
*/ | |
exports.Win = function(_params){ | |
var Log = require('log'); | |
var Utils = require('utils'); | |
_params = _params || {}; | |
// make it heavy weight | |
_params.fullscreen = a.fullscreen || false; | |
var win = Ti.UI.createWindow(a); | |
function openEvent(){ | |
win.removeEventListener('open', openEvent); | |
if(win.isActivity){ | |
var activity = win.activity; | |
Utils.putAndroidInBackground(false); | |
Log.Info('OPEN EVENT: Utils.isAndroidInBackground: ' + Utils.isAndroidInBackground); | |
if(activity.addEventListener){ | |
activity.addEventListener('resume', function(){ | |
Log.Info('Activity Resume') | |
Utils.putAndroidInBackground(false); | |
Log.Info('RESUME EVENT: Utils.isAndroidInBackground: ' + Utils.isAndroidInBackground); | |
}); | |
activity.addEventListener('pause', function(){ | |
Log.Info('Activity Pause') | |
Utils.putAndroidInBackground(true); | |
Log.Info('RESUME EVENT: Utils.isAndroidInBackground: ' + Utils.isAndroidInBackground); | |
}); | |
} | |
} | |
} | |
}; | |
win.addEventListener('open', openEvent); | |
return win; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Boolea to know whether the app is in background or not | |
* ONLY ANDROID | |
* @type { Boolean } | |
*/ | |
exports.isAndroidInBackground = false; | |
/** | |
* Method to change the boolean "isAndroidInBackground" | |
* @param { Boolean } _bool | |
*/ | |
exports.putAndroidInBackground = function(_bool) { | |
exports.isAndroidInBackground = _bool; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment