@Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    //        final Layout layout = getLayout();
    //        if (layout != null) {
    final int lineCount = getLineCount();
    if (lineCount > 0) {
      //                final int ellipsisCount = layout.getEllipsisCount(lineCount - 1);
      //                if (ellipsisCount > 0) {
      //                    setSingleLine(false);

      TypedArray a =
          mContext.obtainStyledAttributes(
              com.android.internal.R.style.TextAppearance_Medium,
              com.android.internal.R.styleable.TextAppearance);
      final int textSize =
          a.getDimensionPixelSize(
              com.android.internal.R.styleable.TextAppearance_textSize,
              (int) (20 * getResources().getDisplayMetrics().density));

      // textSize is already expressed in pixels
      setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
      //                    setMaxLines(2);
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
    //            }
  }
    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);

      // Re-measure if we went beyond our maximum size.
      if (mMaxTabWidth > 0 && getMeasuredWidth() > mMaxTabWidth) {
        super.onMeasure(
            MeasureSpec.makeMeasureSpec(mMaxTabWidth, MeasureSpec.EXACTLY), heightMeasureSpec);
      }
    }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   try {
     super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   } catch (ArrayIndexOutOfBoundsException e) {
     setText(getText().toString());
     super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   } catch (IndexOutOfBoundsException e) {
     setText(getText().toString());
     super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   }
 }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    float textSize = getTextSize();
    float textLen = getText().length();
    mRadius = Math.round(2 * textSize);
    mTickLen = Math.round(mRadius / 180 * 3.14 * mSweepAngMin);
    mMaxRippleWidth = mRadius;
    mLineWidth = Math.round(mRadius / 10);
    mRippleWidth = mLineWidth;
    mInitRippleWidth = mRippleWidth;
    mRecWidth = textLen * textSize;
    float mWidth = mRecWidth + 2 * (mRadius + mLineWidth + mMaxRippleWidth);
    float mHeight = 2 * (mRadius + mLineWidth + mMaxRippleWidth);
    mLineRadius = mRadius + mLineWidth;
    cxLeft = mLineRadius + mMaxRippleWidth;
    cyLeft = mLineRadius + mMaxRippleWidth;
    cxRight = cxLeft + mRecWidth;
    cyRight = cyLeft;

    mLinePaint.setStrokeWidth(mLineWidth);
    mLinePaint.setStrokeCap(Paint.Cap.ROUND);
    mTickPaint.setStrokeWidth(mLineWidth);
    mTickPaint.setStrokeCap(Paint.Cap.ROUND);

    int width = MeasureSpec.makeMeasureSpec((int) mWidth, MeasureSpec.getMode(widthMeasureSpec));
    int height = MeasureSpec.makeMeasureSpec((int) mHeight, MeasureSpec.getMode(heightMeasureSpec));
    super.onMeasure(width, height);
  }
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   if (this.mHeightRatio > 0.0d) {
     int width = MeasureSpec.getSize(widthMeasureSpec);
     setMeasuredDimension(width, (int) (((double) width) * this.mHeightRatio));
     return;
   }
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 }
Example #6
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
   int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
   refitText(this.getText().toString(), parentWidth);
   this.setMeasuredDimension(parentWidth, parentHeight);
 }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   try {
     super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   } catch (IndexOutOfBoundsException e) {
     fixOnMeasure(widthMeasureSpec, heightMeasureSpec);
   }
 }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   // TODO Auto-generated method stub
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   int measuredWidth = getMeasuredWidth();
   int measuredHeight = getMeasuredHeight();
   int max = Math.max(measuredWidth, measuredHeight);
   setMeasuredDimension(max, max);
 }
Example #9
0
 protected void onMeasure(int paramInt1, int paramInt2) {
   super.onMeasure(paramInt1, paramInt2);
   if (this.flag) {
     paramInt1 = Math.max(getMeasuredWidth(), getMeasuredHeight());
     setMeasuredDimension(paramInt1, paramInt1);
     return;
   }
   setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight());
 }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   if (mHeightRatio > 0.0) {
     // set the image views size
     int width = MeasureSpec.getSize(widthMeasureSpec);
     int height = (int) (width * mHeightRatio);
     setMeasuredDimension(width, height);
   } else {
     super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   }
 }
Example #11
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);
        }
      }
    }
  }
Example #12
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   if (myheight == 0) {
     myheight = CaldroidFragment.getheights();
   }
   if (myheight == 0) {
     // Log.v ("onMeasure status","my height is still 0");
     myheight = 600;
   }
   this.setMeasuredDimension(widthMeasureSpec, myheight / 5);
 }
Example #13
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    Layout layout = getLayout();
    if (layout != null) {
      int height =
          (int) FloatMath.ceil(getMaxLineHeight(this.getText().toString()))
              + getCompoundPaddingTop()
              + getCompoundPaddingBottom();
      int width = getMeasuredWidth();
      setMeasuredDimension(width, height);
    }
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    width = MeasureSpec.getSize(widthMeasureSpec);
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    if (widthMode != MeasureSpec.EXACTLY) {
      throw new IllegalStateException("ScrollLayout only canmCurScreen run at EXACTLY mode!");
    }

    // System.out.println("text: " + text);
    if (text == null || text.length() == 0) {
      return;
    }

    // 下面的代码是根据宽度和字体大小,来计算textview显示的行数。

    textList.clear();

    StringBuilder builder = new StringBuilder();

    for (int i = 0; i < text.length(); i++) {

      if (length < width) {
        builder.append(text.charAt(i));
        length += textSize;
        if (i == text.length() - 1) {

          textList.add(builder.toString());
          // System.out.println("now i:" + i + " line:" +
          // textList.size()
          // + " addstr:" + builder.toString());

        }
      } else {

        if (builder.toString().length() > 0) {
          textList.add(builder.toString().substring(0, builder.toString().length() - 1));

          // System.out
          // .println("now i:" + i + " line:" + textList.size()
          // + " addstr:" + builder.toString());

          builder.delete(0, builder.length() - 1);
        }
        length = mPaint.measureText(text.substring(i, i + 1));
        i--;
      }
    }
  }
