コード例 #1
0
ファイル: MainCanvas.java プロジェクト: kubaodias/bluectrl
  /** Metoda uruchamiana przez watek, odpowiedzialna za przerysowywanie ekranu */
  public void run() {
    int loopCount = 0;

    displayLogo();

    Runtime.getRuntime().gc();
    // setFullScreenMode(false);

    while (true) {
      updateState(); // sprawdzenie stanu przyciskow
      updateScreen(); // wyswietlenie nowej zawartosci ekranu

      loopCount++;

      if (loopCount > 200) {
        Runtime.getRuntime().gc();
        loopCount = 0;
      }

      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        soundPlayer.play(SoundPlayer.ERROR_SOUND);
        System.out.println("Praca watku przerysowujacego zawartosc ekranu zostala przerwana!");
      }
    }
  }
コード例 #2
0
ファイル: MainCanvas.java プロジェクト: kubaodias/bluectrl
  /** Metoda sprawdzajaca stan klawiszy i aktualizujaca zmienne odpowiedzialne za stan gry */
  public void updateState() {
    int keys = getKeyStates();

    if (bluetoothPlayer.getIsConnectedToServer() == true) {
      if (displayedScreen == PLAYER_SCREEN) { // jesli wyswietlany jest ekran odtwarzacza
        // jesli przycisk 'Play / Pause' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & FIRE_PRESSED) != 0) && (nextPressed == false) && (previousPressed == false)) {
          if (playPauseSprite.getFrame() == PLAY_ICON) {
            playPauseSprite.setFrame(PLAY_ICON_PRESSED);
          } else if (playPauseSprite.getFrame() == PAUSE_ICON) {
            playPauseSprite.setFrame(PAUSE_ICON_PRESSED);
          }

          if (firePressed == false) soundPlayer.play(SoundPlayer.CLICK_SOUND);

          firePressed = true;
        }
        // przycisk zostal zwolniony
        else if (((keys & FIRE_PRESSED) == 0) && (firePressed == true)) {
          if (playPauseSprite.getFrame() == PLAY_ICON_PRESSED) { // zmiana stanu przycisku
            bluetoothPlayer.play();
            playPauseSprite.setFrame(PAUSE_ICON);

          } else if (playPauseSprite.getFrame() == PAUSE_ICON_PRESSED) {
            bluetoothPlayer.pause();
            playPauseSprite.setFrame(PLAY_ICON);
          }

          firePressed = false;
        }
        // jesli przycisk 'Next' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & RIGHT_PRESSED) != 0) && (firePressed == false) && (previousPressed == false)) {
          if (nextSprite.getFrame() == NEXT_ICON) nextSprite.setFrame(NEXT_ICON_PRESSED);

          if (nextPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          nextPressed = true;
        }
        // przycisk zostal zwolniony
        else if (((keys & RIGHT_PRESSED) == 0) && (nextPressed == true)) {
          if (nextSprite.getFrame() == NEXT_ICON_PRESSED) nextSprite.setFrame(NEXT_ICON);

          bluetoothPlayer.addCommandToProcess(BluetoothPlayer.COMMAND_NEXT);
          nextPressed = false;

          if (bluetoothPlayer.getTotalTime() != 0) // jesli utwor jest odtwarzany lub zapauzowany
          playPauseSprite.setFrame(PAUSE_ICON);
        }
        // jesli przycisk 'Previous' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & LEFT_PRESSED) != 0) && (nextPressed == false) && (firePressed == false)) {
          if (previousSprite.getFrame() == PREVIOUS_ICON)
            previousSprite.setFrame(PREVIOUS_ICON_PRESSED);

          if (previousPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          previousPressed = true;
        }
        // przycisk zostal zwolniony
        else if (((keys & LEFT_PRESSED) == 0) && (previousPressed == true)) {
          if (previousSprite.getFrame() == PREVIOUS_ICON_PRESSED)
            previousSprite.setFrame(PREVIOUS_ICON);

          bluetoothPlayer.addCommandToProcess(BluetoothPlayer.COMMAND_PREV);
          previousPressed = false;

          if (bluetoothPlayer.getTotalTime() != 0) // jesli utwor jest odtwarzany lub zapauzowany
          playPauseSprite.setFrame(PAUSE_ICON);
        }
        // jesli przycisk 'Up' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & UP_PRESSED) != 0)
            && (previousPressed == false)
            && (nextPressed == false)
            && (firePressed == false)) {
          if (previousPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          bluetoothPlayer.volumeUp();
        }
        // jesli przycisk 'Down' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & DOWN_PRESSED) != 0)
            && (previousPressed == false)
            && (nextPressed == false)
            && (firePressed == false)) {
          if (previousPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          bluetoothPlayer.volumeDown();
        }
      }
    }
    // jesli wyswietlany jest ekran biblioteki muzycznej
    if (displayedScreen == MEDIA_LIBRARY_SCREEN) {
      // jesli przycisk akcji jest wcisniety, a pozostale nie sa wcisniete
      if (((keys & FIRE_PRESSED) != 0) && (nextPressed == false) && (previousPressed == false)) {
        buttonPressedInARowCount = 0;
        if (firePressed == false) soundPlayer.play(SoundPlayer.CLICK_SOUND);
        firePressed = true;
      }
      // przycisk zostal zwolniony
      else if (((keys & FIRE_PRESSED) == 0) && (firePressed == true)) {
        buttonPressedInARowCount = 0;
        firePressed = false;
      }
      // jesli przycisk 'Down' jest wcisniety, a pozostale nie sa wcisniete
      if (((keys & DOWN_PRESSED) != 0) && (firePressed == false) && (previousPressed == false)) {
        if (nextPressed == true) buttonPressedInARowCount++;
        else buttonPressedInARowCount = 0;
        nextPressed = true;
      }
      // button was released or hold down for more than MAX_BUTTON_PRESSED_IN_A_ROW_COUNT clicks
      if ((((keys & DOWN_PRESSED) == 0) && (nextPressed == true))
          || (((keys & DOWN_PRESSED) != 0)
              && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))) {
        // jesli wybrany utwor nie byl ostatni na liscie
        if (bluetoothPlayer.getMediaLibrary().selectItemInMediaLibrary(NEXT_ITEM) == true) {
          if (mediaLibrarySelectedItemOnScreen < mediaLibraryItemsNumberOnScreen - 1)
            mediaLibrarySelectedItemOnScreen++;
        }

        // nextPressed is set to false only if button was released
        if ((((keys & DOWN_PRESSED) != 0)
                && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))
            == false) nextPressed = false;
      }

      // jesli przycisk 'Previous' jest wcisniety, a pozostale nie sa wcisniete
      if (((keys & UP_PRESSED) != 0) && (nextPressed == false) && (firePressed == false)) {
        if (previousPressed == true) buttonPressedInARowCount++;
        else buttonPressedInARowCount = 0;
        previousPressed = true;
      }

      // button was released or hold down for more than MAX_BUTTON_PRESSED_IN_A_ROW_COUNT clicks
      if ((((keys & UP_PRESSED) == 0) && (previousPressed == true))
          || (((keys & UP_PRESSED) != 0)
              && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))) {

        // jesli wybrany utwor nie byl pierwszy na liscie
        if (bluetoothPlayer.getMediaLibrary().selectItemInMediaLibrary(PREVIOUS_ITEM) == true) {
          if (mediaLibrarySelectedItemOnScreen > 0) mediaLibrarySelectedItemOnScreen--;
        }

        // previousPressed is set to false only if button was released
        if ((((keys & UP_PRESSED) != 0)
                && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))
            == false) previousPressed = false;
      }
    }
    // if volume level has changed
    if (volumeLevel != bluetoothPlayer.getVolumeLevel()) {
      showVolume = 15;
      volumeLevel = bluetoothPlayer.getVolumeLevel();
    }

    if (bluetoothPlayer.getIsConnectedToServer() == false) {
      if (buttonsLocation < 70) buttonsLocation += 5;
    }

    if ((bluetoothPlayer.getIsConnectedToServer() == true) && (buttonsLocation > 0)) {
      buttonsLocation -= 5;
    }

    if (bluetoothPlayer.getStateChanged()) {
      String state = bluetoothPlayer.getPlayingState();

      if (state != null) {
        if (state.equals("PLAY") || state.equals("OTHER")) {
          playPauseSprite.setFrame(PAUSE_ICON);
        } else if (state.equals("PAUSE") || state.equals("STOP"))
          playPauseSprite.setFrame(PLAY_ICON);
      }

      soundPlayer.play(SoundPlayer.POPUP_SOUND);
    }
  }
