This is a migrated thread and some comments may be shown as answers.
flashlight animation synchronize problem
10 Answers 11 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
huseyin celik
Top achievements
Rank 1
huseyin celik asked on 14 Apr 2015, 05:14 PM

 

  Hi ,

i want to develop animation app.

All device's (which installed app) flashlight will do that animation at specific time.They must be start at same time.

i will give array about off-on.All device must be on at same time and then off at same time.

 

So i do ajax call for to get animation begin time.

 

 

animation start at sametime for all devices.if time does not ready all of them wait when time is ok all devices start at same time .i give same array(whic include on-off info) but same devices get off when other is still on...How can i handle this?this is my code and descripton 

 

 

 

 

 

  receivedEvent: function (id) {
var on = [true,false,true]; 
 var todayDate = (new Date().getTime()/1000); 
 var dateGSF = new Date(2020,11,25);



 $.ajax({url: "URL...",
  async: false,

  success: function(result){//


            var on1=result.split("?")[1];
on=on1.split(",");//this is on-off information array like this    var on = [true,false,true]

 window.localStorage.setItem("tarih",result.split("?")[2]);//this is animation start time 
 window.localStorage.setItem("dizi",on);
 
var serverTime=result.split("?")[3];//i get server unix UTC time.Maybe device time is wrong.
 window.localStorage.setItem("ileri_geri",(todayDate-(serverTime)));// ileri_geri is difference between server time and device time.So if device time

//was more or less i will calculate.So i want to start animation with same time 

 flashlightDemo1(on); 
 }});
},

 

 

function flashlightDemo1(on) {

   var ileri_geri=window.localStorage.getItem("ileri_geri");//difference device time and server time for synchronise

var tarih=window.localStorage.getItem("tarih");//this is animation start time 
  var baladiMi=false;//if animation start then i set this to true


if (parseInt(new Date().getTime()/1000)>(parseInt(new Date(tarih).getTime()/1000)+parseInt(ileri_geri))) //if animation time is ok let animation begin
  {
flashlightDemo(on);
 baladiMi=true;
 } 
 var Fsettimeout=setTimeout(flashlightDemo1,100,on);
if(baladiMi){ 
 clearTimeout(Fsettimeout);//if animation start clear interval
}
}

 

 

 

 

and this is my plugin 

 

var index = 0;
function flashlightDemo(on) {
   if ( on[ index ]==='true') {//if true on else off
 
  window.plugins.flashlight.switchOn(); 
    } else { 

 window.plugins.flashlight.switchOff();  
       }    
    index++; 
   setTimeout( flashlightDemo,1000,on ); 
}

10 Answers, 1 is accepted

Sort by
0
huseyin celik
Top achievements
Rank 1
answered on 14 Apr 2015, 08:52 PM
i use localstorage because when user install app he has internet so i can get animation start time.i store animation start time,on-off information array..... in localstorage so user can use that app without internet 
0
huseyin celik
Top achievements
Rank 1
answered on 15 Apr 2015, 09:26 AM

i make work around solution but

 

   window.plugins.flashlight.switchOn(); 

this not work inside if--while....

 

 

?what is problem with this? 