Example #15
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY
        || MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST) {
      int totalWidth = 0;

      {
        int unspecifiedMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        // find padding amount
        super.onMeasure(unspecifiedMeasureSpec, unspecifiedMeasureSpec);
        totalWidth = getMeasuredWidth();
      }

      // scale the textview so it don't wrap (looks ugly)
      int maxWidth = MeasureSpec.getSize(widthMeasureSpec);
      if (totalWidth > maxWidth) {
        // Log.i(getClass().getName(), "Timer text too wide, shrinking...");
        setTextSize(TypedValue.COMPLEX_UNIT_PX, getTextSize() * maxWidth / totalWidth);
        // Log.i(getClass().getName(), "Changed textWidth from " + totalWidth + " with max of " +
        // maxWidth);
      }
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int wMode = MeasureSpec.getMode(widthMeasureSpec);
    int hMode = MeasureSpec.getMode(heightMeasureSpec);
    int width = getMeasuredWidth();
    int height = getMeasuredHeight();
    if (width < height) {
      width = height;
    }
    switch (wMode) {
      case MeasureSpec.AT_MOST:
        Log.i("info", "wMode:MeasureSpec.AT_MOST");
        break;
      case MeasureSpec.EXACTLY:
        Log.i("info", "wMode:MeasureSpec.EXACTLY");
        width = getMeasuredWidth();
        break;
      case MeasureSpec.UNSPECIFIED:
        Log.i("info", "wMode:MeasureSpec.UNSPECIFIED");
        break;
    }
    switch (hMode) {
      case MeasureSpec.AT_MOST:
        Log.i("info", "hMode:MeasureSpec.AT_MOST");
        break;
      case MeasureSpec.EXACTLY:
        Log.i("info", "hMode:MeasureSpec.EXACTLY");
        break;
      case MeasureSpec.UNSPECIFIED:
        Log.i("info", "hMode:MeasureSpec.UNSPECIFIED");
        break;
    }

    setMeasuredDimension(width, height);
  }
  @SuppressLint("WrongCall")
  private void removeUnneededSpaces(
      int widthMeasureSpec,
      int heightMeasureSpec,
      SpannableStringBuilder builder,
      FixingResult result) {

    for (Object span : result.spansWithSpacesAfter) {
      int spanEnd = builder.getSpanEnd(span);
      builder.delete(spanEnd, spanEnd + 1);
      try {
        setTextAndMeasure(builder, widthMeasureSpec, heightMeasureSpec);
      } catch (IndexOutOfBoundsException ignored) {
        builder.insert(spanEnd, " ");
      }
    }

    boolean needReset = true;
    for (Object span : result.spansWithSpacesBefore) {
      int spanStart = builder.getSpanStart(span);
      builder.delete(spanStart - 1, spanStart);
      try {
        setTextAndMeasure(builder, widthMeasureSpec, heightMeasureSpec);
        needReset = false;
      } catch (IndexOutOfBoundsException ignored) {
        needReset = true;
        int newSpanStart = spanStart - 1;
        builder.insert(newSpanStart, " ");
      }
    }

    if (needReset) {
      setText(builder);
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
  }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   setTextSize(TypedValue.COMPLEX_UNIT_PX, getMeasuredWidth() / 3);
 }
Example #19
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    mRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (useDefault) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      return;
    }

    int width = 0, height = 0;

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    switch (widthMode) {
      case MeasureSpec.EXACTLY:
        width = widthSize;
        break;
      case MeasureSpec.AT_MOST:
        width = widthSize;
        break;
      case MeasureSpec.UNSPECIFIED:
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        width = displayMetrics.widthPixels;
        break;
      default:
        break;
    }
    if (maxWidth > 0) width = Math.min(width, maxWidth);

    paint.setTextSize(this.getTextSize());
    // paint.setColor(textColor);
    int realHeight = measureContentHeight((int) width);

    // 如果实际行宽少于预定的宽度,减少行宽以使其内容横向居中
    int leftPadding = getCompoundPaddingLeft();
    int rightPadding = getCompoundPaddingRight();
    width = Math.min(width, (int) lineWidthMax + leftPadding + rightPadding);

    if (oneLineWidth > -1) {
      width = oneLineWidth;
    }
    switch (heightMode) {
      case MeasureSpec.EXACTLY:
        height = heightSize;
        break;
      case MeasureSpec.AT_MOST:
        height = realHeight;
        break;
      case MeasureSpec.UNSPECIFIED:
        height = realHeight;
        break;
      default:
        break;
    }

    height += getCompoundPaddingTop() + getCompoundPaddingBottom();

    height = Math.max(height, minHeight);

    setMeasuredDimension(width, height);
  }
Example #21
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(heightMeasureSpec, widthMeasureSpec);
   setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
 }
Example #22
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   int viewLength = MeasureSpec.getSize(heightMeasureSpec);
   setMeasuredDimension(viewLength, viewLength);
 }
 @SuppressLint("WrongCall")
 private void setTextAndMeasure(CharSequence text, int widthMeasureSpec, int heightMeasureSpec) {
   setText(text);
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 }
Example #24
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   popupWindow.setWidth(View.MeasureSpec.getSize(widthMeasureSpec));
   popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 }
Example #25
0
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   heightMode = MeasureSpec.getMode(heightMeasureSpec);
 };