Example usage for android.widget TextView setTypeface

List of usage examples for android.widget TextView setTypeface

Introduction

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

Prototype

public void setTypeface(@Nullable Typeface tf, @Typeface.Style int style) 

Source Link

Document

Sets the typeface and style in which the text should be displayed, and turns on the fake bold and italic bits in the Paint if the Typeface that you provided does not have all the bits in the style that you specified.

Usage

From source file:mobisocial.musubi.objects.PictureObj.java

@Override
public void getSummaryText(Context context, TextView view, FeedSummary summary) {
    view.setTypeface(null, Typeface.ITALIC);

    JSONObject json = summary.getJson();
    if (json != null && json.optString(PictureObj.TEXT).length() > 0) {
        StringBuilder summaryText = new StringBuilder(50).append(summary.getSender())
                .append(" shared a picture with the caption \"" + json.optString(StatusObj.TEXT) + "\"");
        view.setText(summaryText.toString());
    } else {/*from w  w  w . j av  a 2 s .  c  om*/
        StringBuilder summaryText = new StringBuilder(50).append(summary.getSender())
                .append(" shared a picture.");
        view.setText(summaryText.toString());
    }
}

From source file:com.google.android.gcm.demo.ui.GroupsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> senders = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < senders.size(); i++) {
        Sender sender = senders.valueAt(i);
        if (sender.groups.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderText = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderText.setText(getString(R.string.groups_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (DeviceGroup deviceGroup : sender.groups.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.group_grey600);
                label.setText(deviceGroup.notificationKeyName);
                label.setBackgroundResource(selectableBackgroundResource);
                label.setTag(R.id.tag_action, ACTION_OPEN_GROUP);
                label.setTag(R.id.tag_senderid, sender.senderId);
                label.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                label.setOnClickListener(this);

                button.setText(R.string.groups_delete);
                button.setTag(R.id.tag_action, ACTION_DELETE_GROUP);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }/*from w ww. j a  v  a  2  s .  c  o  m*/
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.groups_no_groups_available));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.groups_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:com.google.android.gcm.demo.ui.InstanceIdFragment.java

@Override
public void refresh() {
    new AsyncTask<Void, Void, Void>() {
        @Override//from  w  w w.j a  v  a 2 s . c  o  m
        protected Void doInBackground(Void... params) {
            final String instanceId = mInstanceIdHelper.getInstanceId();
            final String creationTime = DateFormat.getDateTimeInstance()
                    .format(new Date(mInstanceIdHelper.getCreationTime()));
            final Activity activity = getActivity();
            if (activity != null) {
                Handler handler = new Handler(activity.getMainLooper());
                handler.post(new Runnable() {
                    public void run() {
                        setValue(activity.findViewById(R.id.iid_instance_id), instanceId);
                        setValue(activity.findViewById(R.id.iid_creation_time), creationTime);
                    }
                });
            }
            return null;
        }
    }.execute();
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        if (sender.appTokens.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Token token : sender.appTokens.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.smartphone_grey600);
                label.setText(token.scope + " - " + AbstractFragment.truncateToMediumString(token.token));
                button.setText(R.string.iid_delete_token);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_scope, token.scope);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.iid_no_tokens));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout tokensView = (FrameLayout) getActivity().findViewById(R.id.iid_tokens_wrapper);
    tokensView.removeAllViews();
    tokensView.addView(sendersList);
}

From source file:br.com.frs.foodrestrictions.FoodMessages.java

@SuppressLint("SetTextI18n")
private void refreshMessages(View v) {

    int nAllergic = 0;
    int nDontEat = 0;

    llAllergic.removeAllViews();//from  w w w .ja va2 s . c  o m
    llDontEat.removeAllViews();

    for (final FoodIconItem iconItem : restrictList) {
        final String foodName = getResources().getString(iconItem.getNameId());
        final String allergic_text = getResources().getString(R.string.allergic_to) + " " + foodName;
        final String dont_eat_text = getResources().getString(R.string.dont_eat) + " " + foodName;

        TextView tv = new TextView(v.getContext());
        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tv.setTypeface(null, Typeface.BOLD_ITALIC);
        tv.setText("* " + foodName);

        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (iconItem.getRestrictionType()) {
                case FoodIconList.FOOD_RESTRICTION_TYPE_ALLERGIC:
                    Snackbar.make(v, allergic_text, Snackbar.LENGTH_LONG).setAction("Action", null).show();
                    break;
                case FoodIconList.FOOD_RESTRICTION_TYPE_DONT_EAT:
                    Snackbar.make(v, dont_eat_text, Snackbar.LENGTH_LONG).setAction("Action", null).show();
                    break;
                }
            }
        });

        if (iconItem.getRestrictionType() == FoodIconList.FOOD_RESTRICTION_TYPE_ALLERGIC) {
            llAllergic.addView(tv);
            ++nAllergic;
        } else {
            llDontEat.addView(tv);
            ++nDontEat;
        }

    }

    if (nAllergic == 0) {
        allergicText.setVisibility(View.GONE);

        TextView tv = new TextView(v.getContext());
        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tv.setTypeface(null, Typeface.BOLD_ITALIC);
        tv.setText("* " + getResources().getString(R.string.food_msg_not_allergic));
        llAllergic.addView(tv);
    } else {
        allergicText.setText(getResources().getString(R.string.message_allergic_to));
    }

    if (nDontEat == 0) {
        dontEatText.setVisibility(View.GONE);

        TextView tv = new TextView(v.getContext());
        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tv.setTypeface(null, Typeface.BOLD_ITALIC);
        tv.setText("* " + getResources().getString(R.string.food_msg_not_picker));
        llDontEat.addView(tv);
    } else {
        dontEatText.setText(getResources().getString(R.string.message_dont_eat));
    }
}

