Package net.rim.device.api.script

Examples of net.rim.device.api.script.ScriptableFunction


               //problem
          }else{
                _vec = (Vector)_listenerHash.get(eService);
               
                for(int i=0; i < _vec.size(); i++){
                  final ScriptableFunction sf = (ScriptableFunction)_vec.elementAt(i);
                    _appObject.invokeLater(new Runnable() {
                        public void run() {
                              try {
                                 
                                  sf.invoke(null, new Object[] { eService, msg });

                              } catch (Exception e) {
                                    System.out.println("Error invoking callback: " + e.getMessage());
                                    throw new RuntimeException("Error invoking callback: " + e.getMessage());
                              }
View Full Code Here


            MessageListItem item = new MessageListItem(message);
           
            Object[] result = new Object[] {item};
         
            // Pass the event back to the JavaScript callback
            ScriptableFunction onItemOpened = getOnItemOpened();
            onItemOpened.invoke(onItemOpened, result);
          }
          catch (Exception e) {
            throw new RuntimeException(e.getMessage());
          }
        }
View Full Code Here

            MessageListItem item = new MessageListItem(message);
           
            Object[] result = new Object[]{item};
         
            // Pass the event back to the JavaScript callback
            ScriptableFunction onItemMarkedRead = getOnItemMarkedRead();
            onItemMarkedRead.invoke(onItemMarkedRead, result);
          }
          catch (Exception e) {
            throw new RuntimeException(e.getMessage());
          }
        }
View Full Code Here

            MessageListItem item = new MessageListItem(message);
           
            Object[] result = new Object[]{item};
         
            // Pass the event back to the JavaScript callback
            ScriptableFunction onItemMarkedUnread = getOnItemMarkedUnread();
            onItemMarkedUnread.invoke(onItemMarkedUnread, result);
          }
          catch (Exception e) {
            throw new RuntimeException(e.getMessage());
          }
        }
View Full Code Here

            MessageListItem item = new MessageListItem(message);
           
            Object[] result = new Object[]{item};
         
            // Pass the event back to the JavaScript callback
            ScriptableFunction onItemDeleted = getOnItemDeleted();
            onItemDeleted.invoke(onItemDeleted, result);
          }
          catch (Exception e) {
            throw new RuntimeException(e.getMessage());
          }
        }
