Example usage for android.widget TextView getTypeface

List of usage examples for android.widget TextView getTypeface

Introduction

In this page you can find the example usage for android.widget TextView getTypeface.

Prototype

public Typeface getTypeface() 

Source Link

Document

Gets the current Typeface that is used to style the text.

Usage

From source file:com.cytmxk.test.animation.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    View tabView;//from w w w  .  ja v  a  2 s.c o  m
    if (mTabIcons != null && position < mTabIcons.length) {
        View iconView = new View(getContext());
        iconView.setBackgroundResource(mTabIcons[position]);
        iconView.setContentDescription(tabTitle);

        tabView = iconView;
    } else {
        final TextView textView = new TextView(getContext());
        textView.setText(tabTitle);
        textView.setBackgroundResource(R.drawable.view_pager_tab_background);

        // Assign various text appearance related attributes to child views.
        if (mTextStyle > 0) {
            textView.setTypeface(textView.getTypeface(), mTextStyle);
        }
        if (mTextSize > 0) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
        }
        if (mTextColor != null) {
            textView.setTextColor(mTextColor);
        }
        textView.setAllCaps(mTextAllCaps);
        textView.setGravity(Gravity.CENTER);

        tabView = textView;
    }

    tabView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    tabView.setOnLongClickListener(new OnTabLongClickListener(position));

    tabView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(tabView, new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));

    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        tabView.setSelected(true);
    }
}

From source file:com.viewpagerindicator.TabMovablePageIndicator.java

private void moveIndicator(TextView tabView) {
    int left = tabView.getLeft();
    int width = tabView.getWidth();
    int textWidth = getTextWidth(tabView.getText().toString(), tabView.getTextSize(), tabView.getTypeface());

    int x = left + (width - textWidth) / 2;

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(textWidth,
            mIndicator.getLayoutParams().height);
    lp.leftMargin = x;// w  w w  . ja v  a 2s  . com
    mIndicator.setLayoutParams(lp);
}

From source file:com.lloydtorres.stately.helpers.SparkleHelper.java

/**
 * Overloaded to deal with spoilers.//from   w  w w.  j  av  a2s . c om
 */
