private void createLabels() {
    Context context = new ContextThemeWrapper(getContext(), mLabelsStyle);

    for (int i = 0; i < mButtonsCount; i++) {

      if (getChildAt(i) == mImageToggle) continue;

      final FloatingActionButton fab = (FloatingActionButton) getChildAt(i);
      String text = fab.getLabelText();

      if (fab == mMenuButton || TextUtils.isEmpty(text) || fab.getTag(R.id.fab_label) != null) {
        continue;
      }

      final Label label = new Label(context);
      label.setFab(fab);
      label.setShowAnimation(AnimationUtils.loadAnimation(getContext(), mLabelsShowAnimation));
      label.setHideAnimation(AnimationUtils.loadAnimation(getContext(), mLabelsHideAnimation));

      if (mLabelsStyle > 0) {
        label.setTextAppearance(getContext(), mLabelsStyle);
        label.setShowShadow(false);
        label.setUsingStyle(true);
      } else {
        label.setColors(mLabelsColorNormal, mLabelsColorPressed, mLabelsColorRipple);
        label.setShowShadow(mLabelsShowShadow);
        label.setCornerRadius(mLabelsCornerRadius);
        if (mLabelsEllipsize > 0) {
          setLabelEllipsize(label);
        }
        label.setMaxLines(mLabelsMaxLines);
        label.updateBackground();

        label.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLabelsTextSize);
        label.setTextColor(mLabelsTextColor);

        int left = mLabelsPaddingLeft;
        int top = mLabelsPaddingTop;
        if (mLabelsShowShadow) {
          left += fab.getShadowRadius() + Math.abs(fab.getShadowXOffset());
          top += fab.getShadowRadius() + Math.abs(fab.getShadowYOffset());
        }

        label.setPadding(left, top, mLabelsPaddingLeft, mLabelsPaddingTop);

        if (mLabelsMaxLines < 0 || mLabelsSingleLine) {
          label.setSingleLine(mLabelsSingleLine);
        }
      }

      label.setText(text);

      addView(label);
      fab.setTag(R.id.fab_label, label);
    }
  }
