Example usage for android.graphics Typeface BOLD

List of usage examples for android.graphics Typeface BOLD

Introduction

In this page you can find the example usage for android.graphics Typeface BOLD.

Prototype

int BOLD

To view the source code for android.graphics Typeface BOLD.

Click Source Link

Usage

From source file:com.codename1.impl.android.AndroidImplementation.java

@Override
public Object createFont(int face, int style, int size) {
    Typeface typeface = null;//from   w ww.j  ava  2 s .co  m
    switch (face) {
    case Font.FACE_MONOSPACE:
        typeface = Typeface.MONOSPACE;
        break;
    default:
        typeface = Typeface.DEFAULT;
        break;
    }

    int fontstyle = Typeface.NORMAL;
    if ((style & Font.STYLE_BOLD) != 0) {
        fontstyle |= Typeface.BOLD;
    }
    if ((style & Font.STYLE_ITALIC) != 0) {
        fontstyle |= Typeface.ITALIC;
    }

    int height = this.defaultFontHeight;
    int diff = height / 3;

    switch (size) {
    case Font.SIZE_SMALL:
        height -= diff;
        break;
    case Font.SIZE_LARGE:
        height += diff;
        break;
    }

    Paint font = new CodenameOneTextPaint(Typeface.create(typeface, fontstyle));
    font.setAntiAlias(true);
    font.setUnderlineText((style & Font.STYLE_UNDERLINED) != 0);
    font.setTextSize(height);
    return new NativeFont(face, style, size, font);

}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * Loads a native font based on a lookup for a font name and attributes.
 * Font lookup values can be separated by commas and thus allow fallback if
 * the primary font isn't supported by the platform.
 *
 * @param lookup string describing the font
 * @return the native font object//from   ww w  . j  a  v a2s . c  o  m
 */