public static void setStyledTextView(Context c, TextView t, String holder, List<Spoiler> spoilers,
        FragmentManager fm) {
    if (t instanceof HtmlTextView) {
        try {
            ((HtmlTextView) t).setHtml(holder);
        } catch (Exception e) {
            logError(e.toString());
            t.setText(c.getString(R.string.bbcode_parse_error));
            t.setTypeface(t.getTypeface(), Typeface.ITALIC);
        }
    } else {
        t.setText(fromHtml(holder));
    }

    // Deal with spoilers here
    styleLinkifiedTextView(c, t); // Ensures TextView contains a spannable
    Spannable span = new SpannableString(t.getText());
    String rawSpan = span.toString();
    int startFromIndex = 0;

    for (int i = 0; i < spoilers.size(); i++) {
        Spoiler s = spoilers.get(i);
        int start = rawSpan.indexOf(s.replacer, startFromIndex);
        if (start != -1) {
            int end = start + s.replacer.length();
            startFromIndex = end;
            SpoilerSpan clickyDialog = new SpoilerSpan(c, s, fm);
            span.setSpan(clickyDialog, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    t.setText(span);
}

From source file:com.odoo.OdooActivity.java

private View generateView(String title, int res_id) {
    View view = LayoutInflater.from(this).inflate(R.layout.base_drawer_account_item, mDrawerAccountContainer,
            false);//from  w  w  w.  j  a v a  2 s  .  c  o  m
    OControls.setGone(view, R.id.profile_url_text);
    ImageView icon = (ImageView) view.findViewById(R.id.profile_image);
    icon.setImageResource(res_id);
    icon.setColorFilter(OResource.color(this, R.color.body_text_2));
    TextView name = (TextView) view.findViewById(R.id.profile_name_text);
    name.setTypeface(name.getTypeface(), Typeface.BOLD);
    name.setText(title);
    return view;
}

From source file:com.weekcalendar.WeekFragment.java

@SuppressWarnings("unchecked")
@Override//  w  ww  . jav  a2 s. com
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    /*Setting the date info in the Application class*/
    mStartDate = AppController.getInstance().getDate();
    mCurrentDate = AppController.getInstance().getDate();
    /*Setting the Resources values and Customization values to the views*/
    String identifierName = getArguments().getString(WeekCalendarFragment.ARGUMENT_SELECTED_DATE_BACKGROUND);
    if (identifierName != null) {
        Resources resources = getActivity().getResources();
        mSelectorDateIndicatorValue = resources.getIdentifier(identifierName, "drawable",
                WeekCalendarFragment.PACKAGE_NAME_VALUE);
    }

    mCurrentDateIndicatorValue = getArguments().getInt(WeekCalendarFragment.ARGUMENT_CURRENT_DATE_TEXT_COLOR);
    mSelectorHighlightColor = getArguments()
            .getInt(WeekCalendarFragment.ARGUMENT_SELECTED_DATE_HIGHLIGHT_COLOR);

    mDatePosition = getArguments().getInt(POSITION_KEY);
    int addDays = mDatePosition * 7;

    mStartDate = mStartDate.plusDays(addDays);//Adding the 7days to the previous week

    mSelectedDate = AppController.getInstance().getSelected();

    /*Fetching the data's for the week to display*/
    for (int i = 0; i < 7; i++) {
        if (mSelectedDate != null) {
            if (mSelectedDate.getDayOfMonth() == mStartDate.getDayOfMonth()) {
                /*Indicate  if the day is selected*/
                setSelectedDateBackground(mTextViewArray[i]);
                AppController.getInstance().setSelected(null);//null the selected date
            }
        }
        mDateInWeekArray.add(mStartDate);//Adding the days in the selected week to list
        mStartDate = mStartDate.plusDays(1); //Next day
    }

    int primaryTextStyle = getArguments().getInt(WeekCalendarFragment.ARGUMENT_DAY_TEXT_STYLE, -1);
    int primaryTextSize = getArguments().getInt(WeekCalendarFragment.ARGUMENT_DAY_TEXT_SIZE, 0);
    if (primaryTextSize > 0 || primaryTextStyle > -1) {
        for (TextView tv : mTextViewArray) {
            if (primaryTextSize > 0) {
                tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, primaryTextSize);
            }
            if (primaryTextStyle > -1) {
                tv.setTypeface(tv.getTypeface(), primaryTextStyle);
            }
        }
    }

    /*Setting color in the week views*/
    mPrimaryTextColor = getArguments().getInt(WeekCalendarFragment.ARGUMENT_PRIMARY_TEXT_COLOR);
    for (TextView tv : mTextViewArray) {
        tv.setTextColor(mPrimaryTextColor);
    }

    long[] eventDaysPrim = (long[]) getArguments().getSerializable(WeekCalendarFragment.ARGUMENT_EVENT_DAYS);
    ArrayList<LocalDateTime> eventDays = new ArrayList<>();
    if (eventDaysPrim != null) {
        for (long eventDay : eventDaysPrim) {
            eventDays.add(LocalDateTime.fromDateFields(new Date(eventDay)));
        }
    }
    int eventColorDrawable = getEventColorDrawable(
            getArguments().getString(WeekCalendarFragment.ARGUMENT_EVENT_COLOR));

    /*Displaying the days in the week views*/
    int dayOfWeek = 0;
    for (TextView dayTv : mTextViewArray) {
        dayTv.setText(Integer.toString(mDateInWeekArray.get(dayOfWeek).getDayOfMonth()));
        if (!eventDays.isEmpty()) {
            if (CalUtil.isDayInList(mDateInWeekArray.get(dayOfWeek), eventDays)) {
                mImageViewArray[dayOfWeek].setImageResource(eventColorDrawable);
            }
        }
        dayOfWeek++;
    }

    /*if the selected week is the current week indicates the current day*/
    if (mDatePosition == 0) {
        for (int i = 0; i < 7; i++) {
            if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) == mDateInWeekArray.get(i).getDayOfMonth()) {
                mCurrentDateIndex = i;
                mTextViewArray[i].setTextColor(mCurrentDateIndicatorValue);
            }
        }
    }

    setSelectedDateBackground(mTextViewArray[0]); //Setting the first days of the week as selected

    /**
     * Click listener of all week days with the indicator change and passing listener info.
     */
    mSundayTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mSelectedDateInfo(0);
            setSelectedDateBackground((TextView) view);
        }
    });
    mMondayTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mSelectedDateInfo(1);
            setSelectedDateBackground((TextView) view);
        }
    });
    mTuesdayTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mSelectedDateInfo(2);
            setSelectedDateBackground((TextView) view);
        }
    });
    mWednesdayTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mSelectedDateInfo(3);
            setSelectedDateBackground((TextView) view);
        }
    });
    mThursdayTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mSelectedDateInfo(4);
            setSelectedDateBackground((TextView) view);
        }
    });
    mFridayTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mSelectedDateInfo(5);
            setSelectedDateBackground((TextView) view);
        }
    });
    mSaturdayTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mSelectedDateInfo(6);
            setSelectedDateBackground((TextView) view);
        }
    });
}

From source file:com.gh4a.activities.IssueEditActivity.java

private void setLabelSelection(TextView view, boolean selected) {
    Label label = (Label) view.getTag();
    if (selected) {
        int color = ApiHelpers.colorForLabel(label);
        view.setTypeface(view.getTypeface(), Typeface.BOLD);
        view.setBackgroundColor(color);// w  w  w  . java  2  s . co m
        view.setTextColor(UiUtils.textColorForBackground(this, color));
    } else {
        view.setTypeface(view.getTypeface(), 0);
        view.setBackgroundColor(0);
        view.setTextColor(ContextCompat.getColor(this,
                Gh4Application.THEME != R.style.LightTheme ? R.color.label_fg_light : R.color.label_fg_dark));
    }
}

