예제 #1
0
  /**
   * Metoda wyswietlajaca pasek postepu nad przyciskami
   *
   * @param g Referencja do obiektu klasy Graphics, ktory pozwala na narysowanie pasku postepu
   * @param current Aktualny czas trwania piosenki, 0 <= progress <= max
   * @param max Calkowity czas trwania piosenki
   */
  public void showProgressBar(Graphics g, int current, int max) {
    int color = g.getColor(); // przechowanie uzywanego koloru
    int progressBarWidth = screenWidth - 25; // szerokosc paska postepu
    int progress = (progressBarWidth * current) / max;

    if (current == -1) // jesli timer jest wylaczony
    progress = 0;

    g.setColor(110, 110, 110); // narysowanie szarej obwodki
    g.drawRect(10, screenHeight - 29 + buttonsLocation, progressBarWidth + 3, 17);

    g.setColor(90, 90, 90); // narysowanie ciemnej obwodki
    g.drawRect(11, screenHeight - 28 + buttonsLocation, progressBarWidth + 1, 15);

    g.setColor(BACKGROUND_COLOR);
    g.fillRect(12, screenHeight - 27 + buttonsLocation, progressBarWidth, 14);

    g.setColor(230, 230, 230);
    g.fillRect(12, screenHeight - 27 + buttonsLocation, progress, 14);

    g.setColor(70, 70, 70);

    if (this.displayedScreen == MainCanvas.PLAYER_SCREEN)
      g.drawString(
          bluetoothPlayer.getCurrentTimeString(),
          screenWidth / 2 - 17,
          screenHeight - 26 + buttonsLocation,
          Graphics.TOP | Graphics.LEFT);

    g.setColor(color);
  }
예제 #2
0
  /**
   * Metoda wyswietlajaca biblioteke muzyczna na wyswietlaczu
   *
   * @param g Referencja do obiektu klasy Graphics, ktory pozwala na wyswietlenie tekstu
   * @param player Referencja do obiektu klasy odtwarzacza muzycznego
   * @param screenSelectedItemIndex Indeks wybranego elementu na wyswietlaczu
   * @param screenNumberOfItems Liczba elementow wyswietlonych na wyswietlaczu
   */
  public void showMediaLibrary(
      Graphics g, BluetoothPlayer player, int screenSelectedItemIndex, int screenNumberOfItems) {
    int color = g.getColor(); // przechowanie uzywanego koloru
    int textPos = 0;
    String text;

    g.setColor(255, 255, 255); // biala czcionka

    for (int i = 0; i < screenNumberOfItems; i++) {
      text =
          bluetoothPlayer
              .getMediaLibrary()
              .getItem(
                  bluetoothPlayer.getMediaLibrary().getMediaLibrarySelectedItem()
                      - screenSelectedItemIndex
                      + i,
                  g);

      if (text != null) {
        // jesli zmienil sie wybrany tekst
        if ((screenSelectedItemIndex == i) && (text.equals(mediaLibraryLastText) == false)) {
          mediaLibraryLastText = text;
          mediaLibraryTextPos = 0;
          mediaLibraryWaitTimeText = SCROLL_TIME_WAIT;
        }
        textPos = mediaLibraryTextPos;

        // if whole text can be displayed at once
        if (Font.getDefaultFont().stringWidth(text) <= screenWidth - 32) {
          g.setColor(255, 255, 255); // biala czcionka
          g.drawString(text, 10, i * (fontHeight + 5) + 8, Graphics.TOP | Graphics.LEFT);
        }
        // if text doesn't fit into the screen
        else {
          String leftTextTmp = "";
          int j = 0;

          // cut text from the left as long as it doesn't fit to the screen (only for selected item)
          if (screenSelectedItemIndex == i)
            while (Font.getDefaultFont().stringWidth(leftTextTmp) < textPos) {
              leftTextTmp = text.substring(0, ++j);
            }

          String textTmp = text.substring(j, text.length());

          boolean textRightCut = false;
          // cut text from the right as long as it doesn't fit to the screen
          while (Font.getDefaultFont().stringWidth(textTmp) > screenWidth - 24) {
            textTmp = textTmp.substring(0, textTmp.length() - 1);
            textRightCut = true;
          }

          g.setColor(255, 255, 255); // biala czcionka
          g.drawString(textTmp, 10, i * (fontHeight + 5) + 8, Graphics.TOP | Graphics.LEFT);

          g.setColor(BACKGROUND_COLOR); // zamazanie tekstu po bokach
          g.fillRect(screenWidth - 10, i * (fontHeight + 5) + 8, 5, fontHeight);

          if (screenSelectedItemIndex == i) {
            if ((textRightCut == false)
                && (mediaLibraryWaitTimeText == 0)) // jesli tekst przewinal sie do konca
            mediaLibraryWaitTimeText = SCROLL_TIME_WAIT;

            if (mediaLibraryWaitTimeText == 0) mediaLibraryTextPos += 2; // przewiniecie tekstu
            // if text is going to be displayed statically (without scrolling it)
            else {
              mediaLibraryWaitTimeText--;
              // if wait time has ended, start scrolling from the beginning
              if ((mediaLibraryWaitTimeText == 0) && (mediaLibraryTextPos != 0)) {
                mediaLibraryWaitTimeText = SCROLL_TIME_WAIT;
                mediaLibraryTextPos = 0;
              }
            }
          }
        }
      }
    }

    g.setColor(255, 255, 255);

    // obwodka dla podswietlonego elementu
    if (screenNumberOfItems > 0)
      g.drawRect(
          7, screenSelectedItemIndex * (fontHeight + 5) + 6, screenWidth - 16, fontHeight + 1);

    g.setColor(color);
  }
예제 #3
0
 /** Metoda sluzaca do ponownego polaczenia sie z serwerem */
 public void reconnectToServer() {
   bluetoothPlayer
       .closeConnection(); // wystarczy sie rozlaczyc, reszta zostanie wykonana w metodzie run
                           // klasy BluetoothPlayer
 }
예제 #4
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();
  }
예제 #5
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);
    }
  }
예제 #6
0
 /** Metoda odpowiedzialna za czyszczenie pozostalosci po aplikacji */
 public void destroy() {
   bluetoothPlayer.closeConnection();
   scene = null;
 }