turn on android LED light "enabletorch" for X amount of time? - led

I have the code below that turns ON my phones LED flash every time the button is clicked, but I also need the LED to turn OFF automatically after 3 seconds. Not sure how to do it, please help.
input type="button" onclick="ipwajax('enabletorch')" value="Turn on LED"

Assuming ipwajax('enabletorch') enables the LED, and ipwajax('disabletorch') disables it, you would want something like
<script language="JavaScript">
function enableTorch(milliSeconds) {
ipwajax('enabletorch');
window.setTimeout("ipwajax('disabletorch');",milliSeconds);
}
</script>
<input type="button" onclick="enableTorch(3000);" value="Turn on LED">

Related

Angular not updating list fast enough

I have a list of 'cards' that when a filter is selected on the left side of the screen, the cards shown in the middle of the screen will update accordingly. Here is a snippet of the js:
$scope.isReady = false;
// This is an async method to retrieve from DB
AssignmentManagerService.getAssignmentsForClass(teacherId, classId).success(function(response) {
var instances = response.instances;
$scope.assignmentListData = instances;
$scope.isReady = true;
});
And here is a piece of the template:
<div flex class="item-list" ng-if="isReady">
<md-card ng-repeat="assign in assignmentListData track by assign.instanceId"
ng-click="selectCard(assign)"
class="item-list-item"
style="font-size:16px;"
ng-class="getCardClass(assign)"
ng-style="getCardStyle(assign)">
<div>
<span style='font-weight:500'>Title</span>: {{assign.title}}
</div>
<div style="margin-top:10px;">
<span style='font-weight:500' ng-if="assign.availableDate">Available Date:</span> {{assign.availableDate | date:'fullDate'}}
<span style='font-weight:500' ng-if="assign.createDate">Create Date:</span> {{assign.createDate | date:'fullDate'}}
</div>
</md-card>
</div>
One of two things will happen: I will either get two sections of cards on top of each other, one section with the old selection and one section with the new selection, for a half second before the old selection is removed OR the cards will all be integrated before the old cards are removed. All of this happens within the time span of a second but looks very unprofessional and ugly.
What is supposed to occur is the user makes a filter selection, the cards immediately hide, the new data is retrieved, and the new cards are shown. No overlapping, no multiple groups.
Here's what I have done:
Wrapped the async method/success into a $timeout function: Didn't work. Same results.
Wrapped the async method/success into a $scope.$$postDigest function: Didn't work. Same results.
Added a 400ms thread sleep in the back-end: While it does work, I'm not inserting a back-end fix for a front-end problem.
Tried various combinations of ng-if/ng-show on the div and the md-card: Didn't work. Same results.
The template was originally ~500 lines. I have stripped out all the extraneous markup except for this card bit to see if it was the digest cycle taking too long. Didn't work. Same results.
Any help would be greatly appreciated. Thanks!
Wow. My coworker and I just found some really old and buried CSS animations that were affecting the list in question. After removing them, everything works as it should. Doh! I'd like to thank #The.Bear and #JBNizet for pointing me in the right direction on this!

Angular 2 digest fails at executing a function, or finding a change at an object's property

I have absolutely no idea on what's going on; my two theories are already in the title. Thing is, this should be working, but somehow one of the core parts of Angular, the digest cycle, is failing hard.
What I want to do, and how I did it
A comments section that is instantiated in a parent view, when you click a button. Then the comments appear, and they behave similarly to Reddit's: you can upvote or downvote them. Pretty much the same! So I just added some with the arrows, and the rating of the comments between them:
<div class="rating">
<ion-row>
<button class="nocolor" (click)="rateComment(comment, true)">
<ion-icon large name="arrow-up" [color]="isRated(comment.rated, 1)"></ion-icon>
</button>
</ion-row>
<ion-row>
<span [style.margin-left]="pointsMargin(comment.rating)">{{comment.rating}}</span>
</ion-row>
<ion-row>
<button class="nocolor" (click)="rateComment(comment, false)">
<ion-icon large name="arrow-down" [color]="isRated(comment.rated, 2)"></ion-icon>
</button>
</ion-row>
</div>
As you can see, when I click in the icons, they execute the "rateComment" function, which is:
rateComment(comment, liked){
if (liked==true){
comment.rating++;
comment.rated=1;
//register like
}else{
comment.rating--;
comment.rated=-1;
//register unlike
}
}
Ok, pretty straightforward. Now that the object's property is properly changed, we should somehow change the icon's color from the default gray-like color, to something more like amber. This works perfectly when the data is first represented: you see the voted comments with the proper arrow, proper colored. Great. But if you click in the arrow, the color doesn't change.
The function that chooses the color of the icon, which works good at start but fails when updating the view, is this one:
isRated(value, component){
if(component == 1 && value == 1){
return 'amber';
}else if(component == 2 && value == -1){
return 'amber';
}
}
Basically, as you can see, the upper arrow uses 1 as component value and the down arrow uses 2, just to reuse the function.
So, what's the problem?
As I already said, the problem I'm having here, is that either the "isRated" function is not being executed in the digest's cycle, or that the change os the ion-icon color is not working, or the property change of the object does not trigger a view update. I just don't know what's going on; but something is failing hard and I can't find any error in my code.
EDIT: the "isRated" function executed, BUT with the old value, like if the new one doens't get registered in the object. This is odd, since it actually gets changed in the "rateComment" function.

