protected void wrapContent(){
  if (!DO_WRAP) {
    return;
  }
  if (mText == null) {
    return;
  }
  Canvas c=new Canvas();
  c.setFont(mFont);
  FontMetrics fm=c.getFontMetrics(mFont);
  String string=getText();
  if (mToUpperCase) {
    string=string.toUpperCase();
  }
  int tw=fm.stringWidth(string) + 2 * (mHorizontalPadding + mHorizontalMargin);
  int th=fm.getMaxAscent() + 2 * fm.getMaxDescent() + 2 * (mVerticalPadding + mVerticalMargin);
  mWidget.setWrapWidth(tw);
  mWidget.setWrapHeight(th);
  if (tw > mWidget.getMinWidth()) {
    mWidget.setMinWidth(tw);
  }
  if (th > mWidget.getMinHeight()) {
    mWidget.setMinHeight(th);
  }
  if (mWidget.getHorizontalDimensionBehaviour() == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) {
    mWidget.setWidth(tw);
  }
  if (mWidget.getVerticalDimensionBehaviour() == ConstraintWidget.DimensionBehaviour.WRAP_CONTENT) {
    mWidget.setHeight(th);
  }
  if (mWidget.getHorizontalDimensionBehaviour() == ConstraintWidget.DimensionBehaviour.FIXED) {
    if (mWidget.getWidth() <= mWidget.getMinWidth()) {
      mWidget.setHorizontalDimensionBehaviour(ConstraintWidget.DimensionBehaviour.WRAP_CONTENT);
    }
  }
  if (mWidget.getVerticalDimensionBehaviour() == ConstraintWidget.DimensionBehaviour.FIXED) {
    if (mWidget.getHeight() <= mWidget.getMinHeight()) {
      mWidget.setVerticalDimensionBehaviour(ConstraintWidget.DimensionBehaviour.WRAP_CONTENT);
    }
  }
  int baseline=fm.getAscent() + fm.getMaxDescent() + mVerticalPadding+ mVerticalMargin;
  mWidget.setBaselineDistance(baseline);
}

protected void wrapContent ( ) { if ( ! DO_WRAP ) { return ; } if ( mText == null ) { return ; } Canvas c = new Canvas ( ) ; c . setFont ( mFont ) ; FontMetrics fm = c . getFontMetrics ( mFont ) ; String string = getText ( ) ; if ( mToUpperCase ) { string = string . toUpperCase ( ) ; } int tw = fm . stringWidth ( string ) + 2 * ( mHorizontalPadding + mHorizontalMargin ) ; int th = fm . getMaxAscent ( ) + 2 * fm . getMaxDescent ( ) + 2 * ( mVerticalPadding + mVerticalMargin ) ; mWidget . setWrapWidth ( tw ) ; mWidget . setWrapHeight ( th ) ; if ( tw > mWidget . getMinWidth ( ) ) { mWidget . setMinWidth ( tw ) ; } if ( th > mWidget . getMinHeight ( ) ) { mWidget . setMinHeight ( th ) ; } if ( mWidget . getHorizontalDimensionBehaviour ( ) == ConstraintWidget . DimensionBehaviour . WRAP_CONTENT ) { mWidget . setWidth ( tw ) ; } if ( mWidget . getVerticalDimensionBehaviour ( ) == ConstraintWidget . DimensionBehaviour . WRAP_CONTENT ) { mWidget . setHeight ( th ) ; } if ( mWidget . getHorizontalDimensionBehaviour ( ) == ConstraintWidget . DimensionBehaviour . FIXED ) { if ( mWidget . getWidth ( ) <= mWidget . getMinWidth ( ) ) { mWidget . setHorizontalDimensionBehaviour ( ConstraintWidget . DimensionBehaviour . WRAP_CONTENT ) ; } } if ( mWidget . getVerticalDimensionBehaviour ( ) == ConstraintWidget . DimensionBehaviour . FIXED ) { if ( mWidget . getHeight ( ) <= mWidget . getMinHeight ( ) ) { mWidget . setVerticalDimensionBehaviour ( ConstraintWidget . DimensionBehaviour . WRAP_CONTENT ) ; } } int baseline = fm . getAscent ( ) + fm . getMaxDescent ( ) + mVerticalPadding + mVerticalMargin ; mWidget . setBaselineDistance ( baseline ) ; }
utility method computing the size of the widget if dimensions are set to wrap_content , using the default font
