예제 #1
0
  /** Metoda odpowiedzialna za przerysowanie ekranu */
  public void updateScreen() {
    Graphics g = getGraphics();
    if (displayedScreen == PLAYER_SCREEN) {
      if (backgroundLayer != null) {
        backgroundLayer.paint(g);
      }

      if ((bluetoothPlayer.getIsConnectedToServer() == false)
          && (bluetoothPlayer.getBluetoothError() == false)) drawText(g, "Connecting...", 0);
      else if (bluetoothPlayer.getBluetoothError() == true) drawText(g, "Disconnected", 0);
      else {
        if (bluetoothPlayer.getTitle() != null) {
          drawText(g, bluetoothPlayer.getTitle(), 0);
        }
        if (bluetoothPlayer.getArtist() != null) {
          drawText(g, bluetoothPlayer.getArtist(), 1);
        }

        if (showVolume > 0) {
          showVolume--;

          drawText(g, "      Volume: " + volumeLevel + "%", 2);
        }
      }

      if (bluetoothPlayer.isBluetoothOn()) {
        if (bluetoothPlayer.getInquiryStarted()) {
          showInquiryProgress(g, inquiryProgress += 20);
          if (inquiryProgress >= 360) inquiryProgress = 0;
        } else {
          inquiryProgress = 0;
          showInquiryProgress(g, 0);
        }

      } else {
        drawText(g, "Please turn your Bluetooth device on", 1);
      }

      playPauseSprite.setPosition(screenWidth / 2 - 16, screenHeight - 66 + buttonsLocation);
      previousSprite.setPosition(screenWidth / 2 - 55, screenHeight - 66 + buttonsLocation);
      nextSprite.setPosition(screenWidth / 2 + 23, screenHeight - 66 + buttonsLocation);
      playPauseSprite.paint(g);
      previousSprite.paint(g);
      nextSprite.paint(g);

      if (bluetoothPlayer.getTotalTime() != 0)
        showProgressBar(g, bluetoothPlayer.getCurrentTime(), bluetoothPlayer.getTotalTime());
      else showProgressBar(g, 0, 100);
    } else if (displayedScreen == MEDIA_LIBRARY_LOADING) {
      if (backgroundLayer != null) {
        backgroundLayer.paint(g);
      }

      if (bluetoothPlayer.getIsConnectedToServer() == true) {
        drawText(g, "Loading media library", 0);
        drawText(g, "Please wait...", 1);

        // display size of the media library
        if (bluetoothPlayer.getMediaLibrarySize() >= 1024) {
          drawText(
              g,
              "Total size: "
                  + bluetoothPlayer.getMediaLibrarySize() / 1024
                  + "."
                  + (bluetoothPlayer.getMediaLibrarySize() % 1024) * 100 / 1024
                  + " kB",
              3);
        } else drawText(g, "Total size: " + bluetoothPlayer.getMediaLibrarySize() + " B", 3);

        int size = bluetoothPlayer.getMediaLibrarySize();

        if (size == 0) // to avoid dividing by zero
        size = 1;

        showProgressBar(g, bluetoothPlayer.getMediaLibraryDownloadedBytes(), size);

        // if the playlist file was downloaded and parsed
        if (bluetoothPlayer.getMediaLibrary().getLibraryDownloadedAndParsed() == true)
          setDisplayedScreen(MainCanvas.MEDIA_LIBRARY_SCREEN);
      } else drawText(g, "You're not connected", 0);
    } else if (displayedScreen == MEDIA_LIBRARY_SCREEN) {
      if (backgroundLayer != null) {
        backgroundLayer.paint(g);
      }
      showMediaLibrary(
          g, bluetoothPlayer, mediaLibrarySelectedItemOnScreen, mediaLibraryItemsNumberOnScreen);
    }

    flushGraphics();
  }
예제 #2
0
  /** 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);
    }
  }