public WebCustomRequest map(FilterableRequestSpecification requestSpec, FilterContext ctx) {
    try {
      URL url = new URL(ctx.getCompleteRequestPath());
      String method = String.valueOf(ctx.getRequestMethod());

      WebCustomRequest request = new WebCustomRequest();
      request.setName(method + " to " + url.toString());
      request.setUrl(url.toString());
      request.setMethod(method);
      request.setResource("0");
      request.setSnapshot(
          String.format("t%d.inf", (long) (System.currentTimeMillis() % Math.pow(10, 10))));
      request.setMode(url.getProtocol());
      request.setBody((String) requestSpec.getBody());

      request.getBeforeFunctions().add(new WebRequestSaveParam());

      for (Header header : requestSpec.getHeaders()) {
        request.getBeforeFunctions().add(headerMapper.map(header));
      }

      return request;
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
  }
  /** Test client - play an A major scale to standard audio. */
  public static void main(String[] args) {
    // 440 Hz for 1 sec
    double freq = 440.0;
    for (int i = 0; i <= StdAudio.SAMPLE_RATE; i++) {
      StdAudio.play(0.5 * Math.sin(2 * Math.PI * freq * i / StdAudio.SAMPLE_RATE));
    }

    // scale increments
    int[] steps = {0, 2, 4, 5, 7, 9, 11, 12};
    for (int i = 0; i < steps.length; i++) {
      double hz = 440.0 * Math.pow(2, steps[i] / 12.0);
      StdAudio.play(note(hz, 1.0, 0.5));
    }

    // need to call this in non-interactive stuff so the program doesn't
    // terminate
    // until all the sound leaves the speaker.
    StdAudio.close();

    // need to terminate a Java program with sound
    System.exit(0);
  }
Exemple #3
0
  /** Get an image based on index numbers */
  public BufferedImage getIndexedImage(
      int x, int y, int zoom, int cacheZoom, GMapListener listener) {

    if (listener != null) {
      if (!getGDataSource().isCached(x, y, zoom)) {
        listener.updateGMapPainting();
        listener.updateGMapMessage(GMap.MESSAGE_DOWNLOADING);
      } else {
        listener.updateGMapMessage(GMap.MESSAGE_PAINTING);
      }
    }

    BufferedImage thumbImage = getGDataSource().getImage(x, y, zoom, true);

    if (thumbImage == null) return defaultImage;

    // if we dont have to paint cache, return here
    if (cacheZoom == (GPhysicalPoint.MIN_ZOOM - 1) || cacheZoom >= zoom) return thumbImage;

    BufferedImage paintedImage =
        new BufferedImage(
            GDataSource.sourceSize.width,
            GDataSource.sourceSize.height,
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = paintedImage.createGraphics();
    graphics2D.drawImage(
        thumbImage, 0, 0, GDataSource.sourceSize.width, GDataSource.sourceSize.height, null);

    // now lets move to painting the cache
    double imageNum = Math.pow(2, zoom - cacheZoom);

    // draw cache lines
    int startX = (int) (imageNum * x);
    int startY = (int) (imageNum * y);

    // get composite to restore later, set new transparent composite
    Composite originalComposite = graphics2D.getComposite();
    graphics2D.setComposite(opacity40);

    // draw grid
    for (int i = 0; i < imageNum; i++) {
      for (int j = 0; j < imageNum; j++) {
        // points
        Point upperLeft =
            new Point(
                (int) (GDataSource.sourceSize.width / imageNum) * i,
                (int) (GDataSource.sourceSize.height / imageNum) * j);
        Dimension size =
            new Dimension(
                (int) (GDataSource.sourceSize.width / imageNum),
                (int) (GDataSource.sourceSize.height / imageNum));

        // draw lines
        graphics2D.setColor(new Color(100, 100, 100));
        graphics2D.drawLine(upperLeft.x, upperLeft.y, upperLeft.x + size.width, upperLeft.y);
        graphics2D.drawLine(upperLeft.x, upperLeft.y, upperLeft.x, upperLeft.y + size.height);

        // check if file exists
        if (getGDataSource().isCached(startX + i, startY + j, cacheZoom))
          graphics2D.setColor(Color.RED);
        else graphics2D.setColor(new Color(155, 155, 155));

        // shade rectangle
        graphics2D.fillRect(upperLeft.x, upperLeft.y, size.width, size.height);
      }
    }

    // restore composite
    graphics2D.setComposite(originalComposite);

    return paintedImage;
  }
Exemple #4
0
  public void processSectionSpline(boolean shiftDown) {
    mCurrPC.setBatchModeOn();

    if (!shiftDown) mCurrPC.unselectAll();

    // loop on spline pts
    for (int s = 0; s < mSplinePoints.size() - 2; s++) {
      Point p1 = (Point) mSplinePoints.elementAt(s);
      Point p2 = (Point) mSplinePoints.elementAt(s + 1);

      int x1 = p1.x - mLeft - 5;
      int y1 = p1.y - mTop - 5;
      int x2 = p2.x - mLeft - 5;
      int y2 = p2.y - mTop - 5;

      // construct the search polygon
      double dx = x1 - x2;
      double dy = y1 - y2;
      int width1 = ComputeSectionPixelWidth(p1);
      int width2 = ComputeSectionPixelWidth(p2);

      if (dx == 0 && dy == 0) return;
      double dist = (double) Math.pow(dx * dx + dy * dy, 0.5f);

      double p1x = x1 + (double) width1 * (-dy / dist);
      double p1y = y1 + (double) width1 * (dx / dist);

      double p2x = x1 - (double) width1 * (-dy / dist);
      double p2y = y1 - (double) width1 * (dx / dist);

      double p3x = x2 + (double) width2 * (-dy / dist);
      double p3y = y2 + (double) width2 * (dx / dist);

      double p4x = x2 - (double) width2 * (-dy / dist);
      double p4y = y2 - (double) width2 * (dx / dist);

      Polygon srcArea = new Polygon();
      srcArea.addPoint((int) p2x, (int) p2y);
      srcArea.addPoint((int) p1x, (int) p1y);
      srcArea.addPoint((int) p3x, (int) p3y);
      srcArea.addPoint((int) p4x, (int) p4y);

      // search for matches
      byte[] currFilterResults = fdm.getResults();
      double[] yArray1 = getYArray1();
      double[] xArray1 = getXArray1();
      double[] yArray2 = getYArray2();
      double[] xArray2 = getXArray2();
      mCurrPC.setBatchModeOn();
      for (int i = 0; i < mCurrPC.getSize(); i++) {
        if (!mIgnoreFilter
            && (mCurrPC.isDeleted(i) || currFilterResults[i] != 4 || !mCurrPC.isSelectedLayer(i)))
          continue;
        double yi = yArray1[i];
        double xi = xArray1[i];
        double xi2 = Float.NaN;
        double yi2 = Float.NaN;
        double xx2 = Float.NaN;
        double yy2 = Float.NaN;

        // correct the X value if necessary
        xi = correctX(xi);

        double xx1 = (xi - winXOrigin) * winXScale;
        double yy1 = (yi - winYOrigin) * winYScale;

        // correct the Y coordinate if necessary
        yy1 = correctY(yy1);

        if (!isYAxisScaler()) {
          yi2 = yArray2[i];
          yy2 = (yi2 - winYOrigin) * winYScale;
          ;
          yy2 = correctY(yy2);
        } else yy2 = yy1;

        if (!isXAxisScaler()) {
          xi2 = xArray2[i];
          xi2 = correctX(xi2);
          xx2 = (xi2 - winXOrigin) * winXScale;
        } else xx2 = xx1;

        if (srcArea.contains(new Point((int) xx1, (int) yy1))
            || srcArea.contains(new Point((int) xx2, (int) yy2))) {
          mCurrPC.select(i);
        }
      }
    } // for splines

    mSplinePoints.removeAllElements();
    mViewManager.invalidateAllViews();
    mCurrPC.setBatchModeOff();
  }
        public void onPreviewFrame(byte[] frame, Camera c) {
          if (!inProcessing) {
            inProcessing = true;

            int picWidth = cameraView_.Width();
            int picHeight = cameraView_.Height();
            ByteBuffer bbuffer = ByteBuffer.wrap(frame);
            try {
              bbuffer.get(preFrame, 0, picWidth * picHeight + picWidth * picHeight / 2);

              int numFilled = 0;

              int y = picHeight / 2;
              for (int i = 0; i < PIN_LENGTH; i++) {
                int x =
                    picWidth / 2 + (int) ((i + 0.5f - PIN_LENGTH / 2) * SYMBOL_SPACING * picWidth);
                int p = 0;
                // Take 4 nearby pixels, to filter out noise
                p += preFrame[picWidth * y + x] & 0xFF;
                p += preFrame[picWidth * y + x + 1] & 0xFF;
                p += preFrame[picWidth * (y + 1) + x] & 0xFF;
                p += preFrame[picWidth * (y + 1) + x + 1] & 0xFF;
                p /= 4;
                pinEntered[i] = (p < BRIGHTNESS_THRESHOLD);

                if (pinEntered[i]) numFilled++;
              }
              overlayView_.invalidate();

              if (System.currentTimeMillis() > delay) {
                delay = System.currentTimeMillis() + SEND_DELAY;

                if (sendEnter && numFilled == 0) {
                  sendEnter = false;
                  currentPin++;
                  runOnUiThread(
                      new Runnable() {
                        public void run() {
                          tvMessage2.setText("PIN: " + currentPin);
                        }
                      });
                }

                if (sendEnter && numFilled == PIN_LENGTH) {
                  final String[] cmd = {
                    "/system/bin/sh",
                    "-c",
                    "echo 'echo enter | "
                        + getFilesDir().getAbsolutePath()
                        + "/hid-gadget-test /dev/hidg0 keyboard' | su"
                  };
                  runOnUiThread(
                      new Runnable() {
                        public void run() {
                          tvMessage2.setText("PIN: " + currentPin + " - sending Enter");
                        }
                      });
                  Runtime.getRuntime().exec(cmd).waitFor();
                }

                if (!sendEnter && numFilled == PIN_LENGTH) {
                  sendEnter = true;
                }

                if (!sendEnter && numFilled < PIN_LENGTH) {
                  final int digit =
                      (currentPin / (int) Math.pow(10, PIN_LENGTH - numFilled - 1)) % 10;
                  final int pos = numFilled + 1;
                  final String[] cmd = {
                    "/system/bin/sh",
                    "-c",
                    "echo 'echo "
                        + digit
                        + " | "
                        + getFilesDir().getAbsolutePath()
                        + "/hid-gadget-test /dev/hidg0 keyboard' | su"
                  };
                  runOnUiThread(
                      new Runnable() {
                        public void run() {
                          tvMessage2.setText(
                              "PIN: "
                                  + String.format("%04d", currentPin)
                                  + " - sending digit #"
                                  + pos
                                  + " : "
                                  + digit);
                        }
                      });
                  Runtime.getRuntime().exec(cmd).waitFor();
                }
              }

            } catch (Exception e) {
              e.printStackTrace();
            }

            inProcessing = false;
          }
        }