@SuppressWarnings("ConstantConditions")
    public void onPreviewFrame(byte[] data, Camera incomingCamera) {
      try {
        if (System.currentTimeMillis() > lastSnapshotTime) {
          lastSnapshotTime = System.currentTimeMillis() + SNAPSHOT_DELAY;

          Camera.Parameters cameraParameters = incomingCamera.getParameters();
          Camera.Size previewSize = cameraParameters.getPreviewSize();
          Image barcode = new Image(previewSize.width, previewSize.height, GREY_COLOR_SPACE);
          barcode.setData(data);

          if (scanner.scanImage(barcode) != 0) {
            SymbolSet scannerResults = scanner.getResults();

            if (vibrator != null) vibrator.vibrate(VIBRATE_TIME);

            for (Symbol symbol : scannerResults)
              if (scannerListener == null)
                Toast.makeText(getActivity(), symbol.getData(), Toast.LENGTH_LONG).show();
              else scannerListener.onDataReceive(symbol.getData(), symbol.getType());
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
Exemplo n.º 2
0
 private void read_write(CommonTree tr, char c) {
   String op = null;
   String type = null;
   String irname = null;
   Symbol sym;
   if (c == 'r') op = "READ";
   else op = "WRITE";
   for (int i = 0; i < tr.getChildren().size(); i++) {
     sym = getSym(getChToken(tr, i));
     type = sym.getType();
     irname = checkName(sym);
     if (type.equals("INT")) link(op + "I " + irname);
     else if (type.equals("FLOAT")) {
       link(op + "F " + irname);
     } else if (type.equals("STRING")) {
       link(op + "S " + irname);
     } else System.out.println("unrecognized type:" + type);
   }
 }
Exemplo n.º 3
0
  public static String ReplaceVariablesToDefaults(String expr, Vector memory, int tryUnknow) {

    StringBuffer newExpr = new StringBuffer();
    // iterador de elementos do codigo
    IteratorExpression tok = new IteratorExpression(expr);
    Symbol var;
    String elem;
    while (tok.hasMoreElements()) {
      elem = tok.current();
      tok.next();
      var = Variable.getVariable(elem, memory);
      // se for uma variavel vai selecionar o valor
      if (var != null) {
        if (var.getType() != var.DESCONHECIDO) newExpr.append(var.getDefaultValue() + " ");
        else newExpr.append(Symbol.getDefaultValue(tryUnknow) + " ");
      }
      // senao mete o elmento
      else newExpr.append(elem + " ");
    }
    return newExpr.toString().trim();
  }