From source file:com.google.android.gcm.demo.ui.TopicsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        // Check if at least a topic is subscribed for this sender
        int subscribedTopics = 0;
        for (Boolean subscribed : sender.topics.values()) {
            if (subscribed) {
                subscribedTopics++;/*w ww .  ja  v a  2 s  . c  om*/
            }
        }
        if (subscribedTopics > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Map.Entry<String, Boolean> topic : sender.topics.entrySet()) {
                if (topic.getValue()) {
                    LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                            .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                    ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                    TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                    Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                    icon.setImageResource(R.drawable.bigtop_updates_grey600);
                    label.setText(topic.getKey());
                    button.setText(R.string.topics_unsubscribe);
                    button.setTag(R.id.tag_action, ACTION_UNSUBSCRIBE);
                    button.setTag(R.id.tag_senderid, sender.senderId);
                    button.setTag(R.id.tag_topic, topic.getKey());
                    button.setOnClickListener(this);
                    row.setPadding((int) (16 * density), 0, 0, 0);
                    sendersList.addView(row);
                }
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.topics_no_topic_subscribed));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.topics_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:com.wellsandwhistles.android.redditsp.reddit.prepared.RedditPreparedMessage.java

@Override
public View getBody(final AppCompatActivity activity, final Integer textColor, final Float textSize,
        final boolean showLinkButtons) {

    final LinearLayout subjectLayout = new LinearLayout(activity);
    subjectLayout.setOrientation(LinearLayout.VERTICAL);

    final TextView subjectText = new TextView(activity);
    subjectText.setText(StringEscapeUtils.unescapeHtml4(src.subject != null ? src.subject : "(no subject)"));
    subjectText.setTextColor(textColor);
    subjectText.setTextSize(textSize);/*from w  ww  .jav a2 s.  co m*/
    subjectText.setTypeface(null, Typeface.BOLD);

    subjectLayout.addView(subjectText);
    subjectLayout.addView(body.buildView(activity, textColor, textSize, showLinkButtons));

    return subjectLayout;
}

From source file:de.hackerspacebremen.fragments.StatusFragment.java

public void onEvent(final RefreshEvent event) {
    if (statusAnimation != null) {
        statusAnimation.start();//ww  w  .j  av  a2  s .c o m
    }
    if (messageAnimation != null) {
        messageAnimation.start();
    }
    StatusViewHolder.get().messageBlock.setVisibility(RelativeLayout.GONE);
    StatusViewHolder.get().imgStatus.setVisibility(ImageView.VISIBLE);
    StatusViewHolder.get().imgConnErr.setVisibility(ImageView.GONE);
    final TextView text = StatusViewHolder.get().statusMessage;
    text.setTypeface(null, Typeface.NORMAL);
    text.setText(getString(R.string.fetch_status));
    final TextView messageText = StatusViewHolder.get().messageText;
    messageText.setText(getString(R.string.fetch_message));
    final TextView messageLabel = StatusViewHolder.get().messageLabel;
    messageLabel.setVisibility(TextView.GONE);
    startStatusCommunication();
}

From source file:fm.krui.kruifm.ScheduleFragment.java

/**
 * Adds a show to the schedule./* ww  w . ja  va  2  s  .c  o m*/
 * @param title Title of show to display
 * @param description Description of show to display
 * @param startTime Start time of show in minutes from midnight
 * @param endTime End time of show in minutes from midnight
 * @param category Format of this show, required to correctly color the event.
 *
 * Valid settings for category include:
 *                 1 - Regular Rotation
 *                 2 - Music Speciality
 *                 3 - Sports
 *                 4 - News/Talk
 *                 5 - Specials
 */
