List of usage examples for android.widget TextView getHeight
@ViewDebug.ExportedProperty(category = "layout") public final int getHeight()
From source file:Main.java
public static int getLastLine(TextView tv) { int height = tv.getHeight(); int scrollY = tv.getScrollY(); Layout layout = tv.getLayout();/* w w w . j ava 2 s . c om*/ if (layout == null) { return 0; } // int firstVisibleLineNumber = layout.getLineForVertical(scrollY); int lastVisibleLineNumber = layout.getLineForVertical(scrollY + height); return lastVisibleLineNumber; }
From source file:com.bangalore.barcamp.BCBUtils.java
public static void createActionBarOnActivity(final Activity activity, boolean isHome) { // ******** Start of Action Bar configuration ActionBar actionbar = (ActionBar) activity.findViewById(R.id.actionBar1); actionbar.setHomeLogo(R.drawable.home); actionbar.setHomeAction(new Action() { @Override//from w ww.j ava2 s . c o m public void performAction(View view) { ((SlidingMenuActivity) activity).toggle(); } @Override public int getDrawable() { return R.drawable.home; } }); actionbar.setTitle(R.string.app_title_text); TextView logo = (TextView) activity.findViewById(R.id.actionbar_title); Shader textShader = new LinearGradient(0, 0, 0, logo.getHeight(), new int[] { Color.WHITE, 0xff999999 }, null, TileMode.CLAMP); logo.getPaint().setShader(textShader); actionbar.setOnTitleClickListener(new OnClickListener() { @Override public void onClick(View v) { } }); // ******** End of Action Bar configuration }
From source file:Main.java
private static void onCenterDraw(TextView view, Canvas canvas, Drawable drawable, int gravity) { int drawablePadding = view.getCompoundDrawablePadding(); int ratio = 1; float total;/* w ww . j a v a 2 s.c o m*/ switch (gravity) { case Gravity.END: ratio = -1; case Gravity.START: total = view.getPaint().measureText(view.getText().toString()) + drawable.getIntrinsicWidth() + drawablePadding + view.getPaddingLeft() + view.getPaddingRight(); canvas.translate(ratio * (view.getWidth() - total) / 2, 0); break; case Gravity.BOTTOM: ratio = -1; case Gravity.TOP: Paint.FontMetrics fontMetrics = view.getPaint().getFontMetrics(); total = fontMetrics.descent - fontMetrics.ascent + drawable.getIntrinsicHeight() + drawablePadding + view.getPaddingTop() + view.getPaddingBottom(); canvas.translate(0, ratio * (view.getHeight() - total) / 2); break; } }
From source file:com.alainesp.fan.sanderson.MainActivity.java
/** * Set the badge number to all menu items visible *//*ww w . j a v a 2 s .c o m*/ 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:Main.java
private static void onCenterDraw(TextView view, Canvas canvas, Drawable drawable, int gravity) { int drawablePadding = view.getCompoundDrawablePadding(); int ratio = 1; float total;/*from w ww . ja v a 2s . com*/ switch (gravity) { case Gravity.RIGHT: ratio = -1; case Gravity.LEFT: total = view.getPaint().measureText(view.getText().toString()) + drawable.getIntrinsicWidth() + drawablePadding + view.getPaddingLeft() + view.getPaddingRight(); canvas.translate(ratio * (view.getWidth() - total) / 2, 0); break; case Gravity.BOTTOM: ratio = -1; case Gravity.TOP: Paint.FontMetrics fontMetrics0 = view.getPaint().getFontMetrics(); total = fontMetrics0.descent - fontMetrics0.ascent + drawable.getIntrinsicHeight() + drawablePadding + view.getPaddingTop() + view.getPaddingBottom(); canvas.translate(0, ratio * (view.getHeight() - total) / 2); break; } }
From source file:dcheungaa.procal.MainActivity.java
@Override public void onWindowFocusChanged(boolean hasFocus) { TextView cursor = (TextView) MainActivity.views.get("cursor"); TextView matrixDisplay = (TextView) MainActivity.views.get("matrixDisplay"); super.onWindowFocusChanged(hasFocus); if (call_load) { call_load = false;/*from w w w.jav a2s.c o m*/ fontWidth = cursor.getWidth(); fontHeight = cursor.getHeight(); cursor.setText(Character.toString((char) 0x258E)); //cursor.setTop(matrixDisplay.getTop()); cursor.setPadding(matrixDisplay.getPaddingLeft(), cursor.getPaddingTop(), cursor.getPaddingRight(), cursor.getPaddingBottom()); cursor.setLeft(matrixDisplay.getLeft()); //CursorHandler.hideCursor(); RelativeLayout cm = (RelativeLayout) findViewById(R.id.content_main); LinearLayout rows = (LinearLayout) findViewById(R.id.llKeyPad); keyPad.KeyPad_resize(cm, rows); int fnBtnHeight = keyPad.btn_rows.get(0).get(0).get_mheight(); System.out.print(Integer.toString(fnBtnHeight)); varPad.resize(fnBtnHeight, fnBtnHeight * 3, svVar); cmdPad.resize(fnBtnHeight, fnBtnHeight * 3, svCmd); constPad.resize(fnBtnHeight, fnBtnHeight * 3, svConst); } }
From source file:com.gsbabil.antitaintdroid.UtilityFunctions.java
public void statusUpdate(String msg) { TextView tv = (TextView) MyApp.context.findViewById(R.id.textview); tv.append(msg);/*from www.j av a 2s . c om*/ try { int lineTop = 0; try { lineTop = tv.getLayout().getLineTop(tv.getLineCount()); } catch (Throwable e) { lineTop = 0; } final int scrollAmount = lineTop - tv.getHeight(); if (scrollAmount > 0) { tv.scrollTo(0, scrollAmount); } else { tv.scrollTo(0, 0); } } catch (Throwable e) { Log.i(MyApp.TAG, e.getMessage().toString()); } }
From source file:com.android.mail.browse.ConversationItemViewCoordinates.java
private ConversationItemViewCoordinates(final Context context, final Config config, final CoordinatesCache cache) { Utils.traceBeginSection("CIV coordinates constructor"); final Resources res = context.getResources(); final int layoutId = R.layout.conversation_item_view; ViewGroup view = (ViewGroup) cache.getView(layoutId); if (view == null) { view = (ViewGroup) LayoutInflater.from(context).inflate(layoutId, null); cache.put(layoutId, view);//w w w . j a v a 2s .c om } // Show/hide optional views before measure/layout call final TextView folders = (TextView) view.findViewById(R.id.folders); folders.setVisibility(config.areFoldersVisible() ? View.VISIBLE : View.GONE); View contactImagesView = view.findViewById(R.id.contact_image); switch (config.getGadgetMode()) { case GADGET_CONTACT_PHOTO: contactImagesView.setVisibility(View.VISIBLE); break; case GADGET_CHECKBOX: contactImagesView.setVisibility(View.GONE); contactImagesView = null; break; default: contactImagesView.setVisibility(View.GONE); contactImagesView = null; break; } final View replyState = view.findViewById(R.id.reply_state); replyState.setVisibility(config.isReplyStateVisible() ? View.VISIBLE : View.GONE); final View personalIndicator = view.findViewById(R.id.personal_indicator); personalIndicator.setVisibility(config.isPersonalIndicatorVisible() ? View.VISIBLE : View.GONE); setFramePadding(context, view, config.useFullPadding()); // Layout the appropriate view. ViewCompat.setLayoutDirection(view, config.getLayoutDirection()); final int widthSpec = MeasureSpec.makeMeasureSpec(config.getWidth(), MeasureSpec.EXACTLY); final int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); view.measure(widthSpec, heightSpec); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); // Once the view is measured, let's calculate the dynamic width variables. folderLayoutWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_max_width_proportion) / 100.0); folderCellWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_cell_max_width_proportion) / 100.0); // Utils.dumpViewTree((ViewGroup) view); // Records coordinates. // Contact images view if (contactImagesView != null) { contactImagesWidth = contactImagesView.getWidth(); contactImagesHeight = contactImagesView.getHeight(); contactImagesX = getX(contactImagesView); contactImagesY = getY(contactImagesView); } else { contactImagesX = contactImagesY = contactImagesWidth = contactImagesHeight = 0; } final boolean isRtl = ViewUtils.isViewRtl(view); final View star = view.findViewById(R.id.star); final int starPadding = res.getDimensionPixelSize(R.dimen.conv_list_star_padding_start); starX = getX(star) + (isRtl ? 0 : starPadding); starY = getY(star); starWidth = star.getWidth(); final TextView senders = (TextView) view.findViewById(R.id.senders); final int sendersTopAdjust = getLatinTopAdjustment(senders); sendersX = getX(senders); sendersY = getY(senders) + sendersTopAdjust; sendersWidth = senders.getWidth(); sendersHeight = senders.getHeight(); sendersLineCount = SINGLE_LINE; sendersFontSize = senders.getTextSize(); final TextView subject = (TextView) view.findViewById(R.id.subject); final int subjectTopAdjust = getLatinTopAdjustment(subject); subjectX = getX(subject); subjectY = getY(subject) + subjectTopAdjust; subjectWidth = subject.getWidth(); subjectHeight = subject.getHeight(); subjectFontSize = subject.getTextSize(); final TextView snippet = (TextView) view.findViewById(R.id.snippet); final int snippetTopAdjust = getLatinTopAdjustment(snippet); snippetX = getX(snippet); snippetY = getY(snippet) + snippetTopAdjust; maxSnippetWidth = snippet.getWidth(); snippetHeight = snippet.getHeight(); snippetFontSize = snippet.getTextSize(); if (config.areFoldersVisible()) { foldersLeft = getX(folders); foldersRight = foldersLeft + folders.getWidth(); foldersY = getY(folders); foldersTypeface = folders.getTypeface(); foldersFontSize = folders.getTextSize(); } else { foldersLeft = 0; foldersRight = 0; foldersY = 0; foldersTypeface = null; foldersFontSize = 0; } final View colorBlock = view.findViewById(R.id.color_block); if (config.isColorBlockVisible() && colorBlock != null) { colorBlockX = getX(colorBlock); colorBlockY = getY(colorBlock); colorBlockWidth = colorBlock.getWidth(); colorBlockHeight = colorBlock.getHeight(); } else { colorBlockX = colorBlockY = colorBlockWidth = colorBlockHeight = 0; } if (config.isReplyStateVisible()) { replyStateX = getX(replyState); replyStateY = getY(replyState); } else { replyStateX = replyStateY = 0; } if (config.isPersonalIndicatorVisible()) { personalIndicatorX = getX(personalIndicator); personalIndicatorY = getY(personalIndicator); } else { personalIndicatorX = personalIndicatorY = 0; } final View infoIcon = view.findViewById(R.id.info_icon); infoIconX = getX(infoIcon); infoIconXRight = infoIconX + infoIcon.getWidth(); infoIconY = getY(infoIcon); final TextView date = (TextView) view.findViewById(R.id.date); dateX = getX(date); dateXRight = dateX + date.getWidth(); dateY = getY(date); datePaddingStart = ViewUtils.getPaddingStart(date); dateFontSize = date.getTextSize(); dateYBaseline = dateY + getLatinTopAdjustment(date) + date.getBaseline(); final View paperclip = view.findViewById(R.id.paperclip); paperclipY = getY(paperclip); paperclipPaddingStart = ViewUtils.getPaddingStart(paperclip); height = view.getHeight() + sendersTopAdjust; Utils.traceEndSection(); }
From source file:com.example.gaurav.calculator.Calculator.java
@Override public void onTextSizeChanged(final TextView textView, float oldSize) { if (mCurrentState != CalculatorState.INPUT) { // Only animate text changes that occur from user input. return;//from w ww . j a v a 2 s . com } // Calculate the values needed to perform the scale and translation animations, // maintaining the same apparent baseline for the displayed text. final float textScale = oldSize / textView.getTextSize(); final float translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - ViewCompat.getPaddingEnd(textView)); final float translationY = (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(ObjectAnimator.ofFloat(textView, "scaleX", textScale, 1.0f), ObjectAnimator.ofFloat(textView, "scaleY", textScale, 1.0f), ObjectAnimator.ofFloat(textView, "translationX", translationX, 0.0f), ObjectAnimator.ofFloat(textView, "translationY", translationY, 0.0f)); animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.start(); }
From source file:com.tct.mail.browse.ConversationItemViewCoordinates.java
private ConversationItemViewCoordinates(final Context context, final Config config, final CoordinatesCache cache) { Utils.traceBeginSection("CIV coordinates constructor"); final Resources res = context.getResources(); mMinListWidthForWide = res.getDimensionPixelSize(R.dimen.list_min_width_is_wide); mMode = calculateMode(res, config);/* ww w. j av a2 s. c om*/ final int layoutId = R.layout.conversation_item_view; ViewGroup view = (ViewGroup) cache.getView(layoutId); if (view == null) { view = (ViewGroup) LayoutInflater.from(context).inflate(layoutId, null); cache.put(layoutId, view); } // Show/hide optional views before measure/layout call final TextView folders = (TextView) view.findViewById(R.id.folders); folders.setVisibility(config.areFoldersVisible() ? View.VISIBLE : View.GONE); View contactImagesView = view.findViewById(R.id.contact_image); switch (config.getGadgetMode()) { case GADGET_CONTACT_PHOTO: contactImagesView.setVisibility(View.VISIBLE); break; case GADGET_CHECKBOX: contactImagesView.setVisibility(View.GONE); contactImagesView = null; break; default: contactImagesView.setVisibility(View.GONE); contactImagesView = null; break; } final View replyState = view.findViewById(R.id.reply_state); replyState.setVisibility(config.isReplyStateVisible() ? View.VISIBLE : View.GONE); final View personalIndicator = view.findViewById(R.id.personal_indicator); personalIndicator.setVisibility(config.isPersonalIndicatorVisible() ? View.VISIBLE : View.GONE); setFramePadding(context, view, config.useFullPadding()); // Layout the appropriate view. ViewCompat.setLayoutDirection(view, config.getLayoutDirection()); final int widthSpec = MeasureSpec.makeMeasureSpec(config.getWidth(), MeasureSpec.EXACTLY); final int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); view.measure(widthSpec, heightSpec); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); // Once the view is measured, let's calculate the dynamic width variables. folderLayoutWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_max_width_proportion) / 100.0); folderCellWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_cell_max_width_proportion) / 100.0); // Utils.dumpViewTree((ViewGroup) view); // Records coordinates. // Contact images view if (contactImagesView != null) { contactImagesWidth = contactImagesView.getWidth(); contactImagesHeight = contactImagesView.getHeight(); contactImagesX = getX(contactImagesView); contactImagesY = getY(contactImagesView); } else { contactImagesX = contactImagesY = contactImagesWidth = contactImagesHeight = 0; } final boolean isRtl = ViewUtils.isViewRtl(view); final View star = view.findViewById(R.id.star); final int starPadding = res.getDimensionPixelSize(R.dimen.conv_list_star_padding_start); starX = getX(star) + (isRtl ? 0 : starPadding); starY = getY(star); starWidth = star.getWidth(); final TextView senders = (TextView) view.findViewById(R.id.senders); final int sendersTopAdjust = getLatinTopAdjustment(senders); sendersX = getX(senders); sendersY = getY(senders) + sendersTopAdjust; sendersWidth = senders.getWidth(); sendersHeight = senders.getHeight(); sendersLineCount = SINGLE_LINE; sendersFontSize = senders.getTextSize(); final TextView subject = (TextView) view.findViewById(R.id.subject); final int subjectTopAdjust = getLatinTopAdjustment(subject); subjectX = getX(subject); subjectY = getY(subject) + subjectTopAdjust; subjectWidth = subject.getWidth(); subjectHeight = subject.getHeight(); subjectFontSize = subject.getTextSize(); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_S final TextView status = (TextView) view.findViewById(R.id.status); final int statusTopAdjust = getLatinTopAdjustment(status); statusX = getX(status); statusY = getY(status) + statusTopAdjust; statusWidth = status.getWidth(); statusHeight = status.getHeight(); statusFontSize = status.getTextSize(); statusPaddingStart = ViewUtils.getPaddingStart(status); statusPanddingEnd = ViewUtils.getPaddingEnd(status); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_E final TextView snippet = (TextView) view.findViewById(R.id.snippet); final int snippetTopAdjust = getLatinTopAdjustment(snippet); snippetX = getX(snippet); snippetY = getY(snippet) + snippetTopAdjust; maxSnippetWidth = snippet.getWidth(); snippetHeight = snippet.getHeight(); snippetFontSize = snippet.getTextSize(); if (config.areFoldersVisible()) { // vertically align folders min left edge with subject foldersLeft = getX(folders); foldersRight = foldersLeft + folders.getWidth(); foldersY = getY(folders) + sendersTopAdjust; foldersHeight = folders.getHeight(); foldersTypeface = folders.getTypeface(); foldersTextBottomPadding = res.getDimensionPixelSize(R.dimen.folders_text_bottom_padding); foldersFontSize = folders.getTextSize(); } else { foldersLeft = 0; foldersRight = 0; foldersY = 0; foldersHeight = 0; foldersTypeface = null; foldersTextBottomPadding = 0; foldersFontSize = 0; } final View colorBlock = view.findViewById(R.id.color_block); if (config.isColorBlockVisible() && colorBlock != null) { colorBlockX = getX(colorBlock); colorBlockY = getY(colorBlock); colorBlockWidth = colorBlock.getWidth(); colorBlockHeight = colorBlock.getHeight(); } else { colorBlockX = colorBlockY = colorBlockWidth = colorBlockHeight = 0; } if (config.isReplyStateVisible()) { replyStateX = getX(replyState); replyStateY = getY(replyState); } else { replyStateX = replyStateY = 0; } if (config.isPersonalIndicatorVisible()) { personalIndicatorX = getX(personalIndicator); personalIndicatorY = getY(personalIndicator); } else { personalIndicatorX = personalIndicatorY = 0; } final View infoIcon = view.findViewById(R.id.info_icon); infoIconX = getX(infoIcon); infoIconXRight = infoIconX + infoIcon.getWidth(); infoIconY = getY(infoIcon); final TextView date = (TextView) view.findViewById(R.id.date); dateX = getX(date); dateXRight = dateX + date.getWidth(); dateY = getY(date); datePaddingStart = ViewUtils.getPaddingStart(date); dateFontSize = date.getTextSize(); dateYBaseline = dateY + getLatinTopAdjustment(date) + date.getBaseline(); final View paperclip = view.findViewById(R.id.paperclip); paperclipY = getY(paperclip); paperclipPaddingStart = ViewUtils.getPaddingStart(paperclip); height = view.getHeight() + sendersTopAdjust; Utils.traceEndSection(); }