public Object loadNativeFont(String lookup) {
    try {
        lookup = lookup.split(";")[0];
        int typeface = Typeface.NORMAL;
        String familyName = lookup.substring(0, lookup.indexOf("-"));
        String style = lookup.substring(lookup.indexOf("-") + 1, lookup.lastIndexOf("-"));
        String size = lookup.substring(lookup.lastIndexOf("-") + 1, lookup.length());

        if (style.equals("bolditalic")) {
            typeface = Typeface.BOLD_ITALIC;
        } else if (style.equals("italic")) {
            typeface = Typeface.ITALIC;
        } else if (style.equals("bold")) {
            typeface = Typeface.BOLD;
        }
        Paint font = new CodenameOneTextPaint(Typeface.create(familyName, typeface));
        font.setAntiAlias(true);
        font.setTextSize(Integer.parseInt(size));
        return new NativeFont(0, 0, 0, font);
    } catch (Exception err) {
        return null;
    }
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private void showAccessNotification(int uid) {
    String name = TextUtils.join(", ", Util.getApplicationNames(uid, ServiceSinkhole.this));

    Intent main = new Intent(ServiceSinkhole.this, ActivityMain.class);
    main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
    PendingIntent pi = PendingIntent.getActivity(ServiceSinkhole.this, uid + 10000, main,
            PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    int colorOn = tv.data;
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    int colorOff = tv.data;

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_cloud_upload_white_24dp).setGroup("AccessAttempt")
            .setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.msg_access, name))
            .setContentIntent(pi).setColor(colorOff).setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }/*from  w w  w  . j  a  v a 2s .c  om*/

    DateFormat df = new SimpleDateFormat("dd HH:mm");

    NotificationCompat.InboxStyle notification = new NotificationCompat.InboxStyle(builder);
    String sname = getString(R.string.msg_access, name);
    int pos = sname.indexOf(name);
    Spannable sp = new SpannableString(sname);
    sp.setSpan(new StyleSpan(Typeface.BOLD), pos, pos + name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    notification.addLine(sp);

    Cursor cursor = DatabaseHelper.getInstance(ServiceSinkhole.this).getAccessUnset(uid, 7);
    int colDAddr = cursor.getColumnIndex("daddr");
    int colTime = cursor.getColumnIndex("time");
    int colAllowed = cursor.getColumnIndex("allowed");
    while (cursor.moveToNext()) {
        StringBuilder sb = new StringBuilder();
        sb.append(df.format(cursor.getLong(colTime))).append(' ');

        String daddr = cursor.getString(colDAddr);
        if (Util.isNumericAddress(daddr))
            try {
                daddr = InetAddress.getByName(daddr).getHostName();
            } catch (UnknownHostException ignored) {
            }
        sb.append(daddr);

        int allowed = cursor.getInt(colAllowed);
        if (allowed >= 0) {
            pos = sb.indexOf(daddr);
            sp = new SpannableString(sb);
            ForegroundColorSpan fgsp = new ForegroundColorSpan(allowed > 0 ? colorOn : colorOff);
            sp.setSpan(fgsp, pos, pos + daddr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        notification.addLine(sp);
    }
    cursor.close();

    NotificationManagerCompat.from(this).notify(uid + 10000, notification.build());
}

From source file:com.skytree.epubtest.BookViewActivity.java

public void fillBookmarkList() {
    this.listView.removeAllViews();
    ArrayList<PageInformation> pis = sd.fetchBookmarks(this.bookCode);
    for (int i = 0; i < pis.size(); i++) {
        int textColor = Color.BLACK;
        Theme theme = getCurrentTheme();
        textColor = theme.foregroundColor;
        PageInformation pi = pis.get(i);
        SkyLayout item = new SkyLayout(this);
        setFrame(item, 0, 0, listBox.getWidth(), ps(80));
        ImageButton mark = this.makeImageButton(9898, R.drawable.bookmarked2x, ps(50), ps(90));
        item.addView(mark);//from  ww  w  . jav  a  2s  . c o  m
        setFrame(mark, ps(10), ps(5), ps(60), ps(120));
        int ci = pi.chapterIndex;
        if (rv.isRTL()) {
            ci = rv.getNumberOfChapters() - ci - 1;
        }
        String chapterTitle = rv.getChapterTitle(ci);
        if (chapterTitle == null || chapterTitle.isEmpty())
            chapterTitle = "Chapter " + ci;
        TextView chapterLabel = this.makeLabel(9899, chapterTitle, Gravity.LEFT, 16, textColor);
        setFrame(chapterLabel, ps(80), ps(5), this.listBox.getWidth() - ps(80), ps(40));
        item.addView(chapterLabel);
        TextView dateLabel = this.makeLabel(9899, pi.datetime, Gravity.LEFT, 12, textColor);
        setFrame(dateLabel, this.listBox.getWidth() - ps(50 + 250), ps(48), this.listBox.getWidth() - ps(40),
                ps(40));
        View lineView = new View(this);
        lineView.setBackgroundColor(Color.LTGRAY);
        setFrame(lineView, 0, ps(79), this.listBox.getWidth(), ps(1));
        item.addView(dateLabel);
        item.addView(lineView);
        item.setSkyLayoutListener(bookmarkListDelegate);
        item.setId(pi.code);
        item.data = pi;

        Button deleteButton = new Button(this);
        GradientDrawable grad = new GradientDrawable(Orientation.TOP_BOTTOM,
                new int[] { 0xffcf666e, 0xff671521 });
        grad.setStroke(ps(2), 0xff282828);
        deleteButton.setBackgroundDrawable(grad);
        deleteButton.setText(getString(R.string.delete));
        deleteButton.setTextSize(12);
        deleteButton.setTypeface(null, Typeface.BOLD);
        deleteButton.setTextColor(Color.WHITE);
        deleteButton.setId(pi.code);
        deleteButton.setVisibility(View.INVISIBLE);
        deleteButton.setVisibility(View.GONE);
        deleteButton.setOnClickListener(deleteBookmarkDelegate);
        int dw = ps(120);
        int dh = ps(50);
        setFrame(deleteButton, this.listView.getWidth() - dw, (ps(80) - dh) / 2, dw, dh);
        item.deleteControl = deleteButton;
        item.addView(deleteButton);

        this.listView.addView(item);
    }
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static CharSequence getKeywordBoldedText(final CharSequence orig, final String... keywords) {
    return getKeywordHighlightedText(orig, new StyleSpan(Typeface.BOLD), keywords);
}

From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java

/**
 * Refresh the pushers list/*from   w w  w  .  j a  v  a 2  s .c om*/
 */
private void refreshPushersList() {
    final GcmRegistrationManager gcmRegistrationManager = Matrix.getInstance(getActivity())
            .getSharedGCMRegistrationManager();
    final List<Pusher> pushersList = new ArrayList<>(gcmRegistrationManager.mPushersList);

    if (pushersList.isEmpty()) {
        getPreferenceScreen().removePreference(mPushersSettingsCategory);
        getPreferenceScreen().removePreference(mPushersSettingsDivider);
        return;
    }

    // check first if there is an update
    boolean isNewList = true;
    if ((null != mDisplayedPushers) && (pushersList.size() == mDisplayedPushers.size())) {
        isNewList = !mDisplayedPushers.containsAll(pushersList);
    }

    if (isNewList) {
        // remove the displayed one
        mPushersSettingsCategory.removeAll();

        // add new emails list
        mDisplayedPushers = pushersList;

        int index = 0;

        for (final Pusher pusher : mDisplayedPushers) {
            if (null != pusher.lang) {
                boolean isThisDeviceTarget = TextUtils
                        .equals(gcmRegistrationManager.getCurrentRegistrationToken(), pusher.pushkey);

                VectorCustomActionEditTextPreference preference = new VectorCustomActionEditTextPreference(
                        getActivity(), isThisDeviceTarget ? Typeface.BOLD : Typeface.NORMAL);
                preference.setTitle(pusher.deviceDisplayName);
                preference.setSummary(pusher.appDisplayName);
                preference.setKey(PUSHER_PREFERENCE_KEY_BASE + index);
                index++;
                mPushersSettingsCategory.addPreference(preference);

                // the user cannot remove the self device target
                if (!isThisDeviceTarget) {
                    preference.setOnPreferenceLongClickListener(
                            new VectorCustomActionEditTextPreference.OnPreferenceLongClickListener() {
                                @Override
                                public boolean onPreferenceLongClick(Preference preference) {
                                    final String dialogMessage = getString(
                                            R.string.settings_delete_notification_targets_confirmation);
                                    new AlertDialog.Builder(getActivity())
                                            .setTitle(R.string.dialog_title_confirmation)
                                            .setMessage(dialogMessage).setPositiveButton(R.string.remove,
                                                    new DialogInterface.OnClickListener() {
                                                        @Override
                                                        public void onClick(DialogInterface dialog, int which) {
                                                            dialog.dismiss();

                                                            displayLoadingView();
                                                            gcmRegistrationManager.unregister(mSession, pusher,
                                                                    new ApiCallback<Void>() {
                                                                        @Override
                                                                        public void onSuccess(Void info) {
                                                                            refreshPushersList();
                                                                            onCommonDone(null);
                                                                        }

                                                                        @Override
                                                                        public void onNetworkError(
                                                                                Exception e) {
                                                                            onCommonDone(
                                                                                    e.getLocalizedMessage());
                                                                        }

                                                                        @Override
                                                                        public void onMatrixError(
                                                                                MatrixError e) {
                                                                            onCommonDone(
                                                                                    e.getLocalizedMessage());
                                                                        }

                                                                        @Override
                                                                        public void onUnexpectedError(
                                                                                Exception e) {
                                                                            onCommonDone(
                                                                                    e.getLocalizedMessage());
                                                                        }
                                                                    });
                                                        }
                                                    })
                                            .setNegativeButton(R.string.cancel,
                                                    new DialogInterface.OnClickListener() {
                                                        @Override
                                                        public void onClick(DialogInterface dialog, int which) {
                                                            dialog.dismiss();
                                                        }
                                                    })
                                            .create().show();
                                    return true;
                                }
                            });
                }
            }
        }
    }
}

From source file:jmri.enginedriver.throttle.java

void showDirectionIndication(int whichThrottle, int direction) {

    boolean setLeftDirectionButtonEnabled;
    if (direction == 0) { //0=reverse 1=forward
        setLeftDirectionButtonEnabled = directionButtonsAreCurrentlyReversed(whichThrottle);
    } else {//from www  . j  av a 2s. co m
        setLeftDirectionButtonEnabled = !directionButtonsAreCurrentlyReversed(whichThrottle);
    }

    if (!getConsist(whichThrottle).isActive()) {
        bFwds[whichThrottle].setSelected(false);
        bRevs[whichThrottle].setSelected(false);
    } else {
        if (!setLeftDirectionButtonEnabled) {
            bFwds[whichThrottle].setSelected(false);
            bRevs[whichThrottle].setSelected(true);
            bFwds[whichThrottle].setTypeface(null, Typeface.NORMAL);
            bRevs[whichThrottle].setTypeface(null, Typeface.ITALIC + Typeface.BOLD);
            if ((getSpeed(whichThrottle) > 0) && (!dirChangeWhileMoving)) {
                bFwds[whichThrottle].setEnabled(false);
            }
            bRevs[whichThrottle].setEnabled(true);
        } else {
            bFwds[whichThrottle].setSelected(true);
            bRevs[whichThrottle].setSelected(false);
            bFwds[whichThrottle].setTypeface(null, Typeface.ITALIC + Typeface.BOLD);
            bRevs[whichThrottle].setTypeface(null, Typeface.NORMAL);
            bFwds[whichThrottle].setEnabled(true);
            if ((getSpeed(whichThrottle) > 0) && (!dirChangeWhileMoving)) {
                bRevs[whichThrottle].setEnabled(false);
            }
        }
    }

}

From source file:com.skytree.epubtest.BookViewActivity.java

public void fillHighlightList() {
    Theme theme = getCurrentTheme();//from w w  w . ja  va2s .co m
    int textColor = theme.foregroundColor;
    this.listView.removeAllViews();
    Highlights highlights = sd.fetchAllHighlights(this.bookCode);
    for (int i = 0; i < highlights.getSize(); i++) {
        Highlight highlight = highlights.getHighlight(i);
        SkyLayout item = new SkyLayout(this);
        int ci = highlight.chapterIndex;
        if (rv.isRTL()) {
            ci = rv.getNumberOfChapters() - ci - 1;
        }
        String chapterTitle = rv.getChapterTitle(ci);
        if (chapterTitle == null || chapterTitle.isEmpty())
            chapterTitle = "Chapter " + ci;

        TextView chapterLabel = this.makeLabel(9899, chapterTitle, Gravity.LEFT, 16, textColor);
        setFrame(chapterLabel, ps(20), ps(5), this.listView.getWidth() - ps(20), ps(40));
        item.addView(chapterLabel);

        GradientDrawable textGrad = new GradientDrawable(Orientation.TOP_BOTTOM,
                new int[] { getBrighterColor(highlight.color), getDarkerColor(highlight.color) });
        TextView textLabel = this.makeLabel(9899, highlight.text, Gravity.LEFT, 16, Color.BLACK);
        setFrame(textLabel, ps(20), ps(5 + 40 + 5), this.listView.getWidth() - ps(20), ps(70));
        textLabel.setBackgroundDrawable(textGrad);
        textLabel.getBackground().setAlpha(180);

        item.addView(textLabel);

        int noteHeight = 0;

        if (highlight.isNote && highlight.note != null && highlight.note.length() != 0
                && !highlight.note.equalsIgnoreCase("null")) {
            TextView noteLabel = this.makeLabel(9899, highlight.note, Gravity.LEFT, 16, Color.BLACK);
            noteLabel.setTextColor(getDarkerColor(highlight.color));
            noteHeight = 70;
            setFrame(noteLabel, ps(20), ps(5 + 40 + 5 + 70 + 5), this.listView.getWidth() - ps(20),
                    ps(noteHeight));
            item.addView(noteLabel);
        }

        TextView dateLabel = this.makeLabel(9899, highlight.datetime, Gravity.RIGHT, 12, textColor);
        int lw = this.listView.getWidth();
        setFrame(dateLabel, 0, ps(5 + 40 + 5 + 70 + 5 + noteHeight + 5), lw, ps(40));
        item.addView(dateLabel);

        int itemHeight = ps(5 + 40 + 5 + 90 + 5 + noteHeight + 5 + 15 + 5);

        View lineView = new View(this);
        lineView.setBackgroundColor(Color.LTGRAY);
        setFrame(lineView, 0, itemHeight - ps(1), this.listView.getWidth(), ps(1));
        item.addView(lineView);

        setFrame(item, 0, 0, listView.getWidth(), itemHeight);
        item.setSkyLayoutListener(highlightListDelegate);
        item.setId(highlight.code);
        item.data = highlight;

        Button deleteButton = new Button(this);
        GradientDrawable grad = new GradientDrawable(Orientation.TOP_BOTTOM,
                new int[] { 0xffcf666e, 0xff671521 });
        grad.setStroke(ps(2), 0xff282828);
        deleteButton.setBackgroundDrawable(grad);
        deleteButton.setText(getString(R.string.delete));
        deleteButton.setTypeface(null, Typeface.BOLD);
        deleteButton.setTextColor(Color.WHITE);
        deleteButton.setTextSize(12);
        deleteButton.setId(highlight.code);
        deleteButton.setVisibility(View.INVISIBLE);
        deleteButton.setVisibility(View.GONE);
        deleteButton.setOnClickListener(deleteHighlightDelegate);
        int dw = ps(120);
        int dh = ps(50);
        setFrame(deleteButton, this.listView.getWidth() - dw, (itemHeight - dh) / 2, dw, dh);
        item.deleteControl = deleteButton;
        item.addView(deleteButton);

        this.listView.addView(item);
    }
}

From source file:android_network.hetnet.vpn_service.ServiceSinkhole.java

private void showAccessNotification(int uid) {
    String name = TextUtils.join(", ", Util.getApplicationNames(uid, ServiceSinkhole.this));

    Intent main = new Intent(ServiceSinkhole.this, MainActivity.class);
    main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(uid));
    PendingIntent pi = PendingIntent.getActivity(ServiceSinkhole.this, uid + 10000, main,
            PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    int colorOn = tv.data;
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    int colorOff = tv.data;

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_cloud_upload_white_24dp).setGroup("AccessAttempt").setContentIntent(pi)
            .setColor(colorOff).setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        builder.setContentTitle(name).setContentText(getString(R.string.msg_access_n));
    else/*from w  w  w .j  av  a  2 s. c o m*/
        builder.setContentTitle(getString(R.string.app_name))
                .setContentText(getString(R.string.msg_access, name));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }

    DateFormat df = new SimpleDateFormat("dd HH:mm");

    NotificationCompat.InboxStyle notification = new NotificationCompat.InboxStyle(builder);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        notification.addLine(getString(R.string.msg_access_n));
    else {
        String sname = getString(R.string.msg_access, name);
        int pos = sname.indexOf(name);
        Spannable sp = new SpannableString(sname);
        sp.setSpan(new StyleSpan(Typeface.BOLD), pos, pos + name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        notification.addLine(sp);
    }

    Cursor cursor = DatabaseHelper.getInstance(ServiceSinkhole.this).getAccessUnset(uid, 7);
    int colDAddr = cursor.getColumnIndex("daddr");
    int colTime = cursor.getColumnIndex("time");
    int colAllowed = cursor.getColumnIndex("allowed");
    while (cursor.moveToNext()) {
        StringBuilder sb = new StringBuilder();
        sb.append(df.format(cursor.getLong(colTime))).append(' ');

        String daddr = cursor.getString(colDAddr);
        if (Util.isNumericAddress(daddr))
            try {
                daddr = InetAddress.getByName(daddr).getHostName();
            } catch (UnknownHostException ignored) {
            }
        sb.append(daddr);

        int allowed = cursor.getInt(colAllowed);
        if (allowed >= 0) {
            int pos = sb.indexOf(daddr);
            Spannable sp = new SpannableString(sb);
            ForegroundColorSpan fgsp = new ForegroundColorSpan(allowed > 0 ? colorOn : colorOff);
            sp.setSpan(fgsp, pos, pos + daddr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            notification.addLine(sp);
        } else
            notification.addLine(sb);
    }
    cursor.close();

    NotificationManagerCompat.from(this).notify(uid + 10000, notification.build());
}

From source file:jmri.enginedriver.throttle.java

void set_function_request(int whichThrottle, int function, int reqState) {
    // Log.d("Engine_Driver","starting set_function_request");
    Button b;//from  w  w w.j  a v  a2  s  .  co m
    b = functionMaps[whichThrottle].get(function);
    if (b != null) {
        if (reqState != 0) {
            b.setTypeface(null, Typeface.ITALIC + Typeface.BOLD);
        } else {
            b.setTypeface(null, Typeface.NORMAL);
        }
    }
}