Пример #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
  /**
   * Paint this window. This method should not generally be overridden by subclasses. This method
   * carefully stores the clip, translation, and color before calling into subclasses. The graphics
   * context should be translated such that it is in this window's coordinate space (0,0 is the top
   * left corner of this window).
   *
   * @param g The graphics object to use to paint this window.
   * @param refreshQ The custom queue which holds the set of refresh regions needing to be blitted
   *     to the screen
   */
  public void paint(Graphics g, CGraphicsQ refreshQ) {
    // We reset our dirty flag first. Any layers that become
    // dirty in the duration of this method will then cause it
    // to toggle back to true for the subsequent pass.
    // IMPL NOTE: when layers start to do complex animation, there will
    // likely need to be better atomic handling of the dirty state,
    // and layers becoming dirty and getting painted
    this.dirty = false;

    // Store the clip, translate, font, color
    cX = g.getClipX();
    cY = g.getClipY();
    cW = g.getClipWidth();
    cH = g.getClipHeight();

    tranX = g.getTranslateX();
    tranY = g.getTranslateY();

    font = g.getFont();
    color = g.getColor();

    // We set the basic clip to the size of this window
    g.setClip(bounds[X], bounds[Y], bounds[W], bounds[H]);

    synchronized (layers) {
      sweepAndMarkLayers();
      copyAndCleanDirtyLayers();
    }
    paintLayers(g, refreshQ);

    // We restore the original clip. The original font, color, etc.
    // have already been restored
    g.setClip(cX, cY, cW, cH);
  }
Пример #3
0
 /**
  * Draws the specified character.
  *
  * @param g the graphics context
  * @param c the character to be drawn
  * @param x the x coordinate of the anchor point
  * @param y the y coordinate of the anchor point
  * @return the x coordinate for the next character
  */
 public int drawChar(Graphics g, char c, int x, int y) {
   setColor(g.getColor());
   int nextX = drawOneChar(g, c, x, y);
   if ((style & Font.STYLE_UNDERLINED) != 0) {
     int yU = y + this.baseline + 2;
     g.drawLine(x, yU, nextX - 1, yU);
   }
   return nextX;
 }
Пример #4
0
  /**
   * Metoda wyswietlajaca okreg obrazujacy postep wykrywania urzadzen
   *
   * @param g Referencja do obiektu klasy Graphics, ktory pozwala na narysowanie pasku postepu
   * @param progress Liczba z zakresu 0 - 359: zakres luku
   */
  public void showInquiryProgress(Graphics g, int progress) {
    int c = g.getColor();

    g.setColor(255, 255, 255);

    g.drawArc(screenWidth - 25, screenHeight - 57, 10, 16, 0, progress);

    g.setColor(c);

    bluetoothLogoSmallSprite.setPosition(screenWidth - 24, screenHeight - 56);
    bluetoothLogoSmallSprite.paint(g);
  }
Пример #5
0
 /**
  * Draws the specified characters.
  *
  * @param g the graphics context
  * @param data the array of characters to be drawn
  * @param offset the start offset in the data
  * @param length the number of characters to be drawn
  * @param x the x coordinate of the anchor point
  * @param y the y coordinate of the anchor point
  * @param anchors the anchor point for positioning the text
  * @return the x coordinate for the next character
  */
 public int drawChars(Graphics g, char[] data, int offset, int length, int x, int y, int anchors) {
   int xx = getX(charsWidth(data, offset, length), x, anchors);
   int yy = getY(y, anchors);
   setColor(g.getColor());
   for (int i = offset; i < offset + length; i++) {
     xx = drawOneChar(g, data[i], xx, yy);
   }
   if ((style & Font.STYLE_UNDERLINED) != 0) {
     int yU = y + this.baseline + 2;
     g.drawLine(x, yU, xx - 1, yU);
   }
   return xx;
 }