function flashlightDemo(on) {
var tarih=window.localStorage.getItem("tarih");
var ileri_geri=window.localStorage.getItem("ileri_geri");



while(2>1){
alert('while başı');
for (;;) {
alert('for basi');
if(parseInt(new Date().getTime()/1000)>(parseInt(new Date(tarih).getTime()/1000)+parseInt(ileri_geri)+parseInt(index*50))) 
{
alert('if ici');




   if ( on[ index ]==='true') {
  alert('on basi');
   window.plugins.flashlight.switchOn(); 
  index++; 

  break;
alert('on sonu');

     } else { 
alert('off basi');
window.plugins.flashlight.switchOff(); 
index++; 
break;
alert('on sonu');

       }   

0
huseyin celik
Top achievements
Rank 1
answered on 15 Apr 2015, 09:54 PM

hi

i do my own way  for example if administrator want to animation start at 20:30 with on= [true,false,true,true,false....] arrayi check if time is 20:30 if yes i start it for first item(on[0])and then i check time again if time is 20:30+X(difference two action time) if time is ok then i process it for seconde item(on[1]) this algoritm good looks but when i call switch on or off function it does not work  

calling this function does not work

flashlightPlugin(on[ index ]);

 

function flashlightDemo(on) {
var tarih=window.localStorage.getItem("tarih");
var ileri_geri=window.localStorage.getItem("ileri_geri");



while(2>1){

for (;;) {

if(parseInt(new Date().getTime()/1000)>(parseInt(new Date(tarih).getTime()/1000)+parseInt(ileri_geri)+parseInt(index*20))) 
{


flashlightPlugin(on[ index ]);
index++; 
break;

.....................

 

 

 

 

and this is flashlightPlugin(on[ index ]); 

 

 

function flashlightPlugin(on) {

if ( on==='true') {
window.plugins.flashlight.switchOn();
}
else
{
window.plugins.flashlight.switchOff();
}
}

0
Tsvetina
Telerik team
answered on 17 Apr 2015, 02:13 PM
Hello Hüseyin,

Have you tried debugging your method to ensure that the ​if ( on==='true') check passes and the switchOn() method is indeed called? If the method is called but does not work, do you see any errors?

Additionally, make sure that you are testing this functionality directly on a device. The plugin us use is a custom plugin and it cannot be tested in a Companion app. The app needs to be deployed on a device.

Regards,
Tsvetina
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
0
huseyin celik
Top achievements
Rank 1
answered on 17 Apr 2015, 08:38 PM

i added alert before switch on it give alert

but when i added alert after switchOn( ) it does not work

 

if ( on==='true') {

alert(before);//this works

window.plugins.flashlight.switchOn();

alert(after);//it does not give allert  

}

 

how can i handle error?

0
huseyin celik
Top achievements
Rank 1
answered on 19 Apr 2015, 11:32 AM

function flashlightPlugin(index) {
var on=window.localStorage.getItem("dizi");
on=on.split(",");

if ( on[index]==='true') {

alert('on');
window.plugins.flashlight.switchOn(onSuccess, onError);
}
else
{
alert('off');
window.plugins.flashlight.switchOff(onSuccess, onError);
}

..................... 

 i handle time and call flashlightPlugin function.it work

if value (on[index] ) on it alert on

if value off it alert off

 

but it call window.plugins.flashlight.switchOn(onSuccess, onError); that function it does not work

 

i added

this function 

 

var onSuccess = function (msg) { alert(msg) };
var onError = function (msg) { alert( msg) }; 

 

but it does not give any alert......

0
huseyin celik
Top achievements
Rank 1
answered on 19 Apr 2015, 08:44 PM

this plugin does not work with for

 

for example

function flashlightDemo1(on) {

for (i = 0; i < 4; i++) {





if(i===3)

{​

window.plugins.flashlight.switchOn(onSuccess, onError);

}

else 

{

 window.plugins.flashlight.switchOff(onSuccess, onError);

}​




    
}
}  

 

why this not work 

0
Tsvetina
Telerik team
answered on 21 Apr 2015, 12:10 PM
Hello Hüseyin,

You did not say if you test this directly on a device or in the companion app. Note that custom plugins do not work in the companion app and you need to deploy the app directly on the device.

Additonally, if you are using the Windows client or the Visual Studio extension and your app is running on a connected device, you can check the Output window for any runtime errors.

You can learn more about the debugging options in AppBuilder here:
Debugging Your Code

Regards,
Tsvetina
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
0
huseyin celik
Top achievements
Rank 1
answered on 21 Apr 2015, 12:23 PM

i test in my iphone-device

normal on-off work very well but this not work

 

function flashlightDemo1(on) {

for (i = 0; i < 4; i++) {





if(i===3)

{​

window.plugins.flashlight.switchOn(onSuccess, onError);

}

else 

{

 window.plugins.flashlight.switchOff(onSuccess, onError);

}​




    
}
}  

are there any problem with this?with for it does not work

0
Tsvetina
Telerik team
answered on 24 Apr 2015, 09:11 AM
Hello Hüseyin,

I tested the plugin on my side on an Android 4.4.4 device and an iPhone 5s and the flashlight switched on and off as expected. I am attaching my test project to this message. Am I missing anything out in trying to reproduce the issue? 

Regards,
Tsvetina
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
Tags
General Discussion
Asked by
huseyin celik
Top achievements
Rank 1
Answers by
huseyin celik
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or