Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created May 21, 2012 17:15
Show Gist options
  • Save pec1985/2763369 to your computer and use it in GitHub Desktop.
Save pec1985/2763369 to your computer and use it in GitHub Desktop.
Android pause and resume events
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;
}
}
/**
* 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;
};
/**
* 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