private void addShow(String title, String description, int startTime, int endTime, int category) {

    /* Build the LinearLayout to function as the container for this show. Since the size of the container is to represent
    the length of the show, its height must be proportional (1dp = 1 minute) to the length. Determine length by finding the difference
    between the start and end times. */

    // Fix for corner case of shows ending at midnight.
    if (endTime == 0) {
        endTime = 1440;
    }
    int difference = endTime - startTime;

    /* Define the margins of this show. All shows must not overlap the displayed times, which are 50dp in width.
    Add 5 more (to the right and left) to see the schedule lines for clarity. Push the show down to align with the appropriate time marker using the top margin value set to the
    difference (in minutes) between midnight and the start of the show. */

    Log.v(TAG, "Configuring " + title);
    //Log.v(TAG, "Start time: " + startTime + " End time: " + endTime);
    //Log.v(TAG, "Setting parameters for " + title);
    RelativeLayout.LayoutParams rrLayoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, dpToPixels(difference));
    rrLayoutParams.leftMargin = dpToPixels(55);
    //Log.v(TAG, "Left margin: " + rrLayoutParams.leftMargin);
    rrLayoutParams.topMargin = dpToPixels(startTime);
    //Log.v(TAG, "Top margin: " + rrLayoutParams.topMargin);
    rrLayoutParams.rightMargin = dpToPixels(5);
    //Log.v(TAG, "Right margin: " + rrLayoutParams.rightMargin);

    /* Build LinearLayout and apply parameters */
    LinearLayout eventLL = new LinearLayout(getActivity());
    eventLL.setOrientation(LinearLayout.VERTICAL);
    eventLL.setPadding(dpToPixels(5), dpToPixels(2), dpToPixels(5), dpToPixels(5));

    // Get background for this event
    eventLL.setBackgroundResource(getEventBackground(category));

    /* Add title of event to LinearLayout */
    TextView titleTV = new TextView(getActivity());

    // Title of a show should be bolded
    titleTV.setText(title);
    titleTV.setTypeface(null, Typeface.BOLD);
    titleTV.setPadding(dpToPixels(5), 0, dpToPixels(5), 0);
    eventLL.addView(titleTV);

    /* Determine length of event to see if we have room to attach a description (if one was passed) */
    int length = endTime - startTime;

    /* Attach a description with a size that depends on the event length (longer events can hold more description text). */
    if (description != null) {
        TextView descriptionTV = new TextView(getActivity());
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        descriptionTV.setText(description);

        // ~hour long shows can display 1 line of description
        if (difference >= 30 && difference <= 60) {
            descriptionTV.setMaxLines(1);
        }

        // 1:30 long shows can display 2 lines of description
        else if (difference >= 60 && difference <= 90) {
            descriptionTV.setMaxLines(2);
        }

        // 2:00 long shows can display 4 lines of description
        else if (difference >= 120) {
            descriptionTV.setMaxLines(4);
        }

        descriptionTV.setEllipsize(TextUtils.TruncateAt.END);
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        eventLL.addView(descriptionTV);
    }

    /* Add this view to the schedule UI */
    RelativeLayout rl = (RelativeLayout) rootView.findViewById(R.id.schedule_container_relativelayout);
    rl.addView(eventLL, rrLayoutParams);
}

From source file:asu.edu.msse.gpeddabu.moviedescriptions.MovieListAdapter.java

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    String headerTitle = (String) getGroup(groupPosition);
    if (convertView == null) {
        android.util.Log.d(this.getClass().getSimpleName(), "in getGroupView null so creating new view");
        LayoutInflater inflater = (LayoutInflater) this.parent
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.movie_group, null);
    }//from w w  w  .  j  a va2s  .  c  o  m

    TextView genreName = (TextView) convertView.findViewById(R.id.genreName);
    //android.util.Log.d(this.getClass().getSimpleName(),"in getGroupView text is: "+lblListHeader.getText());
    genreName.setTypeface(null, Typeface.BOLD);
    genreName.setText(headerTitle);
    return convertView;
}

From source file:de.hackerspacebremen.fragments.StatusFragment.java

@Override
public void onStart() {
    super.onStart();

    EventBus.getDefault().register(this);

    // initializing the statusview holder
    StatusViewHolder.init(this.getView());

    StatusViewHolder.get().statusLayout.setOnLongClickListener(new OnLongClickListener() {

        @Override//  ww w  .jav  a2  s .  c om
        public boolean onLongClick(View v) {
            if (statusAnimation != null) {
                statusAnimation.start();
            }
            if (messageAnimation != null) {
                messageAnimation.start();
            }
            StatusViewHolder.get().messageBlock.setVisibility(RelativeLayout.GONE);
            StatusViewHolder.get().imgStatus.setVisibility(ImageView.VISIBLE);
            StatusViewHolder.get().imgConnErr.setVisibility(ImageView.GONE);
            final TextView text = StatusViewHolder.get().statusMessage;
            text.setTypeface(null, Typeface.NORMAL);
            text.setText(getString(R.string.fetch_status));
            final TextView messageText = StatusViewHolder.get().messageText;
            messageText.setText(getString(R.string.fetch_message));
            final TextView messageLabel = StatusViewHolder.get().messageLabel;
            messageLabel.setVisibility(TextView.GONE);
            startStatusCommunication();
            return true;
        }
    });

    if (this.spaceData == null) {
        this.startAnimation();
        this.startStatusCommunication();
        if (notificationRegistry == null) {
            this.notificationRegistry = new NotificationRegistry(this.getActivity());
        }
        this.notificationRegistry.register();
    } else {
        this.outputStatus(this.spaceData);
    }
}