Java Code Examples for com.codename1.ui.Display#getInstance()

The following examples show how to use com.codename1.ui.Display#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidLocationPlayServiceManager.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
private void setupBackgroundLocationRequest(LocationRequest req) {
    Display d = Display.getInstance();
    String priorityStr = d.getProperty("android.backgroundLocation.priority", "PRIORITY_BALANCED_POWER_ACCURACY");
    String fastestIntervalStr = d.getProperty("android.backgroundLocation.fastestInterval", "5000");
    String intervalStr = d.getProperty("android.backgroundLocation.interval", "10000");
    String smallestDisplacementStr = d.getProperty("android.backgroundLocation.smallestDisplacement", "50");

    int priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
    if ("PRIORITY_HIGH_ACCURACY".equals(priorityStr)) {
        priority = LocationRequest.PRIORITY_HIGH_ACCURACY;
    } else if ("PRIORITY_LOW_POWER".equals(priorityStr)) {
        priority = LocationRequest.PRIORITY_LOW_POWER;
    } else if ("PRIORITY_NO_POWER".equals(priorityStr)) {
        priority = LocationRequest.PRIORITY_NO_POWER;
    }

    long interval = Long.parseLong(intervalStr);
    long fastestInterval = Long.parseLong(fastestIntervalStr);
    int smallestDisplacement = Integer.parseInt(smallestDisplacementStr);

    req.setPriority(priority)
            .setFastestInterval(fastestInterval)
            .setInterval(interval)
            .setSmallestDisplacement(smallestDisplacement);
}
 
Example 2
Source File: InPlaceEditView.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public static void setEditedTextField(final TextArea textarea) {
    Display display = Display.getInstance();
    Runnable task = new Runnable(){
        public void run() {
            AndroidImplementation.getInstance().setFocusedEditingText(textarea);
        }
    };
    if (display.isEdt()) {
        task.run();
    } else {
        display.callSeriallyAndWait(task);
    }
}
 
Example 3
Source File: Canvas.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public Canvas(){
    Display d = Display.getInstance();
    bounds = new Rectangle(0,0, d.getDisplayWidth(), d.getDisplayHeight());
    absoluteX = bounds.getX();
    absoluteY = bounds.getY();
    
}
 
Example 4
Source File: Switch.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
void fireActionEvent() {
    dispatcher.fireActionEvent(new ActionEvent(this, ActionEvent.Type.PointerPressed));
    Display d = Display.getInstance();
    if (d.isBuiltinSoundsEnabled()) {
        d.playBuiltinSound(Display.SOUND_TYPE_BUTTON_PRESS);
    }
}
 
Example 5
Source File: SplitPane.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Dimension calcPreferredSize() {
    Display d = Display.getInstance();
    switch (orientation) {
        case VERTICAL_SPLIT : return new Dimension(d.getDisplayWidth(), d.convertToPixels(dividerThicknessMM));
        default: return new Dimension(d.convertToPixels(dividerThicknessMM), d.getDisplayHeight());
    }
}
 
Example 6
Source File: OnOffSwitch.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void fireActionEvent(){
    dispatcher.fireActionEvent(new ActionEvent(this,ActionEvent.Type.PointerPressed));
    Display d = Display.getInstance();
    if(d.isBuiltinSoundsEnabled()) {
        d.playBuiltinSound(Display.SOUND_TYPE_BUTTON_PRESS);
    }
}
 
Example 7
Source File: SolitaireLayout.java    From codenameone-demos with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Dimension getPreferredSize(Container parent) {
    Display d = Display.getInstance();
    return new Dimension(d.getDisplayWidth(), d.getDisplayHeight());
}
 
Example 8
Source File: PerspectiveCamera.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Transform getTransform() {
    Display d = Display.getInstance();
    float zNear = (float)nearClip.get().doubleValue();
    double dw = d.getDisplayWidth();
    double dh = d.getDisplayHeight();
    int x = scene.getAbsoluteX();
    int y = scene.getAbsoluteY();
    int w = scene.getWidth();
    int h = scene.getHeight();
    Transform perspectiveT = Transform.makePerspective((float)verticalFieldOfView.get().doubleValue(), (float)(dw/dh), zNear, (float)farClip.get().doubleValue());
    float displayH = Display.getInstance().getDisplayHeight();
    float displayW = (float)dw;
    //double midX = (float)x+(float)w/2.0;
    //double midY = (float)y+(float)h/2.0;

    //if (perspectiveT == null) {
    //    perspectiveT = Transform.makeIdentity();
    //}
    //makePerspectiveTransform(perspectiveT);
    float[] bottomRight = perspectiveT.transformPoint(new float[]{displayW, displayH, zNear});
    Transform currTransform = Transform.makeIdentity();



    float xfactor = -displayW/bottomRight[0];
    float yfactor = -displayH/bottomRight[1];

    currTransform.translate((float)dw/2, y+h/2, zNear);
    currTransform.scale(xfactor,yfactor,1f);

    //currTransform.translate((float)dw/2/xfactor, (y+h/2)/yfactor, 0);

    currTransform.concatenate(perspectiveT);
    float zState = 0f;
    float cameraZ = -zNear-w/2*zState;
    float cameraX = (float)-dw/2;//-x-w/2;
    float cameraY = -y-h/2;
    currTransform.translate(cameraX, cameraY, cameraZ);

    //if ( transitionState == STATE_FLIP){
    //currTransform.translate((float)midX, y, 0);
    //}
    float[] tl = new float[3];
    float[] tr = new float[3];
    float[] bl = new float[3];
    float[] br = new float[3];
    currTransform.transformPoint(new float[]{x, y, 0}, tl);
    currTransform.transformPoint(new float[]{x+w, y, 0}, tr);
    currTransform.transformPoint(new float[]{x+w, y+h, 0}, br);
    currTransform.transformPoint(new float[]{x, y+h, 0}, bl);
    System.out.println("Camera transform "+x+", "+y+", "+0+"->"+Arrays.toString(tl));
    System.out.println("Camera transform "+(x+w)+", "+y+", "+0+"->"+Arrays.toString(tr));
    System.out.println("Camera transform "+(x+w)+", "+(y+h)+", "+0+"->"+Arrays.toString(br));
    System.out.println("Camera transform "+(x)+", "+(y+h)+", "+0+"->"+Arrays.toString(bl));

    return currTransform;
}
 
Example 9
Source File: CommonTransitions.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
private Image createMutableImage(int w, int h) {
    Display d = Display.getInstance();
    return Image.createImage(Math.min(d.getDisplayWidth(), w), Math.min(d.getDisplayHeight(), h));
}
 
Example 10
Source File: FlipTransition.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
private Image createMutableImage(int w, int h) {
    Display d = Display.getInstance();
    return Image.createImage(Math.min(d.getDisplayWidth(), w), Math.min(d.getDisplayHeight(), h));
}
 
Example 11
Source File: BubbleTransition.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
private Image createMutableImage(int w, int h) {
    Display d = Display.getInstance();
    return Image.createImage(Math.min(d.getDisplayWidth(), w), Math.min(d.getDisplayHeight(), h));
}
 
Example 12
Source File: BorderLayout.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
private boolean isLandscape() {
    Display d = Display.getInstance();
    return !d.isPortrait();
}
 
Example 13
Source File: SignatureComponent.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Dimension calcPreferredSize() {
    Display d = Display.getInstance();
    return new Dimension(d.convertToPixels(100, true), d.convertToPixels(60, false));
}