Search in sources :

Example 31 with Log

use of com.codename1.io.Log in project CodenameOne by codenameone.

the class TestUtils method pointerRelease.

/**
 * A component release on a given named component at x/y where x and y are <b>NOT pixels</b>
 * but rather a number between 0 to 1 representing the percentage within the component where the
 * event took place. E.g. For a 100x100 component a press within 10,5 would be 0.1f, 0.05f.
 * @param x the offset within the component as a number between 0 and 1
 * @param y the offset within the component as a number between 0 and 1
 * @param componentName the name of the component
 */
public static void pointerRelease(float x, float y, String componentName) {
    if (verbose) {
        log("pointerRelease(" + x + ", " + y + ", " + componentName + ")");
    }
    Component c = findByName(componentName);
    int actualX = c.getAbsoluteX() + (int) (x * c.getWidth());
    int actualY = c.getAbsoluteY() + (int) (y * c.getHeight());
    Display.getInstance().getCurrent().pointerReleased(actualX, actualY);
    waitFor(30);
}
Also used : Component(com.codename1.ui.Component)

Example 32 with Log

use of com.codename1.io.Log in project CodenameOne by codenameone.

the class TestUtils method assertLabel.

/**
 * Asserts that we have a label with the given text baring the given name
 * @param text the text of the label
 */
public static void assertLabel(String text) {
    if (verbose) {
        log("assertLabel(" + text + ")");
    }
    Label l = findLabelText(text);
    assertBool(l != null, "Null label " + text);
}
Also used : Label(com.codename1.ui.Label)

Example 33 with Log

use of com.codename1.io.Log in project CodenameOne by codenameone.

the class TestUtils method goBack.

/**
 * Executes the back command for the current form, similarly to pressing the back button
 */
public static void goBack() {
    if (verbose) {
        log("goBack()");
    }
    Form f = Display.getInstance().getCurrent();
    Command c = f.getBackCommand();
    assertBool(c != null, "The current form doesn't have a back command at this moment! for form name " + f.getName());
    f.dispatchCommand(c, new ActionEvent(c, ActionEvent.Type.Command));
    waitFor(20);
}
Also used : Form(com.codename1.ui.Form) Command(com.codename1.ui.Command) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 34 with Log

use of com.codename1.io.Log in project CodenameOne by codenameone.

the class TestUtils method assertTextAreaStartingWith.

/**
 * Asserts that we have a TextArea with the a text starting with the given text and with the given name
 * @param name the name of the TextArea
 * @param text the prefix to search for in the TextArea
 */
public static void assertTextAreaStartingWith(String name, String text) {
    if (verbose) {
        log("assertTextAreaStartingWith(" + name + ", " + text + ")");
    }
    TextArea l = (TextArea) findByName(name);
    assertBool(l != null, "Null area " + text);
    assertBool(l.getText().startsWith(text), "assertTextArea: \"" + l.getText() + "\" is not starting with: \"" + text + "\"");
}
Also used : TextArea(com.codename1.ui.TextArea)

Example 35 with Log

use of com.codename1.io.Log in project CodenameOne by codenameone.

the class TestUtils method pointerPress.

/**
 * A component press on a given named component at x/y where x and y are <b>NOT pixels</b>
 * but rather a number between 0 to 1 representing the percentage within the component where the
 * event took place. E.g. For a 100x100 component a press within 10,5 would be 0.1f, 0.05f.
 * @param x the offset within the component as a number between 0 and 1
 * @param y the offset within the component as a number between 0 and 1
 * @param componentName the name of the component
 */
public static void pointerPress(float x, float y, String componentName) {
    if (verbose) {
        if (componentName == null) {
            log("pointerPress(" + x + ", " + y + ", null)");
        } else {
            log("pointerPress(" + x + ", " + y + ", " + componentName + ")");
        }
    }
    waitFor(20);
    if (componentName != null) {
        Component c = findByName(componentName);
        int actualX = c.getAbsoluteX() + (int) (x * c.getWidth());
        int actualY = c.getAbsoluteY() + (int) (y * c.getHeight());
        Display.getInstance().getCurrent().pointerPressed(actualX, actualY);
    } else {
        Display.getInstance().getCurrent().pointerPressed((int) (x * Display.getInstance().getDisplayWidth()), (int) (y * Display.getInstance().getDisplayHeight()));
    }
    waitFor(10);
}
Also used : Component(com.codename1.ui.Component)

Aggregations

Component (com.codename1.ui.Component)9 IOException (java.io.IOException)9 TextArea (com.codename1.ui.TextArea)8 Label (com.codename1.ui.Label)4 InputStream (java.io.InputStream)4 Button (com.codename1.ui.Button)3 Form (com.codename1.ui.Form)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ParseException (java.text.ParseException)3 Date (java.util.Date)3 TimerTask (java.util.TimerTask)3 Cursor (android.database.Cursor)2 Address (com.codename1.contacts.Address)2 Contact (com.codename1.contacts.Contact)2 BufferedInputStream (com.codename1.io.BufferedInputStream)2 Location (com.codename1.location.Location)2 Command (com.codename1.ui.Command)2 ActionEvent (com.codename1.ui.events.ActionEvent)2 SimpleDateFormat (java.text.SimpleDateFormat)2