Пример #1
0
  private void showCamera() {
    try {
      mPlayer = Manager.createPlayer("capture://video");
      mPlayer.realize();

      mVideoControl = (VideoControl) mPlayer.getControl("VideoControl");

      Canvas canvas = new CameraCanvas(this, mVideoControl);
      canvas.addCommand(mBackCommand);
      canvas.addCommand(mCaptureCommand);
      canvas.setCommandListener(this);
      mDisplay.setCurrent(canvas);

      /*
      Form form = new Form("Camera form");
      Item item = (Item)mVideoControl.initDisplayMode(
          GUIControl.USE_GUI_PRIMITIVE, null);
      form.append(item);
      form.addCommand(mBackCommand);
      form.addCommand(mCaptureCommand);
      form.setCommandListener(this);
      mDisplay.setCurrent(form);
      */

      mPlayer.start();
    } catch (IOException ioe) {
      handleException(ioe);
    } catch (MediaException me) {
      handleException(me);
    }
  }
Пример #2
0
  public CopterForm(
      String title,
      Command cmdExit,
      CommandListener cl,
      ItemStateListener isl,
      Canvas canv,
      CopterAudioScene cas) {
    _f = new Form(title);
    _f.addCommand(cmdExit);
    _f.setItemStateListener(isl);
    _f.setCommandListener(cl);

    _c = new Command(title, Command.ITEM, 2);
    canv.addCommand(_c);
    _cas = cas;
  }
Пример #3
0
  public void startApp() {
    if (svgCanvas == null) {
      // If there is a splash screen defined, show it immediately.
      boolean hasSplash = ((splashImageName != null) && !"".equals(splashImageName));

      if (hasSplash) {
        InputStream splashStream = getClass().getResourceAsStream(splashImageName);

        try {
          Image splashImage = Image.createImage(splashStream);
          splashCanvas = new SplashCanvas(splashImage);
        } catch (IOException ioe) {
          ioe.printStackTrace();
          hasSplash = false;
        }

        if (splashCanvas != null) {
          Display.getDisplay(this).setCurrent(splashCanvas);
        }
      }

      long start = System.currentTimeMillis();

      // Get input stream to the SVG image stored in the MIDlet's jar.
      InputStream svgDemoStream = getClass().getResourceAsStream(svgImageName);

      // Build an SVGImage instance from the stream
      svgImage = null;

      if (svgDemoStream != null) {
        try {
          svgImage = (SVGImage) SVGImage.createImage(svgDemoStream, null);
        } catch (IOException io) {
          io.printStackTrace();
        }
      }

      if (svgImage == null) {
        throw new Error(ERROR_COULD_NOT_LOAD_SVG + svgImageName);
      }

      // Build an SVGAnimator from the SVGImage. The SVGAnimator will handle
      // all the animation details and run the SVG animation in a
      // Canvas instance.
      svgAnimator = SVGAnimator.createAnimator(svgImage);

      // Set to 10 fps (frames per second)
      svgAnimator.setTimeIncrement(0.01f);

      // Get the Canvas managed by the SVGAnimator and set the
      // svgImage's size to the canvas display area.
      svgCanvas = (Canvas) svgAnimator.getTargetComponent();
      svgImage.setViewportWidth(svgCanvas.getWidth());
      svgImage.setViewportHeight(svgCanvas.getHeight());

      // Hook the exit command so that we can exit the animation demo.
      svgCanvas.addCommand(exitCommand);
      svgCanvas.setCommandListener(this);

      // The SVG root element is used to reset the time on a stop operation.
      doc = svgImage.getDocument();
      svg = (SVGSVGElement) doc.getDocumentElement();

      // Hook-in key listeners to play, pause and stop the animation.
      svgAnimator.setSVGEventListener(this);

      long end = System.currentTimeMillis();

      if (hasSplash) {
        long waitMore = SPLASH_MIN_LENGTH - (end - start);

        if (waitMore > 0) {
          try {
            Thread.currentThread().sleep(waitMore);
          } catch (InterruptedException ie) {
            // Do nothing.
          }
        }
      }

      if (autoStart) {
        svgAnimator.play();
        state = STATE_PLAYING;
        System.err.println("PLAYING...");
      }
    }

    Display.getDisplay(this).setCurrent(svgCanvas);
    resumeAnimation();
  }