leecrossley / cordova-plugin-shake

Cordova / PhoneGap Plugin to detect when a physical device performs a shake gesture
http://ilee.co.uk
92 stars 33 forks source link

shake event not firing state change after state change shake is working in ionic can you please help me #28

Open mganigapeta opened 7 years ago

mganigapeta commented 7 years ago

this is my code:

if(!$window.localStorage.Shakecount){ $window.localStorage.setItem('Shakecount', 1); } if(!$window.localStorage.themecolor){ $window.localStorage.setItem('themecolor', "awesome_blue"); }

$scope.themecolor = $window.localStorage.getItem("themecolor");
var indexcount = $window.localStorage.getItem("Shakecount");

var onShake =  function() {
    alert("afterloadedok");
    switch(indexcount){
        case "1":
            var index = parseInt(indexcount) + 1;
            $scope.themecolor = "royal_pink";
            alert(index);
            alert($scope.themecolor);
            $window.localStorage.setItem('Shakecount', index);
            $window.localStorage.setItem('themecolor', $scope.themecolor);
            shake.stopWatch();
            $window.location.reload();
            break;
        case "2":
            var index = 1;
            $scope.themecolor = "awesome_blue";
            alert(index);
            alert($scope.themecolor);
            $window.localStorage.setItem('Shakecount', index);
            $window.localStorage.setItem('themecolor', $scope.themecolor);
            shake.stopWatch();
            $window.location.reload();
            break;

        default:
            index = 1;
            $scope.themecolor = "awesome_blue";
            alert(indexcount);
            alert($scope.themecolor);
            $window.localStorage.setItem('Shakecount', index);
            $window.localStorage.setItem('themecolor', $scope.themecolor);
            shake.stopWatch();
            $window.location.reload();
            break;
    }
}

if(window.shake) shake.startWatch(onShake,40);
Ritzlgrmft commented 7 years ago

What is your problem? Do you see the first alert "afterloadedok" when you shake the device? If yes then there is something wrong in your function...

mganigapeta commented 7 years ago

first time not coming when click on any button or navigation then only you can able do shake event

Ritzlgrmft commented 7 years ago

Do you wait for Cordova's deviceready event before calling shake.startWatch?

mganigapeta commented 7 years ago

yes i waited

Ritzlgrmft commented 6 years ago

Have a look at https://github.com/Ritzlgrmft/ionic-feedback-sample, an app using the shake event