List of usage examples for android.widget TextView measure
public final void measure(int widthMeasureSpec, int heightMeasureSpec)
This is called to find out how big a view should be.
From source file:net.naonedbus.appwidget.HoraireWidgetProvider.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private int getHorairesCount(final Context context, final Bundle bundle) { synchronized (sLock) { if (sHoraireTextWidth == Integer.MIN_VALUE) { final TextView horaireTextView = new TextView(context); horaireTextView.setTextAppearance(horaireTextView.getContext(), android.R.style.TextAppearance_Medium); final DateTime noon = new DateTime().withHourOfDay(12).withMinuteOfHour(00); final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context); horaireTextView.setText(/* w ww.j a v a 2 s. com*/ FormatUtils.formatTimeAmPm(context, timeFormat.format(noon.toDate())) + " \u2022 "); final int specY = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); final int specX = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); horaireTextView.measure(specX, specY); sHoraireTextWidth = horaireTextView.getMeasuredWidth(); } } final Resources r = context.getResources(); final int padding = r.getDimensionPixelSize(R.dimen.padding_small); final int minWidth = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH); final int minWidthPixel = Math.round( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, minWidth, r.getDisplayMetrics())) - padding; return (minWidthPixel / sHoraireTextWidth); }
From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java
private void setBasketListViewHeight() { final Point displaySize = UIUtils.getDisplaySize(mActivity); final TextView nameLbl = (TextView) mBasketDialog.findViewById(R.id.name); final ListView listView = (ListView) mBasketDialog.findViewById(R.id.list_view); final LinearLayout buttonContainer = (LinearLayout) mBasketDialog.findViewById(R.id.button_container); int maxPopupHeight = (int) Math.floor(displaySize.y * 0.75); nameLbl.measure(0, 0); int nameLblHeight = nameLbl.getMeasuredHeight(); buttonContainer.measure(0, 0);//from w ww. ja va 2s . c o m int buttonContainerHeight = buttonContainer.getMeasuredHeight(); UIUtils.setListViewHeightBasedOnItems(listView, maxPopupHeight - nameLblHeight - buttonContainerHeight); }
From source file:de.tobiasbielefeld.solitaire.games.Game.java
/** * Create a textView and add it to the given layout (game content). Used to add custom texts * to a game. This also sets the text apperance to AppCompat and the gravity to center. * The width and height is also measured, so you can use it directly. * * @param width The width to apply to the * @param layout he textView will be added to this layout * @param context Context to create view *//* w w w .j a v a 2s . c o m*/ protected void addTextViews(int count, int width, RelativeLayout layout, Context context) { for (int i = 0; i < count; i++) { TextView textView = new TextView(context); textView.setWidth(width); TextViewCompat.setTextAppearance(textView, R.style.TextAppearance_AppCompat); textView.setGravity(Gravity.CENTER); textView.setTextColor(Color.rgb(0, 0, 0)); layout.addView(textView); textView.measure(0, 0); textViews.add(textView); } }
From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java
private void correctNameAndPriceWidth(final View v, final AdvancedOrderCategoryItemRow row) { mActivity.getMainService().postOnUIHandler(new SafeRunnable() { @Override/* www . j av a2 s . c o m*/ protected void safeRun() throws Exception { TextView nameLbl = (TextView) v.findViewById(R.id.name); if (!row.name.equals(nameLbl.getText())) { return; } LinearLayout txtContainer = (LinearLayout) v.findViewById(R.id.text_container); txtContainer.measure(0, 0); int currentWidth = txtContainer.getMeasuredWidth(); int maxWidth = txtContainer.getWidth() - UIUtils.convertDipToPixels(mActivity, 35); nameLbl.measure(0, 0); int nameWidth = nameLbl.getMeasuredWidth(); int priceWidth = 0; if (row.hasPrice) { TextView priceLbl = (TextView) v.findViewById(R.id.price); priceLbl.measure(0, 0); priceWidth = priceLbl.getMeasuredWidth(); ViewGroup.LayoutParams lpPrice = priceLbl.getLayoutParams(); lpPrice.width = priceWidth; priceLbl.setLayoutParams(lpPrice); priceLbl.requestLayout(); } ViewGroup.LayoutParams lpName = nameLbl.getLayoutParams(); if (maxWidth > 0 && currentWidth < maxWidth) { if (maxWidth - priceWidth > nameWidth) { lpName.width = nameWidth; } else { lpName.width = maxWidth - priceWidth; } } else { lpName.width = maxWidth - priceWidth; } nameLbl.setLayoutParams(lpName); nameLbl.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 w ww . jav a2 s . com*/ 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.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java
private int computeStableWidth(TextView v, int maxNumber) { int maxWidth = 0; for (int i = 0; i < maxNumber; i++) { final String text = String.format("%02d", i); v.setText(text);/*w ww . j a v a 2 s. c o m*/ v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); final int width = v.getMeasuredWidth(); if (width > maxWidth) { maxWidth = width; } } return maxWidth; }
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); int nameLblHeight = nameLbl.getMeasuredHeight(); int priceLblHeight = 0; if (priceLbl.getVisibility() == View.VISIBLE) { priceLbl.measure(desiredWidth, 0); priceLblHeight = priceLbl.getMeasuredHeight(); }// w ww .j a va2s. com 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:io.doist.datetimepicker.time.RadialTimePickerView.java
private void drawDebug(Canvas canvas) { // Draw outer numbers circle final float outerRadius = mCircleRadius[HOURS] * mNumbersRadiusMultiplier[HOURS]; canvas.drawCircle(mXCenter, mYCenter, outerRadius, mPaintDebug); // Draw inner numbers circle final float innerRadius = mCircleRadius[HOURS] * mNumbersRadiusMultiplier[HOURS_INNER]; canvas.drawCircle(mXCenter, mYCenter, innerRadius, mPaintDebug); // Draw outer background circle canvas.drawCircle(mXCenter, mYCenter, mCircleRadius[HOURS], mPaintDebug); // Draw outer rectangle for circles float left = mXCenter - outerRadius; float top = mYCenter - outerRadius; float right = mXCenter + outerRadius; float bottom = mYCenter + outerRadius; canvas.drawRect(left, top, right, bottom, mPaintDebug); // Draw outer rectangle for background left = mXCenter - mCircleRadius[HOURS]; top = mYCenter - mCircleRadius[HOURS]; right = mXCenter + mCircleRadius[HOURS]; bottom = mYCenter + mCircleRadius[HOURS]; canvas.drawRect(left, top, right, bottom, mPaintDebug); // Draw outer view rectangle canvas.drawRect(0, 0, getWidth(), getHeight(), mPaintDebug); // Draw selected time final String selected = String.format("%02d:%02d", getCurrentHour(), getCurrentMinute()); ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); TextView tv = new TextView(getContext()); tv.setLayoutParams(lp);/* ww w.j av a 2s . co m*/ tv.setText(selected); tv.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); Paint paint = tv.getPaint(); paint.setColor(DEBUG_TEXT_COLOR); final int width = tv.getMeasuredWidth(); float height = paint.descent() - paint.ascent(); float x = mXCenter - width / 2; float y = mYCenter + 1.5f * height; canvas.drawText(selected, x, y, paint); }
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:org.onebusaway.android.ui.ArrivalsListHeader.java
/** * Sets the popup for the status/*from w w w . ja v a 2 s . com*/ * * @param index 0 if this is for the top ETA row, 1 if it is for the second * @param color color resource id to use for the popup background * @param statusText text to show in the status popup * @return a new PopupWindow initialized based on the provided parameters */ private PopupWindow setupPopup(final int index, int color, String statusText) { LayoutInflater inflater = LayoutInflater.from(mContext); TextView statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_large, null); statusView.setBackgroundResource(R.drawable.round_corners_style_b_status); GradientDrawable d = (GradientDrawable) statusView.getBackground(); if (color != R.color.stop_info_ontime) { // Show early/late color d.setColor(mResources.getColor(color)); } else { // For on-time, use header default color d.setColor(mResources.getColor(R.color.theme_primary)); } d.setStroke(UIUtils.dpToPixels(mContext, 1), mResources.getColor(R.color.header_text_color)); int pSides = UIUtils.dpToPixels(mContext, 5); int pTopBottom = UIUtils.dpToPixels(mContext, 2); statusView.setPadding(pSides, pTopBottom, pSides, pTopBottom); statusView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); statusView.measure(TextView.MeasureSpec.UNSPECIFIED, TextView.MeasureSpec.UNSPECIFIED); statusView.setText(statusText); PopupWindow p = new PopupWindow(statusView, statusView.getWidth(), statusView.getHeight()); p.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); p.setBackgroundDrawable(new ColorDrawable(mResources.getColor(android.R.color.transparent))); p.setOutsideTouchable(true); p.setTouchInterceptor(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { boolean touchInView; if (index == 0) { touchInView = UIUtils.isTouchInView(mEtaAndMin1, event); } else { touchInView = UIUtils.isTouchInView(mEtaAndMin2, event); } return touchInView; } }); return p; }