com.codename1.ui.Display Java Examples
The following examples show how to use
com.codename1.ui.Display.
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: TabIteratorSample2775.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); hi.add(new TextField("Text 1")); Picker p1 = new Picker(); p1.setType(Display.PICKER_TYPE_STRINGS); p1.setStrings("Red", "Green", "Blue", "Orange"); hi.add(p1); hi.add(new TextField("Text 2")); CheckBox enableTabsCheckBox = new CheckBox("Enable Tabbing"); enableTabsCheckBox.setSelected(true); enableTabsCheckBox.addActionListener(e->{ $("*", hi).each(c->{ c.setPreferredTabIndex(enableTabsCheckBox.isSelected() ? 0 : -1); }); }); hi.add(enableTabsCheckBox); hi.show(); }
Example #2
Source File: Tree.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ protected Dimension calcPreferredSize() { Dimension d = super.calcPreferredSize(); // if the tree is entirely collapsed try to reserve at least 6 rows for the content int count = getComponentCount(); for(int iter = 0 ; iter < count ; iter++) { if(getComponentAt(iter) instanceof Container) { return d; } } int size = Math.max(1, model.getChildren(null).size()); if(size < 6) { return new Dimension(Math.max(d.getWidth(), Display.getInstance().getDisplayWidth() / 4 * 3), d.getHeight() / size * 6); } return d; }
Example #3
Source File: FacebookImpl.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
@Override public void login() { loginCompleted = false; loginCancelled = false; nativeInterface.facebookLogin(this); Display.getInstance().invokeAndBlock(new Runnable() { public void run() { while(!loginCompleted && !loginCancelled) { try { Thread.sleep(50); } catch(InterruptedException ie) {} } } }); if (loginCancelled) { return; } if(callback != null) { if(isLoggedIn()) { FaceBookAccess.setToken(getToken()); callback.loginSuccessful(); } else { callback.loginFailed(""); } } }
Example #4
Source File: WKWebViewTest.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } hi = new Form("Hi World", BoxLayout.y()); Button a = new Button("Show old webview"); a.addActionListener((e) -> { Display.getInstance().setProperty("BrowserComponent.useWKWebView", "false"); showWebView(); }); Button b = new Button("Show WKwebview"); b.addActionListener((e) -> { Display.getInstance().setProperty("BrowserComponent.useWKWebView", "true"); showWebView(); }); hi.add(a).add(b); hi.show(); }
Example #5
Source File: TestRecorder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void assertTextAreasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_assertTextAreasActionPerformed Form f = Display.getInstance().getCurrent(); visitComponents(f.getContentPane(), new ComponentVisitor() { public void visit(Component c) { if(c instanceof com.codename1.ui.TextArea) { com.codename1.ui.TextArea lbl = (com.codename1.ui.TextArea)c; String labelText = "null"; if(lbl.getText() != null) { labelText = "\"" + lbl.getText().replace("\n", "\\n") + "\""; } if(lbl.getName() != null) { generatedCode += " assertTextArea(" + getPathOrName(lbl) + ", " + labelText + ");\n"; } else { generatedCode += " assertTextArea(" + labelText + ");\n"; } } } }); updateTestCode(); }
Example #6
Source File: ScaleImageButton.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ @Override protected Dimension calcPreferredSize() { Image i = getIcon(); if(i == null) { return new Dimension(); } int dw = Display.getInstance().getDisplayWidth(); int iw = i.getWidth(); int ih = i.getHeight(); // a huge preferred width might be requested that is bigger than screen size. Normally this isn't a problem but in // a scrollable container the vertical height might be granted providing so much space as to make this unrealistic... if(iw > dw) { float ratio = ((float)iw) / ((float)dw); iw = (int) (((float)iw) / ((float)ratio)); ih = (int) (((float)ih) / ((float)ratio)); } Style s = getStyle(); return new Dimension(iw + s.getPaddingLeftNoRTL() + s.getPaddingRightNoRTL(), ih + s.getPaddingTop() + s.getPaddingBottom()); }
Example #7
Source File: SocialChat.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
private void listenToMessages() { try { pb = new Pubnub(PUBNUB_PUB_KEY, PUBNUB_SUB_KEY); pb.subscribe(tokenPrefix + uniqueId, new Callback() { @Override public void successCallback(String channel, Object message, String timetoken) { if(message instanceof String) { pendingAck.remove(channel); return; } Message m = new Message((JSONObject)message); pb.publish(tokenPrefix + m.getSenderId(), "ACK", new Callback() {}); Display.getInstance().callSerially(() -> { addMessage(m); respond(m); }); } }); } catch(PubnubException err) { Log.e(err); Dialog.show("Error", "There was a communication error: " + err, "OK", null); } }
Example #8
Source File: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * This method effectively pops the form navigation stack and goes back * to the previous form if back navigation is enabled and there is * a previous form. * * @param sourceComponent the component that triggered the back command which effectively * allows us to find the EmbeddedContainer for a case of container navigation. Null * can be used if not applicable. */ public void back(Component sourceComponent) { Vector formNavigationStack = getFormNavigationStackForComponent(sourceComponent); if(formNavigationStack != null && formNavigationStack.size() > 0) { Hashtable h = (Hashtable)formNavigationStack.elementAt(formNavigationStack.size() - 1); if(h.containsKey(FORM_STATE_KEY_CONTAINER)) { Form currentForm = Display.getInstance().getCurrent(); if(currentForm != null) { exitForm(currentForm); } } String formName = (String)h.get(FORM_STATE_KEY_NAME); if(!h.containsKey(FORM_STATE_KEY_CONTAINER)) { Form f = (Form)createContainer(fetchResourceFile(), formName); initBackForm(f); onBackNavigation(); beforeShow(f); f.showBack(); postShowImpl(f); } else { showContainerImpl(formName, null, sourceComponent, true); } } }
Example #9
Source File: GoogleImpl.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
@Override public void nativelogin() { loginCompleted = false; nativeInterface.googleLogin(this); Display.getInstance().invokeAndBlock(new Runnable() { public void run() { while(!loginCompleted) { try { Thread.sleep(50); } catch(InterruptedException ie) {} } } }); if(callback != null) { if(nativeIsLoggedIn()) { this.setAccessToken(new AccessToken(nativeInterface.getGoogleToken(), null)); callback.loginSuccessful(); } else { callback.loginFailed(loginMessage); } } }
Example #10
Source File: Progress.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Binds the progress UI to the completion of this request * * @param title the title of the progress dialog * @param request the network request pending * @param showPercentage shows percentage on the progress bar */ public Progress(String title, ConnectionRequest request, boolean showPercentage) { super(title); this.request = request; SliderBridge b = new SliderBridge(request); b.setRenderPercentageOnTop(showPercentage); b.setRenderValueOnTop(true); setLayout(new BoxLayout(BoxLayout.Y_AXIS)); addComponent(b); Command cancel = new Command(UIManager.getInstance().localize("cancel", "Cancel")); if(Display.getInstance().isTouchScreenDevice() || getSoftButtonCount() < 2) { // if this is a touch screen device or a blackberry use a centered button Button btn = new Button(cancel); Container cnt = new Container(new FlowLayout(CENTER)); cnt.addComponent(btn); addComponent(cnt); } else { // otherwise use a command addCommand(cancel); } setDisposeWhenPointerOutOfBounds(false); setAutoDispose(false); NetworkManager.getInstance().addProgressListener(this); }
Example #11
Source File: CustomToolbar2.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
@Override public void scrollChanged(int scrollX, int scrollY, int oldscrollX, int oldscrollY) { //modify the alpha value alpha = scrollY; alpha = Math.max(alpha, 0); alpha = Math.min(alpha, 255); //push the title to the right when the scroll moves up int padding = (int) ((float) alpha * (Display.getInstance().getDisplayWidth() * 40 / 100) / (float) 255); padding = Math.min((Display.getInstance().getDisplayWidth()) / 2, padding); title.getStyle().setPadding(LEFT, padding); //change the size of the tollbar bottomPadding.setPreferredH(Math.max(0, topHeight - minimumHeight - scrollY)); topPadding.setPreferredH(bottomPadding.getPreferredH()); revalidate(); }
Example #12
Source File: AndroidLocationManager.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void setLocationManagerStatus(final int status) { int current = getStatus(); if (current != status) { setStatus(status); synchronized (this) { Display.getInstance().callSerially(new Runnable() { @Override public void run() { com.codename1.location.LocationListener l = getLocationListener(); if (l != null) { l.providerStateChanged(status); } } }); } } }
Example #13
Source File: MultiComboBox.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * {{@inheritDoc}} */ public void keyReleased(int keyCode) { // other events are in keyReleased to prevent the next event from reaching the next form int gameAction = Display.getInstance().getGameAction(keyCode); if ((multiple) && (gameAction == Display.GAME_FIRE)) { boolean h = handlesInput(); //setHandlesInput(!h); if (h) { fireActionEvent(); } repaint(); return; } else { super.keyReleased(keyCode); } }
Example #14
Source File: TestRecorder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private com.codename1.ui.Component findLowestVisibleComponent() { Form f = Display.getInstance().getCurrent(); final com.codename1.ui.Component[] cmp = new com.codename1.ui.Component[1]; visitComponents(f.getContentPane(), new ComponentVisitor() { int lowest = -1; public void visit(Component c) { int abY = c.getAbsoluteY(); if(abY > lowest && abY + c.getHeight() < Display.getInstance().getDisplayHeight()) { lowest = abY; cmp[0] = c; } } }); return cmp[0]; }
Example #15
Source File: Solitaire.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
public void init(Object context) { try { theme = Resources.openLayered("/theme"); UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0])); int dpi = Preferences.get("dpi", calculateDPI()); cards = Resources.open("/gamedata.res",dpi); currentZoom = Preferences.get("zoom", defaultZoom); } catch(IOException e){ e.printStackTrace(); } // Pro users - uncomment this code to get crash reports sent to you automatically Display.getInstance().addEdtErrorHandler(new ActionListener() { public void actionPerformed(ActionEvent evt) { evt.consume(); Log.p("Exception in AppName version " + Display.getInstance().getProperty("AppVersion", "Unknown")); Log.p("OS " + Display.getInstance().getPlatformName()); Log.p("Error " + evt.getSource()); Log.p("Current Form " + Display.getInstance().getCurrent().getName()); Log.e((Throwable)evt.getSource()); Log.sendLog(); } }); }
Example #16
Source File: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void processCommandImpl(ActionEvent ev, Command cmd) { processCommand(ev, cmd); if(ev.isConsumed()) { return; } if(globalCommandListeners != null) { globalCommandListeners.fireActionEvent(ev); if(ev.isConsumed()) { return; } } if(localCommandListeners != null) { Form f = Display.getInstance().getCurrent(); EventDispatcher e = (EventDispatcher)localCommandListeners.get(f.getName()); if(e != null) { e.fireActionEvent(ev); } } }
Example #17
Source File: StyleParser.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private Border createDottedBorder() { if (this.getWidthUnit() == Style.UNIT_TYPE_DIPS) { return Border.createDottedBorder(Display.getInstance().convertToPixels(getWidth()), getColor()); } else { return Border.createDottedBorder(getWidth().intValue(), getColor()); } }
Example #18
Source File: CSSMediaQueriesSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); hi.add(new Label("Hi World")); hi.add(new Label("Platform "+Display.getInstance().getPlatformName())); hi.add(new Label("Density: "+Display.getInstance().getDensityStr())); hi.show(); }
Example #19
Source File: TestUtils.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private static void waitForUnnamedFormImpl(long timeout) { long t = System.currentTimeMillis() + timeout; while(Display.getInstance().getCurrent().getName() != null) { try { Thread.sleep(50); } catch (InterruptedException ex) { } if(System.currentTimeMillis() > t) { assertBool(false, "Waiting for form unnamed form timed out! Current form name is: " + Display.getInstance().getCurrent().getName()); } } }
Example #20
Source File: AsyncStackTracesTest.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private void testAsyncStackTraces() { Display.getInstance().setEnableAsyncStackTraces(true); Form f = new Form("Hello World", BoxLayout.y()); Button b = new Button("Test"); b.addActionListener(e->{ callSerially(()->{ ArrayList a = new ArrayList(); callSerially(()->{ a.add(5, "Hello World"); }); }); }); f.add(b); f.show(); }
Example #21
Source File: Switch.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private static Image createRoundThumbImage(int pxDim, int color, int shadowSpread, int thumbInset) { Image img = Image.createImage(pxDim + 2 * shadowSpread, pxDim + 2 * shadowSpread, 0x0); Graphics g = img.getGraphics(); g.setAntiAliased(true); int shadowOpacity = 200; float shadowBlur = 10; if (shadowSpread > 0) { // draw a gradient of sort for the shadow for (int iter = shadowSpread - 1; iter >= 0; iter--) { g.translate(iter, iter); g.setColor(0); g.setAlpha(shadowOpacity / shadowSpread); g.fillArc( Math.max(1, thumbInset+shadowSpread + shadowSpread / 2 - iter), Math.max(1, thumbInset + 2 * shadowSpread - iter), Math.max(1, pxDim - (iter * 2) - 2*thumbInset), Math.max(1, pxDim - (iter * 2) - 2*thumbInset), 0, 360); g.translate(-iter, -iter); } if (Display.getInstance().isGaussianBlurSupported()) { Image blured = Display.getInstance().gaussianBlurImage(img, shadowBlur / 2); //img = Image.createImage(pxDim+2*shadowSpread, pxDim+2*shadowSpread, 0); img = blured; g = img.getGraphics(); //g.drawImage(blured, 0, 0); g.setAntiAliased(true); } } //g.translate(shadowSpread, shadowSpread); g.setAlpha(255); g.setColor(color); g.fillArc(shadowSpread+thumbInset, shadowSpread+thumbInset, Math.max(1, pxDim-2*thumbInset), Math.max(1, pxDim-2*thumbInset), 0, 360); //g.setColor(outlinecolor); //g.drawArc(shadowSize, shadowSize, pxDim-1, pxDim-1, 0, 360); return img; }
Example #22
Source File: StubLocationManager.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private void checkLocationRegistration() { if(!checked) { Map<String, String> m = Display.getInstance().getProjectBuildHints(); if(m != null) { if(!m.containsKey("ios.locationUsageDescription")) { Display.getInstance().setProjectBuildHint("ios.locationUsageDescription", "Some functionality of the application depends on your location"); } } checked = true; } }
Example #23
Source File: SignatureComponent.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * * @param g */ @Override public void paint(Graphics g) { super.paint(g); g.setColor(0x666666); calcSignatureRect(signatureRect); g.drawRect(signatureRect.getX(), signatureRect.getY(), signatureRect.getWidth(), signatureRect.getHeight()); g.drawString("X", signatureRect.getX() + Display.getInstance().convertToPixels(1, true), signatureRect.getY() + signatureRect.getHeight() / 2); g.pushClip(); g.clipRect(signatureRect.getX(), signatureRect.getY(), signatureRect.getWidth(), signatureRect.getHeight()); paintSignature(g); g.popClip(); }
Example #24
Source File: Mail.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
public Container createDemo() { Container message = new Container(new BoxLayout(BoxLayout.Y_AXIS)); ComponentGroup gp = new ComponentGroup(); message.addComponent(gp); final TextField to = new TextField(""); to.setHint("TO:"); gp.addComponent(to); final TextField subject = new TextField("Codename One Is Cool"); subject.setHint("Subject"); gp.addComponent(subject); final TextField body = new TextField("Try it out at http://www.codenameone.com/"); body.setSingleLineTextArea(false); body.setRows(4); body.setHint("Message Body"); gp.addComponent(body); ComponentGroup buttonGroup = new ComponentGroup(); Button btn = new Button("Send"); buttonGroup.addComponent(btn); message.addComponent(buttonGroup); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Message msg = new Message(body.getText()); Display.getInstance().sendMessage(new String[] {to.getText()}, subject.getText(), msg); } }); return message; }
Example #25
Source File: ZoozPurchase.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public synchronized Product[] getProducts(String[] skus) { int numSkus = skus.length; final Product[] p = new Product[numSkus]; for(int iter = 0; iter < numSkus; iter++) { p[iter] = new Product(); } fetchProductsFailed = false; fetchProductsComplete = false; nativeInstance.fetchProducts(skus, p); // wait for request to complete Display.getInstance().invokeAndBlock(new Runnable() { @Override public void run() { while(!fetchProductsFailed && !fetchProductsComplete) { try { Thread.currentThread().sleep(10); } catch (InterruptedException ex) { } } } }); if(fetchProductsFailed) { Log.e(new IOException("Failed to fetch products: " + fetchProductsFailedMessage)); return null; } return p; }
Example #26
Source File: UITimer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
void testEllapse() { long t = System.currentTimeMillis(); if(t - lastEllapse >= ms) { if(!repeat) { Display.getInstance().getCurrent().deregisterAnimated(i); } lastEllapse = t; i.run(); } }
Example #27
Source File: BlackBerryOS5Implementation.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void openImageGallery(final ActionListener response) { app.invokeLater(new Runnable() { public void run() { try { final FilePicker picker = FilePicker.getInstance(); picker.setFilter(".jpg"); final String file = picker.show(); Display.getInstance().callSerially(new Runnable() { public void run() { if (file != null) { response.actionPerformed(new ActionEvent(file)); } else { response.actionPerformed(null); } } }); } catch (Throwable e) { Display.getInstance().callSerially(new Runnable() { public void run() { BlackBerryOS5Implementation.this.openParentImageGallery(response); } }); } } }); }
Example #28
Source File: CodenameOneMiGComponentWrapper.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public final int getMaximumWidth(int sz) { Container p = c.getParent(); if(p != null) { int w = p.getWidth(); if(w > 10) { return w; } } return Display.getInstance().getDisplayWidth(); }
Example #29
Source File: Picker.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Checks if the given type is supported in LightWeight mode. * @param type The type. Expects one of the Display.PICKER_XXX constants. * @return True if the given type is supported in lightweight mode. */ private static boolean isLightweightModeSupportedForType(int type) { switch (type) { case Display.PICKER_TYPE_STRINGS: case Display.PICKER_TYPE_DATE: case Display.PICKER_TYPE_TIME: case Display.PICKER_TYPE_DATE_AND_TIME: case Display.PICKER_TYPE_DURATION: case Display.PICKER_TYPE_DURATION_HOURS: case Display.PICKER_TYPE_DURATION_MINUTES: case Display.PICKER_TYPE_CALENDAR: return true; } return false; }
Example #30
Source File: JUnitXMLReporting.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public void writeReport(OutputStream os) throws IOException { os.write(("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<testsuite failures=\"" + failed + "\" " + "skipped=\"0\" tests=\"" + (passed + failed) + "\" name=\"" + Display.getInstance().getProperty("AppName", "Unnamed") + "\">\n" + testCases + "\n</testsuite>").getBytes()); }