com.codename1.io.Util Java Examples
The following examples show how to use
com.codename1.io.Util.
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: CSSBorder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Sets the background-repeat for the background images. * @param repeat Repeat options for respective background images. * @return Self for chaining. */ public CSSBorder backgroundRepeat(String... repeat) { int len = repeat.length; if (len == 1 && repeat[0].indexOf(",") != -1) { return backgroundRepeat(Util.split(repeat[0], ",")); } if (backgroundImages == null) { backgroundImages = new BackgroundImage[len]; } else { if (backgroundImages.length < len) { BackgroundImage[] tmp = new BackgroundImage[len]; System.arraycopy(backgroundImages, 0, tmp, 0, backgroundImages.length); backgroundImages = tmp; } } for (int i=0; i<len; i++) { if (backgroundImages[i] == null) { backgroundImages[i] = new BackgroundImage(); } backgroundImages[i].repeat = parseRepeat(repeat[i].trim()); } return this; }
Example #2
Source File: BlackBerryOS5Implementation.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public static void onMessage(final PushInputStream stream, final StreamConnection sc) { if(pushCallback != null) { new Thread() { public void run() { try { final byte[] buffer = Util.readInputStream(stream); try { stream.accept(); Util.cleanup(stream); sc.close(); } catch(Throwable t) {} updateIndicator(unreadCount + 1); Display.getInstance().callSerially(new Runnable() { public void run() { pushCallback.push(new String(buffer)); } }); } catch(IOException err) { err.printStackTrace(); } } }.start(); } }
Example #3
Source File: CloudStorage.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
protected void readResponse(InputStream input) throws IOException { DataInputStream di = new DataInputStream(input); for(int iter = 0 ; iter < objects.length ; iter++) { try { if(di.readBoolean()) { objects[iter].setLastModified(di.readLong()); objects[iter].setValues((Hashtable)Util.readObject(di)); } objects[iter].setStatus(CloudObject.STATUS_COMMITTED); } catch (IOException ex) { Log.e(ex); } } Util.cleanup(di); returnValue = RETURN_CODE_SUCCESS; }
Example #4
Source File: PhotoShare.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
public Image getItemAt(final int index) { if(images[index] == null) { images[index] = placeholder; Util.downloadUrlToStorageInBackground(IMAGE_URL_PREFIX + imageIds[index], "FullImage_" + imageIds[index], new ActionListener() { public void actionPerformed(ActionEvent evt) { try { images[index] = EncodedImage.create(Storage.getInstance().createInputStream("FullImage_" + imageIds[index])); listeners.fireDataChangeEvent(index, DataChangedListener.CHANGED); } catch(IOException err) { err.printStackTrace(); } } }); } return images[index]; }
Example #5
Source File: WAVWriter.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Closes the writer, and writes the WAV file. * @throws Exception */ @Override public void close() throws Exception { this.out.close(); final FileSystemStorage fs = FileSystemStorage.getInstance(); fs.rename(this.outputFile.getAbsolutePath(), new File(this.getPCMFile()).getName()); try { this.out = fs.openOutputStream(this.outputFile.getAbsolutePath()); final InputStream in = fs.openInputStream(this.getPCMFile()); this.writeHeader(); Util.copy(in, this.out); try { this.out.close(); } catch (Throwable t) {} try { in.close(); } catch (Throwable t2) {} } finally { fs.delete(this.getPCMFile()); } }
Example #6
Source File: ParseObject.java From parse4cn1 with Apache License 2.0 | 6 votes |
/** * Serializes the contents of the ParseObject in a manner that complies with * the {@link com.codename1.io.Externalizable} interface. * * @param out The data stream to serialize to. * @throws IOException if any IO error occurs * @throws ParseException if the object is {@link #isDirty() dirty} */ public void externalize(DataOutputStream out) throws IOException, ParseException { if (isDirty()) { throw new ParseException(ParseException.OPERATION_FORBIDDEN, "A dirty ParseObject cannot be serialized to storage"); } Util.writeUTF(getObjectId(), out); Util.writeObject(getCreatedAt(), out); Util.writeObject(getUpdatedAt(), out); // Persist actual data out.writeInt(keySet().size()); for (String key : keySet()) { out.writeUTF(key); Object value = get(key); if (value instanceof ParseObject) { value = ((ParseObject)value).asExternalizable(); } else if (ExternalizableJsonEntity.isExternalizableJsonEntity(value)) { value = new ExternalizableJsonEntity(value); } Util.writeObject(value, out); } }
Example #7
Source File: ExternalizableParseObject.java From parse4cn1 with Apache License 2.0 | 6 votes |
/** * @see com.codename1.io.Externalizable */ public void internalize(int version, DataInputStream in) throws IOException { className = Util.readUTF(in); if (className != null) { parseObject = ParseObject.create(className); try { parseObject.internalize(version, in); } catch (ParseException ex) { Logger.getInstance().error( "An error occurred while trying to deserialize ParseObject"); throw new IOException(ex.getMessage()); } } else { final String msg = "Unable to deserialize ParseObject " + "(null class name). Is class properly registered?"; Logger.getInstance().error(msg); throw new RuntimeException(msg); } }
Example #8
Source File: Receipt.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ public void externalize(DataOutputStream out) throws IOException { Map m = new HashMap(); m.put("sku", getSku()); m.put("expiryDate", getExpiryDate()); m.put("cancellationDate", getCancellationDate()); m.put("purchaseDate", getPurchaseDate()); m.put("orderData", getOrderData()); m.put("transactionId", getTransactionId()); m.put("quantity", getQuantity()); m.put("storeCode", getStoreCode()); m.put("internalId", getInternalId()); Util.writeObject(m, out); }
Example #9
Source File: CSSBorder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Sets the background position. * @param pos The background positions of background images. * @return Self for chaining. */ public CSSBorder backgroundPosition(String... pos) { int len = pos.length; if (len == 1 && pos[0].indexOf(",") != -1) { return backgroundPosition(Util.split(pos[0], ",")); } if (backgroundImages == null) { backgroundImages = new BackgroundImage[len]; } else { if (backgroundImages.length < len) { BackgroundImage[] tmp = new BackgroundImage[len]; System.arraycopy(backgroundImages, 0, tmp, 0, backgroundImages.length); backgroundImages = tmp; } } for (int i=0; i<len; i++) { if (backgroundImages[i] == null) { backgroundImages[i] = new BackgroundImage(); } backgroundImages[i].setPosition(pos[i].trim()); } return this; }
Example #10
Source File: EasyThread.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Invokes the given runnable on the thread and waits for its execution to complete * @param r the runnable */ public void runAndWait(final Runnable r) { final boolean[] flag = new boolean[1]; synchronized(LOCK) { queue.add(new Runnable() { public void run() { r.run(); synchronized(flag) { flag[0] = true; flag.notify(); } } }); LOCK.notify(); } Display.getInstance().invokeAndBlock(new Runnable() { public void run() { synchronized(flag) { if(!flag[0]) { Util.wait(flag); } } } }); }
Example #11
Source File: UIFragment.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void decorate(Element el, Component cmp) { String classAttr = el.getAttribute("class"); if (classAttr != null && classAttr.length() > 0) { String[] tags = Util.split(classAttr, " "); $(cmp).addTags(tags); } String uiid = el.getAttribute("uiid"); if (uiid != null && uiid.length() > 0){ cmp.setUIID(uiid); } String id = el.getAttribute("id"); if (id != null && id.length() > 0) { index.put(id, cmp); } String name = el.getAttribute("name"); if (name != null && name.length() > 0) { cmp.setName(name); } String flags = el.getAttribute("flags"); if (flags != null && flags.indexOf("safeArea") >= 0 && (cmp instanceof Container)) { ((Container)cmp).setSafeArea(true); } }
Example #12
Source File: ParseBatch.java From parse4cn1 with Apache License 2.0 | 6 votes |
/** * Adds multiple objects to the batch to be {@link #execute() executed}. * * @param objects The objects to be added to the batch. * @param opType The type of operation to be performed on ALL * {@code objects}. * @return {@code this} to enable chaining. * @throws ParseException if any of the objects does not meet the * constraints for {@code opType}, for example, an objectId is required for * {@link EBatchOpType#UPDATE} and {@link EBatchOpType#DELETE} but should * not exist for {@link EBatchOpType#CREATE}. because it already has an * objectId. */ public ParseBatch addObjects(final Collection<? extends ParseObject> objects, final EBatchOpType opType) throws ParseException { final String urlPath = StringUtil.replaceAll(Util.getURLPath(Parse.getApiEndpoint()), "/", ""); final String pathPrefix = "/" + (!Parse.isEmpty(urlPath) ? urlPath + "/" : ""); final String method = opTypeToHttpMethod(opType); for (ParseObject object : objects) { validate(object, opType); final JSONObject objData = new JSONObject(); try { objData.put("method", method); objData.put("path", pathPrefix + getObjectPath(object, opType)); objData.put("body", object.getParseData()); } catch (JSONException ex) { throw new ParseException(ParseException.INVALID_JSON, ParseException.ERR_PREPARING_REQUEST, ex); } data.put(objData); parseObjects.add(object); } return this; }
Example #13
Source File: ParseRelation.java From parse4cn1 with Apache License 2.0 | 6 votes |
/** * @see com.codename1.io.Externalizable */ public void externalize(DataOutputStream out) throws IOException { /* Note that ParseRelations are applied on ParseObjects and since only saved ParseObjects are serialized by design, the only piece of information needed to reconstruct the relation is the targetClass. However, for completeness, we include other fields except the parent since serializing the parent will result in an infinite loop. If there's ever a usecase where a ParseRelation is deemed useful outside a ParseObject, a smart way to store the parent would be implemented. */ Util.writeUTF(targetClass, out); Util.writeUTF(key, out); Util.writeObject(setToArray(addedObjects), out); Util.writeObject(setToArray(removedObjects), out); }
Example #14
Source File: FacebookRESTService.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
protected void readResponse(InputStream input) throws IOException { //BufferedInputStream i = new BufferedInputStream(new InputStreamReader(input, )); BufferedInputStream i; if(input instanceof BufferedInputStream){ i = (BufferedInputStream) input; }else{ i = new BufferedInputStream(input); } i.setYield(-1); InputStreamReader reader = new InputStreamReader(i, "UTF-8"); JSONParser.parse(reader, this); Util.cleanup(reader); if(stack.size() > 0){ fireResponseListener(new NetworkEvent(this, stack.elementAt(0))); } }
Example #15
Source File: URLImage.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private void loadImageFromFileURLToStorage(final String targetKey) { Display.getInstance().scheduleBackgroundTask(new Runnable() { public void run() { try { InputStream input = FileSystemStorage.getInstance().openInputStream(url); OutputStream output = Storage.getInstance().createOutputStream(targetKey); Util.copy(input, output); CN.callSerially(new Runnable() { public void run() { try { Image value = Image.createImage(Storage.getInstance().createInputStream(targetKey)); DownloadCompleted onComplete = new DownloadCompleted(); onComplete.setSourceImage(value); onComplete.actionPerformed(new ActionEvent(value)); } catch (Exception ex) { if(exceptionHandler != null) { exceptionHandler.onError(URLImage.this, ex); } else { throw new RuntimeException(ex.toString()); } } } }); } catch (Exception t) { if(exceptionHandler != null) { exceptionHandler.onError(URLImage.this, t); } else { throw new RuntimeException(t.toString()); } } } }); }
Example #16
Source File: EasyThread.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Runs the given runnable on the thread and blocks until it completes, returns the value object * * @param r the runnable with result that will execute on the thread * @return value returned by r */ public <T> T run(final RunnableWithResultSync<T> r) { // we need the flag and can't use the result object. Since null would be a valid value for the result // we would have a hard time of detecting the case of the code completing before the wait call final boolean[] flag = new boolean[1]; final Object[] result = new Object[1]; final SuccessCallback<T> sc = new SuccessCallback<T>() { public void onSucess(T value) { synchronized(flag) { result[0] = value; flag[0] = true; flag.notify(); } } }; RunnableWithResult<T> rr = new RunnableWithResult<T>() { public void run(SuccessCallback<T> onSuccess) { sc.onSucess(r.run()); } }; synchronized(LOCK) { queue.add(rr); queue.add(sc); LOCK.notify(); } Display.getInstance().invokeAndBlock(new Runnable() { public void run() { synchronized(flag) { if(!flag[0]) { Util.wait(flag); } } } }); return (T)result[0]; }
Example #17
Source File: URLImage.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private void loadImageFromStorageURLToFileSystem(final String targetFile) { Display.getInstance().scheduleBackgroundTask(new Runnable() { public void run() { try { InputStream input = Storage.getInstance().createInputStream(url); OutputStream output = FileSystemStorage.getInstance().openOutputStream(targetFile); Util.copy(input, output); CN.callSerially(new Runnable() { public void run() { try { Image value = Image.createImage(FileSystemStorage.getInstance().openInputStream(targetFile)); DownloadCompleted onComplete = new DownloadCompleted(); onComplete.setSourceImage(value); onComplete.actionPerformed(new ActionEvent(value)); } catch (Exception ex) { if(exceptionHandler != null) { exceptionHandler.onError(URLImage.this, ex); } else { throw new RuntimeException(ex.toString()); } } } }); } catch (Exception t) { if(exceptionHandler != null) { exceptionHandler.onError(URLImage.this, t); } else { throw new RuntimeException(t.toString()); } } } }); }
Example #18
Source File: BrowserComponent.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Executes the given JavaScript and returns a result string from the underlying platform * where applicable. * <p><strong>Note</strong>: Some platforms use {@link Display#invokeAndBlock(java.lang.Runnable) } inside this method which is very costly. Try to avoid this synchronous method, and * prefer to use one of the asynchronous versions. E.g. {@link #execute(java.lang.String, com.codename1.util.SuccessCallback) }</p> * @param javaScript the JavaScript code to execute * @return the string returned from the Javascript call */ public String executeAndReturnString(String javaScript){ if (internal == null) { while (internal == null) { CN.invokeAndBlock(new Runnable() { public void run() { Util.sleep(50); } }); } } return Display.impl.browserExecuteAndReturnString(internal, javaScript); }
Example #19
Source File: URLImage.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private void loadImageFromStorageURLToStorage(final String targetKey) { Display.getInstance().scheduleBackgroundTask(new Runnable() { public void run() { try { if (!Objects.equals(url, targetKey)) { InputStream input = Storage.getInstance().createInputStream(url); OutputStream output = Storage.getInstance().createOutputStream(targetKey); Util.copy(input, output); } CN.callSerially(new Runnable() { public void run() { try { Image value = Image.createImage(Storage.getInstance().createInputStream(targetKey)); DownloadCompleted onComplete = new DownloadCompleted(); onComplete.setSourceImage(value); onComplete.actionPerformed(new ActionEvent(value)); } catch (Exception ex) { if(exceptionHandler != null) { exceptionHandler.onError(URLImage.this, ex); } else { throw new RuntimeException(ex.toString()); } } } }); } catch (Exception t) { if(exceptionHandler != null) { exceptionHandler.onError(URLImage.this, t); } else { throw new RuntimeException(t.toString()); } } } }); }
Example #20
Source File: URLImage.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private void loadImageFromFileURLToFileSystem(final String targetFile) { Display.getInstance().scheduleBackgroundTask(new Runnable() { public void run() { try { InputStream input = FileSystemStorage.getInstance().openInputStream(url); OutputStream output = FileSystemStorage.getInstance().openOutputStream(targetFile); Util.copy(input, output); CN.callSerially(new Runnable() { public void run() { try { Image value = Image.createImage(FileSystemStorage.getInstance().openInputStream(targetFile)); DownloadCompleted onComplete = new DownloadCompleted(); onComplete.setSourceImage(value); onComplete.actionPerformed(new ActionEvent(value)); } catch (Exception ex) { if(exceptionHandler != null) { exceptionHandler.onError(URLImage.this, ex); } else { throw new RuntimeException(ex.toString()); } } } }); } catch (Exception t) { if(exceptionHandler != null) { exceptionHandler.onError(URLImage.this, t); } else { throw new RuntimeException(t.toString()); } } } }); }
Example #21
Source File: EncodedImage.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Tries to create an encoded image from RGB which is more efficient, * however if this fails it falls back to regular RGB image. This method * is slower than creating an RGB image (not to be confused with the RGBImage class which is * something ENTIRELY different!). * * @param argb an argb array * @param width the width for the image * @param height the height for the image * @param jpeg uses jpeg format internally which is opaque and could be faster/smaller * @return an image which we hope is an encoded image */ public static Image createFromRGB(int[] argb, int width, int height, boolean jpeg) { Image i = Image.createImage(argb, width, height); ImageIO io = ImageIO.getImageIO(); if(io != null) { String format; if(jpeg) { if(!io.isFormatSupported(ImageIO.FORMAT_JPEG)) { return i; } format = ImageIO.FORMAT_JPEG; } else { if(!io.isFormatSupported(ImageIO.FORMAT_PNG)) { return i; } format = ImageIO.FORMAT_PNG; } try { ByteArrayOutputStream bo = new ByteArrayOutputStream(); io.save(i, bo, format, 0.9f); EncodedImage enc = EncodedImage.create(bo.toByteArray()); Util.cleanup(bo); enc.width = width; enc.height = height; if(jpeg) { enc.opaque = true; enc.opaqueChecked = true; } enc.cache = Display.getInstance().createSoftWeakRef(i); return enc; } catch(IOException err) { Log.e(err); } } return i; }
Example #22
Source File: BrowserComponent.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * This uses invokeAndBlock to wait for the result of the given javascript expression. It is extremely important * that the js expression calls either {@code callback.onSuccess(value) } or {@code literalcallback.onError(message, code) } * at some point, or this method will never return. * * <h3>{@link #executeAndWait(java.lang.String)} vs {@link #executeAndReturnString(java.lang.String) }</h3> * * <p>{@link #executeAndReturnString(java.lang.String) } is also blocking, but it uses javascript {@literal eval } * to return the value of the expression. Therefore it can't return the result of any asynchronous operations.</p> * * <p>{@link #executeAndWait(java.lang.String) } is built directly on top of {@link #execute(java.lang.String, com.codename1.util.SuccessCallback) } * which is fully asynchronous, and allows you to specify where and when you call the callback within the * javascript code. This means that you <strong>must</strong> explicitly call either {@code callback.onSuccess(value) } or {@code literalcallback.onError(message, code) } * at some point in the Javascript expression - or the method will block indefinitely.</p> * * @param timeout Timeout in ms * @param js The javascript expression to execute. You must call {@code callback.onSuccess(value)} with the result that you want to have returned. * @return The result that is returned from javascript when it calls {@code callback.onSuccess(value) } */ public JSRef executeAndWait(int timeout, String js) { final ExecuteResult res = new ExecuteResult(); execute(timeout, js, new Callback<JSRef>() { public void onSucess(JSRef value) { synchronized(res) { res.complete = true; res.value = value; res.notifyAll(); } } public void onError(Object sender, Throwable err, int errorCode, String errorMessage) { synchronized(res) { res.complete = true; res.error = err; res.notifyAll(); } } }); while (!res.complete) { Display.getInstance().invokeAndBlock(new Runnable() { public void run() { Util.wait(res, 1000); } }); } if (res.error != null) { throw new RuntimeException(res.error.getMessage()); } else { return res.value; } }
Example #23
Source File: EncodedImage.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Creates an image from the input stream * * @param i the input stream * @return newly created encoded image * @throws java.io.IOException if thrown by the input stream */ public static EncodedImage create(InputStream i) throws IOException { byte[] buffer = Util.readInputStream(i); if(buffer.length > 200000) { System.out.println("Warning: loading large images using EncodedImage.create(InputStream) might lead to memory issues, try using EncodedImage.create(InputStream, int)"); } return new EncodedImage(new byte[][] {buffer}); }
Example #24
Source File: CSSBorder.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Sets the border widths. * @param widths The widths. 1 value sets all borders. 2 sets top/bottom, left/right. 3 sets top, left/right, bottom. 4 sets top, right, bottom, left. * @return Self for chaining. */ public CSSBorder borderWidth(String... widths) { if (this.stroke == null) { return this.borderStroke("solid").borderWidth(widths); } else { int len = widths.length; if (len == 4) { stroke[TOP].thickness = BorderStroke.parseThickness(widths[0]); stroke[RIGHT].thickness = BorderStroke.parseThickness(widths[1]); stroke[BOTTOM].thickness = BorderStroke.parseThickness(widths[2]); stroke[LEFT].thickness = BorderStroke.parseThickness(widths[3]); } else if (len == 3) { stroke[TOP].thickness = BorderStroke.parseThickness(widths[0]); stroke[LEFT].thickness = BorderStroke.parseThickness(widths[1]); stroke[RIGHT].thickness = stroke[LEFT].thickness.copy(); stroke[BOTTOM].thickness = BorderStroke.parseThickness(widths[2]); } else if (len == 2) { stroke[TOP].thickness = BorderStroke.parseThickness(widths[0]); stroke[BOTTOM].thickness = stroke[TOP].thickness.copy(); stroke[LEFT].thickness = BorderStroke.parseThickness(widths[1]); stroke[RIGHT].thickness = stroke[LEFT].thickness.copy(); } else if (len == 1) { if (widths[0].indexOf(" ") != -1) { return borderWidth(Util.split(widths[0], " ")); } stroke[TOP].thickness = BorderStroke.parseThickness(widths[0]); stroke[RIGHT].thickness = BorderStroke.parseThickness(widths[0]); stroke[BOTTOM].thickness = BorderStroke.parseThickness(widths[0]); stroke[LEFT].thickness = BorderStroke.parseThickness(widths[0]); } else { throw new IllegalArgumentException("Border width expects 1 to 4 parameters"); } } return this; }
Example #25
Source File: CSSBorder.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Sets the border colors. * @param colors The colors. 1 value sets all borders. 2 sets top/bottom, left/right. 3 sets top, left/right, bottom. 4 sets top, right, bottom, left. * @return Self for chaining. */ public CSSBorder borderColor(String... colors) { if (this.stroke == null) { return this.borderStroke("solid").borderColor(colors); } else { int len = colors.length; if (len == 1 && colors[0].indexOf(" ") != -1) { return borderColor(Util.split(colors[0], " ")); } if (len == 4) { stroke[TOP].color = Color.parse(colors[0]); stroke[RIGHT].color = Color.parse(colors[1]); stroke[BOTTOM].color = Color.parse(colors[2]); stroke[LEFT].color = Color.parse(colors[3]); } else if (len == 3) { stroke[TOP].color = Color.parse(colors[0]); stroke[RIGHT].color = Color.parse(colors[1]); stroke[LEFT].color = Color.parse(colors[1]); stroke[BOTTOM].color = Color.parse(colors[2]); } else if (len == 2) { stroke[TOP].color = stroke[BOTTOM].color = Color.parse(colors[0]); stroke[LEFT].color = stroke[RIGHT].color = Color.parse(colors[1]); } else if (len == 1) { stroke[TOP].color = stroke[BOTTOM].color = stroke[LEFT].color = stroke[RIGHT].color = Color.parse(colors[0]); } else { throw new IllegalArgumentException("borderColor expects 1-4 parameters"); } } return this; }
Example #26
Source File: UiBinding.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
@Override public Object convert(Object source) { if(source == null) { return null; } if(source instanceof Boolean) { return ((Boolean)source).booleanValue(); } if(source instanceof String) { String s = ((String)source).toLowerCase(); return s.indexOf("true") > 0 || s.indexOf("yes") > 0 || s.indexOf("1") > 0; } return Util.toIntValue(source) > 0; }
Example #27
Source File: CookiesTest.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
void waitReady() { while (status != READY) { Display.getInstance().invokeAndBlock(()->{ synchronized(BrowserStatus.this) { Util.wait(BrowserStatus.this, 2000); } }); } }
Example #28
Source File: UiBinding.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
@Override public Object convert(Object source) { if(source == null) { return null; } return Util.toLongValue(source); }
Example #29
Source File: UiBinding.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
@Override public Object convert(Object source) { if(source == null) { return null; } if(source instanceof Date) { return (Date)source; } return new Date(Util.toLongValue(source)); }
Example #30
Source File: UiBinding.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
@Override public Object convert(Object source) { if(source == null) { return null; } return Util.toIntValue(source); }