on-hold also firing ng-click on Samsung phones

I have two functions openMenu() and openItem()
* If i click on item it will activate ng-click with openItem()
* If i hold, it will trigger on-hold with openMenu() calling $ionicActionSheet.show({.....});
It works fine on Motorola and Asus devices, but Samsung is firing twice.
Is it opening the menu and opening the item (causing the change of the view and closing menu at once)
Any solutions?
PS:
I'm using Ionic Framework
I have discovered something.. If you hold and stay with your finger in the same point before move up yout finger, it will occurs, BUT.. if you do a litte swipe (move to any side, just 1mm movement) it will not!
I had the same problem and found the solution.i code as bellow.
<div ng-repeat="array in location.location track by $id($index)">
<div on-hold="array.qty = 0;array.showInput=true" on-release="array.showInput=false">
<label ng-show="!showDisabled(array.showInput)" ng-bind="array.qty" ng-click="$event.preventDefault();$event.stopPropagation();array.qty = array.qty + 1;></label>
<label ng-show="showDisabled(array.showInput)" ng-bind="array.qty"></label>
</div>
</div>
if i directly write ng-show="array.showIput" AND ng-show="!array.showIput" then ng-click fire after on-hold.
So i took two label one show after on-hold, without click-able label the other label with click-able and show it using the function. Then function is
$scope.showDisabled = function(val){
setTimeout(function(){
if(val){return true;}
else{return false;}
});
}

Angular show on click

<button ng-show="color.show" ng-click="addNewColor(color);color.show=false;">Add this color to mine collection</button>
I have this code and when i click on that button, button does not disappear. When I go somewhere else and come back into that template(i am using angularUI router) that button disappears. color.show define variable is true.
You probably have a js error in this expression:
addNewColor(color);
Look at this fiddle example and see that everything works correctly if there are no js errors.
I have made a sample program for your code here.
<body ng-app="myApp">
<div ng-controller="myController">
<button ng-show="color.show" ng-click="addColor(color);color.show=false;">Add this color to mine collection</button>
</div>
</body>
As it is, this code is working, you might have written some code in addColor() that might be breaking your code.

toggle skips/misses 2nd sidebar

Today's bogglement! I have two sidebars and a main content area. When I click on a button to expand the page, the sidebars should go away and the main content area spreads to 100%. (I'm trying to do something like what quandl.com does in its api displays, which is totally nifty.)
This should be really simple! I just add a class of 'apponly', which set the main-content to 100% and the sidebars to display:none. In my controller, I've got:
$scope.toggle = function() {
$scope.displayed = !$scope.displayed;
}
and in my html, I've got basically:
<div class="sidebar left" ng-class="{'apponly' : displayed }">
--something something--
</div>
<div class="main-content" ng-class="{'apponly' : displayed }">
<button class="btn btn-info device" ng-click="toggle()">[icon]</button>
--something something--
</div>
<div class="sidebar right" ng-class="{'apponly' : displayed }">
--something something--
</div>
...but it consistently only applies the class 'apponly' to the first sidebar and main content, and leaves the second sidebar intact (wrapped around to the next line, but still right there, w/no class of 'apponly' applied).
I tried to set up a plnk (http://plnkr.co/edit/ER4TPGexGnZ8knb4ThXQ?p=preview) but it won't work at all [okay that was a stupid oversight, now it does work except now I'm even more confused]. What really simple obvious thing am I totally missing here?
many thanks in advance!
AS PSL said, juste update your plunkr to <body ng-app="app" ng-controller="mainController"> and it will work. It actually does what you were expecting, so the issue is probably somewhere else.
Welp, I might as well answer since I (sort of) figured it out, and you never know, I might not be the only one baffled by such behavior.
It's tied to the animation. If you take the animation away, then everything behaves. You add it back in, and things get wacky again.
Why is this? I have no idea. But when I took the animation off the sidebars (so they simply disappear immediately), then the right-hand sidebar doesn't get pushed to the next line and end up remaining despite the added-class that should make it disappear. From behavior at least, it seems that the browser is trying to render animation at the same time the css-class is trying to make the section disappear. Which doesn't make any sense, b/c this works fine in other places, but all I know is that if you leave the animation on the main (middle) part, and turn it off on the sidebars, then everything behaves properly.
I'm not counting this as an answer, though, since it's more of a "well, that fixed it, if inadequately," which is less of an answer and more of a workaround left here for posterity, the enlightenment of any confused devs behind me, and the entertainment of any senior devs wandering through.

Resources