Пример #1
0
 private float getMaxLineWidth(Layout layout) {
   float max_width = 0.0f;
   int lines = layout.getLineCount();
   for (int i = 0; i < lines; i++) {
     if (layout.getLineWidth(i) > max_width) {
       max_width = layout.getLineWidth(i);
     }
   }
   return max_width;
 }
Пример #2
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int specModeW = MeasureSpec.getMode(widthMeasureSpec);
    if (specModeW != MeasureSpec.EXACTLY) {
      Layout layout = getLayout();
      int linesCount = layout.getLineCount();
      if (linesCount > 1) {
        float textRealMaxWidth = 0;
        for (int n = 0; n < linesCount; ++n) {
          textRealMaxWidth = Math.max(textRealMaxWidth, layout.getLineWidth(n));
        }
        int w = Math.round(textRealMaxWidth);
        if (w < getMeasuredWidth()) {
          super.onMeasure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.AT_MOST), heightMeasureSpec);
        }
      }
    }
  }
Пример #3
0
 private boolean down(TextView widget, Spannable buffer) {
   if (DBG) {
     Log.d(LOG_TAG, "--- down:");
   }
   Layout layout = widget.getLayout();
   int end = getEndPos(widget);
   int line = layout.getLineForOffset(end);
   if (line < layout.getLineCount() - 1) {
     int to;
     if (layout.getParagraphDirection(line) == layout.getParagraphDirection(line + 1)) {
       float h = layout.getPrimaryHorizontal(end);
       to = layout.getOffsetForHorizontal(line + 1, h);
     } else {
       to = layout.getLineStart(line + 1);
     }
     mManager.setSelectedEndPos(to);
     mManager.onCursorMoved();
     return true;
   }
   return false;
 }
Пример #4
0
    private int chooseSize(PopupWindow pop, View parentView, CharSequence text, TextView tv) {
      int wid = tv.getPaddingLeft() + tv.getPaddingRight();
      int ht = tv.getPaddingTop() + tv.getPaddingBottom();

      /*
       * Figure out how big the text would be if we laid it out to the
       * full width of this view minus the border.
       */
      int cap = width - wid;

      Layout l =
          new StaticLayout(text, tv.getPaint(), cap, Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
      float max = 0;
      for (int i = 0; i < l.getLineCount(); i++) {
        max = Math.max(max, l.getLineWidth(i));
      }

      /*
       * Now set the popup size to be big enough for the text plus the border.
       */
      pop.setWidth(width);
      pop.setHeight(ht + l.getHeight());
      return l.getHeight();
    }