Java Code Examples for com.codename1.io.Log#e()
The following examples show how to use
com.codename1.io.Log#e() .
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: FacebookConnect.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Gets the FacebookConnect singleton instance * . * @return the FacebookConnect instance */ public static FacebookConnect getInstance() { if (instance == null) { if (implClass != null) { try { instance = (FacebookConnect) implClass.newInstance(); } catch (Throwable t) { Log.e(t); instance = new FacebookConnect(); } } else { instance = new FacebookConnect(); } } return instance; }
Example 2
Source File: Solitaire.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
void refreshZoom(Container solitairContainer) { int dpi = DPIS[currentZoom / 5]; Preferences.set("dpi", dpi); Preferences.set("zoom", currentZoom); try { cards = Resources.open("/gamedata.res",dpi); cardImageCache.clear(); Image cardBack = getCardImage("card_back.png"); for(Component c : solitairContainer) { CardComponent crd = (CardComponent)c; crd.setImages(getCardImage(crd.getCard().getFileName()), cardBack); } solitairContainer.revalidate(); solitairContainer.getParent().replace(solitairContainer.getParent().getComponentAt(0), createPlacementContainer(solitairContainer), null); } catch(IOException e) { Log.e(e); } }
Example 3
Source File: Purchase.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Gets all of the receipts for this app. Note: You should periodically * reload the receipts from the server to make sure that the user * hasn't canceled a receipt or renewed one. * @return List of receipts for purchases this app. */ public final List<Receipt> getReceipts() { synchronized (RECEIPTS_KEY) { if (receipts == null) { if (Storage.getInstance().exists(RECEIPTS_KEY)) { Receipt.registerExternalizable(); try { receipts = (List<Receipt>)Storage.getInstance().readObject(RECEIPTS_KEY); } catch (Exception ex) { Log.p("Failed to load receipts from "+RECEIPTS_KEY); Log.e(ex); receipts = new ArrayList<Receipt>(); } } else { receipts = new ArrayList<Receipt>(); } } return receipts; } }
Example 4
Source File: FileEncodedImage.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ public byte[] getImageData() { if(data != null) { return data; } InputStream i = null; try { byte[] imageData = new byte[(int) FileSystemStorage.getInstance().getLength(fileName)]; i = FileSystemStorage.getInstance().openInputStream(fileName); Util.readFully(i, imageData); if(keep) { data = imageData; } return imageData; } catch (IOException ex) { Log.e(ex); return null; } finally { Util.cleanup(i); } }
Example 5
Source File: IndexedImage.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Loads a packaged image that was stored in a stream using the toByteArray method * * @param data previously stored image data * @return newly created packed image */ public static IndexedImage load(byte[] data) { try { DataInputStream input = new DataInputStream(new ByteArrayInputStream(data)); int width = input.readShort(); int height = input.readShort(); int[] palette = new int[input.readByte() & 0xff]; int plen = palette.length; for (int iter = 0; iter < plen; iter++) { palette[iter] = input.readInt(); } byte[] arr = new byte[width * height]; input.readFully(arr); return new IndexedImage(width, height, palette, arr); } catch (IOException ex) { Log.e(ex); return null; } }
Example 6
Source File: SideMenuBar.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Creates the Side Menu open button. * @return a Button instance to place on the TitleArea */ protected Button createOpenButton(){ Button ob = new Button(); ob.setUIID("MenuButton"); UIManager uim = parent.getUIManager(); Image i = (Image) uim.getThemeImageConstant("sideMenuImage"); if (i != null) { ob.setIcon(i); } else { float size = 4.5f; try { size = Float.parseFloat(uim.getThemeConstant("menuImageSize", "4.5")); } catch(Throwable t) { Log.e(t); } FontImage.setMaterialIcon(ob, FontImage.MATERIAL_MENU, size); } Image p = (Image) uim.getThemeImageConstant("sideMenuPressImage"); if (p != null) { ob.setPressedIcon(p); } return ob; }
Example 7
Source File: CameraKitPickerTest7.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void addVideo(String path) { try { Media m = MediaManager.createMedia(path, true); m.prepare(); //m.setNativePlayerMode(true); Component videoCmp = m.getVideoComponent(); videoCmp.setPreferredW(isTablet() ? convertToPixels(50) : convertToPixels(20)); videoCmp.setPreferredH(isTablet() ? convertToPixels(30) : convertToPixels(12)); add(videoCmp); } catch (Exception ex) { Log.e(ex); ToastBar.showErrorMessage("Failed to load video from path "+path); } }
Example 8
Source File: Form.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ protected void initLaf(UIManager uim) { super.initLaf(uim); LookAndFeel laf = uim.getLookAndFeel(); transitionOutAnimator = laf.getDefaultFormTransitionOut(); transitionInAnimator = laf.getDefaultFormTransitionIn(); focusScrolling = laf.isFocusScrolling(); if (menuBar == null || !menuBar.getClass().equals(laf.getMenuBarClass())) { try { menuBar = (MenuBar) laf.getMenuBarClass().newInstance(); } catch (Exception ex) { Log.e(ex); menuBar = new MenuBar(); } menuBar.initMenuBar(this); } tintColor = laf.getDefaultFormTintColor(); tactileTouchDuration = laf.getTactileTouchDuration(); }
Example 9
Source File: RequestBuilder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Executes the request synchronously * * @param type the type of the business object to create * @return Response Object */ public Response<List<PropertyBusinessObject>> getAsPropertyList(Class type) { ConnectionRequest request = createRequest(true); fetched = true; CN.addToQueueAndWait(request); Map response = ((Connection)request).json; try { List<Map> lst = (List<Map>)response.get("root"); List<PropertyBusinessObject> result = new ArrayList<PropertyBusinessObject>(); for(Map m : lst) { PropertyBusinessObject pb = (PropertyBusinessObject)type.newInstance(); pb.getPropertyIndex().populateFromMap(m); result.add(pb); } return new Response(request.getResponseCode(), result, request.getResponseErrorMessage()); } catch(Exception err) { Log.e(err); throw new RuntimeException(err.toString()); } }
Example 10
Source File: XMLParser.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * This is the entry point for parsing a document and the only non-private member method in this class * * @param is The InputStream containing the XML * @return an Element object describing the parsed document (Basically its DOM) */ public Element parse(Reader is) { buffOffset = 0; buffSize = -1; eventParser = false; Element rootElement=createNewElement("ROOT"); // ROOT is a "dummy" element that all other document elements are added to try { parseTagContent(rootElement, is); } catch (IOException ioe) { Log.e(ioe); } if (rootElement.getNumChildren()==0) { notifyError(ParserCallback.ERROR_NO_ROOTS, null, null, null, "XML document contains no root element."); return null; } else if (rootElement.getNumChildren()>1) { String roots=""; for(int i=1;i<rootElement.getNumChildren();i++) { Element elem=rootElement.getChildAt(i); if (elem.isTextElement()) { roots+="Text ("+elem.getText()+"),"; } else { roots+=elem.getTagName()+","; } } if (roots.endsWith(",")) { roots=roots.substring(0, roots.length()-1); } Element firstRoot=rootElement.getChildAt(0); String str=null; if (firstRoot.isTextElement()) { str="TEXT:"+firstRoot.getText(); } else { str=firstRoot.getTagName(); } notifyError(ParserCallback.ERROR_MULTIPLE_ROOTS, null, null, null, "XML document contains multiple root elements, only the first root ("+str+") will be used. Excessive roots: "+roots); } rootElement=rootElement.getChildAt(0); return rootElement; }
Example 11
Source File: UIFragment.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Parses a JSON string into a template. * @param json A JSON string representing a UI hierarchy. * @return * @throws IOException */ public static UIFragment parseJSON(String json) { try { Element el = UINotationParser.parseJSONNotation(json); return new UIFragment(el); } catch (Exception ex) { Log.e(ex); throw new RuntimeException(ex.getMessage()); } }
Example 12
Source File: Capture.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * <p>Invokes the camera and takes a photo synchronously while blocking the EDT, the sample below * demonstrates a simple usage and applying a mask to the result</p> * <script src="https://gist.github.com/codenameone/b18c37dfcc7de752e0e6.js"></script> * <img src="https://www.codenameone.com/img/developer-guide/graphics-image-masking.png" alt="Picture after the capture was complete and the resulted image was rounded. The background was set to red so the rounding effect will be more noticeable" /> * * @param width the target width for the image if possible, some platforms don't support scaling. To maintain aspect ratio set to -1 * @param height the target height for the image if possible, some platforms don't support scaling. To maintain aspect ratio set to -1 * @return the photo file location or null if the user canceled */ public static String capturePhoto(int width, int height) { CallBack c = new CallBack(); if("ios".equals(Display.getInstance().getPlatformName()) && (width != -1 || height != -1)) { // workaround for threading issues in iOS https://github.com/codenameone/CodenameOne/issues/2246 capturePhoto(c); Display.getInstance().invokeAndBlock(c); if(c.url == null) { return null; } ImageIO scale = Display.getInstance().getImageIO(); if(scale != null) { try { String path = c.url.substring(0, c.url.indexOf(".")) + "s" + c.url.substring(c.url.indexOf(".")); OutputStream os = FileSystemStorage.getInstance().openOutputStream(path); scale.save(c.url, os, ImageIO.FORMAT_JPEG, width, height, 1); Util.cleanup(os); FileSystemStorage.getInstance().delete(c.url); return path; } catch (IOException ex) { Log.e(ex); } } } else { c.targetWidth = width; c.targetHeight = height; capturePhoto(c); Display.getInstance().invokeAndBlock(c); } return c.url; }
Example 13
Source File: LocationManager.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Returns the current location synchronously, this is useful if you just want * to know the location NOW and don't care about tracking location. Notice that * this method will block until a result is returned so you might want to use something * like InfiniteProgress while this is running * * @param timeout timeout in milliseconds or -1 to never timeout * @return the current location or null in case of an error */ public Location getCurrentLocationSync(long timeout) { try { if(getStatus() != AVAILABLE) { LL l = new LL(); l.timeout = timeout; l.bind(); return l.result; } return getCurrentLocation(); } catch(IOException err) { Log.e(err); return null; } }
Example 14
Source File: UIFragment.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Parses input stream of XML into a Template * @param input InputStream with XML content to parse * @return The corresponding template, or a RuntimeException if parsing failed. */ public static UIFragment parseXML(InputStream input) { try { XMLParser p = new XMLParser(); Element el = p.parse(new InputStreamReader(input)); return new UIFragment(el); } catch (Exception ex) { Log.e(ex); throw new RuntimeException(ex.getMessage()); } }
Example 15
Source File: PropertyIndex.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Loads JSON for the object from storage with the given name * @param name the name of the storage */ public void loadJSON(String name) { try { InputStream is = Storage.getInstance().createInputStream(name); JSONParser jp = new JSONParser(); JSONParser.setUseBoolean(true); JSONParser.setUseLongs(true); populateFromMap(jp.parseJSON(new InputStreamReader(is, "UTF-8")), parent.getClass()); } catch(IOException err) { Log.e(err); throw new RuntimeException(err.toString()); } }
Example 16
Source File: FileTreeModel.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ public Vector getChildren(Object parent) { Vector response = new Vector(); try { if(parent == null) { String[] roots = FileSystemStorage.getInstance().getRoots(); for(int iter = 0 ; iter < roots.length ; iter++) { response.addElement(roots[iter]); } } else { String name = (String)parent; if(!name.endsWith("/")) { name += "/"; } String[] res = FileSystemStorage.getInstance().listFiles(name); if(res != null){ if(showFiles) { for(int iter = 0 ; iter < res.length ; iter++) { String f = res[iter]; if(!FileSystemStorage.getInstance().isDirectory(name + f) && ext != null){ int i = f.lastIndexOf('.'); if(i > 0){ String e = f.substring(i + 1, f.length()); if(ext.contains(e)){ response.addElement(name + f); } } }else{ response.addElement(name + f); } } } else { for(int iter = 0 ; iter < res.length ; iter++) { if(FileSystemStorage.getInstance().isDirectory(name + res[iter])) { response.addElement(name + res[iter]); } } } } } } catch(Throwable err) { Log.e(err); return new Vector(); } return response; }
Example 17
Source File: Display.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
/** * Implementation of the event dispatch loop content */ void edtLoopImpl() { try { // transitions shouldn't be bound by framerate if(animationQueue == null || animationQueue.size() == 0) { // prevents us from waking up the EDT too much and // thus exhausting the systems resources. The + 1 // prevents us from ever waiting 0 milliseconds which // is the same as waiting with no time limit if(!noSleep){ synchronized(lock){ impl.edtIdle(true); lock.wait(Math.max(1, framerateLock - (time))); impl.edtIdle(false); } } } else { // paint transition or intro animations and don't do anything else if such // animations are in progress... paintTransitionAnimation(); return; } } catch(Exception ignor) { Log.e(ignor); } long currentTime = System.currentTimeMillis(); // minimal amount of sync, just flipping the stack pointers synchronized(lock) { inputEventStackPointerTmp = inputEventStackPointer; inputEventStackPointer = 0; lastDragOffset = -1; int[] qt = inputEventStackTmp; inputEventStackTmp = inputEventStack; // We have a special flag here for a case where the input event stack might still be processing this can // happen if an event callback calls something like invokeAndBlock while processing and might reach // this code again if(qt[qt.length - 1] == Integer.MAX_VALUE) { inputEventStack = new int[qt.length]; } else { inputEventStack = qt; qt[qt.length - 1] = 0; } } // we copy the variables to the stack since the array might be replaced while we are working if the EDT // is nested into an "invokeAndBlock" int actualTmpPointer = inputEventStackPointerTmp; inputEventStackPointerTmp = 0; int[] actualStack = inputEventStackTmp; int offset = 0; actualStack[actualStack.length - 1] = Integer.MAX_VALUE; while(offset < actualTmpPointer) { offset = handleEvent(offset, actualStack); } actualStack[actualStack.length - 1] = 0; if(!impl.isInitialized()){ return; } codenameOneGraphics.setGraphics(impl.getNativeGraphics()); impl.paintDirty(); // draw the animations Form current = impl.getCurrentForm(); if(current != null){ current.repaintAnimations(); // check key repeat events long t = System.currentTimeMillis(); if(keyRepeatCharged && nextKeyRepeatEvent <= t) { current.keyRepeated(keyRepeatValue); nextKeyRepeatEvent = t + keyRepeatNextIntervalTime; } if(longPressCharged && longPressInterval <= t - longKeyPressTime) { longPressCharged = false; current.longKeyPress(keyRepeatValue); } if(longPointerCharged && longPressInterval <= t - longKeyPressTime) { longPointerCharged = false; current.longPointerPress(pointerX, pointerY); } } processSerialCalls(); time = System.currentTimeMillis() - currentTime; }
Example 18
Source File: CloudListModel.java From CodenameOne with GNU General Public License v2.0 | 2 votes |
/** * Invoked when a cloud error occurs * @param err the exception representing the error in cloud communications */ protected void onError(CloudException err) { Log.e(err); }
Example 19
Source File: CN.java From CodenameOne with GNU General Public License v2.0 | 2 votes |
/** * Prints to the log * @param s the exception */ public static void log(Throwable s) { Log.e(s); }
Example 20
Source File: TestReporting.java From CodenameOne with GNU General Public License v2.0 | 2 votes |
/** * Indicates an error from the current test case * @param err the error message */ public void logException(Throwable err) { Log.e(err); }