View Full Code Here

    /* @Override */
    public Object invoke(final Object thiz, final Object[] args) throws Exception {

      String contentArg = null;
        ScriptableFunction onGenerateArg = null;
        ScriptableFunction onErrorArg = null;
        Scriptable optionsArg = null;
       
        if(args.length < 2){
          throw new IllegalArgumentException("Missing Captured Callback");
        }else{
          contentArg = (String) args[0];
      onGenerateArg = (ScriptableFunction) args[1];
      if(args.length > 2){
        onErrorArg =  (ScriptableFunction) args[2];
        if(args.length > 3){
          optionsArg = (Scriptable) args[3];
        }
      }
        }             
     
      final String contents = contentArg;
        final ScriptableFunction generatededCallback = onGenerateArg;
        final ScriptableFunction errorCallback = onErrorArg;
        final Scriptable options = optionsArg;
       
        Application.getApplication().invokeLater(new Runnable(){
         
          private final String[] ALLOWED_EXTENSIONS = {"jpq","jpeg","png"};

            public void run() {

              FileConnection fconn = null;
              try{
                  MultiFormatWriter writer = new MultiFormatWriter();

                  int width = 50;
                  int height = 50;
                  BarcodeFormat format = BarcodeFormat.QR_CODE;
                  Hashtable hints = new Hashtable(2);
                  String filePath = "file:///SDCard/";
                  String fileName = ""+(new Date()).getTime();
                  String fileExtension = "png";
                 
                  if(options != null){
                    Object  widthObj =options.getField("width");
                    if(widthObj != UNDEFINED){
                      width =((Integer)widthObj).intValue();
                    }
                   
                    Object heightObj = options.getField("height");
                    if(heightObj != UNDEFINED){
                      height = ((Integer)heightObj).intValue();
                    }
                   
                    Object formatObj = options.getField("format");
                    if(formatObj != UNDEFINED){
                      format = BarcodeFormat.valueOf(((String)formatObj).toUpperCase());
                    }                   
                   
                    //Hints
                    Object charSetObj = options.getField("characterSet");
                    if(charSetObj != UNDEFINED){
                      hints.put(EncodeHintType.CHARACTER_SET, (String)charSetObj);
                    }
                    Object errorCorrectionObj = options.getField("errorCorrection");
                    if(errorCorrectionObj != UNDEFINED){
                      hints.put(EncodeHintType.ERROR_CORRECTION, (Integer)errorCorrectionObj);
                    }
                   
                    Object filePathObj = options.getField("filePath");
                    if(filePathObj != UNDEFINED){
                      String filePathOrig = (String)filePathObj;
                      fileExtension = filePathOrig.substring(filePathOrig.lastIndexOf('.')+1);
                      fileName = filePathOrig.substring(filePathOrig.lastIndexOf('/')+1,filePathOrig.lastIndexOf('.'));
                      filePath = filePathOrig.substring(0, filePathOrig.lastIndexOf('/'));
                     
                      boolean validExtension = false;
                      for( int i =0; i< ALLOWED_EXTENSIONS.length;i++){
                        validExtension |= fileExtension.equals(ALLOWED_EXTENSIONS[i]);
                      }
                      if(!validExtension){
                        fileExtension = "png";
                      }
                    }                                                         
                   
                  }
                 
                  ByteMatrix bm;                 
                  try{
                     bm = writer.encode(contents, format, width, height,hints);
                  }catch(ClassCastException cce){
                    throw new Exception("ZXing Barcode Writer FAILURE - try different paramteres and pray");
                  }
                  //Bitmap b = BarcodeBitmap.createBitmap(bm,0);
                  Bitmap b = new Bitmap(width,height);

                  byte[][] array = bm.getArray();
                  //iterate through the matrix and draw the pixels to the image
                  //a Jeff and BT super hack to make generating a barcode work
                  for (int y = 0; y < height; y++) {
                    int[] argbArray = new int[width];
                   for (int x = 0; x < width; x++) {
                    int grayValue = array[y][x] & 0xff;
                    int pixel = (grayValue == 0 ? 0xFF000000 : 0xFFFFFFFF);
                    argbArray[x] = pixel;
                   }
                   b.setARGB(argbArray,0, width, 0,y, width, 1);
                  }
                 
                 


                 
                fconn = (FileConnection)Connector.open(filePath+"/"+fileName+"."+fileExtension, Connector.READ_WRITE);

                    if(fconn.exists()){
                      fileName += (new Date()).getTime();                     
                      fconn.close();
                      fconn = (FileConnection)Connector.open(filePath+"//"+fileName+"."+fileExtension, Connector.READ_WRITE);
                    }
        
                    fconn.create();

                    OutputStream outputStream = fconn.openOutputStream();
                    EncodedImage encodedImage;
                    if(fileExtension.equals("jpg") || fileExtension.equals("jpeg")){
                      encodedImage = JPEGEncodedImage.encode(b, 100);
                    }else{
                      encodedImage = PNGEncodedImage.encode(b);
                    }
                    byte[] imageBytes = encodedImage.getData();
                    outputStream.write(imageBytes);
                    outputStream.close();
                   
                    fconn.close();
                    Object[] args = {filePath+"//"+fileName+"."+fileExtension};
                    generatededCallback.invoke(thiz, args);
                 
              }catch(Exception e){               
                throwError(e);
              }finally{
          try {
            fconn.close();
          } catch (IOException e) {
            throwError(e);
          }
              }

            }
            public void throwError(Exception e){
              if(errorCallback != null){
               
          try {
            errorCallback.invoke(thiz, new Object[] {new ErrorObject(-1, e.getMessage())} );
          } catch (Exception e1) {
          }
              }
            }

View Full Code Here

  public int opticalZoom = -1;
  /* @Override */
  public Object invoke(final Object thiz, final Object[] args)
      throws Exception {

    ScriptableFunction onCaptureArg = null;
    ScriptableFunction onErrorArg = null;
    Scriptable optionsArg = null;
    Scriptable focusArgs = null;
    Scriptable zoomArgs = null;


    if (args.length < 1) {
      throw new IllegalArgumentException("Missing Captured Callback");
    } else {
      for(int i=0; i<args.length; i++) {
        switch(i) {
        case 0:
          onCaptureArg = (ScriptableFunction) args[i];
          break;
        case 1:
          onErrorArg = (ScriptableFunction) args[i];
          break;
        case 2:
          optionsArg = (Scriptable) args[i];
          break;
        case 3:
          focusArgs = (Scriptable) args[i];
          break;
        case 4:
          zoomArgs = (Scriptable) args[i];
          break;
        }
         
      }
    }

    final ScriptableFunction capturedCallback = onCaptureArg;
    final ScriptableFunction errorCallback = onErrorArg;

    final Hashtable hints = new Hashtable(5);
    if (optionsArg != UNDEFINED) {
      try {
        Object tryHarder = optionsArg.getField("tryHarder");
View Full Code Here

   
    public void contactDeclined(BBMPlatformConnection connection, BBMPlatformContact contact) {
        this.waitForConnDelivery();
       
        try {
            final ScriptableFunction callback = (ScriptableFunction) _connObj.getField(ConnectionObject.EVENT_ON_USER_DECLINED);
            final Object[] args = new Object[] {
                new BBMPlatformUser(contact),
            };
            Util.dispatchCallback(callback, args);
        } catch(Exception e) {
View Full Code Here

    public void contactLeft(BBMPlatformConnection connection, BBMPlatformContact contact) {
        this.waitForConnDelivery();
       
        try {
            final ScriptableFunction callback = (ScriptableFunction) _connObj.getField(ConnectionObject.EVENT_ON_USER_LEFT);
            final Object[] args = new Object[] {
                new BBMPlatformUser(contact),
            };
            Util.dispatchCallback(callback, args);
        } catch(Exception e) {
View Full Code Here

    public void contactsInvited(BBMPlatformConnection connection, BBMPlatformContactList contactList) {
        this.waitForConnDelivery();
       
        try {
            final ScriptableFunction callback = (ScriptableFunction) _connObj.getField(ConnectionObject.EVENT_ON_USERS_INVITED);
            final Object[] args = new Object[] {
                Util.contactListToArray(contactList),
            };
            Util.dispatchCallback(callback, args);
        } catch(Exception e) {
View Full Code Here

TOP

Related Classes of net.rim.device.api.script.ScriptableFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.