Exemple #2
0
  /** Initializes the screen. */
  public void initScreen() {
    gameScreen.setCurrentLevelNumber(1); // reset level

    gameScreen.setBackground("start_screen.png");

    startGameButton = new Button("Start Game", 130, 30, GameScreen.FONT_M);
    startGameButton.setBorderColor(Color.RED);
    startGameButton.setIcon(GameScreen.ICON_START);
    startGameButton.setBackgroundColor(new Color(255, 205, 205));
    gameScreen.addObject(startGameButton, GameScreen.WIDTH_IN_CELLS / 2, 10);

    if (MyKara.HIGHSCORE_ENABLED) {
      highscoreButton = new Button("Highscore", 130, 30, GameScreen.FONT_M);
      highscoreButton.setBorderColor(Color.RED);
      highscoreButton.setIcon(GameScreen.ICON_HIGHSCORE);
      highscoreButton.setBackgroundColor(new Color(255, 205, 205));
      gameScreen.addObject(highscoreButton, GameScreen.WIDTH_IN_CELLS / 2, 12);
    }

    Label enterPasswordLabel =
        new Label("Enter Level Password With Keyboard:", 230, 21, GameScreen.FONT_S);
    enterPasswordLabel.setBackgroundColor(Color.BLACK);
    enterPasswordLabel.setTextColor(new Color(255, 205, 205));
    gameScreen.addObject(enterPasswordLabel, GameScreen.WIDTH_IN_CELLS / 2, 14);

    passwordInputLabel = new InputLabel("", 180, 21, GameScreen.FONT_M);
    passwordInputLabel.setBorderColor(null);
    passwordInputLabel.setBackgroundColor(new Color(255, 205, 205));
    // passwordInputLabel.setMaxLength(10);
    gameScreen.addObject(passwordInputLabel, GameScreen.WIDTH_IN_CELLS / 2, 15);

    passwordOkLabel = new Label(95, 24, GameScreen.ICON_LOCKED);
    passwordOkLabel.setBackgroundTransparency(0);
    passwordOkLabel.setTextColor(new Color(255, 205, 205));
    passwordOkLabel.setFont(GameScreen.FONT_S);
    passwordOkLabel.setIconVisible(true);
    passwordOkLabel.setAlign(Label.ALIGN_LEFT);
    gameScreen.addObject(passwordOkLabel, GameScreen.WIDTH_IN_CELLS / 2 + 5, 15);
  }
  /** Initializes the screen. */
  public void initScreen() {
    gameScreen.createBlackBackground();

    Label highscoreTitleLabel =
        new Label(
            gameScreen, "Highscore Level " + currentHighscoreLevel, 500, 70, GameScreen.FONT_XL);
    highscoreTitleLabel.setTextColor(new Color(255, 205, 205));
    highscoreTitleLabel.setBackgroundColor(Color.BLACK);
    gameScreen.addObject(highscoreTitleLabel, GameScreen.WIDTH_IN_CELLS / 2, 1);

    arrowRightButton = new Button(gameScreen, 26, 27, WorldImages.ICON_ARROW_RIGHT);
    arrowRightButton.setBackgroundColor(Color.BLACK);
    arrowRightButton.setBorderColor(Color.RED);
    arrowRightButton.setInset(0);
    arrowRightButton.setAlign(Label.ALIGN_LEFT);
    arrowRightButton.setBackgroundColor(new Color(255, 205, 205));
    gameScreen.addObject(arrowRightButton, GameScreen.WIDTH_IN_CELLS / 2 + 6, 1);

    arrowLeftButton = new Button(gameScreen, 26, 27, WorldImages.ICON_ARROW_LEFT);
    arrowLeftButton.setBackgroundColor(Color.BLACK);
    arrowLeftButton.setBorderColor(Color.RED);
    arrowLeftButton.setInset(0);
    arrowLeftButton.setAlign(Label.ALIGN_LEFT);
    arrowLeftButton.setBackgroundColor(new Color(255, 205, 205));
    gameScreen.addObject(arrowLeftButton, GameScreen.WIDTH_IN_CELLS / 2 - 6, 1);

    backToMenuButton = new Button(gameScreen, "Main Menu", 130, 30, GameScreen.FONT_M);
    backToMenuButton.setBorderColor(Color.RED);
    backToMenuButton.setIcon(WorldImages.ICON_HOME);
    backToMenuButton.setBackgroundColor(new Color(255, 205, 205));
    gameScreen.addObject(backToMenuButton, GameScreen.WIDTH_IN_CELLS / 2, 16);

    BufferedImage levelImg =
        gameScreen.getLevel(currentHighscoreLevel).toImage(KaraWorld.CELL_SIZE);
    int width = 420;
    int height = 360;
    levelImg = GGImage.scale(levelImg, width, height);
    Label highscoreLevelLabel = new Label(gameScreen, width, height, levelImg);
    highscoreLevelLabel.setBorderColor(null);
    highscoreLevelLabel.setBackgroundColor(Color.BLACK);
    gameScreen.addObject(
        highscoreLevelLabel, GameScreen.WIDTH_IN_CELLS / 2, GameScreen.HEIGHT_IN_CELLS / 2);

    if (gameScreen.isHighscoreAvailable()) {
      // Get the highscore entries
      Highscore highscore = gameScreen.getHighscoreForLevel(currentHighscoreLevel);
      String first = highscore.getFirstEntry().toString();
      String second = highscore.getSecondEntry().toString();
      String third = highscore.getThirdEntry().toString();

      Label highscoreGoldLabel = new Label(gameScreen, first, 400, 40, GameScreen.FONT_L);
      highscoreGoldLabel.setTextColor(new Color(255, 205, 205));
      highscoreGoldLabel.setBackgroundColor(Color.BLACK);
      highscoreGoldLabel.setBackgroundTransparency(150);
      highscoreGoldLabel.setBorderColor(null);
      highscoreGoldLabel.setIcon(WorldImages.ICON_GOLD);
      gameScreen.addObject(highscoreGoldLabel, GameScreen.WIDTH_IN_CELLS / 2, 10);

      Label highscoreSilverLabel = new Label(gameScreen, second, 400, 40, GameScreen.FONT_L);
      highscoreSilverLabel.setTextColor(new Color(255, 205, 205));
      highscoreSilverLabel.setBackgroundColor(Color.BLACK);
      highscoreSilverLabel.setBackgroundTransparency(150);
      highscoreSilverLabel.setBorderColor(null);
      highscoreSilverLabel.setIcon(WorldImages.ICON_SILVER);
      gameScreen.addObject(highscoreSilverLabel, GameScreen.WIDTH_IN_CELLS / 2, 12);

      Label highscoreBronzeLabel = new Label(gameScreen, third, 400, 40, GameScreen.FONT_L);
      highscoreBronzeLabel.setTextColor(new Color(255, 205, 205));
      highscoreBronzeLabel.setBackgroundColor(Color.BLACK);
      highscoreBronzeLabel.setBackgroundTransparency(150);
      highscoreBronzeLabel.setBorderColor(null);
      highscoreBronzeLabel.setIcon(WorldImages.ICON_BRONZE);
      gameScreen.addObject(highscoreBronzeLabel, GameScreen.WIDTH_IN_CELLS / 2, 14);
    } else {
      // Highscore is not available --> give a hint to the user
      Label highscoreNa1 =
          new Label(gameScreen, "Highscore is not available!", 400, 40, GameScreen.FONT_XL);
      highscoreNa1.setTextColor(new Color(255, 205, 205));
      highscoreNa1.setBackgroundColor(Color.BLACK);
      highscoreNa1.setBackgroundTransparency(150);
      highscoreNa1.setBorderColor(null);
      gameScreen.addObject(highscoreNa1, GameScreen.WIDTH_IN_CELLS / 2, 13);
    }
  }