Example usage for android.widget TextView getMeasuredHeight

List of usage examples for android.widget TextView getMeasuredHeight

Introduction

In this page you can find the example usage for android.widget TextView getMeasuredHeight.

Prototype

public final int getMeasuredHeight() 

Source Link

Document

Like #getMeasuredHeightAndState() , but only returns the raw height component (that is the result is masked by #MEASURED_SIZE_MASK ).

Usage

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java

private void setDetailScrollViewHeight() {
    final Point displaySize = UIUtils.getDisplaySize(mActivity);
    final TextView nameLbl = (TextView) mDetailDialog.findViewById(R.id.name);
    final TextView priceLbl = (TextView) mDetailDialog.findViewById(R.id.price);
    final ScrollView scrollView = (ScrollView) mDetailDialog.findViewById(R.id.scroll_view);
    final LinearLayout valueContainer = (LinearLayout) mDetailDialog.findViewById(R.id.value_container);
    final Button dismissBtn = (Button) mDetailDialog.findViewById(R.id.dismiss);
    int maxPopupHeight = (int) Math.floor(displaySize.y * 0.75);

    int desiredWidth = MeasureSpec.makeMeasureSpec(nameLbl.getWidth(), MeasureSpec.AT_MOST);

    nameLbl.measure(desiredWidth, 0);/*  w w w . ja  v  a2s.co  m*/
    int nameLblHeight = nameLbl.getMeasuredHeight();
    int priceLblHeight = 0;
    if (priceLbl.getVisibility() == View.VISIBLE) {
        priceLbl.measure(desiredWidth, 0);
        priceLblHeight = priceLbl.getMeasuredHeight();
    }
    valueContainer.measure(desiredWidth, 0);
    int valueContainerHeight = valueContainer.getMeasuredHeight();
    dismissBtn.measure(desiredWidth, 0);
    int dismissBtnHeight = dismissBtn.getMeasuredHeight();

    int maxScrollViewHeight = maxPopupHeight - nameLblHeight - priceLblHeight - valueContainerHeight
            - dismissBtnHeight;

    ViewGroup.LayoutParams params = scrollView.getLayoutParams();
    scrollView.measure(desiredWidth, 0);
    params.height = scrollView.getMeasuredHeight();
    if (maxScrollViewHeight > 0 && params.height > maxScrollViewHeight) {
        params.height = maxScrollViewHeight;
    }
    scrollView.setLayoutParams(params);
    scrollView.requestLayout();
}

From source file:com.mydatingapp.ui.base.SkBaseInnerActivity.java

public void setActionBarLogoCounter(int count) {
    ImageView logo = (ImageView) findViewById(android.R.id.home);

    if (count < 1) {
        currentLogoCounter = 0;/*from   ww  w.j av a2 s .  c  o  m*/
        logo.setVisibility(View.GONE);
        return;
    } else {
        logo.setVisibility(View.VISIBLE);
    }

    currentLogoCounter = count;

    TextView v = new TextView(getApp());
    v.setText(new Integer(count).toString());
    v.setBackgroundResource(R.drawable.sidebar_menu_counterbg);
    v.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
    v.setDrawingCacheEnabled(true);
    v.setTextColor(Color.WHITE);
    v.setPadding(SKDimensions.convertDpToPixel(6, getApp()), 0, SKDimensions.convertDpToPixel(6, getApp()), 0);

    ActionBar.LayoutParams paramsExample = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, 1);
    paramsExample.setMargins(0, 0, 0, 0);
    v.setHeight(SKDimensions.convertDpToPixel(20, getApp()));
    v.setLayoutParams(paramsExample);

    // this is the important code :)
    // Without it the view will have a dimension of 0,0 and the bitmap will be null
    v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());

    v.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false);

    logo.setImageDrawable(new BitmapDrawable(getApp().getResources(), b));
    logo.setPadding(SKDimensions.convertDpToPixel(3, getApp()), 0, 0, 0);
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private int getSuggestionItemHeight(SearchSuggestion suggestion) {
    int leftRightMarginsWidth = Util.dpToPx(124);

    //todo improve efficiency
    TextView textView = new TextView(getContext());
    textView.setTypeface(Typeface.DEFAULT);
    textView.setText(suggestion.getBody(), TextView.BufferType.SPANNABLE);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mSuggestionsTextSizePx);
    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(mSuggestionsList.getWidth() - leftRightMarginsWidth,
            View.MeasureSpec.AT_MOST);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(widthMeasureSpec, heightMeasureSpec);
    int heightPlusPadding = textView.getMeasuredHeight() + Util.dpToPx(8);
    int minHeight = Util.dpToPx(48);
    int height = heightPlusPadding >= minHeight ? heightPlusPadding : minHeight;
    return heightPlusPadding >= minHeight ? heightPlusPadding : minHeight;
}

From source file:com.skytree.epubtest.BookViewActivity.java

int getLabelHeight(TextView tv) {
    tv.measure(0, 0); //must call measure!
    return tv.getMeasuredHeight(); //get width      
}

