コード例 #1
0
ファイル: ViewsPane.java プロジェクト: jjthrash/wordcorr
    public GraphemeClustersRow(BeanCatalog.Property prop, Object obj, final Refreshable refresh) {
      super(prop, obj);
      _view = (View) obj;

      JPanel btnpanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
      _undefineButton =
          new WButton(
              new WordCorrAction("btnGraphemeClusterUndefine", "accGraphemeClusterUndefine") {
                public void actionPerformed(ActionEvent evt) {
                  if (doUndefineGraphemeCluster()) {
                    try {
                      // update list
                      setValue(_view.getGraphemeClusters());
                    } catch (DatabaseException ex) {
                      ex.printStackTrace();
                    }
                  }
                }
              });
      btnpanel.add(_undefineButton, BorderLayout.NORTH);

      JPanel panel = new JPanel(new BorderLayout());
      panel.add(_text, BorderLayout.NORTH);
      panel.add(btnpanel, BorderLayout.CENTER);
      init(panel, _text);
      _text.setFont(FontCache.getIPA());
    }
コード例 #2
0
ファイル: ViewsPane.java プロジェクト: jjthrash/wordcorr
 /** Constructor. */
 public ViewsUndefineGraphemeClusterRow(
     BeanCatalog.Property prop, Object obj, Refreshable refresh) {
   super(prop, obj);
   _data = (UndefineGraphemeClusterTask) obj;
   _refresh = refresh;
   init(_combo, _combo);
   _combo.setFont(FontCache.getIPA());
   refresh();
 }
コード例 #3
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;
  }
コード例 #4
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;
  }
コード例 #5
0
/** @author Eugene Stahov */
public class ComplexString extends Vector implements VirtualElement {

  // private Vector v;
  public static final int IMAGE = 0x00000000;
  public static final int COLOR = 0x01000000;
  public static final int RALIGN = 0x02000000;
  public static final int UNDERLINE = 0x03000000;
  // #if NICK_COLORS
  // #     public final static int NICK_ON   = 0x04000000;
  // #     public final static int NICK_OFF  = 0x05000000;
  // #endif

  protected Font font = FontCache.getMsgFont();
  private int height;
  private int width;
  private ImageList imageList;
  private int colorBGnd = ColorScheme.LIST_BGND;
  private int color = ColorScheme.LIST_INK;

  /** Creates a new instance of ComplexString */
  public ComplexString() {
    super();
  }

  /** Creates a new instance of ComplexString */
  public ComplexString(ImageList imageList) {
    this();
    this.imageList = imageList;
  }

  private int imgHeight() {
    return (imageList == null) ? 0 : imageList.getHeight();
  }

  private int imgWidth() {
    return (imageList == null) ? 0 : imageList.getWidth();
  }

  public int getColor() {
    return color;
  }

  public int getColorBGnd() {
    return colorBGnd;
  }

  public void setColorBGnd(int color) {
    colorBGnd = color;
  }

  public void setColor(int color) {
    this.color = color;
  }

  public void onSelect() {};

