Example usage for com.google.gwt.core.client JsArrayInteger push

List of usage examples for com.google.gwt.core.client JsArrayInteger push

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsArrayInteger push.

Prototype

public final native void push(int value) ;

Source Link

Document

Pushes the given integer onto the end of the array.

Usage

From source file:com.ait.toolkit.node.core.JavaScriptUtils.java

License:Open Source License

public static JsArrayInteger toIntegerArray(byte... bytes) {
    JsArrayInteger ret = JavaScriptObject.createArray().cast();
    for (byte byt : bytes) {
        ret.push(byt);
    }/*from  w w  w  .jav a2 s . com*/
    return ret;
}

From source file:com.emitrom.ti4j.mobile.client.media.Media.java

License:Apache License

/**
 * Play a device vibration with the given durationOn Android, a pattern
 * argument can be provided to specify a vibration pattern. The pattern is
 * an array of Number values. Each number in the array is interpreted as a
 * duration in milliseconds. The first number is the delay before the
 * pattern starts, and the remaining numbers are interpreted as alternating
 * periods of on and off times. For example, the following pattern: [ 0,
 * 500, 100, 500, 100, 500 ] Would cause the vibration to start immediately
 * (delay = 0), and perform three long vibrations (500 ms) separated by
 * short pauses (100ms)./*w  w  w.jav  a 2s  . c o m*/
 * 
 * @Android only
 */
public void vibrate(int[] pattern) {
    JsArrayInteger values = JsArrayInteger.createArray().cast();
    for (int i : pattern) {
        values.push(i);
    }
    _vibrate(values);
}

From source file:com.emitrom.ti4j.mobile.client.ui.Window.java

License:Apache License

public void setOrientationModes(int... modes) {
    JsArrayInteger values = JsArrayInteger.createArray().cast();
    for (int mode : modes) {
        values.push(mode);
    }/*w w  w . j  a va  2s  .c  om*/
    setOrientationModes(values);
}

From source file:com.github.gwtcannonjs.demo.client.impl.BunnyDemo.java

License:Open Source License

@Override
public void run() {
    ScriptInjector.fromString(BunnyResource.INSTANCE.source().getText()).inject();

    final Demo demo = CANNON.newDemo();

    demo.addScene("Bunny", new AddSceneCallback() {
        @Override//from ww  w. ja  v  a 2  s  .c om
        public void execute() {
            World world = demo.getWorld();

            world.getGravity().set(0, 0, -20);
            world.setBroadphase(CANNON.newNaiveBroadphase());
            ((GSSolver) world.getSolver().cast()).setIterations(20);
            world.getDefaultContactMaterial().setContactEquationStiffness(1e10);
            world.getDefaultContactMaterial().setContactEquationRelaxation(10);

            JsArray<CustomPolyhedron> bunny = getBunny();

            Body bunnyBody = CANNON.newBody(CANNON.newBodyOptions().withMass(1));
            for (int i = 0; i < bunny.length(); i++) {

                JsArrayNumber rawVerts = bunny.get(i).getVertices();
                JsArrayNumber rawFaces = bunny.get(i).getFaces();
                JsArrayNumber rawOffset = bunny.get(i).getOffset();

                JsArray<Vec3> verts = JsArray.createArray().cast();
                JsArray<JsArrayInteger> faces = JsArray.createArray().cast();
                Vec3 offset;

                // Get vertices
                for (int j = 0; j < rawVerts.length(); j += 3) {
                    verts.push(CANNON.newVec3(rawVerts.get(j), rawVerts.get(j + 1), rawVerts.get(j + 2)));
                }

                // Get faces
                for (int j = 0; j < rawFaces.length(); j += 3) {
                    JsArrayInteger face = JsArray.createArray().cast();
                    face.push((int) rawFaces.get(j));
                    face.push((int) rawFaces.get(j + 1));
                    face.push((int) rawFaces.get(j + 2));
                    faces.push(face);
                }

                // Get offset
                offset = CANNON.newVec3(rawOffset.get(0), rawOffset.get(1), rawOffset.get(2));

                // Construct polyhedron
                Shape bunnyPart = CANNON.newConvexPolyhedron(verts, faces);

                // Add to compound
                bunnyBody.addShape(bunnyPart, offset);
            }

            // Create body
            bunnyBody.getQuaternion().setFromAxisAngle(CANNON.newVec3(1, 0, 0), -Math.PI / 2);
            Quaternion z180 = CANNON.newQuaternion();
            z180.setFromAxisAngle(CANNON.newVec3(0, 0, 1), Math.PI);
            bunnyBody.setQuaternion(z180.mult(bunnyBody.getQuaternion(), null));
            world.addBody(bunnyBody);
            demo.addVisual(bunnyBody);

            // ground plane
            Shape groundShape = CANNON.newPlane();
            Body groundBody = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            groundBody.addShape(groundShape);
            groundBody.getPosition().set(0, 0, -5);
            world.addBody(groundBody);
            demo.addVisual(groundBody);
        }
    });

    demo.start();
}

From source file:com.github.gwtcannonjs.demo.client.impl.ConvexDemo.java

License:Open Source License