コード例 #3
0
ファイル: MainCanvas.java プロジェクト: kubaodias/bluectrl
  /** Metoda odpowiedzialna za wyswietlenie i animacje trojwymiarowego logo */
  public void displayLogo() {
    try {
      int keys;
      int frames = 0;
      float angle = 10.0f; // kat o jaki obraca sie logo w animacji

      Graphics3D g3d = Graphics3D.getInstance();
      Graphics g = getGraphics();

      // setFullScreenMode(true);

      Thread.sleep(100);

      // zaladowanie obiektu zapisanego w pliku m3g
      Object3D[] objects = Loader.load("/res/blue_logo.m3g");

      scene = (World) objects[0];

      Camera camera = new Camera();
      camera.setPerspective(30.0f, (float) getWidth() / (float) getHeight(), 1.0f, 1000.0f);
      camera.setTranslation(0.0f, 0.0f, 24.0f);
      scene.addChild(camera);
      scene.setActiveCamera(camera);

      scene.getChild(0).preRotate(180.0f, 1.0f, 0.0f, 0.0f);

      keys = getKeyStates();

      while (((keys & FIRE_PRESSED) == 0) && (frames < 36)) { // oczekiwanie na nacisniecie klawisza
        g3d.bindTarget(g);

        scene.getChild(0).preRotate(angle, 0.0f, 0.7f, 1.0f);
        // wyrenderowanie sceny
        g3d.render(scene);
        // zwolnienie kontekstu graficznego
        g3d.releaseTarget();

        flushGraphics();

        Thread.sleep(30); // uspienie watku na 30ms

        keys = getKeyStates();

        frames++;
      }

      while (((getKeyStates() & FIRE_PRESSED) != 0)
          && (frames < 36)) {} // oczekiwanie na zwolnienie przycisku fire

      if ((keys & FIRE_PRESSED)
          == 0) // jesli przycisk nie zostal wcisniety, tylko animacja dobiegla konca
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      soundPlayer.play(SoundPlayer.ERROR_SOUND);
      System.out.println("Praca watku przerysowujacego zawartosc ekranu zostala przerwana!");
      e.printStackTrace();
    } catch (IOException e) {
      soundPlayer.play(SoundPlayer.ERROR_SOUND);
      System.out.println("Blad podczas wczytywania pliku z zasobow!");
      e.printStackTrace();
    } catch (Exception e) {
      soundPlayer.play(SoundPlayer.ERROR_SOUND);
      System.out.println("Nieznany wyjatek");
      e.printStackTrace();
    }
  }