cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

using of $timeout

DF_9703795
9-Granite

using of $timeout

Hi everyone,
i am currently trying to make a HoloLense experience with two views, where i can switch between these views with a voice command.

I created an application event "Switch view" and linked it to the "Navigate" option of both views. This works fine, whenever i say "Switch view" it immediatelly switches. 

But now i want to make this a little bit slower, with a delay of 1second for example. I tried to use $timeout but:

How do i use it and where do I have to write the command? (in Home.js or into the JS of the application event)

 

Thank you all for your help!

1 ACCEPTED SOLUTION

Accepted Solutions

Here is another approach:

 

That's say we have 2 view, "first" and "second".

In first.js and second.js

 

$scope.app.switchView = function(destination){
  $timeout(function(){
    twx.app.fn.navigate(destination);
  }, 2000)
}

 

 

Then in APPLICATION EVENTS:

Name: firstToSecond

Voice Alias: switch to second view

JS: viewCtrl.app.switchView("second")

 

Name: secondToFirst

Voice Alias: switch to first view

JS: viewCtrl.app.switchView("first")

 

 

View solution in original post

6 REPLIES 6

 

 

1. Let suppose you have 2 views Home / wich is the the start view and a second view named mySecondVIEW

2. Copy the below script in Home.js

 

$scope.app.mySecondViewCmd = function () { // will call the view "mySecondVIEW"
// with delay 2 secs
$timeout(function() {
  twx.app.fn.navigate("mySecondVIEW")
}, 2000); // call with delay of 2 seconds = 2000 miliseconds
};

 

3. In the js script of the second view in mySecondVIEW.js wirte the code:

 

$scope.app.myViewCmdHome = function () {
$timeout(function() {// will call the home view with 3 secs delay
   twx.app.fn.navigate("Home")
}, 3000); // call with delay of 3 seconds = 3000 miliseconds
}

 

4.) then for the voice command add in the js UI section the function call which should call mySecondView:

 

viewCtrl.app.mySecondViewCmd();

 

 

and for the voice command which should call  back the Home view:

 

viewCtrl.app.myViewCmdHome()

 

 I think the both defintions  of the functions  $scope.app.mySecondViewCmd() and  $scope.app.myViewCmdHome could be done in the start view (so that when this view was called then the definitions are available then)

Here is another approach:

 

That's say we have 2 view, "first" and "second".

In first.js and second.js

 

$scope.app.switchView = function(destination){
  $timeout(function(){
    twx.app.fn.navigate(destination);
  }, 2000)
}

 

 

Then in APPLICATION EVENTS:

Name: firstToSecond

Voice Alias: switch to second view

JS: viewCtrl.app.switchView("second")

 

Name: secondToFirst

Voice Alias: switch to first view

JS: viewCtrl.app.switchView("first")

 

 

Yes, this is better appraoch - more general- using only one deffinition. I see you confirmed that we need to define the function in each view.js - because I did this some time ago and could not remember if the voice command java code defintion will remember the defintion from the start view - also when we navigate to a second view.

Hi, @RolandRaytchev 

 

Thanks for reply. I just try to provide a more general approach.

 

As to Function Declaration  part, here is the clarification:

 

With ".app",

Functions declared in one View can be used in any other Views.

e.g.

$scope.app.switchView = function(destination){
  $timeout(function(){
    twx.app.fn.navigate(destination);
  }, 2000)
}

 

Without ".app

Function can only works in the View in which was declared.

e.g.

$scope.switchView = function(destination){
  $timeout(function(){
    twx.app.fn.navigate(destination);
  }, 2000)
}

 

In other words, $scope.app.switchView be declared in either View is sufficient in my approach above.

 

Sorry for misleading.

 

regards, 

ClarK

That’s   fine, thanks for clarification. Such details are something what we can find during tests , but after some time I could not really remember all the details, so that I appreciate such kind of comments. Thanks!

A big thank you to both of you!!

Announcements

Topics available:
AR/VR for Data Optimization AR/VR for Security and Control AR/VR for Inspection