List of usage examples for android.widget TextView getPaint
public TextPaint getPaint()
From source file:so.contacts.hub.basefunction.widget.viewpagerindicator.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from www.j av a2s. c o m } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float deltX = 0; if (currentTab instanceof TextView) { TextView textView = (TextView) currentTab; float measureText = textView.getPaint().measureText(textView.getText(), 0, textView.getText().length()); deltX = (float) (((currentTab.getRight() - currentTab.getLeft()) - measureText) / 3.0); } float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates // between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } canvas.drawRect(lineLeft + deltX, height - indicatorHeight, lineRight - deltX, height, rectPaint); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } }
From source file:org.telegram.ui.Components.BotKeyboardView.java
public void setButtons(TLRPC.TL_replyKeyboardMarkup buttons) { botButtons = buttons;//from w w w.j a v a2s . co m container.removeAllViews(); buttonViews.clear(); if (buttons != null && botButtons.rows.size() != 0) { isFullSize = !buttons.resize; buttonHeight = !isFullSize ? 42 : (int) Math.max(42, (panelHeight - AndroidUtilities.dp(30) - (botButtons.rows.size() - 1) * AndroidUtilities.dp(10)) / botButtons.rows.size() / AndroidUtilities.density); for (int a = 0; a < buttons.rows.size(); a++) { TLRPC.TL_keyboardButtonRow row = buttons.rows.get(a); LinearLayout layout = new LinearLayout(getContext()); layout.setOrientation(LinearLayout.HORIZONTAL); container.addView(layout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, buttonHeight, 15, a == 0 ? 15 : 10, 15, a == buttons.rows.size() - 1 ? 15 : 0)); float weight = 1.0f / row.buttons.size(); for (int b = 0; b < row.buttons.size(); b++) { TLRPC.KeyboardButton button = row.buttons.get(b); TextView textView = new TextView(getContext()); textView.setTag(button); textView.setTextColor(ContextCompat.getColor(getContext(), R.color.bot_keyboard_text)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setGravity(Gravity.CENTER); textView.setBackgroundResource(R.drawable.bot_keyboard_button2); textView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); textView.setText(Emoji.replaceEmoji(button.text, textView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false)); layout.addView(textView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, weight, 0, 0, b != row.buttons.size() - 1 ? 10 : 0, 0)); textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { delegate.didPressedButton((TLRPC.KeyboardButton) v.getTag()); } }); buttonViews.add(textView); } } } }
From source file:net.coding.program.third.WechatTab.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/* w w w . ja v a 2 s . co m*/ } final int height = getHeight(); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } // TextView tv = ((TextView) currentTab); // String s = tv.getText().toString(); // float widths[] = new float[s.length()]; // tv.getPaint().getTextWidths(s, widths); // float StringWidth = 0; // for (float item : widths) { // StringWidth += item; // } // int padding = (int) ((tv.getWidth() - StringWidth) / 2 - mMyUnderlinePadding); // if (padding < 0) { // padding = 0; // } float padding = 0.0f; if (currentTab instanceof TextView) { TextView itemTextView = (TextView) currentTab; float textWidth = itemTextView.getPaint().measureText(itemTextView.getText().toString()); padding = (lineRight - lineLeft - textWidth) / 2; } if (padding <= 0.0f) { padding = mMyUnderlinePadding; } float lineMiddle = (lineLeft + lineRight) / 2; // canvas.drawRect(lineLeft + padding, height - indicatorHeight, lineRight - padding, height, rectPaint); canvas.drawRect(lineMiddle - halfIndecatorWidth, height - indicatorHeight, lineMiddle + halfIndecatorWidth, height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } }
From source file:com.stx.xhb.dmgameapp.view.PagerSlidingTabStrip.java
private void updateTabStyles() { for (int i = 0; i < tabCount; i++) { View v = tabsContainer.getChildAt(i); v.setBackgroundResource(!tabSwitch ? tabBackgroundResId : transparentColorId); if (v instanceof TextView) { TextView tab = (TextView) v; tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); TextPaint tp = tab.getPaint(); tp.setFakeBoldText(false);//w w w. j ava 2 s.c o m tab.setTypeface(tabTypeface, tabTypefaceStyle); tab.setTextColor(tabSwitch && i != 0 ? tabDeactivateTextColor : tabTextColor); // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a // pre-ICS-build if (textAllCaps) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { tab.setAllCaps(true); } else { tab.setText(tab.getText().toString().toUpperCase(locale)); } } } else if (v instanceof ImageButton) { ImageButton tab = (ImageButton) v; tab.setSelected(tabSwitch && i == 0 ? true : false); } } }
From source file:org.mozilla.mozstumbler.client.mapview.MapFragment.java
private void initTextView(int textViewId, String bound) { TextView textView = (TextView) mRootView.findViewById(textViewId); Paint textPaint = textView.getPaint(); int width = (int) Math.ceil(textPaint.measureText(bound)); textView.setWidth(width);//from www .ja va2 s. co m android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.MATCH_PARENT); textView.setLayoutParams(params); textView.setText("0"); }
From source file:com.taobao.weex.extend.module.actionsheet.WXActionSheet.java
private void addItem() { for (int i = 0; i < actionItems.size(); i++) { View item = makeItem(actionItems.get(i), i); if (item != null) { sheetContainer.addView(item); sheetContainer.addView(createLine()); }//from w ww . j ava 2s . co m } for (int i = 0; i < actionItems.size(); i++) { Pair<String, String> item = actionItems.get(i); if ("1".equals(item.first)) { if (hasCancelItemAdded) { if (actionListener != null) { actionListener.onError("Can only add most 1 item with type 1"); } return; } TextView textView = createItemBase(); textView.setText(item.second); textView.setTextColor(COLOR_ITEM_NORMAL); textView.getPaint().setFakeBoldText(true); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp2px(48)); lp.topMargin = dp2px(8); textView.setLayoutParams(lp); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (actionListener != null) { actionListener.onCancel(); dismiss(); } } }); sheetContainer.addView(textView); hasCancelItemAdded = true; } } }
From source file:com.android.yijiang.kzx.widget.PagerSlidingTabStrip.java
private void changeToChild(int position) { if (tabCount == 0) { return;/*from ww w . java 2 s . co m*/ } // if(position!=mPageIndex){ // TextView childTextView=(TextView) tabsContainer.getChildAt(position); // TextView offsetTextView=(TextView) tabsContainer.getChildAt(mPageIndex); // //// childTextView.setTextColor(indicatorColor); //// offsetTextView.setTextColor(tabTextColor); // childTextView.setTextColor(Color.parseColor("#666666")); // childTextView.getPaint().setFakeBoldText(false); // offsetTextView.setTextColor(Color.parseColor("#666666")); // offsetTextView.getPaint().setFakeBoldText(false); // }else{ // TextView childTextView=(TextView) tabsContainer.getChildAt(position); //// childTextView.setTextColor(indicatorColor); // childTextView.setTextColor(Color.parseColor("#444444")); // childTextView.getPaint().setFakeBoldText(true); // } // for (int i = 0; i < tabCount; i++) { View v = tabsContainer.getChildAt(i); if (v instanceof TextView) { TextView tab = (TextView) v; if (position == i) { tab.setTextColor(Color.parseColor("#444444")); tab.setAlpha(1.0f); tab.getPaint().setFakeBoldText(true); } else { tab.setTextColor(Color.parseColor("#666666")); tab.setAlpha(0.7f); tab.getPaint().setFakeBoldText(false); } } } }
From source file:com.github.irshulx.Components.InputExtensions.java
public void setLineSpacing(TextView textView, float lineHeight) { int fontHeight = textView.getPaint().getFontMetricsInt(null); textView.setLineSpacing(Utilities.dpToPx(editorCore.getContext(), lineHeight) - fontHeight, 1); }
From source file:com.coreform.open.android.formidablevalidation.SetErrorHandler.java
private void chooseSize(PopupWindow pop, CharSequence text, TextView tv) { int wid = tv.getPaddingLeft() + tv.getPaddingRight(); int ht = tv.getPaddingTop() + tv.getPaddingBottom(); //com.android.internal.R.dimen.textview_error_popup_default_width introduced after Gingerbread, only has one variant (240dip) int defaultWidthInPixels = mContext.getResources() .getDimensionPixelSize(R.dimen.textview_error_popup_default_width); Layout l = new StaticLayout(text, tv.getPaint(), defaultWidthInPixels, Layout.Alignment.ALIGN_NORMAL, 1, 0, true);//ww w . j a v a 2 s . com float max = 0; for (int i = 0; i < l.getLineCount(); i++) { max = Math.max(max, l.getLineWidth(i)); } if (DEBUG) Log.d(TAG, "max: " + max + ", height: " + l.getHeight()); /* * Now set the popup size to be big enough for the text plus the border. */ pop.setWidth(wid + (int) Math.ceil(max)); pop.setHeight(ht + l.getHeight()); //TODO: buggy (the 2 shouldnt need to be there) }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java
public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip) { final boolean shouldShowUiToAcceptTypedWord = Settings.getInstance() .getCurrent().mShouldShowUiToAcceptTypedWord; final int stripWidth = addToDictionaryStrip.getWidth(); final int width = shouldShowUiToAcceptTypedWord ? stripWidth : stripWidth - mDividerWidth - mPadding * 2; final TextView wordView = (TextView) addToDictionaryStrip.findViewById(R.id.word_to_save); wordView.setTextColor(mColorTypedWord); final int wordWidth = (int) (width * mCenterSuggestionWeight); final CharSequence wordToSave = getEllipsizedText(word, wordWidth, wordView.getPaint()); final float wordScaleX = wordView.getTextScaleX(); wordView.setText(wordToSave);/* ww w . j ava 2 s . c o m*/ wordView.setTextScaleX(wordScaleX); setLayoutWeight(wordView, mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT); final int wordVisibility = shouldShowUiToAcceptTypedWord ? View.GONE : View.VISIBLE; wordView.setVisibility(wordVisibility); addToDictionaryStrip.findViewById(R.id.word_to_save_divider).setVisibility(wordVisibility); final Resources res = addToDictionaryStrip.getResources(); final CharSequence hintText; final int hintWidth; final float hintWeight; final TextView hintView = (TextView) addToDictionaryStrip.findViewById(R.id.hint_add_to_dictionary); if (shouldShowUiToAcceptTypedWord) { hintText = res.getText(R.string.hint_add_to_dictionary_without_word); hintWidth = width; hintWeight = 1.0f; hintView.setGravity(Gravity.CENTER); } else { final boolean isRtlLanguage = (ViewCompat .getLayoutDirection(addToDictionaryStrip) == ViewCompat.LAYOUT_DIRECTION_RTL); final String arrow = isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW; final boolean isRtlSystem = SubtypeLocaleUtils.isRtlLanguage(res.getConfiguration().locale); final CharSequence hint = res.getText(R.string.hint_add_to_dictionary); hintText = (isRtlLanguage == isRtlSystem) ? (arrow + hint) : (hint + arrow); hintWidth = width - wordWidth; hintWeight = 1.0f - mCenterSuggestionWeight; hintView.setGravity(Gravity.CENTER_VERTICAL | Gravity.START); } hintView.setTextColor(mColorAutoCorrect); final float hintScaleX = getTextScaleX(hintText, hintWidth, hintView.getPaint()); hintView.setText(hintText); hintView.setTextScaleX(hintScaleX); setLayoutWeight(hintView, hintWeight, ViewGroup.LayoutParams.MATCH_PARENT); }