I am attempting(and failing) to insert elements into every page visited. I am only able to insert elements into the initial page(the page displayed after the add-on has been installed). The code snippet below demonstrates this behaviour.
I have tried placing the logic that inserts the H1 element within onOpenWindow(), although that doesn't seem to make any difference.
NOTE: The code below is in addition to template boilerplate code
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import('resource://gre/modules/Services.jsm');
function loadIntoWindow(window) {
if (!window)
return;
window.NativeWindow.toast.show("Inserting script", "short");
var contentWindow = window.BrowserApp.selectedBrowser.contentWindow;
var document = contentWindow.document;
document.body.innerHTML = "<h1>THIS TEXT WAS INSERTED</h1>";
}
var DOMWindows = Services.wm.getEnumerator('navigator:browser');
while (DOMWindows.hasMoreElements()) {
var aDOMWindow = DOMWindows.getNext();
var allTabs = aDOMWindow.BrowserApp._tabs;
for (var i=0; i<allTabs.length; i++) {
var aContentWindow = allTabs[i].window;
}
}
Related
I am working on Protractor with Android hybrid app. I am trying to count the elements and Retrieve and display all the elements. I am able to get the count of the elements. But when I try to display, the For loop is not getting executed, nor gives any Error.
Kindly Advise. Here's my code below.
var n1 = browser.element.all(by.className('program-details-directive-container')).count();
browser.element.all(by.className('program-details-directive-container')).
then( function(n1)
{
for(var i=0; i<n1; ++i)
{
n1(i).getText().then( function(text1)
{
console.log(text1);
})
}
});
It looks the promise chain is not continuing try the following with the help of bluebird
var Promise = require('bluebird');
var n1 = browser.element.all(by.className('program-details-directive-container')).count();
browser.element.all(by.className('program-details-directive-container'))
.then(function(n1) {
var promises = n1.map(function(elm){
return elm.getText().then( function(text1) {
console.log(text1);
})
});
return Promise.all(promises);
});
});
I'm stuck to a rather simple solution, with my script translated run in Android with Unity3d. I'm having a gameObject "Cube" and a js script attached for rotation.
Also I' m having a script "ClickButton.js" attached to a GUI.Texture. Everything works o.k. in Unity Player, but I want to translate this script to be used by touches in Android devices. Problem is I can't do it, although I have read the Unity documentation.
Here is the code snippet:
//This script is attached on a GUI.Texture acting as a button
var normalTexture : Texture2D;
var hoverTexture : Texture2D;
function Update(){
for (var i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch(i).phase == TouchPhase.Began)
var rotate = Input.GetTouch(i);
rotate == doRotate();
}
}
}
function OnMouseEnter(){
guiTexture.texture = hoverTexture;
}
function OnMouseExit(){
guiTexture.texture = normalTexture;
}
function OnMouseDown(){
var runScriptRotate : GameObject[] = GameObject.FindGameObjectsWithTag("Marker");
for(var doRotation : GameObject in runScriptRotate){
var scriptRT : doRotate = doRotation.GetComponent(doRotate);
if(scriptRT){
// access the function "doRotation" on a script named "doRotate" on gameObject "Cube"
doRotate.doRotation();
}
}
}
Can somebody, be kind enough to edit this code script, so to make it work on Android by touching? Thank you all in advance!
Why don't you just copy the contents of OnMouseDown()? Basically touch is the same as mouse down on android devices, isn't it?
if(Input.touchCount > 0){
if(Input.GetTouch(0).phase == TouchPhase.Began){
var runScriptRotate : GameObject[] = GameObject.FindGameObjectsWithTag("Marker");
for(var doRotation : GameObject in runScriptRotate){
var scriptRT : doRotate = doRotation.GetComponent(doRotate);
if(scriptRT){
// access the function "doRotation" on a script named "doRotate" on gameObject "Cube"
doRotate.doRotation();
}
}
}
}
I am new to Unity so a well stepped out answer would be nice. I am trying to make a dice roller on an Android platform. I was following this very well put together tutorial http://games.ucla.edu/resource/unity-1-beginner-tutorial-dice-making-pt-1/ (There is a second part too)
The problem is that it was made for a Web Player. If I try to build it for Android I get two particular errors.
I have two simple scripts with one error associated with each one.
SideTrigger.js - Error: BCE0019: 'currentValue' is not a member of 'UnityEngine.Component'.
public var faceValue = 0;
function OnTriggerEnter( other : Collider ) {
var dieGameObject = GameObject.Find("SixSidedDie");
var dieValueComponent = dieGameObject.GetComponent("DieValue");
dieValueComponent.currentValue = faceValue; //ERROR HERE
Debug.Log("Die1: " + faceValue);
}
DieValue.js - Error: BCE0019: 'text' is not a member of 'UnityEngine.Component'.
public var currentValue = 0;
function Update () {
var dieTextGameObject = GameObject.Find("DieText");
var textMeshComponent = dieTextGameObject.GetComponent("TextMesh");
textMeshComponent.text = currentValue.ToString(); //ERROR HERE
}
I'm assume it's purely a syntactical issue, but I can't seem to find a solution.
GetComponent using string is not recommended due to performance reasons, it is documented here.
It is better to use this:
var dieValueComponent : DieValue = dieGameObject.GetComponent(DieValue)
Or this:
var dieValueComponent : DieValue = dieGameObject.GetComponent.<DieValue>()
See if that works.
How to pull to refresh?
In Titanium appcelerator I need to show a list of content in tableview. If I pull the view it needs to update. In iPhone I complete but in Android it won't work. Please any one help to solve this problem in Android.
My Android code:-
tableView.addEventListener('scroll',function(e)
{
var offset = e.contentOffset.y;
if (offset < -65.0 && !pulling && !reloading)
{
var t = Ti.UI.create2DMatrix();
t = t.rotate(-180);
pulling = true;
arrow.animate({transform:t,duration:180});
statusLabel.text = "Release to refresh...";
}
else if((offset > -65.0 && offset < 0 ) && pulling && !reloading)
{
pulling = false;
var t = Ti.UI.create2DMatrix();
arrow.animate({transform:t,duration:180});
statusLabel.text = "Pull down to refresh...";
}
});
tableView.addEventListener('dragEnd', function(e)
{
if(pulling && !reloading)
{
reloading = true;
pulling = false;
arrow.hide();
actInd.show();
statusLabel.text = "Reloading...";
tableView.setContentInsets({top:60},{animated:true});
tableView.scrollToTop(-60,true);
arrow.transform=Ti.UI.create2DMatrix();
beginReloading();
}
});
Titanium now supports pull to refresh for BOTH Android (> v6.2.0) and iOS (>3.2.0) with a Titanium.UI.TableView, Titanium.UI.ListView or Titanium.UI.ScrollView object.
See the docs:
https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.ListView
https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.RefreshControl
Sample code taken from the docs:
var win = Ti.UI.createWindow({
fullscreen:true
});
var counter = 0;
function genData() {
var data = [];
for (var i=1; i<=3; i++) {
data.push({properties:{title:'ROW '+(counter+i)}})
}
counter += 3;
return data;
}
var section = Ti.UI.createListSection();
section.setItems(genData());
var control = Ti.UI.createRefreshControl({
tintColor:'red'
})
var listView = Ti.UI.createListView({
sections:[section],
refreshControl:control
});
control.addEventListener('refreshstart',function(e){
Ti.API.info('refreshstart');
setTimeout(function(){
Ti.API.debug('Timeout');
section.appendItems(genData());
control.endRefreshing();
}, 2000);
})
win.add(listView);
win.open();
Is this just the IOS code form the Kitchen Sink example?
There are a couple of attempts at getting this working on Android, though I haven't confirmed that any of them work as expected. From what I understand, the problem is that you can't get the offset the same way in Android as in IOS.
A quick Google search turned up this link, which was referenced from the official Appcelerator forums.
https://gist.github.com/903895
I've created one App using Phonegap and HTML5 (jqueryMobile). I've put rotate3D for one div,
it is working fine in google chrome and Safari, but it is not working in Android 2.3+
Any suggestion?
I think It is a bug of android browser. I make a function to test if rotate3d is supported and it says Yes:
function styleSupport( prop )
{
var vendorProp;
var supportedProp;
// capitalize first character of the prop to test vendor prefix
var capProp = prop.charAt(0).toUpperCase() + prop.slice(1);
var prefixes = [ "Moz", "Webkit", "O", "ms" ];
var div = document.createElement( "div" );
if ( prop in div.style )
{
//browser supports standard CSS property name
supportedProp = prop;
}
else
{
//otherwise test support for vendor-prefixed property names
for ( var i = 0; i < prefixes.length; i++ )
{
vendorProp = prefixes[i] + capProp;
if ( vendorProp in div.style )
{
supportedProp = vendorProp;
break;
}
}
}
// avoid memory leak in IE
div = null;
return supportedProp;
}
alert(styleSupport('perspective'));
alert(styleSupport('transform'));
As you can see her, CSS transforms3D are not supported by Android 2.3 :
http://caniuse.com/#feat=transforms3d
try to upgrade to Android 4 (it works for me)