From source file:com.juick.android.MessagesFragment.java

public void lastPrepareMessages(final List<JuickMessage> list, final Runnable then) {
    databaseGetter.getService(new Utils.ServiceGetter.Receiver<DatabaseService>() {
        @Override//from w ww.j a  v a 2 s  .  c o m
        public void withService(final DatabaseService service) {
            new Thread("processLastReads cont") {
                @Override
                public void run() {
                    for (JuickMessage juickMessage : list) {
                        // we can use service inside here, because getMessageReadStatus0 is thread-safe
                        final DatabaseService.MessageReadStatus messageReadStatus0 = service
                                .getMessageReadStatus0(juickMessage.getMID());
                        if (messageReadStatus0.read) {
                            juickMessage.read = true;
                            juickMessage.readComments = messageReadStatus0.nreplies;
                        }
                    }

                    final Activity act = getActivity();

                    if (act != null) {
                        if (sp.getBoolean("text_accelerated", false)) {
                            // accelerate text draw

                            final Bitmap bm = Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8);
                            while (MessagesFragment.this.getView().getMeasuredWidth() == 0) {
                                try {
                                    Thread.sleep(100);
                                } catch (InterruptedException e) {
                                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                                }
                            }

                            TextView tv = new TextView(act);
                            tv.setTextSize(JuickMessagesAdapter.getTextSize(act));
                            MainActivity.restyleChildrenOrWidget(tv);
                            final int outerViewWidth = MessagesFragment.this.getView().getMeasuredWidth();
                            final int width = outerViewWidth - 6;
                            tv.setWidth(width);
                            tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT));
                            final ArrayList<JuickMessagesAdapter.CanvasPainter> stuff = new ArrayList<JuickMessagesAdapter.CanvasPainter>();

                            Canvas canvas = new Canvas(bm) {
                                @Override
                                public void drawText(char[] text, int index, int count, float x, float y,
                                        Paint paint) {
                                    super.drawText(text, index, count, x, y, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawText(String text, float x, float y, Paint paint) {
                                    super.drawText(text, x, y, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawText(String text, int start, int end, float x, float y,
                                        Paint paint) {
                                    super.drawText(text, start, end, x, y, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawText(CharSequence text, int start, int end, float x, float y,
                                        Paint paint) {
                                    super.drawText(text, start, end, x, y, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawVertices(VertexMode mode, int vertexCount, float[] verts,
                                        int vertOffset, float[] texs, int texOffset, int[] colors,
                                        int colorOffset, short[] indices, int indexOffset, int indexCount,
                                        Paint paint) {
                                    super.drawVertices(mode, vertexCount, verts, vertOffset, texs, texOffset,
                                            colors, colorOffset, indices, indexOffset, indexCount, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawPosText(char[] text, int index, int count, float[] pos,
                                        Paint paint) {
                                    super.drawPosText(text, index, count, pos, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawPosText(String text, float[] pos, Paint paint) {
                                    super.drawPosText(text, pos, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawTextOnPath(char[] text, int index, int count, Path path,
                                        float hOffset, float vOffset, Paint paint) {
                                    super.drawTextOnPath(text, index, count, path, hOffset, vOffset, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawTextOnPath(String text, Path path, float hOffset, float vOffset,
                                        Paint paint) {
                                    super.drawTextOnPath(text, path, hOffset, vOffset, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                public void drawTextRun(final CharSequence text, final int start, final int end,
                                        final int contextStart, final int contextEnd, final float x,
                                        final float y, final int dir, final Paint paint) {
                                    stuff.add(new JuickMessagesAdapter.CanvasPainter() {

                                        Paint paintClone = getPaintFromCache(paint);

                                        @Override
                                        public void paintOnCanvas(Canvas c, Paint workPaint) {
                                            try {
                                                drawTextRun.invoke(c, text, start, end, contextStart,
                                                        contextEnd, x, y, dir, paintClone);
                                            } catch (Throwable t) {
                                            }
                                        }
                                    });
                                }

                                @Override
                                public boolean getClipBounds(Rect bounds) {
                                    bounds.top = 0;
                                    bounds.bottom = 100000;
                                    bounds.left = 0;
                                    bounds.right = width;
                                    return true;
                                }
                            };

                            for (JuickMessage juickMessage : list) {
                                JuickMessagesAdapter.ParsedMessage pm = (JuickMessagesAdapter.ParsedMessage) juickMessage.parsedText;
                                if (pm != null && pm.textContent != null)
                                    tv.setText(pm.textContent);
                                stuff.clear();
                                tv.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
                                        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                                tv.draw(canvas);
                                if (stuff.size() > 0) {
                                    juickMessage.parsedUI = new JuickMessagesAdapter.RenderedText(
                                            outerViewWidth, tv.getMeasuredHeight(),
                                            new ArrayList<JuickMessagesAdapter.CanvasPainter>(stuff));
                                } else {
                                    juickMessage.parsedUI = null;
                                }
                            }
                        }
                        act.runOnUiThread(then);
                    }
                }
            }.start();
        }
    });
}