private ConvexPolyhedron createTetra() {
    JsArray<Vec3> verts = JsArray.createArray().cast();
    verts.push(CANNON.newVec3(0, 0, 0));
    verts.push(CANNON.newVec3(2, 0, 0));
    verts.push(CANNON.newVec3(0, 2, 0));
    verts.push(CANNON.newVec3(0, 0, 2));
    double offset = -0.35;
    for (int i = 0; i < verts.length(); i++) {
        Vec3 v = verts.get(i);/* www .j  av  a2 s  . c om*/
        v.setX(v.getX() + offset);
        v.setY(v.getY() + offset);
        v.setZ(v.getZ() + offset);
    }
    JsArray<JsArrayInteger> faces = JsArray.createArray().cast();
    JsArrayInteger face = JsArray.createArray().cast();
    face.push(0);
    face.push(3);
    face.push(2);
    faces.push(face); // -x
    face = JsArray.createArray().cast();
    face.push(0);
    face.push(1);
    face.push(3);
    faces.push(face); // -y
    face = JsArray.createArray().cast();
    face.push(0);
    face.push(2);
    face.push(1);
    faces.push(face); // -z
    face = JsArray.createArray().cast();
    face.push(1);
    face.push(2);
    face.push(3);
    faces.push(face); // +xyz

    return CANNON.newConvexPolyhedron(verts, faces);
}

From source file:com.github.nmorel.gwtjackson.client.deser.array.cast.PrimitiveIntegerArrayJsonDeserializer.java

License:Apache License

@Override
public int[] doDeserializeArray(JsonReader reader, JsonDeserializationContext ctx,
        JsonDeserializerParameters params) {
    JsArrayInteger jsArray = JsArrayInteger.createArray().cast();
    reader.beginArray();/*from  ww w .j  a v  a  2s  .  c o  m*/
    while (JsonToken.END_ARRAY != reader.peek()) {
        if (JsonToken.NULL == reader.peek()) {
            reader.skipValue();
            jsArray.push(DEFAULT);
        } else {
            jsArray.push(reader.nextInt());
        }
    }
    reader.endArray();

    if (GWT.isScript()) {
        return reinterpretCast(jsArray);
    } else {
        int length = jsArray.length();
        int[] ret = new int[length];
        for (int i = 0; i < length; i++) {
            ret[i] = jsArray.get(i);
        }
        return ret;
    }
}

From source file:com.github.nmorel.gwtjackson.client.deser.array.cast.PrimitiveShortArrayJsonDeserializer.java

License:Apache License

@Override
public short[] doDeserializeArray(JsonReader reader, JsonDeserializationContext ctx,
        JsonDeserializerParameters params) {
    JsArrayInteger jsArray = JsArrayInteger.createArray().cast();
    reader.beginArray();//from w w  w.j  ava 2s  .c  o  m
    while (JsonToken.END_ARRAY != reader.peek()) {
        if (JsonToken.NULL == reader.peek()) {
            reader.skipValue();
            jsArray.push(DEFAULT);
        } else {
            jsArray.push(reader.nextInt());
        }
    }
    reader.endArray();

    if (GWT.isScript()) {
        return reinterpretCast(jsArray);
    } else {
        int length = jsArray.length();
        short[] ret = new short[length];
        for (int i = 0; i < length; i++) {
            ret[i] = (short) jsArray.get(i);
        }
        return ret;
    }
}

From source file:com.googlecode.gflot.client.jsni.JsArrayUtils.java

License:Apache License

/**
 * Take a Java array, and produce a JS array that is only used for reading.  As
 * this is actually a reference to the original array in prod mode, the source
 * must not be modified while this copy is in use or you will get different
 * behavior between DevMode and prod mode.
 *
 * @param array source array//from ww  w.  j  a  va2s  .  c  om
 * @return JS array, which may be a copy or an alias of the input array
 */
public static JsArrayInteger readOnlyJsArray(byte[] array) {
    if (GWT.isScript()) {
        return arrayAsJsArrayForProdMode(array).cast();
    }
    JsArrayInteger dest = JsArrayInteger.createArray().cast();
    for (int i = 0; i < array.length; ++i) {
        dest.push(array[i]);
    }
    return dest;
}

From source file:com.googlecode.gflot.client.jsni.JsArrayUtils.java

License:Apache License

/**
 * Take a Java array, and produce a JS array that is only used for reading.  As
 * this is actually a reference to the original array in prod mode, the source
 * must not be modified while this copy is in use or you will get different
 * behavior between DevMode and prod mode.
 *
 * @param array source array/*  w  w  w .java2 s .  c  o  m*/
 * @return JS array, which may be a copy or an alias of the input array
 */
public static JsArrayInteger readOnlyJsArray(int[] array) {
    if (GWT.isScript()) {
        return arrayAsJsArrayForProdMode(array).cast();
    }
    JsArrayInteger dest = JsArrayInteger.createArray().cast();
    for (int i = 0; i < array.length; ++i) {
        dest.push(array[i]);
    }
    return dest;
}

From source file:com.googlecode.gflot.client.jsni.JsArrayUtils.java

License:Apache License

/**
 * Take a Java array, and produce a JS array that is only used for reading.  As
 * this is actually a reference to the original array in prod mode, the source
 * must not be modified while this copy is in use or you will get different
 * behavior between DevMode and prod mode.
 *
 * @param array source array//from  w  ww  . jav  a2  s. c om
 * @return JS array, which may be a copy or an alias of the input array
 */
public static JsArrayInteger readOnlyJsArray(short[] array) {
    if (GWT.isScript()) {
        return arrayAsJsArrayForProdMode(array).cast();
    }
    JsArrayInteger dest = JsArrayInteger.createArray().cast();
    for (int i = 0; i < array.length; ++i) {
        dest.push(array[i]);
    }
    return dest;
}