Example usage for android.text.style TypefaceSpan TypefaceSpan

List of usage examples for android.text.style TypefaceSpan TypefaceSpan

Introduction

In this page you can find the example usage for android.text.style TypefaceSpan TypefaceSpan.

Prototype

public TypefaceSpan(@NonNull Parcel src) 

Source Link

Document

Constructs a TypefaceSpan from a parcel.

Usage

From source file:fr.tvbarthel.apps.simpleweatherforcast.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
    setSupportActionBar(toolbar);//www .  ja va  2 s .  c o  m

    // Get the colors used for the background
    mBackgroundColors = getResources().getIntArray(R.array.background_colors);
    //Get the temperature unit symbol
    mTemperatureUnit = SharedPreferenceUtils.getTemperatureUnitSymbol(this);

    mAlphaForegroundColorSpan = new AlphaForegroundColorSpan(Color.WHITE);
    mTypefaceSpanLight = new TypefaceSpan("sans-serif-light");
    mActionBarTitleDateFormat = new SimpleDateFormat("EEEE dd MMMM", Locale.getDefault());

    mProgressBar = (ProgressBar) findViewById(R.id.activity_main_progress_bar);
    mRootView = (ViewGroup) findViewById(R.id.activity_main_root);

    initActionBar();
    initViewPager();
    initRootPadding();
}

From source file:com.woodblockwithoutco.beretainedexample.MainActivity.java

