コード例 #1
0
  static Bitmap smartLines(
      Context context, Bitmap icon, String header, String[] lines, FontCache.FontSize size) {

    Properties props = BitmapCache.getProperties(context, "notification.xml");

    final int textTop = Integer.parseInt(props.getProperty("textTop", "24"));
    final int textLeft = Integer.parseInt(props.getProperty("textLeft", "3"));
    final int textWidth = Integer.parseInt(props.getProperty("textWidth", "90"));
    final int textHeight = Integer.parseInt(props.getProperty("textHeight", "69"));

    final int iconTop = Integer.parseInt(props.getProperty("iconTop", "0"));
    final int iconLeft = Integer.parseInt(props.getProperty("iconLeft", "0"));

    final int headerLeft = Integer.parseInt(props.getProperty("headerLeft", "20"));
    final int headerBaseline = Integer.parseInt(props.getProperty("headerBaseline", "15"));

    final int headerColor =
        props.getProperty("headerColor", "white").equalsIgnoreCase("black")
            ? Color.BLACK
            : Color.WHITE;
    final int textColor =
        props.getProperty("textColor", "black").equalsIgnoreCase("black")
            ? Color.BLACK
            : Color.WHITE;

    FontInfo font = FontCache.instance(context).Get(size);

    Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(bitmap);

    Paint paintHead = new Paint();
    paintHead.setColor(headerColor);
    paintHead.setTextSize(FontCache.instance(context).Large.size);
    paintHead.setTypeface(FontCache.instance(context).Large.face);

    Paint paint = new Paint();
    paint.setColor(textColor);
    paint.setTextSize(font.size);
    paint.setTypeface(font.face);

    canvas.drawColor(Color.WHITE);

    canvas.drawBitmap(Utils.getBitmap(context, "notify_background.png"), 0, 0, null);

    int iconHeight = 16;
    if (icon != null) {
      iconHeight = Math.max(16, icon.getHeight()); // make sure the text fits

      // align icon to bottom of text
      canvas.drawBitmap(icon, iconLeft, iconTop + iconHeight - icon.getHeight(), paint);
    }

    canvas.drawText(header, headerLeft, headerBaseline, paintHead);

    String body = "";
    for (String line : lines) {
      if (body.length() > 0) body += "\n\n";
      body += line;
    }

    TextPaint textPaint = new TextPaint(paint);
    StaticLayout staticLayout =
        new StaticLayout(
            body, textPaint, textWidth, android.text.Layout.Alignment.ALIGN_CENTER, 1.3f, 0, false);

    int layoutHeight = staticLayout.getHeight();
    int textY = textTop + (textHeight / 2) - (layoutHeight / 2);
    if (textY < textTop) textY = textTop;

    canvas.translate(textLeft, textY); // position the text
    staticLayout.draw(canvas);

    return bitmap;
  }
コード例 #2
0
  static Bitmap[] smartNotify(Context context, Bitmap icon, String header, String body) {

    Properties props = BitmapCache.getProperties(context, "notification_sticky.xml");

    final int textTop = Integer.parseInt(props.getProperty("textTop", "24"));
    final int textLeft = Integer.parseInt(props.getProperty("textLeft", "3"));
    final int textWidth = Integer.parseInt(props.getProperty("textWidth", "85"));
    final int textHeight = Integer.parseInt(props.getProperty("textHeight", "69"));

    final int iconTop = Integer.parseInt(props.getProperty("iconTop", "0"));
    final int iconLeft = Integer.parseInt(props.getProperty("iconLeft", "0"));

    final int headerLeft = Integer.parseInt(props.getProperty("headerLeft", "20"));
    final int headerBaseline = Integer.parseInt(props.getProperty("headerBaseline", "15"));

    final int headerColor =
        props.getProperty("headerColor", "white").equalsIgnoreCase("black")
            ? Color.BLACK
            : Color.WHITE;
    final int textColor =
        props.getProperty("textColor", "black").equalsIgnoreCase("black")
            ? Color.BLACK
            : Color.WHITE;

    final int arrowUpLeft = Integer.parseInt(props.getProperty("arrowUpLeft", "91"));
    final int arrowUpTop = Integer.parseInt(props.getProperty("arrowUpTop", "23"));

    final int arrowDownLeft = Integer.parseInt(props.getProperty("arrowDownLeft", "91"));
    final int arrowDownTop = Integer.parseInt(props.getProperty("arrowDownTop", "56"));

    final int closeLeft = Integer.parseInt(props.getProperty("closeLeft", "91"));
    final int closeTop = Integer.parseInt(props.getProperty("closeTop", "89"));

    FontInfo font = FontCache.instance(context).Get();

    List<Bitmap> bitmaps = new ArrayList<Bitmap>();

    Paint paintHead = new Paint();
    paintHead.setColor(headerColor);
    paintHead.setTextSize(FontCache.instance(context).Large.size);
    paintHead.setTypeface(FontCache.instance(context).Large.face);

    Paint paint = new Paint();
    paint.setColor(textColor);
    paint.setTextSize(font.size);
    paint.setTypeface(font.face);

    Paint whitePaint = new Paint();
    whitePaint.setColor(Color.WHITE);

    TextPaint textPaint = new TextPaint(paint);
    StaticLayout staticLayout =
        new StaticLayout(
            body, textPaint, textWidth, android.text.Layout.Alignment.ALIGN_NORMAL, 1.0f, 0, false);

    int iconHeight = 16;
    int iconOffset = 0;
    if (icon != null) {
      iconHeight = Math.max(16, icon.getHeight());
      iconOffset = iconHeight - icon.getHeight(); // align icon to bottom of text
    }

    int h = staticLayout.getHeight();
    int y = 0;
    int displayHeight = textHeight + 3;

    int scroll = textHeight - font.size;
    boolean more = true;

    int pages = 0;

    while (more) {
      more = false;
      Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565);
      Canvas canvas = new Canvas(bitmap);

      canvas.drawColor(Color.WHITE);

      canvas.drawBitmap(Utils.getBitmap(context, "notify_background_sticky.png"), 0, 0, null);

      canvas.save();
      canvas.translate(textLeft, textTop - y); // position the text
      canvas.clipRect(0, y, textWidth, textHeight + y);
      staticLayout.draw(canvas);
      canvas.restore();

      // Draw header
      if (icon != null) canvas.drawBitmap(icon, iconLeft, iconOffset + iconTop, paint);
      canvas.drawText(header, headerLeft, headerBaseline, paintHead);

      if (y > 0)
        canvas.drawBitmap(Utils.getBitmap(context, "arrow_up.bmp"), arrowUpLeft, arrowUpTop, null);

      if ((h - y) > (displayHeight) && pages < 10) {
        more = true;
        pages++;
        canvas.drawBitmap(
            Utils.getBitmap(context, "arrow_down.bmp"), arrowDownLeft, arrowDownTop, null);
      }

      canvas.drawBitmap(Utils.getBitmap(context, "close.bmp"), closeLeft, closeTop, null);

      y += scroll;
      bitmaps.add(bitmap);
    }

    Bitmap[] bitmapArray = new Bitmap[bitmaps.size()];
    bitmaps.toArray(bitmapArray);
    return bitmapArray;
  }