  public void drawItem(Graphics g, int offset, boolean selected, boolean drawsec) {
    // g.setColor(0);
    boolean ralign = false;
    boolean underline = false;

    // #if NICK_COLORS
    // # 	boolean nick=false;
    // #endif

    int w = offset;
    int dw;
    int imageYOfs = ((getVHeight() - imgHeight()) >> 1);
    // #if ALCATEL_FONT
    // #         int fontYOfs=(( getVHeight()-font.getHeight() )>>1) +1;
    // #else
    int fontYOfs = ((getVHeight() - font.getHeight()) >> 1);
    // #endif
    int imgWidth = imgWidth();

    g.setFont(font);
    for (int index = 0; index < elementCount; index++) {
      Object ob = elementData[index];
      if (ob != null) {

        if (ob instanceof String) {
          // string element
          String s = (String) ob;
          // #if NICK_COLORS
          // #                     if (nick) {
          // #                         int color=g.getColor();
          // #                         dw=0;
          // #                         int p1=0;
          // #                         while (p1<s.length()) {
          // #                             int p2=p1;
          // #                             char c1=s.charAt(p1);
          // #                             //processing the same cp
          // #                             while (p2<s.length()) {
          // #                                 char c2=s.charAt(p2);
          // #                                 if ( (c1&0xff00) != (c2 &0xff00) ) break;
          // #                                 p2++;
          // #                             }
          // #                             g.setColor( (c1>255) ? ColorScheme.strong(color) :
          // color);
          // #                             dw=font.substringWidth(s, p1, p2-p1);
          // #                             if (ralign) w-=dw;
          // #                             g.drawSubstring( s, p1, p2-p1,
          // #                                     w,fontYOfs,Graphics.LEFT|Graphics.TOP);
          // #                             if (!ralign) w+=dw;
          // #                             p1=p2;
          // #                         }
          // #
          // #                         g.setColor(color);
          // #                     } else {
          // #endif
          dw = font.stringWidth(s);
          if (ralign) w -= dw;
          g.drawString(s, w, fontYOfs, Graphics.LEFT | Graphics.TOP);
          if (underline) {
            int y = getVHeight() - 1;
            g.drawLine(w, y, w + dw, y);
            underline = false;
          }
          if (!ralign) w += dw;
          // #if NICK_COLORS
          // #                     }
          // #endif

        } else if ((ob instanceof Integer)) {
          // image element or color
          int i = ((Integer) ob).intValue();
          switch (i & 0xff000000) {
            case IMAGE:
              if (imageList == null) break;
              if (ralign) w -= imgWidth;
              imageList.drawImage(g, ((Integer) ob).intValue(), w, imageYOfs);
              if (!ralign) w += imgWidth;
              break;
            case COLOR:
              g.setColor(0xFFFFFF & i);
              break;
            case RALIGN:
              ralign = true;
              w = g.getClipWidth() - 1;
              break;
            case UNDERLINE:
              underline = true;
              break;
              // #if NICK_COLORS
              // #                         case NICK_ON:
              // #                             nick=true;
              // #                             break;
              // #                         case NICK_OFF:
              // #                             nick=false;
              // #                             break;
              // #endif
          }
        } /* Integer*/ else if (ob instanceof VirtualElement) {
          int clipw = g.getClipWidth();
          int cliph = g.getClipHeight();
          ((VirtualElement) ob).drawItem(g, 0, false, false);
          g.setClip(g.getTranslateX(), g.getTranslateY(), clipw, cliph);
          // TODO: рисование не с нулевой позиции и вычисление ширины
        }
      } // if ob!=null
    } // for
  }

  public int getVWidth() {
    // g.setColor(0);
    if (width > 0) return width; // cached

    int w = 0;
    int imgWidth = imgWidth();

    for (int index = 0; index < elementCount; index++) {
      Object ob = elementData[index];
      if (ob != null) {

        if (ob instanceof String) {
          // string element
          w += font.stringWidth((String) ob);
        } else if ((ob instanceof Integer) && imageList != null) {
          // image element or color
          int i = (((Integer) ob).intValue());
          switch (i & 0xff000000) {
            case IMAGE:
              w += imgWidth;
              break;
          }
        } // Integer
      } // if ob!=null
    } // for
    return width = w;
  }

  /*public Object elementAt(int index) {
      if (index<elementCount) return super.elementAt(index);
      return null;
  }*/

  /**
   * Safe version of setElementAt Sets the component at the specified index of this vector to be the
   * specified object. The previous component at that position is discarded. If index is greater or
   * equal to the current size of the vector, size will be automatically enlarged
   *
   * @param obj
   * @param index
   */
  public void setElementAt(Object obj, int index) {
    height = width = 0; // discarding cached values
    if (index >= elementCount) this.setSize(index + 1);
    super.setElementAt(obj, index);
  }

  public int getVHeight() {
    if (height != 0) return height;
    for (int i = 0; i < elementCount; i++) {
      int h = 0;
      Object o = elementData[i];
      if (o == null) continue;
      if (o instanceof String) {
        h = font.getHeight();
      } else if (o instanceof Integer) {
        int a = ((Integer) o).intValue();
        if ((a & 0xff000000) == 0) {
          h = imageList.getWidth();
        }
      } else if (o instanceof VirtualElement) {
        h = ((VirtualElement) o).getVHeight();
      }
      if (h > height) height = h;
    }
    return height;
  }

  public void addElement(Object obj) {
    height = width = 0; // discarding cached values
    super.addElement(obj);
  }

  public void addImage(int imageIndex) {
    addElement(new Integer(imageIndex));
  }

  public void addColor(int colorRGB) {
    addElement(new Integer(COLOR | colorRGB));
  }

  public void addRAlign() {
    addElement(new Integer(RALIGN));
  }

  public void addUnderline() {
    addElement(new Integer(UNDERLINE));
  }

  public Font getFont() {
    return font;
  }

  public void setFont(Font font) {
    this.font = font;
  }

  public String getTipString() {
    return null;
  }

  public String getSecondString() {
    return null;
  }
}
コード例 #6
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));
 }
コード例 #7
0
ファイル: MM3.java プロジェクト: hanmyohtwe/MMFontLib
 private void setStyle(Context context) {
   setTypeface(FontCache.get("mm3.ttf", context));
 }
コード例 #8
0
 private void init(AttributeSet attrs) {
   if (IS_CUSTOM_FONT_ALLOWED) {
     Typeface myTypeface = FontCache.get(getFontName(), getContext());
     setTypeface(myTypeface);
   }
 }