List of usage examples for android.widget TextView getTextSize
@ViewDebug.ExportedProperty(category = "text") public float getTextSize()
From source file:Main.java
/** * Returns the font size for a {@link TextView}. * * @param textview text view instance/*from ww w . j av a 2 s . c o m*/ * @return font size in pixel */ public static float getFontSize(TextView textview) { return textview.getTextSize(); }
From source file:Main.java
private static int getFontHeight(TextView tv) { Paint paint = new Paint(); paint.setTextSize(tv.getTextSize()); Paint.FontMetrics fm = paint.getFontMetrics(); return (int) Math.ceil(fm.bottom - fm.top); }
From source file:Main.java
public static int getFontHeight(TextView textView) { Paint paint = new Paint(); paint.setTextSize(textView.getTextSize()); Paint.FontMetrics fm = paint.getFontMetrics(); return (int) Math.ceil(fm.bottom - fm.top); }
From source file:Main.java
public static String getDefaultFontSize(Context context) { String size = "15.0px"; TextView tv = new TextView(context); if (tv != null) { size = String.valueOf(tv.getTextSize()) + "px"; tv = null;//from w w w . ja v a2 s .c om } return size; }
From source file:android.support.v17.leanback.app.ErrorSupportFragment.java
private static FontMetricsInt getFontMetricsInt(TextView textView) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(textView.getTextSize()); paint.setTypeface(textView.getTypeface()); return paint.getFontMetricsInt(); }
From source file:cn.dreamtobe.emoji.ellipsize.helper.SpanEllipsizeEndHelper.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private static String getMaxWidthKey(CharSequence targetText, TextView textView) { String key = String.format("%s@%d@%d", targetText, textView.getMaxWidth(), (int) textView.getTextSize()); if (targetText instanceof SpannableString) { Object[] spans = ((SpannableString) targetText).getSpans(0, targetText.length(), Object.class); for (Object span : spans) { key += ((SpannableString) targetText).getSpanStart(span); key += ((SpannableString) targetText).getSpanEnd(span); }/*from www . j a v a 2 s. c o m*/ } return key; }
From source file:android.support.design.testutils.TestUtilsMatchers.java
/** * Returns a matcher that matches TextViews with the specified text size. *//* www . java 2s .c om*/ public static Matcher withTextSize(final float textSize) { return new BoundedMatcher<View, TextView>(TextView.class) { private String failedCheckDescription; @Override public void describeTo(final Description description) { description.appendText(failedCheckDescription); } @Override public boolean matchesSafely(final TextView view) { final float ourTextSize = view.getTextSize(); if (Math.abs(textSize - ourTextSize) > 1.0f) { failedCheckDescription = "text size " + ourTextSize + " is different than expected " + textSize; return false; } return true; } }; }
From source file:com.facebook.appevents.codeless.internal.ViewHierarchy.java
public static JSONObject setAppearanceOfView(View view, JSONObject json, float displayDensity) { try {//from w w w. j av a 2s . c om JSONObject textStyle = new JSONObject(); if (view instanceof TextView) { TextView textView = (TextView) view; Typeface typeface = textView.getTypeface(); if (typeface != null) { textStyle.put(TEXT_SIZE, textView.getTextSize()); textStyle.put(TEXT_IS_BOLD, typeface.isBold()); textStyle.put(TEXT_IS_ITALIC, typeface.isItalic()); json.put(TEXT_STYLE, textStyle); } } if (view instanceof ImageView) { Drawable drawable = ((ImageView) view).getDrawable(); if (drawable instanceof BitmapDrawable) { if (view.getHeight() / displayDensity <= ICON_MAX_EDGE_LENGTH && view.getWidth() / displayDensity <= ICON_MAX_EDGE_LENGTH) { Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream.toByteArray(); String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT); json.put(ICON_BITMAP, encoded); } } } } catch (JSONException e) { Utility.logd(TAG, e); } return json; }
From source file:com.alainesp.fan.sanderson.MainActivity.java
/** * Set the badge number to all menu items visible *//*from w ww . ja v a 2s . com*/ private static void setBadgesNumberUI() { if (navigationView != null) { NavigationMenuView v = (NavigationMenuView) navigationView.getChildAt(0); Menu drawerMenu = navigationView.getMenu(); if (v != null) // Iterate all children for (int childIndex = 0; childIndex < v.getChildCount(); childIndex++) { View v1 = v.getChildAt(childIndex); if (v1 instanceof NavigationMenuItemView) { TextView mTextView = (TextView) ((NavigationMenuItemView) v1).getChildAt(0); if (mTextView != null) { // Get the menu index Integer menuIndex = reverseMenuText.get(mTextView.getText().toString()); if (menuIndex != null && menuIndex < badgeNumbers.length) { Drawable numberText = null; if (badgeNumbers[menuIndex] > 0) { int height = mTextView.getHeight(); numberText = new TextDrawable(badgeNumbers[menuIndex], mTextView.getTextSize(), mTextView.getCurrentTextColor(), height); numberText.setBounds(0, 0, height, height); } // Similar to NavigationMenuItemView.setIcon Drawable icon = drawerMenu.getItem(menuIndex).getIcon(); Drawable.ConstantState state = icon.getConstantState(); icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate(); int mIconSize = navigationView.getContext().getResources().getDimensionPixelSize( android.support.design.R.dimen.design_navigation_icon_size); icon.setBounds(0, 0, mIconSize, mIconSize); DrawableCompat.setTintList(icon, navigationView.getItemIconTintList()); TextViewCompat.setCompoundDrawablesRelative(mTextView, icon, null, numberText, null); } } } } } }
From source file:com.google.samples.apps.topeka.widget.TextResizeTransition.java
private void captureValues(TransitionValues transitionValues) { if (!(transitionValues.view instanceof TextView)) { throw new UnsupportedOperationException( "Doesn't work on " + transitionValues.view.getClass().getName()); }//from www. ja v a 2s .c o m TextView view = (TextView) transitionValues.view; transitionValues.values.put(PROPERTY_NAME_TEXT_RESIZE, view.getTextSize()); transitionValues.values.put(PROPERTY_NAME_PADDING_RESIZE, ViewCompat.getPaddingStart(view)); }