I have a number of animations I'd like to run, one after another. How can I tell when one is done so that I know to start the next?
Update Sorry, I should have mentioned that these are skeletal animations that I'm doing.
Couple of options:
1: You can enclose your animations in setTimeout() functions:
setTimeout( function() { animation1; }, waitTime );
setTimeout( function() { animation2; }, waitTime + duration_of_animation1 );
setTimeout( function() { animation3; }, waitTime + duration_of_animation2 );
2: Look at https://github.com/mrdoob/frame.js which has not been released yet.
For animations try to use tween library, it solves much more than this:
https://github.com/tweenjs/tween.js/
Related
Currently I make myself familiar with nativescript and trying to figure out what you can do with it. One thing that I find very interesting and for which I am more interested in is how I can use native Android functions.
As challenge for understanding and learning I have picked out the possibility in apps fill in text fields with specific values like some password managers apps do. If I understand it right, it shouldn't big voodoo.
How, I found two examples. The first one is the autofill feature from the keepass2android app. Sources: https://keepass2android.codeplex.com/SourceControl/changeset/view/9ddc142d987880118be38ee1d69943f2809738d3#src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/autofill/AutoFillService.java
Other sample I found here: AccessibilityNodeInfo - send text
First quick and dirty I hack the app.js, find out how the android native functions works in nativescript. So I want trigger somehow the different events but only init is triggered (so far I also understand it also).
var applicationModule = require("application");
var platform = require("platform");
var context = applicationModule.android.context;
android.accessibilityservice.AccessibilityService;
var aa = android.accessibilityservice.AccessibilityService.extend({
init: function() {
console.log("init()");
},
onInit: function() {
console.log("onInit()");
},
create: function() {
console.log("create()");
},
onCreate: function() {
console.log("onCreate()");
},
destroy: function() {
console.log("destroy()");
},
onDestroy: function() {
console.log("onDestroy()");
},
accessibilityEvent: function(event) {
console.log("accessibilityEvent");
},
onAccessibilityEvent: function(event) {
console.log("onAccessibilityEvent");
},
interrupt: function() {
console.log("interrupt");
},
onInterrupt: function() {
console.log("interrupt");
},
serviceConnected: function() {
console.log("serviceConnected");
},
onServiceConnected: function() {
console.log("onServiceConnected");
}
});
var a = new aa();
Probably android.accessibilityservice.AccessibilityService must somehow be extended in a different way, get it working. But how?
It would be a big deal if the onAccessibilityEvent function would be triggered in nativescript.
Edit:
I made some progress. Found some other nativescript sources and samples and modified my code. Now:
var applicationModule = require("application");
var platform = require("platform");
var utils = require("utils/utils");
var context = android.content.Context;
var ad = utils.ad.getApplicationContext();
var aa = ad.getSystemService(context.ACCESSIBILITY_SERVICE);
But the way, I can register onAccessibilityEvent is currently not clear for me.
You need to register your service (the class from your first code block) similar to this example:
http://developer.android.com/training/accessibility/service.html
and place your logic in onAccessibilityEvent override.
Is there a way in casperjs to ignore a timeout for a specific event? I know there is an onStepTimeout function but I believe it is for all step timeouts. I have a loop doing a refresh and don't care if it times out versus the other steps. Any way to flag or ignore timeout based on the step it is performing?
Edit: here is my code snippet. I got it working using a global variable flag but don't know if this the correct way:
//flag
var tout="yes";
//onStepTimeout function
onStepTimeout: function(self,m) {
console.log('List Detection: Process step timed out.');
if ( tout == "yes" ) {
this.exit();
}
},
//Event I dont want to skip if timeout
tout="no";
casper.thenOpen('https://url/account/gotoLogin.action', function() {
//...
});
//Event I do want to skip if timeout
tout="yes";
casper.thenOpen('https://url/browse/browse.action', function() {
//...
});
You can certainly do this with a global variable, but you missed that casper.then* only schedules the steps and does not execute them. You need to move the global variable inside a step to assure that it is flipped at the right time.
//flag
var mayExit = true;
function addMayExitStep(newMayExit){
casper.then(function(){
mayExit = newMayExit;
});
}
//onStepTimeout function
onStepTimeout: function(self,m) {
console.log('List Detection: Process step timed out.');
if ( mayExit ) {
this.exit();
}
},
//Event I dont want to skip if timeout
addMayExitStep(false);
casper.thenOpen('https://url/account/gotoLogin.action', function() {
//...
});
//Event I do want to skip if timeout
addMayExitStep(true);
casper.thenOpen('https://url/browse/browse.action', function() {
//...
});
I'm trying to get Sencha Touch to listen to the events phonegap gives off, any help I can find online only points to sencha events. I've also tried setting up listeners and " .on " but it doesn't seem to work on outside events.
I'm not talking about any specific event, just any event like 'resume', or 'batterystatus'.
Please don't reply with a reference to Ext.device because Sencha support for Ext.device is limited and outdated as it always has been when one company tries to provide a wrapper around a different company, I'd like to take full advantage of all the features the most up-to-date phonegap version offers.
You should be able to add PhoneGap-specific listeners like this:
document.addEventListener("deviceready", function() {
document.addEventListener("backbutton", MyApp.backButtonListener, false);
document.addEventListener("menubutton", MyApp.menuButtonListener, false);
}, false);
MyApp.backButtonListener = function(e) {
e.preventDefault();
//do other stuff here...
}
MyApp.menuButtonListener = function(e) {
e.preventDefault();
//do other stuff here...
}
You can do something like this, I have tested it and it's working!
Ext.application({
name: 'TestApp',
...
launch: function() {
// Hook up events of PhoneGap here
document.addEventListener("pause", this.onPause, false);
document.addEventListener("resume", this.onResume, false);
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
// Initialize the main view
Ext.Viewport.add(Ext.create('TestApp.view.Main'));
},
onPause: function() {
// this code is fine but using 'this' here is not safe
console.log("onPause");
},
onResume: function() {
console.log("onResume");
}
...
});
Edited:
Turn out it's not a very good idea to put the handler in the app.js file (although it will still work anw). Because if you upgrade sencha, it expects this file not to be modified much.
So you should instead put it in your launch function of a main controller. Controllers' launch function are executed after Application's launch function.
Ext.define('TestApp.controller.Main', {
extend: 'Ext.app.Controller',
...
launch: function() {
// Hook up events of PhoneGap here
document.addEventListener("pause", this.onPause, false);
document.addEventListener("resume", this.onResume, false);
},
onPause: function() {
// this code is fine but using 'this' here is not safe
console.log("onPause");
},
onResume: function() {
console.log("onResume");
}
...
});
I have a slide show with bet 20 - 40 images, but there is a significant delay before each image loads even though I've set them all to preload (I recently increased it to preload: '40'). What can I do to improve this?
The settings for the slideshow are:
$(function () {
$('.fancybox').fancybox({
autoResize: true,
autoCenter: true,
scrolling: 'no',
preload: '40',
helpers: {
overlay: {
closeClick: false
},
},
});
I'm using it in conjunction with this function:
function manipulateDOM1() {
changeObjectsTrendy();
NextImageTrendy();
}
function changeObjectsTrendy() {
document.getElementById("questionTrendy").innerHTML = textTrendy[textTrendyNumber];
}
function NextImageTrendy() {
if (imgTrendyNumber < NumberOfTrendyImages)
{
imgTrendyNumber++;
document.images["trendy"].src = trendy[imgTrendyNumber];
document.images["trendyControl"].src = trendyControl[imgTrendyNumber];
textTrendyNumber++;
document.getElementById["questionTrendy"].innerHTML = textTrendy[textTrendyNumber];
}
Problem solved :-D
I just saw that there had been a recent update to the js for the fancybox slideshow, and thankfully that's made a huge difference (there's now only a marginal delay) :-)
Can anybody help me in finding a solution for this problem.
I have (assume) 3 doh functions 1st one is async and the rest are synchronous. I have to make async function to be called first and the result of this function to be passed to other two functions is it possible?
Example :
doh.register(".....", [
{
name : "asyncFunction",
runTest : function(){
function callback(result){
//How to pass the result to fun_2 and fun_3
//also fun_2 or fun_3 should be deferred until this function executes
}
}
},
function fun_2(result){
//doh.assertTrue(.....);
},
function fun_3(result){
//doh.assertTrue(.....);
}
Any help would be great.
So, it sounds like your first function is basically a setup function for the other tests.
It is possible to do - basically using Deferreds/promises, but it's a little bit icky, and you might get badly stung by test timeouts.
So, here's something that does a setup with a bit of asynchronous code that takes 2s. All the tests become asynchronous tests that do their work once the 'setup' Deferred has completed.
Because your 'follow on' tests have become asynchronous, you need to make sure that their timeouts cope with the time that'll be taken by your asynchronous setup (at least for the first one that happens to run).
// Some asynchronous initialization that takes 2s
setTimeout(function() {
setupCompletion.resolve({ result: 42 });
}, 2000);
doh.register("my.test1", [
{
name: "waits for async setup to complete",
timeout: 5000,
runTest: function() {
var d = new doh.Deferred();
setupCompletion.then(function (res) {
doh.is(42, res.result);
d.callback(true);
});
return d;
}
},
{
name: "also waits for async setup to complete",
timeout: 5000,
runTest: function() {
var d = new doh.Deferred();
setupCompletion.then(function (res) {
doh.is(43, res.result + 1);
d.callback(true);
});
return d;
}
}
]);
Of course, it would be nice if it were possible to arrange for a test's setUp function to return a Deferred, but doh doesn't support that right now (as of v1.7.2).