From source file:com.mobicage.rogerthat.plugins.friends.ServiceSearchActivity.java

private TextView setCatorySelected(LinearLayout label, final boolean selected) {
    final View labelIndicatorView = label.findViewById(R.id.indicator);
    final TextView labelTextView = (TextView) label.findViewById(R.id.category);
    if (selected) {
        labelIndicatorView.setVisibility(View.VISIBLE);
        labelTextView.setTypeface(Typeface.create(labelTextView.getTypeface(), Typeface.BOLD));
        labelTextView.setTextColor(getResources().getColor(R.color.mc_blue2));
    } else {//w w w.ja va 2 s.  c  om
        labelIndicatorView.setVisibility(View.INVISIBLE);
        labelTextView.setTypeface(Typeface.create(labelTextView.getTypeface(), Typeface.NORMAL));
        labelTextView.setTextColor(getResources().getColor(android.R.color.secondary_text_light));
    }
    return labelTextView;
}

From source file:com.android.messaging.ui.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);//from  w  ww  .j a va2  s .  co m
    textView.setBackgroundResource(R.drawable.contact_picker_tab_background_selector);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    // Assign various text appearance related attributes to child views.
    if (mTextStyle > 0) {
        textView.setTypeface(textView.getTypeface(), mTextStyle);
    }
    if (mTextSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
    if (mTextColor != null) {
        textView.setTextColor(mTextColor);
    }
    textView.setAllCaps(mTextAllCaps);
    textView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

From source file:com.achep.acdisplay.ui.widgets.notification.NotificationActions.java

/**
 * Sets new actions.// w  w  w. j  a  v  a2 s.  co m
 *
 * @param notification the host notification
 * @param actions      the actions to set
 */
public void setActions(@Nullable OpenNotification notification, @Nullable Action[] actions) {
    Check.getInstance().isInMainThread();

    mRemoteInputsMap.clear();
    mActionsMap.clear();
    hideRii();

    if (actions == null) {
        // Free actions' container.
        removeAllViews();
        return;
    } else {
        assert notification != null;
    }

    int count = actions.length;
    View[] views = new View[count];

    // Find available views.
    int childCount = getChildCount();
    int a = Math.min(childCount, count);
    for (int i = 0; i < a; i++) {
        views[i] = getChildAt(i);
    }

    // Remove redundant views.
    for (int i = childCount - 1; i >= count; i--) {
        removeViewAt(i);
    }

    LayoutInflater inflater = null;
    for (int i = 0; i < count; i++) {
        final Action action = actions[i];
        View root = views[i];

        if (root == null) {
            // Initialize layout inflater only when we really need it.
            if (inflater == null) {
                inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                assert inflater != null;
            }

            root = inflater.inflate(getActionLayoutResource(), this, false);
            root = onCreateActionView(root);
            // We need to keep all IDs unique to make
            // TransitionManager.beginDelayedTransition(viewGroup, null)
            // work correctly!
            root.setId(getChildCount() + 1);
            addView(root);
        }

        mActionsMap.put(root, action);

        int style = Typeface.NORMAL;
        root.setOnLongClickListener(null);
        if (action.intent != null) {
            root.setEnabled(true);
            root.setOnClickListener(mActionsOnClick);

            RemoteInput remoteInput = getRemoteInput(action);
            if (remoteInput != null) {
                mRemoteInputsMap.put(action, remoteInput);
                root.setOnLongClickListener(mActionsOnLongClick);

                // Highlight the action
                style = Typeface.ITALIC;
            }
        } else {
            root.setEnabled(false);
            root.setOnClickListener(null);
        }

        // Get message view and apply the content.
        TextView textView = root instanceof TextView ? (TextView) root
                : (TextView) root.findViewById(android.R.id.title);
        textView.setText(action.title);
        if (mTypeface == null)
            mTypeface = textView.getTypeface();
        textView.setTypeface(mTypeface, style);

        Drawable icon = NotificationUtils.getDrawable(getContext(), notification, action.icon);
        if (icon != null)
            icon = onCreateActionIcon(icon);

        if (Device.hasJellyBeanMR1Api()) {
            textView.setCompoundDrawablesRelative(icon, null, null, null);
        } else {
            textView.setCompoundDrawables(icon, null, null, null);
        }
    }
}

From source file:com.orangemoo.com.beta.widget.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);//  www.  jav  a2  s  . c o m
    //        textView.setBackgroundResource(R.drawable.view_pager_tab_background);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    textView.setOnLongClickListener(new OnTabLongClickListener(position));

    // Assign various text appearance related attributes to child views.
    if (mTextStyle > 0) {
        textView.setTypeface(textView.getTypeface(), mTextStyle);
    }
    if (mTextSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
    if (mTextColor != null) {
        textView.setTextColor(mTextColor);
    }
    textView.setAllCaps(mTextAllCaps);
    //        textView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView, new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}