コード例 #3
0
 /**
  * Creates and returns a stylesheet builder configured with some useful default styles. The caller
  * can augment the sheet with additional styles and call {@code create}.
  */
 public static Stylesheet.Builder newSheetBuilder(Graphics gfx) {
   final Font font = FontCache.instance().REGULAR;
   int bgColor = 0xFFCCCCCC, ulColor = UL_COLOR, brColor = 0xFFAAAAAA;
   Background butBg = Background.roundRect(gfx, bgColor, 5, ulColor, 2).inset(5, 6, 2, 6);
   Background butSelBg = Background.roundRect(gfx, bgColor, 5, brColor, 2).inset(6, 5, 1, 7);
   Background disabledChangeViewButtonBackground =
       Background.roundRect(gfx, Palette.DIALOG_BACKGROUND, 5, ulColor, 2).inset(5, 6, 2, 6);
   return Stylesheet.builder()
       .add(Button.class, Style.BACKGROUND.is(butBg), Style.FONT.is(font))
       .add(Button.class, Style.Mode.SELECTED, Style.BACKGROUND.is(butSelBg))
       .add(Button.class, Style.ACTION_SOUND.is(SfxCache.instance().CLICK))
       .add(ToggleButton.class, Style.BACKGROUND.is(butBg))
       .add(ToggleButton.class, Style.Mode.SELECTED, Style.BACKGROUND.is(butSelBg))
       .add(
           CheckBox.class,
           Style.BACKGROUND.is(
               Background.roundRect(gfx, bgColor, 5, ulColor, 2).inset(3, 2, 0, 3)))
       .add(
           CheckBox.class,
           Style.Mode.SELECTED,
           Style.BACKGROUND.is(
               Background.roundRect(gfx, bgColor, 5, brColor, 2).inset(3, 2, 0, 3)))
       // flip ul and br to make Field appear recessed
       .add(
           Field.class,
           Style.BACKGROUND.is(Background.beveled(0xFFFFFFFF, brColor, ulColor).inset(5)),
           Style.HALIGN.left)
       .add(
           Field.class,
           Style.Mode.DISABLED,
           Style.BACKGROUND.is(Background.beveled(0xFFCCCCCC, brColor, ulColor).inset(5)))
       .add(
           Menu.class,
           Style.BACKGROUND.is(Background.bordered(0xFFFFFFFF, 0x00000000, 1).inset(6)))
       .add(
           MenuItem.class,
           Style.BACKGROUND.is(Background.solid(0xFFFFFFFF)),
           Style.HALIGN.left,
           Style.FONT.is(font))
       .add(
           MenuItem.class,
           Style.Mode.SELECTED,
           Style.BACKGROUND.is(Background.solid(0xFF000000)),
           Style.COLOR.is(0xFFFFFFFF))
       .add(Tabs.class, Tabs.HIGHLIGHTER.is(Tabs.textColorHighlighter(0xFF000000, 0xFFFFFFFF)))
       .add(Label.class, Style.FONT.is(font))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.BACKGROUND.is(butBg),
           Style.FONT.is(font))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.Mode.SELECTED,
           Style.BACKGROUND.is(butSelBg))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.Mode.DISABLED,
           Style.BACKGROUND.is(disabledChangeViewButtonBackground))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.TEXT_EFFECT.pixelOutline)
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.HIGHLIGHT.is(Palette.UNUSED_SPACE))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.COLOR.is(Palette.FOREGROUND))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.ACTION_SOUND.is(SfxCache.instance().CLICK))
       .add(
           GameInteractionArea.ChangeViewControl.CountLabel.class,
           Style.FONT.is(font.derive(font.size * 0.85f)),
           Style.COLOR.is(GameColors.WHITE),
           Style.TEXT_EFFECT.pixelOutline,
           Style.HIGHLIGHT.is(GameColors.HUNTER_GREEN));
 }