Package net.rim.device.api.script

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


    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('/'));
View Full Code Here


  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");
        if (tryHarder != UNDEFINED) {
          hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        }

        Object formatObj = optionsArg.getField("formats");
        Vector formatVector = new Vector();
        if (formatObj != UNDEFINED) {
          Scriptable formats = (Scriptable) formatObj;
          for (int i = 0; i < formats.getElementCount(); i++) {
            String format = (String) formats.getElement(i);
            BarcodeFormat bcFormat;
            if (format.equalsIgnoreCase("CODE_128")) {
              formatVector.addElement(BarcodeFormat.CODE_128);
              continue;
            } else if (format.equalsIgnoreCase("CODE_39")) {
View Full Code Here

    public static final Object getScriptField(final Scriptable object, final String fieldName, final StringBuffer optionalProperty) {
        // clear optionalField
        optionalProperty.setLength(0);

        // Parse whether leftField contains subfield or attribute
        Scriptable o = object;
        String optional = "";
        String key = fieldName;
        if (key.indexOf('.') >= 0) {
            final StringTokenizer st = new StringTokenizer(key, ".");
            while (true) {
                key = st.nextToken();
                if (!st.hasMoreTokens()) {
                    break;
                }

                Object field;
                try {
                    field = o.getField(key);
                } catch (final Exception e) {
                    field = null;
                }

                if (field == null) {
                    return null;
                }

                if (field instanceof Scriptable) {
                    o = (Scriptable) field;
                }
                else if (field instanceof Date) {
                    optional = st.nextToken();
                    break;
                }
            }
        }

        Object fieldToTest;
        try {
            fieldToTest = o.getField(key);
        } catch (final Exception e) {
            fieldToTest = null;
        }

        optionalProperty.append(optional);
View Full Code Here

        // message
        message = (String) args[ 0 ];

        // choices & values
        Scriptable stringArray = (Scriptable) args[ 1 ];
        int count = stringArray.getElementCount();
        choices = new String[ count ];
        values = new int[ count ];
        for( int i = 0; i < count; i++ ) {
            choices[ i ] = stringArray.getElement( i ).toString();
            values[ i ] = i;
        }

        // default choice
        if( args.length > 2 && args[ 2 ] != null ) {
View Full Code Here

            if (orderByValue == null) {
                vector.addElement(object);
                return ret;
            }

            Scriptable objectInVector;
            Object valueInVector;

            while (end - start >= 2) {
                final int insertPosition = start + (end - start) / 2;
View Full Code Here

    /**
     * @see blackberry.core.ScriptableFunctionBase#execute(Object, Object[])
     */
    public Object execute( Object thiz, Object[] args ) throws Exception {
        boolean allowMultiple = ( (Boolean) args[ 0 ] ).booleanValue();
        Scriptable choices = (Scriptable) args[ 1 ];
        ScriptableFunction callback = (ScriptableFunction) args[ 2 ];

        int numChoices = choices.getElementCount();
        String[] labels = new String[ numChoices ];
        boolean[] enabled = new boolean[ numChoices ];
        boolean[] selected = new boolean[ numChoices ];
        int[] types = new int[ numChoices ];

View Full Code Here

            boolean firstSelected = false;
            boolean canSelect = true;
           
            for( int i = 0; i < fromScriptableChoices.getElementCount(); i++ ) {
                Scriptable choice = (Scriptable) fromScriptableChoices.getElement( i );
                labels[ i ] = (String) choice.getField( "label" );
                enabled[ i ] = ( (Boolean) choice.getField( "enabled" ) ).booleanValue();
               
                type[ i ] = ( (String) choice.getField( "type" ) ).equals( "group" ) ? POPUP_ITEM_TYPE_GROUP
                        : POPUP_ITEM_TYPE_OPTION;
               
                canSelect = (type[ i ] != POPUP_ITEM_TYPE_GROUP) && (allowMultiple || !firstSelected);
                selected[ i ] = canSelect && enabled[ i ] && ( (Boolean) choice.getField( "selected" ) ).booleanValue();
                firstSelected = firstSelected || selected[ i ];
            }
        } catch( Exception e ) {
            throw new RuntimeException( e.getMessage() );
        }
View Full Code Here

    /**
     * @see blackberry.core.ScriptableFunctionBase#execute(Object, Object[])
     */
    public Object execute(Object thiz, Object[] args) throws Exception {
        String type = (String) args[0];
        Scriptable options = (Scriptable) args[1];
        ScriptableFunction callback = (ScriptableFunction) args[2] ;
       
        String value = (String)options.getField("value");
        String min = (String)options.getField("min");
        String max = (String)options.getField("max");
       
        Runnable dr = DialogRunnableFactory.getDateTimeRunnable(type, value, min, max, callback);
       
        // queue
        UiApplication.getUiApplication().invokeLater(dr);
View Full Code Here

        // the default value of the global status. The developer cannot change it.
        final boolean global = false;
        // message
        message = (String) args[ 0 ];
        // choices & values
        Scriptable stringArray = (Scriptable) args[ 1 ];
        int count = stringArray.getElementCount();
        buttons = new String[ count ];
        for( int i = 0; i < count; i++ ) {
            buttons[ i ] = stringArray.getElement( i ).toString();
        }

        Runnable dr = DialogRunnableFactory.getCustomAskRunnable( message, buttons, defaultChoice, global, callback );
        // queue
        UiApplication.getUiApplication().invokeLater( dr );
View Full Code Here

            long expiryTime;
            String cookie;
            ContactListProvider contactList;
           
            if(args.length == 2) {
                final Scriptable options = (Scriptable) args[1];
               
                Object expiryTimeObj = options.getField(OPTIONS_FIELD_EXPIRY_TIME);
                if(expiryTimeObj.equals(UNDEFINED)) {
                    expiryTime = 0;
                } else {
                    try {
                        expiryTime = Long.parseLong(expiryTimeObj.toString());
                    } catch(Exception e) {
                        expiryTime = 0;
                    }
                }
               
                try {
                    cookie = (String) options.getField(OPTIONS_FIELD_COOKIE);
                } catch(Exception e) {
                    cookie = null;
                }
               
                try {
                    BBMPlatformUser[] contacts = (BBMPlatformUser[]) options.getField(OPTIONS_FIELD_CONTACTS);
                    contactList = new Util.SimpleContactListProvider(contacts);
                } catch(Exception e) {
                    contactList = null;
                }
            } else {
View Full Code Here

TOP

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

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.