Java Code Examples for android.graphics.Typeface
The following examples show how to use
android.graphics.Typeface. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: io16experiment-master Source File: DialogUtils.java License: Apache License 2.0 | 6 votes |
/** * Create a progress dialog for the loading spinner or progress indicator * <p/> * @param activity * @param spinner * @param titleId * @param messageId * @param cancelable * @param max * @param onCancelListener * @param typeface * @param formatArgs * @return */ private static MaterialDialog createProgressDialog(final Activity activity, boolean spinner, int titleId, int messageId, boolean cancelable, int max, DialogInterface.OnCancelListener onCancelListener, Typeface typeface, Object... formatArgs) { MaterialDialog.Builder builder = new MaterialDialog.Builder(activity) .cancelable(cancelable); if (titleId > DEFAULT_TITLE_ID) { builder.title(messageId > DEFAULT_MESSAGE_ID ? activity.getString(titleId) : activity.getString(titleId, formatArgs)); } if (messageId > DEFAULT_MESSAGE_ID) { builder.content(activity.getString(messageId, formatArgs)).typeface(typeface, typeface); } if (onCancelListener != null) { builder.cancelListener(onCancelListener); } if (spinner) { builder.progress(true, 0); } else { builder.progress(false, max, true); } return builder.build(); }
Example 2
Source Project: commcare-android Source File: ListWidget.java License: Apache License 2.0 | 6 votes |
@Override protected void addQuestionText() { // Add the text view. Textview always exists, regardless of whether there's text. TextView questionText = new TextView(getContext()); setQuestionText(questionText, mPrompt); questionText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, TEXTSIZE); questionText.setTypeface(null, Typeface.BOLD); questionText.setPadding(0, 0, 0, 7); questionText.setId(buttonIdBase); // assign random id // Wrap to the size of the parent view questionText.setHorizontallyScrolling(false); if (mPrompt.getLongText() == null) { questionText.setVisibility(GONE); } // Put the question text on the left half of the screen LinearLayout.LayoutParams labelParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); labelParams.weight = 1; questionLayout = new LinearLayout(getContext()); questionLayout.setOrientation(LinearLayout.HORIZONTAL); questionLayout.addView(questionText, labelParams); }
Example 3
Source Project: AOSP-Kayboard-7.1.2 Source File: SuggestionStripLayoutHelper.java License: Apache License 2.0 | 6 votes |
private static int getTextWidth(@Nullable final CharSequence text, final TextPaint paint) { if (TextUtils.isEmpty(text)) { return 0; } final int length = text.length(); final float[] widths = new float[length]; final int count; final Typeface savedTypeface = paint.getTypeface(); try { paint.setTypeface(getTextTypeface(text)); count = paint.getTextWidths(text, 0, length, widths); } finally { paint.setTypeface(savedTypeface); } int width = 0; for (int i = 0; i < count; i++) { width += Math.round(widths[i] + 0.5f); } return width; }
Example 4
Source Project: MyBookshelf Source File: FontAdapter.java License: GNU General Public License v3.0 | 6 votes |
@Override public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { if (fileList.size() > 0) { Typeface typeface = Typeface.createFromFile(fileList.get(position)); holder.tvFont.setTypeface(typeface); holder.tvFont.setText(fileList.get(position).getName()); if (fileList.get(position).getAbsolutePath().equals(selectPath)) { holder.ivChecked.setVisibility(View.VISIBLE); } else { holder.ivChecked.setVisibility(View.INVISIBLE); } holder.tvFont.setOnClickListener(view -> { if (thisListener != null) { thisListener.setFontPath(fileList.get(position).getAbsolutePath()); } }); } else { holder.tvFont.setText(R.string.fonts_folder); } }
Example 5
Source Project: Genius-Android Source File: TextView.java License: Apache License 2.0 | 6 votes |
private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) { if (attrs == null) return; final Context context = getContext(); final Resources resources = getResources(); final float density = resources.getDisplayMetrics().density; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextView, defStyleAttr, defStyleRes); int border = a.getInt(R.styleable.TextView_gBorder, 0); int borderSize = a.getDimensionPixelOffset(R.styleable.TextView_gBorderSize, (int) density); int borderColor = a.getColor(R.styleable.TextView_gBorderColor, UiCompat.getColor(resources, R.color.g_default_base_secondary)); String fontFile = a.getString(R.styleable.TextView_gFont); a.recycle(); setBorder(border, borderSize, borderColor); // Check for IDE preview render if (!this.isInEditMode() && fontFile != null && fontFile.length() > 0) { Typeface typeface = Ui.getFont(getContext(), fontFile); if (typeface != null) setTypeface(typeface); } }
Example 6
Source Project: v2ex Source File: UIUtils.java License: Apache License 2.0 | 6 votes |
/** * Given a snippet string with matching segments surrounded by curly * braces, turn those areas into bold spans, removing the curly braces. */ public static Spannable buildStyledSnippet(String snippet) { final SpannableStringBuilder builder = new SpannableStringBuilder(snippet); // Walk through string, inserting bold snippet spans int startIndex, endIndex = -1, delta = 0; while ((startIndex = snippet.indexOf('{', endIndex)) != -1) { endIndex = snippet.indexOf('}', startIndex); // Remove braces from both sides builder.delete(startIndex - delta, startIndex - delta + 1); builder.delete(endIndex - delta - 1, endIndex - delta); // Insert bold style builder.setSpan(new StyleSpan(Typeface.BOLD), startIndex - delta, endIndex - delta - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //builder.setSpan(new ForegroundColorSpan(0xff111111), // startIndex - delta, endIndex - delta - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); delta += 2; } return builder; }
Example 7
Source Project: holoaccent Source File: AccentSwitch.java License: Apache License 2.0 | 6 votes |
public void setSwitchTypeface(Typeface tf, int style) { if (style > 0) { if (tf == null) { tf = Typeface.defaultFromStyle(style); } else { tf = Typeface.create(tf, style); } setSwitchTypeface(tf); // now compute what (if any) algorithmic styling is needed int typefaceStyle = tf != null ? tf.getStyle() : 0; int need = style & ~typefaceStyle; mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0); mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0); } else { mTextPaint.setFakeBoldText(false); mTextPaint.setTextSkewX(0); setSwitchTypeface(tf); } }
Example 8
Source Project: EhViewer Source File: Html.java License: Apache License 2.0 | 6 votes |
private static void endHeader(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Header.class); int where = text.getSpanStart(obj); text.removeSpan(obj); // Back off not to change only the text, not the blank line. while (len > where && text.charAt(len - 1) == '\n') { len--; } if (where != len) { Header h = (Header) obj; text.setSpan(new RelativeSizeSpan(HEADER_SIZES[h.mLevel]), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new StyleSpan(Typeface.BOLD), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } }
Example 9
Source Project: ContactMerger Source File: MergeListAdapter.java License: Apache License 2.0 | 6 votes |
public MergeListAdapter(Activity activity) { super(); model = new ArrayList<MergeContact>(); this.activity = activity; update(); provider = activity.getContentResolver().acquireContentProviderClient( ContactsContract.AUTHORITY_URI); contactMapper = new ContactDataMapper(provider); contactMapper.setCache(new ShiftedExpireLRU(5 * 60 * 1000, 100)); layoutInflater = activity.getLayoutInflater(); font = Typeface.createFromAsset( activity.getAssets(), "fontawesome-webfont.ttf" ); }
Example 10
Source Project: animation-samples Source File: SlidingTabLayout.java License: Apache License 2.0 | 6 votes |
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}. */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
Example 11
Source Project: Telegram Source File: SlidingTabView.java License: GNU General Public License v2.0 | 6 votes |
public void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title); tab.setFocusable(true); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); tab.setTextColor(0xffffffff); tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); tab.setTypeface(Typeface.DEFAULT_BOLD); tab.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR, 0)); tab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { didSelectTab(position); } }); addView(tab); LayoutParams layoutParams = (LayoutParams)tab.getLayoutParams(); layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.width = 0; layoutParams.weight = 50; tab.setLayoutParams(layoutParams); tabCount++; }
Example 12
Source Project: Noyze Source File: iOSVolumePanel.java License: Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); Context context = getContext(); LayoutInflater inflater = LayoutInflater.from(context); Typeface helveticaBold = Typeface.createFromAsset(context.getAssets(), "fonts/HelveticaNeue-Bold.ttf"); Typeface helvetica = Typeface.createFromAsset(context.getAssets(), "fonts/HelveticaNeue.ttf"); root = (ViewGroup) inflater.inflate(R.layout.ios_volume_adjust, null); seekBar = (iOSProgressBar) root.findViewById(android.R.id.progress); icon = (ImageView) root.findViewById(R.id.stream_icon); volumeText = (TextView) root.findViewById(R.id.volume_text); silent = (TextView) root.findViewById(R.id.mediaSilent); volumeText.setTypeface(helveticaBold); silent.setTypeface(helvetica); volumeText.setPaintFlags(volumeText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); silent.setPaintFlags(silent.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); // Set the default color & background. if (!has(COLOR)) color = Color.WHITE; if (!has(BACKGROUND)) backgroundColor = Color.BLACK; mLayout = root; }
Example 13
Source Project: Conversations Source File: MessageAdapter.java License: GNU General Public License v3.0 | 6 votes |
private void toggleWhisperInfo(ViewHolder viewHolder, final Message message, final boolean darkBackground) { if (message.isPrivateMessage()) { final String privateMarker; if (message.getStatus() <= Message.STATUS_RECEIVED) { privateMarker = activity.getString(R.string.private_message); } else { Jid cp = message.getCounterpart(); privateMarker = activity.getString(R.string.private_message_to, Strings.nullToEmpty(cp == null ? null : cp.getResource())); } final SpannableString body = new SpannableString(privateMarker); body.setSpan(new ForegroundColorSpan(getMessageTextColor(darkBackground, false)), 0, privateMarker.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); body.setSpan(new StyleSpan(Typeface.BOLD), 0, privateMarker.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); viewHolder.messageBody.setText(body); viewHolder.messageBody.setVisibility(View.VISIBLE); } else { viewHolder.messageBody.setVisibility(View.GONE); } }
Example 14
Source Project: iOSDialog Source File: iOSDialog.java License: MIT License | 6 votes |
public iOSDialog(Context context, String title, String subtitle, boolean bold, Typeface typeFace,boolean cancelable) { negativeExist=false; dialog = new Dialog(context); dialog.setContentView(R.layout.alerts_two_buttons); if(dialog.getWindow()!=null) dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); initViews(); dialog.setCancelable(cancelable); setTitle(title); setSubtitle(subtitle); setBoldPositiveLabel(bold); setTypefaces(typeFace); initEvents(); }
Example 15
Source Project: SlideDayTimePicker Source File: SlidingTabLayout.java License: Apache License 2.0 | 6 votes |
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}. */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
Example 16
Source Project: journaldev Source File: MainActivity.java License: MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_fonts); /*ambleBold=(TextView)findViewById(R.id.ambleBold); ambleLight=(TextView)findViewById(R.id.ambleLight); ambleRegular=(TextView)findViewById(R.id.ambleRegular); openSansRegular=(TextView)findViewById(R.id.opRegular); openSansItalic=(TextView)findViewById(R.id.opItalic);*/ btn=(Button)findViewById(R.id.pacifico); /*ambleBold.setTypeface(Typeface.createFromAsset(getAssets(), A_BOLD)); ambleLight.setTypeface(Typeface.createFromAsset(getAssets(), A_LIGHT)); ambleRegular.setTypeface(Typeface.createFromAsset(getAssets(), A_REGULAR)); openSansRegular.setTypeface(Typeface.createFromAsset(getAssets(), O_REGULAR)); openSansItalic.setTypeface(Typeface.createFromAsset(getAssets(), O_ITALIC));*/ btn.setTypeface(Typeface.createFromAsset(getAssets(), P_REGULAR)); }
Example 17
Source Project: loaned-android Source File: ItemLoanPieChartView.java License: Apache License 2.0 | 6 votes |
private void init(Context c){ Log.d(TAG,"Init called"); // Create the colour array mColours = new int[6]; mColours[0] = Color.parseColor("#1bc5a4"); mColours[1] = Color.parseColor("#9b59b6"); mColours[2] = Color.parseColor("#2ecc71"); mColours[3] = Color.parseColor("#e74c3c"); mColours[4] = Color.parseColor("#3498db"); mColours[5] = Color.parseColor("#e67e22"); mCentreCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mCentreCirclePaint.setColor(Color.parseColor("#f3f3f3")); mCentreCirclePaint.setStyle(Paint.Style.FILL); mCentreTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mCentreTextPaint.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL)); mCentreTextPaint.setColor(mColours[0]); mCentreTextPaint.setTextAlign(Align.CENTER); mCentreTextPaint.setTextSize(80); mCentreNumberPaint = new Paint(mCentreTextPaint); mCentreNumberPaint.setTextSize(190); mCentreNumberPaint.setColor(c.getResources().getColor(R.color.text_main)); mCentreNumberPaint.setTypeface(Typeface.create("sans-serif-thin", Typeface.NORMAL)); mRect = new RectF(); }
Example 18
Source Project: VideoOS-Android-SDK Source File: TypefaceUtil.java License: GNU General Public License v3.0 | 6 votes |
/** * create typeface * * @param context * @param name * @return */ public static Typeface create( Context context, String name) { Typeface result = SimpleCache.getCache(TAG).get(name); if (result == null) { String fontNameOrAssetPathOrFilePath = ParamUtil.getFileNameWithPostfix(name, "ttf"); result = createFromAsset(context, fontNameOrAssetPathOrFilePath); if (result == null) { result = createFromFile(fontNameOrAssetPathOrFilePath); } if (result == null) { result = createByName(fontNameOrAssetPathOrFilePath); } } SimpleCache.getCache(TAG_TYPEFACE_NAME).put(result, name);//cache name return SimpleCache.getCache(TAG).put(name, result); }
Example 19
Source Project: react-native-text-size Source File: RNTextSizeModule.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** * https://stackoverflow.com/questions/27631736 * /meaning-of-top-ascent-baseline-descent-bottom-and-leading-in-androids-font */ @SuppressWarnings("unused") @ReactMethod public void fontFromSpecs(@Nullable final ReadableMap specs, final Promise promise) { final RNTextSizeConf conf = getConf(specs, promise); if (conf == null) { return; } final Typeface typeface = RNTextSizeConf.getFont(mReactContext, conf.fontFamily, conf.fontStyle); final TextPaint textPaint = sTextPaintInstance; final int fontSize = (int) Math.ceil(conf.scale(conf.fontSize)); textPaint.reset(); textPaint.setTypeface(typeface); textPaint.setTextSize(fontSize); promise.resolve(fontInfoFromTypeface(textPaint, typeface, conf)); }
Example 20
Source Project: JsDroidEditor Source File: ColorsText.java License: Mozilla Public License 2.0 | 6 votes |
private void init() { mNumberPadding = DpiUtils.dip2px(getContext(), 5); mTextPadding = DpiUtils.dip2px(getContext(), 4); mLineNumberBgStrokeWidth = DpiUtils.dip2px(getContext(), 2); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); setLayoutParams(params); setGravity(Gravity.START); // 设值背景透明 setBackgroundColor(Color.TRANSPARENT); // 设值字体大小 setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); // 设置字体颜色(透明是为了兼容不能反射绘制光标以及选择文字背景的情况) setTextColor(Color.TRANSPARENT); setTypeface(Typeface.MONOSPACE); setPadding(0, DpiUtils.dip2px(getContext(), 2), DpiUtils.dip2px(getContext(), 8), DpiUtils.dip2px(getContext(), 48)); }
Example 21
Source Project: ShareSDKShareDifMsgDemo-Android Source File: EditPage.java License: MIT License | 6 votes |
private LinearLayout getBodyBottom() { LinearLayout llBottom = new LinearLayout(getContext()); llBottom.setLayoutParams(new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); String platform = String.valueOf(reqData.get("platform")); LinearLayout line = getAtLine(platform); if (line != null) { llBottom.addView(line); } // 字数统计 tvCounter = new TextView(getContext()); tvCounter.setText(String.valueOf(MAX_TEXT_COUNT)); tvCounter.setTextColor(0xffcfcfcf); tvCounter.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); tvCounter.setTypeface(Typeface.DEFAULT_BOLD); LinearLayout.LayoutParams lpCounter = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpCounter.gravity = Gravity.CENTER_VERTICAL; tvCounter.setLayoutParams(lpCounter); llBottom.addView(tvCounter); return llBottom; }
Example 22
Source Project: android-BasicImmersiveMode Source File: LogFragment.java License: Apache License 2.0 | 5 votes |
public View inflateViews() { mScrollView = new ScrollView(getActivity()); ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); mScrollView.setLayoutParams(scrollParams); mLogView = new LogView(getActivity()); ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; mLogView.setLayoutParams(logParams); mLogView.setClickable(true); mLogView.setFocusable(true); mLogView.setTypeface(Typeface.MONOSPACE); // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! int paddingDips = 16; double scale = getResources().getDisplayMetrics().density; int paddingPixels = (int) ((paddingDips * (scale)) + .5); mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); mLogView.setCompoundDrawablePadding(paddingPixels); mLogView.setGravity(Gravity.BOTTOM); mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); mScrollView.addView(mLogView); return mScrollView; }
Example 23
Source Project: UIWidget Source File: CollapsingTextHelper.java License: Apache License 2.0 | 5 votes |
private Typeface readFontFamilyTypeface(int resId) { final TypedArray a = mView.getContext().obtainStyledAttributes(resId, new int[]{android.R.attr.fontFamily}); try { final String family = a.getString(0); if (family != null) { return Typeface.create(family, Typeface.NORMAL); } } finally { a.recycle(); } return null; }
Example 24
Source Project: Social Source File: ButtonFlat.java License: Apache License 2.0 | 5 votes |
@Override protected void setAttributes(AttributeSet attrs) { // Set text button String text = null; int textResource = attrs.getAttributeResourceValue(ANDROIDXML,"text",-1); if(textResource != -1){ text = getResources().getString(textResource); }else{ text = attrs.getAttributeValue(ANDROIDXML,"text"); } if(text != null){ textButton = new TextView(getContext()); textButton.setText(text.toUpperCase()); textButton.setTextColor(backgroundColor); textButton.setTypeface(null, Typeface.BOLD); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); textButton.setLayoutParams(params); addView(textButton); } int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); if(bacgroundColor != -1){ setBackgroundColor(getResources().getColor(bacgroundColor)); }else{ // Color by hexadecimal // Color by hexadecimal background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); if (background != -1) setBackgroundColor(background); } }
Example 25
Source Project: edx-app-android Source File: DiscussionTextUtilsTest.java License: Apache License 2.0 | 5 votes |
private void assertSetAuthorText(TextView textView, IAuthorData input, String expectedOutput) { DiscussionTextUtils.setAuthorText(textView, input); if (expectedOutput == null) { assertTrue(textView.getVisibility() == View.GONE); } else { String output = textView.getText().toString(); assertEquals(expectedOutput, output); if (!input.isAuthorAnonymous()) { int start = output.indexOf(input.getAuthor()); int end = start + input.getAuthor().length(); Spanned text = (Spanned) textView.getText(); StyleSpan[] styleSpans = text.getSpans(start, end, StyleSpan.class); ForegroundColorSpan[] colorSpans = text.getSpans(start, end, ForegroundColorSpan.class); // Verify that the author text is bold assertEquals(1, styleSpans.length); assertEquals(start, text.getSpanStart(styleSpans[0])); assertEquals(end, text.getSpanEnd(styleSpans[0])); assertEquals(Typeface.BOLD, styleSpans[0].getStyle()); // Verify that the correct foreground color is set assertEquals(1, colorSpans.length); assertEquals(start, text.getSpanStart(colorSpans[0])); assertEquals(end, text.getSpanEnd(colorSpans[0])); assertEquals(context.getResources().getColor(R.color.edx_brand_primary_base), colorSpans[0].getForegroundColor()); } } }
Example 26
Source Project: android_9.0.0_r45 Source File: CaptioningManager.java License: Apache License 2.0 | 5 votes |
/** * @return the preferred {@link Typeface} for video captions, or null if * not specified */ @Nullable public Typeface getTypeface() { if (mParsedTypeface == null && !TextUtils.isEmpty(mRawTypeface)) { mParsedTypeface = Typeface.create(mRawTypeface, Typeface.NORMAL); } return mParsedTypeface; }
Example 27
Source Project: editor Source File: Editor.java License: GNU General Public License v3.0 | 5 votes |
private void monoClicked(MenuItem item) { type = MONO; item.setChecked(true); textView.setTypeface(Typeface.MONOSPACE, Typeface.NORMAL); }
Example 28
Source Project: PercentageChartView Source File: BaseModeRenderer.java License: Apache License 2.0 | 5 votes |
public void setTextStyle(int mTextStyle) { if (this.mTextStyle == mTextStyle) return; this.mTextStyle = mTextStyle; mTypeface = (mTypeface == null) ? Typeface.defaultFromStyle(mTextStyle) : Typeface.create(mTypeface, mTextStyle); mTextPaint.setTypeface(mTypeface); updateText(); }
Example 29
Source Project: XERUNG Source File: GroupSettings.java License: Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_group_edit); roboto = Typeface.createFromAsset(getAssets(), "font/Roboto-Regular.ttf"); androidface = Typeface.createFromAsset(getAssets(), "font/android.ttf"); initialise(); //setProfile(); }
Example 30
Source Project: letterpress Source File: FontUtil.java License: Apache License 2.0 | 5 votes |
@NonNull public static SpannableString applyTypeface(@NonNull String text, @NonNull Context context, @NonNull String fontName) { final Typeface typeface = getTypeface(context, fontName); if (typeface == null) { throw new InvalidParameterException("Font '" + fontName + "' not found"); } return applyTypeface(text, typeface); }