protected CharSequence[] getItems() {
    //filling list with entries like "fieldName 0xfieldHash"
    String[] fieldNames = new String[] { "mIntArray", "mObject", "mMap", };

    String[] fieldHashcodes = new String[] { "0x" + Integer.toHexString(System.identityHashCode(mIntArray)),
            "0x" + Integer.toHexString(System.identityHashCode(mObject)),
            "0x" + Integer.toHexString(System.identityHashCode(mMap)) };

    if (fieldHashcodes.length != fieldNames.length) {
        throw new IllegalStateException("Did you forget to add something?");
    }/*from   ww w  . jav a2  s  .c  om*/

    int length = fieldHashcodes.length;
    CharSequence[] items = new CharSequence[length];
    for (int i = 0; i < length; i++) {
        SpannableStringBuilder description = new SpannableStringBuilder();
        description.append(fieldNames[i]);
        description.setSpan(new TypefaceSpan("bold"), 0, description.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        description.append(" ").append(fieldHashcodes[i]);
        items[i] = description;
    }

    return items;
}

From source file:org.transdroid.core.gui.navigation.NavigationHelper.java

/**
 * Converts a string into a {@link Spannable} that displays the string in the Roboto Condensed font
 * @param string A plain text {@link String}
 * @return A {@link Spannable} that can be applied to supporting views (such as the action bar title) so that the input string will be displayed
 * using the Roboto Condensed font (if the OS has this)
 *///  w ww .  j  av  a 2 s  .c  o m
public static SpannableString buildCondensedFontString(String string) {
    if (string == null) {
        return null;
    }
    SpannableString s = new SpannableString(string);
    s.setSpan(new TypefaceSpan("sans-serif-condensed"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return s;
}

From source file:nya.miku.wishmaster.ui.settings.AutohideActivity.java

@SuppressLint("InflateParams")
@Override/*from  ww  w .j a  v  a2 s .c o m*/
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Object item = l.getItemAtPosition(position);
    final int changeId;
    if (item instanceof AutohideRule) {
        changeId = position - 1;
    } else {
        changeId = -1; //-1 - ?  
    }

    Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
            ? new ContextThemeWrapper(this, R.style.Neutron_Medium)
            : this;
    View dialogView = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_autohide_rule, null);
    final EditText regexEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_regex);
    final Spinner chanSpinner = (Spinner) dialogView.findViewById(R.id.dialog_autohide_chan_spinner);
    final EditText boardEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_boardname);
    final EditText threadEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_threadnum);
    final CheckBox inCommentCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_comment);
    final CheckBox inSubjectCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_subject);
    final CheckBox inNameCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_name);

    chanSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, chans));
    if (changeId != -1) {
        AutohideRule rule = (AutohideRule) item;
        regexEditText.setText(rule.regex);
        int chanPosition = chans.indexOf(rule.chanName);
        chanSpinner.setSelection(chanPosition != -1 ? chanPosition : 0);
        boardEditText.setText(rule.boardName);
        threadEditText.setText(rule.threadNumber);
        inCommentCheckBox.setChecked(rule.inComment);
        inSubjectCheckBox.setChecked(rule.inSubject);
        inNameCheckBox.setChecked(rule.inName);
    } else {
        chanSpinner.setSelection(0);
    }

    DialogInterface.OnClickListener save = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String regex = regexEditText.getText().toString();
            if (regex.length() == 0) {
                Toast.makeText(AutohideActivity.this, R.string.autohide_error_empty_regex, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            try {
                Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL);
            } catch (Exception e) {
                CharSequence message = null;
                if (e instanceof PatternSyntaxException) {
                    String eMessage = e.getMessage();
                    if (!TextUtils.isEmpty(eMessage)) {
                        SpannableStringBuilder a = new SpannableStringBuilder(
                                getString(R.string.autohide_error_incorrect_regex));
                        a.append('\n');
                        int startlen = a.length();
                        a.append(eMessage);
                        a.setSpan(new TypefaceSpan("monospace"), startlen, a.length(),
                                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        message = a;
                    }
                }
                if (message == null)
                    message = getString(R.string.error_unknown);
                Toast.makeText(AutohideActivity.this, message, Toast.LENGTH_LONG).show();
                return;
            }

            AutohideRule rule = new AutohideRule();
            int spinnerSelectedPosition = chanSpinner.getSelectedItemPosition();
            rule.regex = regex;
            rule.chanName = spinnerSelectedPosition > 0 ? chans.get(spinnerSelectedPosition) : ""; // 0 ? = ? 
            rule.boardName = boardEditText.getText().toString();
            rule.threadNumber = threadEditText.getText().toString();
            rule.inComment = inCommentCheckBox.isChecked();
            rule.inSubject = inSubjectCheckBox.isChecked();
            rule.inName = inNameCheckBox.isChecked();

            if (!rule.inComment && !rule.inSubject && !rule.inName) {
                Toast.makeText(AutohideActivity.this, R.string.autohide_error_no_condition, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            if (changeId == -1) {
                rulesJson.put(rule.toJson());
            } else {
                rulesJson.put(changeId, rule.toJson());
            }
            rulesChanged();
        }
    };
    AlertDialog dialog = new AlertDialog.Builder(this).setView(dialogView)
            .setTitle(changeId == -1 ? R.string.autohide_add_rule_title : R.string.autohide_edit_rule_title)
            .setPositiveButton(R.string.autohide_save_button, save)
            .setNegativeButton(android.R.string.cancel, null).create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}

From source file:com.flowzr.activity.EntityListActivity.java

public void setMyTitle(String t) {
    SpannableString s = new SpannableString(t);
    s.setSpan(new TypefaceSpan("sans-serif"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    getSupportActionBar().setTitle(s);/*from www .j  a  v  a2  s  .  co m*/
}

From source file:org.thoughtcrime.securesms.PassphrasePromptActivity.java

private void initializeResources() {

    ImageButton okButton = findViewById(R.id.ok_button);
    Toolbar toolbar = findViewById(R.id.toolbar);

    showButton = findViewById(R.id.passphrase_visibility);
    hideButton = findViewById(R.id.passphrase_visibility_off);
    visibilityToggle = findViewById(R.id.button_toggle);
    passphraseText = findViewById(R.id.passphrase_edit);
    passphraseAuthContainer = findViewById(R.id.password_auth_container);
    fingerprintPrompt = findViewById(R.id.fingerprint_auth_container);
    lockScreenButton = findViewById(R.id.lock_screen_auth_container);
    fingerprintManager = FingerprintManagerCompat.from(this);
    fingerprintCancellationSignal = new CancellationSignal();
    fingerprintListener = new FingerprintListener();

    setSupportActionBar(toolbar);//from  w  w w.  j a v  a  2s.c o  m
    getSupportActionBar().setTitle("");

    SpannableString hint = new SpannableString(
            "  " + getString(R.string.PassphrasePromptActivity_enter_passphrase));
    hint.setSpan(new RelativeSizeSpan(0.9f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);

    passphraseText.setHint(hint);
    okButton.setOnClickListener(new OkButtonClickListener());
    showButton.setOnClickListener(new ShowButtonOnClickListener());
    hideButton.setOnClickListener(new HideButtonOnClickListener());
    passphraseText.setOnEditorActionListener(new PassphraseActionListener());
    passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
            EditorInfo.IME_ACTION_DONE);

    fingerprintPrompt.setImageResource(R.drawable.ic_fingerprint_white_48dp);
    fingerprintPrompt.getBackground().setColorFilter(getResources().getColor(R.color.signal_primary),
            PorterDuff.Mode.SRC_IN);

    lockScreenButton.setOnClickListener(v -> resumeScreenLock());
}

From source file:net.yoching.android.MainActivity.java

private void setupDrawer() {
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open,
            R.string.drawer_close) {//from  w  w  w  . ja v a2  s . c o  m

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

            SpannableString s = new SpannableString("64 WREXAGRAMS");
            s.setSpan(new TypefaceSpan("Exo-Bold.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            getSupportActionBar().setTitle(s);

            // invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getSupportActionBar().setTitle(mActivityTitle);
            //   invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()

        }
    };

    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:com.flowzr.activity.AbstractActionBarActivity.java

public void setMyTitle(String t) {
    SpannableString s = new SpannableString(t);
    s.setSpan(new TypefaceSpan("sans-serif"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    actionBar.setTitle(s);// ww w.  j a  va  2  s .  c om
}

From source file:com.ruesga.rview.misc.Formatter.java

@BindingAdapter("userMessage")
public static void toUserMessage(TextView view, String msg) {
    if (msg == null) {
        view.setText(null);//  w w w  .  j  a  v  a 2s  .  c o  m
        return;
    }

    String message = EmojiHelper.createEmoji(msg);

    // This process mimics the Gerrit formatting process done in class
    // ./gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java

    // Split message into paragraphs
    String[] paragraphs = StringHelper.obtainParagraphs(message);
    StringBuilder sb = new StringBuilder();
    boolean formattedMessage = false;
    for (String p : paragraphs) {
        if (StringHelper.isQuote(p)) {
            sb.append(StringHelper.obtainQuote(StringHelper.removeLineBreaks(p)));
            formattedMessage = true;
        } else if (StringHelper.isList(p)) {
            sb.append(p);
            formattedMessage = true;
        } else if (StringHelper.isPreFormat(p)) {
            sb.append(StringHelper.obtainPreFormatMessage(p));
            formattedMessage = true;
        } else {
            sb.append(p);
        }
        sb.append("\n\n");
    }

    String userMessage = StringHelper.removeExtraLines(sb.toString());
    if (!formattedMessage) {
        view.setText(userMessage);
        return;
    }

    if (sQuoteColor == -1) {
        sQuoteColor = ContextCompat.getColor(view.getContext(), R.color.quote);
        sQuoteWidth = (int) view.getContext().getResources().getDimension(R.dimen.quote_width);
        sQuoteMargin = (int) view.getContext().getResources().getDimension(R.dimen.quote_margin);
    }

    String[] lines = userMessage.split("\n");
    SpannableStringBuilder spannable = new SpannableStringBuilder(userMessage
            .replaceAll(StringHelper.NON_PRINTABLE_CHAR, "").replaceAll(StringHelper.NON_PRINTABLE_CHAR2, ""));

    // Pre-Format
    int start = 0;
    int spans = 0;
    while ((start = userMessage.indexOf(StringHelper.NON_PRINTABLE_CHAR2, start)) != -1) {
        int end = userMessage.indexOf(StringHelper.NON_PRINTABLE_CHAR2, start + 1);
        if (end == -1) {
            //? This is supposed to be formatted by us. Skip it
            break;
        }

        // Find quote token occurrences
        int offset = StringHelper.countOccurrences(StringHelper.NON_PRINTABLE_CHAR, userMessage, 0, start);
        start -= offset;
        end -= offset;

        // Ensure bounds
        int spanStart = start - spans;
        int spanEnd = Math.min(end - spans - 1, spannable.length());
        if (spanStart < 0 || spanEnd < 0) {
            //Something was wrong. Skip it
            break;
        }
        spannable.setSpan(new RelativeSizeSpan(0.8f), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannable.setSpan(new TypefaceSpan("monospace"), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        start = end;
        spans++;
    }

    start = 0;
    for (String line : lines) {
        // Quotes
        int maxIndent = StringHelper.countOccurrences(StringHelper.NON_PRINTABLE_CHAR, line);
        for (int i = 0; i < maxIndent; i++) {
            QuotedSpan span = new QuotedSpan(sQuoteColor, sQuoteWidth, sQuoteMargin);
            spannable.setSpan(span, start, Math.min(start + line.length() - maxIndent, spannable.length()),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        // List
        if (StringHelper.isList(line)) {
            spannable.replace(start, start + 1, "\u2022");
            spannable.setSpan(new LeadingMarginSpan.Standard(sQuoteMargin), start,
                    Math.min(start + line.length(), spannable.length()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        start += line.length() - maxIndent + 1;
    }

    view.setText(spannable);
}

From source file:com.flowzr.activity.MainActivity.java

private void setMyTabText(Tab tab, String text) {
    SpannableString s = new SpannableString(text);
    s.setSpan(new TypefaceSpan("sans-serif"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    tab.setText(s);// w  w  w  .ja v a2  s  . c  o m
}