Пример #6
0
 /**
  * Draws the specified substring.
  *
  * @param g the graphics context
  * @param text the text to be drawn
  * @param offset the index of a first character
  * @param length the number of characters
  * @param x the x coordinate of the anchor point
  * @param y the y coordinate of the anchor point
  * @param anchors the anchor point for positioning the text
  * @return the x coordinate for the next string
  */
 public int drawSubstring(
     Graphics g, String text, int offset, int length, int x, int y, int anchors) {
   int xx = getX(substringWidth(text, offset, length), x, anchors);
   int yy = getY(y, anchors);
   setColor(g.getColor());
   for (int i = offset; i < offset + length; i++) {
     xx = drawOneChar(g, text.charAt(i), xx, yy);
   }
   if ((style & Font.STYLE_UNDERLINED) != 0) {
     int yU = y + this.baseline + 2;
     g.drawLine(x, yU, xx - 1, yU);
   }
   return xx;
 }
Пример #7
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);
  }
Пример #8
0
  /**
   * Metoda sluzaca do wypisania tekstu na ekranie w podanej linii
   *
   * @param g Referencja do obiektu klasy Graphics, ktory pozwala na wyswietlenie tekstu
   * @param text Tekst, ktory ma zostac wypisany
   * @param line Numer linii, w ktorej ma zostac wypisany tekst
   * @return <code>true</code> jesli wypisanie tekstu powiodlo sie, <code>false</code> w przeciwnym
   *     razie
   */
  public boolean drawText(Graphics g, String text, int line) {
    int color = g.getColor(); // przechowanie uzywanego koloru
    int textPos = 0;

    g.setColor(BACKGROUND_COLOR); // zamazanie starego tekstu
    g.fillRect(16, 16 + line * (fontHeight + 3), screenWidth - 32, fontHeight);

    if (line == 0) {
      // if displayed text had changed
      if (text.equals(lastText0) == false) {
        lastText0 = text;
        textPos0 = 0;
        waitTimeText0 = SCROLL_TIME_WAIT;
      }
      textPos = textPos0;
    } else if (line == 1) {
      // if displayed text had changed
      if (text.equals(lastText1) == false) {
        lastText1 = text;
        textPos1 = 0;
        waitTimeText1 = SCROLL_TIME_WAIT;
      }
      textPos = textPos1;
    }
    // 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, 16, 16 + line * (fontHeight + 3), Graphics.TOP | Graphics.LEFT);
    }
    // if text doesn't fit into the screen
    else {
      String leftTextTmp = "";
      int i = 0;

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

      String textTmp = text.substring(i, 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 - 32) {
        textTmp = textTmp.substring(0, textTmp.length() - 1);
        textRightCut = true;
      }

      g.setColor(255, 255, 255); // biala czcionka
      g.drawString(textTmp, 16, 16 + line * (fontHeight + 3), Graphics.TOP | Graphics.LEFT);

      g.setColor(BACKGROUND_COLOR); // zamazanie tekstu po bokach
      g.fillRect(screenWidth - 16, 16 + line * (fontHeight + 3), 11, fontHeight);
      // g.fillRect(5, 16 + line*(fontHeight + 3), 11, fontHeight);

      if (line == 0) {
        if ((textRightCut == false) && (waitTimeText0 == 0)) // jesli tekst przewinal sie do konca
        waitTimeText0 = SCROLL_TIME_WAIT;

        if (waitTimeText0 == 0) textPos0 += 2; // przewiniecie tekstu
        // if text is going to be displayed statically (without scrolling it)
        else {
          waitTimeText0--;
          // if wait time has ended, start scrolling from the beginning
          if ((waitTimeText0 == 0) && (textPos0 != 0)) {
            waitTimeText0 = SCROLL_TIME_WAIT;
            textPos0 = 0;
          }
        }
      } else if (line == 1) {
        if ((textRightCut == false) && (waitTimeText1 == 0)) // jesli tekst przewinal sie do konca
        waitTimeText1 = SCROLL_TIME_WAIT;

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

    g.setColor(color);
    return true;
  }