Skip to content

Instantly share code, notes, and snippets.

@ryugoo
Created February 9, 2014 13:15
Show Gist options
  • Save ryugoo/8898916 to your computer and use it in GitHub Desktop.
Save ryugoo/8898916 to your computer and use it in GitHub Desktop.
Emulate resumed / paused event
(function () {
'use strict';
// OS の判定
var OS_IOS = Ti.Platform.osname === 'iphone' || Ti.Platform.osname === 'ipad',
OS_ANDROID = Ti.Platform.osname === 'android';
// resumed / paused イベント
Ti.App.addEventListener('resumed', function () {
console.debug('resumed');
});
Ti.App.addEventListener('paused', function () {
console.debug('paused');
});
// Android 向けの resumed / paused イベントエミュレート
var platformTools, wasInForeGround, timer;
if (OS_ANDROID) {
timer = require('ti.mely').createTimer();
platformTools = require('bencoding.android.tools').createPlatform();
wasInForeGround = true;
timer.addEventListener('onIntervalChange', function () {
var isInForeground = platformTools.isInForeground();
if (wasInForeGround !== isInForeground) {
Ti.App.fireEvent(isInForeground ? 'resumed' : 'paused');
wasInForeGround = isInForeground;
}
});
timer.start({
interval: 3000,
debug: true
});
}
// UI
var win = Ti.UI.createWindow({
title: 'EventTest'
});
if (OS_IOS) {
win.applyProperties({
backgroundColor: '#FFFFFF'
});
}
win.open();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment