Search in sources :

Example 6 with Log

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

the class DefaultCrashReporter method init.

/**
 * Installs a crash reporter within the system
 * @param promptUser indicates whether the user should be prompted on crash reporting
 * @param frequency the frequency with which we send the log to the server in debug mode in minutes
 * frequency must be at least 1. Any lower level automatically disables this feature
 */
public static void init(boolean promptUser, int frequency) {
    if (Preferences.get("$CN1_crashBlocked", false) || Log.getReportingLevel() == Log.REPORTING_NONE) {
        return;
    }
    if (Preferences.get("$CN1_pendingCrash", false)) {
        // we must have crashed during a report, send it.
        Log.sendLog();
        Preferences.set("$CN1_pendingCrash", false);
    }
    if (Log.getReportingLevel() == Log.REPORTING_DEBUG && frequency > 0) {
        java.util.Timer t = new java.util.Timer();
        t.schedule(new TimerTask() {

            public void run() {
                if (!Display.getInstance().isEdt()) {
                    Display.getInstance().callSerially(this);
                    return;
                }
                Log.sendLog();
            }
        }, frequency * 60000, frequency * 60000);
    }
    DefaultCrashReporter d = new DefaultCrashReporter();
    d.promptUser = promptUser && Preferences.get("$CN1_prompt", true);
    Display.getInstance().setCrashReporter(d);
}
Also used : UITimer(com.codename1.ui.util.UITimer) TimerTask(java.util.TimerTask)

Example 7 with Log

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

the class TestUtils method ensureVisible.

/**
 * Scrolls to show the component in case it is invisible currently
 * @param c the component
 */
public static void ensureVisible(Component c) {
    if (verbose) {
        log("ensureVisible(" + c + ")");
    }
    Form f = Display.getInstance().getCurrent();
    f.scrollComponentToVisible(c);
}
Also used : Form(com.codename1.ui.Form)

Example 8 with Log

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

the class TestUtils method setText.

/**
 * Sets the text for the given component
 * @param name the name of the component
 * @param text the text to set
 */
public static void setText(String name, String text) {
    if (verbose) {
        log("setText(" + name + ", " + text + ")");
    }
    Component c = findByName(name);
    if (c instanceof Label) {
        ((Label) c).setText(text);
        return;
    }
    ((TextArea) c).setText(text);
    Display.getInstance().onEditingComplete(c, text);
}
Also used : TextArea(com.codename1.ui.TextArea) Label(com.codename1.ui.Label) Component(com.codename1.ui.Component)

Example 9 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 path the path to the component
 */
public static void pointerRelease(float x, float y, int[] path) {
    if (verbose) {
        log("pointerRelease(" + x + ", " + y + ", " + toString(path) + ")");
    }
    Component c = getComponentByPath(path);
    int actualX = c.getAbsoluteX() + (int) (x * c.getWidth());
    int actualY = c.getAbsoluteY() + (int) (y * c.getHeight());
    Display.getInstance().getCurrent().pointerReleased(actualX, actualY);
    waitFor(10);
}
Also used : Component(com.codename1.ui.Component)

Example 10 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 path the path to the component
 */
public static void pointerPress(float x, float y, int[] path) {
    if (verbose) {
        log("pointerPress(" + x + ", " + y + ", " + toString(path) + ")");
    }
    Component c = getComponentByPath(path);
    int actualX = c.getAbsoluteX() + (int) (x * c.getWidth());
    int actualY = c.getAbsoluteY() + (int) (y * c.getHeight());
    Display.getInstance().getCurrent().pointerPressed(actualX, actualY);
    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