Java 类android.text.style.TypefaceSpan 实例源码

项目:PeSanKita-android    文件:PassphrasePromptActivity.java   
private void initializeResources() {
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  getSupportActionBar().setCustomView(R.layout.centered_app_title);

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

  showButton       = (ImageButton)     findViewById(R.id.passphrase_visibility);
  hideButton       = (ImageButton)     findViewById(R.id.passphrase_visibility_off);
  visibilityToggle = (AnimatingToggle) findViewById(R.id.button_toggle);
  passphraseText   = (EditText)        findViewById(R.id.passphrase_edit);
  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);
}
项目:My-Android-Base-Code    文件:HtmlTagHandler.java   
@Override
public void handleTag(final boolean opening, final String tag, Editable output, final XMLReader xmlReader) {

    if (tag.equals("ul") || tag.equals("ol") || tag.equals("dd")) {
        if (opening) {
            mListParents.add(tag);
        } else mListParents.remove(tag);

        mListItemCount = 0;
    } else if (tag.equals("li") && !opening) {
        handleListTag(output);
    }
    else if(tag.equalsIgnoreCase("code")) {
        if(opening) {
            output.setSpan(new TypefaceSpan("monospace"), output.length(), output.length(), Spannable.SPAN_MARK_MARK);
        } else {
            Log.d("COde Tag","Code tag encountered");
            Object obj = getLast(output, TypefaceSpan.class);
            int where = output.getSpanStart(obj);

            output.setSpan(new TypefaceSpan("monospace"), where, output.length(), 0);
        }
    }

}
项目:mvvm-template    文件:PreTagHandler.java   
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end) {
    if (isPre) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("\n");//fake padding top + make sure, pre is always by itself
        getPlainText(buffer, node);
        buffer.append("\n");//fake padding bottom + make sure, pre is always by itself
        builder.append(replace(buffer.toString()));
        builder.append("\n");
        builder.setSpan(new CodeBackgroundRoundedSpan(color), start, builder.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.append("\n");
        this.appendNewLine(builder);
        this.appendNewLine(builder);
    } else {
        StringBuffer text = node.getText();
        builder.append(" ");
        builder.append(replace(text.toString()));
        builder.append(" ");
        final int stringStart = start + 1;
        final int stringEnd = builder.length() - 1;
        builder.setSpan(new BackgroundColorSpan(color), stringStart, stringEnd, SPAN_EXCLUSIVE_EXCLUSIVE);
        if (theme == PrefGetter.LIGHT) {
            builder.setSpan(new ForegroundColorSpan(Color.RED), stringStart, stringEnd, SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.setSpan(new TypefaceSpan("monospace"), stringStart, stringEnd, SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
项目:revolution-irc    文件:UserAutoRunCommandHelper.java   
@Override
public void showDialog(Activity activity) {
    super.showDialog(activity);
    dismissDialog(activity);
    ThemedAlertDialog.Builder dialog = new ThemedAlertDialog.Builder(activity);
    dialog.setTitle(R.string.connection_error_command_title);

    StringBuilder commands = new StringBuilder();
    for (String cmd : mCommands) {
        commands.append('/');
        commands.append(cmd);
        commands.append('\n');
    }
    SpannableString commandsSeq = new SpannableString(commands);
    commandsSeq.setSpan(new TypefaceSpan("monospace"), 0, commandsSeq.length(),
            SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
    dialog.setMessage(SpannableStringHelper.format(activity.getResources().getQuantityText(
            R.plurals.connection_error_command_dialog_content, mCommands.size()),
            mNetworkName, commandsSeq));
    dialog.setPositiveButton(R.string.action_ok, null);
    dialog.setOnDismissListener((DialogInterface di) -> {
        dismiss();
    });
    mDialog = dialog.show();
}
项目:xwallet    文件:WalletUtils.java   
public static Editable formatHash(@Nullable final String prefix, final String address, final int groupSize,
                                  final int lineSize, final char groupSeparator) {
    final SpannableStringBuilder builder = prefix != null ? new SpannableStringBuilder(prefix)
            : new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0; i < len; i += groupSize) {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);
        builder.setSpan(new TypefaceSpan("monospace"), builder.length() - part.length(), builder.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (end < len) {
            final boolean endOfLine = lineSize > 0 && end % lineSize == 0;
            builder.append(endOfLine ? '\n' : groupSeparator);
        }
    }

    return builder;
}
项目:Cable-Android    文件:PassphrasePromptActivity.java   
private void initializeResources() {
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  getSupportActionBar().setCustomView(R.layout.centered_app_title);

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

  showButton       = (ImageButton)     findViewById(R.id.passphrase_visibility);
  hideButton       = (ImageButton)     findViewById(R.id.passphrase_visibility_off);
  visibilityToggle = (AnimatingToggle) findViewById(R.id.button_toggle);
  passphraseText   = (EditText)        findViewById(R.id.passphrase_edit);
  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);
}
项目:okwallet    文件:SampleActivity.java   
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (requestCode == REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            final String txHash = BitcoinIntegration.transactionHashFromResult(data);
            if (txHash != null) {
                final SpannableStringBuilder messageBuilder = new SpannableStringBuilder("Transaction hash:\n");
                messageBuilder.append(txHash);
                messageBuilder.setSpan(new TypefaceSpan("monospace"), messageBuilder.length() - txHash.length(),
                        messageBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

                if (BitcoinIntegration.paymentFromResult(data) != null)
                    messageBuilder.append("\n(also a BIP70 payment message was received)");

                donateMessage.setText(messageBuilder);
                donateMessage.setVisibility(View.VISIBLE);
            }

            Toast.makeText(this, "Thank you!", Toast.LENGTH_LONG).show();
        } else if (resultCode == Activity.RESULT_CANCELED) {
            Toast.makeText(this, "Cancelled.", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, "Unknown result.", Toast.LENGTH_LONG).show();
        }
    }
}
项目:okwallet    文件:WalletUtils.java   
public static Editable formatHash(@Nullable final String prefix, final String address, final int groupSize,
        final int lineSize, final char groupSeparator) {
    final SpannableStringBuilder builder = prefix != null ? new SpannableStringBuilder(prefix)
            : new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0; i < len; i += groupSize) {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);
        builder.setSpan(new TypefaceSpan("monospace"), builder.length() - part.length(), builder.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (end < len) {
            final boolean endOfLine = lineSize > 0 && end % lineSize == 0;
            builder.append(endOfLine ? '\n' : groupSeparator);
        }
    }

    return builder;
}
项目:ScribaNotesApp    文件:Html.java   
private void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("br")) {
        handleBr(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("p")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("b")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("i")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("font")) {
        endFont(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("blockquote")) {
        handleP(mSpannableStringBuilder);
        end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
    } else if (tag.equalsIgnoreCase("tt")) {
        end(mSpannableStringBuilder, Monospace.class,
                new TypefaceSpan("monospace"));
    } else if (tag.equalsIgnoreCase("u")) {
        end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
    } else if (mTagHandler != null) {
        mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
    }
}
项目:TextSecure    文件:PassphrasePromptActivity.java   
private void initializeResources() {
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  getSupportActionBar().setCustomView(R.layout.light_centered_app_title);
  mitigateAndroidTilingBug();

  ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);
  passphraseText       = (EditText)    findViewById(R.id.passphrase_edit);
  SpannableString hint = new SpannableString(getString(R.string.PassphrasePromptActivity_enter_passphrase));

  hint.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  hint.setSpan(new ForegroundColorSpan(0x66000000), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  passphraseText.setHint(hint);
  okButton.setOnClickListener(new OkButtonClickListener());
  passphraseText.setOnEditorActionListener(new PassphraseActionListener());
  passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
                                   EditorInfo.IME_ACTION_DONE);
}
项目:Vafrinn    文件:ExpandablePreferenceGroup.java   
/**
 * Set the title for the preference group.
 * @param resourceId The resource id of the text to use.
 * @param count The number of entries the preference group contains.
 */
public void setGroupTitle(int resourceId, int count) {
    SpannableStringBuilder spannable =
            new SpannableStringBuilder(getContext().getResources().getString(resourceId));
    String prefCount = String.format(Locale.getDefault(), " - %d", count);
    spannable.append(prefCount);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),
                   0,
                   spannable.length() - prefCount.length(),
                   Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        spannable.setSpan(new TypefaceSpan("sans-serif-medium"),
                   0,
                   spannable.length() - prefCount.length(),
                   Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    int gray = getContext().getResources().getColor(R.color.expandable_group_dark_gray);
    spannable.setSpan(new ForegroundColorSpan(gray),
               spannable.length() - prefCount.length(),
               spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    setTitle(spannable);
}
项目:chaincloud-v    文件:BitcoinUtil.java   
public static Editable formatHash(@Nullable final String prefix, @NonNull final String
        address, final int groupSize, final int lineSize, final char groupSeparator) {
    final SpannableStringBuilder builder = prefix != null ? new SpannableStringBuilder
            (prefix) : new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0;
         i < len;
         i += groupSize) {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);
        builder.setSpan(new TypefaceSpan("monospace"), builder.length() - part.length(),
                builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (end < len) {
            final boolean endOfLine = lineSize > 0 && end % lineSize == 0;
            builder.append(endOfLine ? '\n' : groupSeparator);
        }
    }

    return builder;
}
项目:ombuds-android    文件:WalletUtils.java   
public static Editable formatHash(@Nullable final String prefix, final String address, final int groupSize, final int lineSize,
        final char groupSeparator)
{
    final SpannableStringBuilder builder = prefix != null ? new SpannableStringBuilder(prefix) : new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0; i < len; i += groupSize)
    {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);
        builder.setSpan(new TypefaceSpan("monospace"), builder.length() - part.length(), builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (end < len)
        {
            final boolean endOfLine = lineSize > 0 && end % lineSize == 0;
            builder.append(endOfLine ? '\n' : groupSeparator);
        }
    }

    return builder;
}
项目:TextSecureSMP    文件:PassphrasePromptActivity.java   
private void initializeResources() {
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  getSupportActionBar().setCustomView(R.layout.centered_app_title);

  ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);
  passphraseText       = (EditText)    findViewById(R.id.passphrase_edit);
  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());
  passphraseText.setOnEditorActionListener(new PassphraseActionListener());
  passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
                                   EditorInfo.IME_ACTION_DONE);
}
项目:Silence    文件:PassphrasePromptActivity.java   
private void initializeResources() {
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  getSupportActionBar().setCustomView(R.layout.centered_app_title);

  ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);
  passphraseText       = (EditText)    findViewById(R.id.passphrase_edit);
  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());
  passphraseText.setOnEditorActionListener(new PassphraseActionListener());
  passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
                                   EditorInfo.IME_ACTION_DONE);
}
项目:transistor    文件:Tx3gDecoderTest.java   
public void testInitializationDecodeWithStyl() throws IOException, SubtitleDecoderException {
  byte[] initBytes = TestUtil.getByteArray(getInstrumentation(), INITIALIZATION);
  Tx3gDecoder decoder = new Tx3gDecoder(Collections.singletonList(initBytes));
  byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL);
  Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
  SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
  assertEquals("CC Test", text.toString());
  assertEquals(5, text.getSpans(0, text.length(), Object.class).length);
  StyleSpan styleSpan = findSpan(text, 0, text.length(), StyleSpan.class);
  assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle());
  findSpan(text, 0, text.length(), UnderlineSpan.class);
  TypefaceSpan typefaceSpan = findSpan(text, 0, text.length(), TypefaceSpan.class);
  assertEquals(C.SERIF_NAME, typefaceSpan.getFamily());
  ForegroundColorSpan colorSpan = findSpan(text, 0, text.length(), ForegroundColorSpan.class);
  assertEquals(Color.RED, colorSpan.getForegroundColor());
  colorSpan = findSpan(text, 0, 6, ForegroundColorSpan.class);
  assertEquals(Color.GREEN, colorSpan.getForegroundColor());
  assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.1f);
}
项目:transistor    文件:Tx3gDecoderTest.java   
public void testInitializationDecodeWithTbox() throws IOException, SubtitleDecoderException {
  byte[] initBytes = TestUtil.getByteArray(getInstrumentation(), INITIALIZATION);
  Tx3gDecoder decoder = new Tx3gDecoder(Collections.singletonList(initBytes));
  byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_TBOX);
  Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
  SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
  assertEquals("CC Test", text.toString());
  assertEquals(4, text.getSpans(0, text.length(), Object.class).length);
  StyleSpan styleSpan = findSpan(text, 0, text.length(), StyleSpan.class);
  assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle());
  findSpan(text, 0, text.length(), UnderlineSpan.class);
  TypefaceSpan typefaceSpan = findSpan(text, 0, text.length(), TypefaceSpan.class);
  assertEquals(C.SERIF_NAME, typefaceSpan.getFamily());
  ForegroundColorSpan colorSpan = findSpan(text, 0, text.length(), ForegroundColorSpan.class);
  assertEquals(Color.RED, colorSpan.getForegroundColor());
  assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.1875f);
}
项目:Dashchan    文件:InterfaceFragment.java   
@Override
public void onPreferenceAfterChange(Preference preference) {
    super.onPreferenceAfterChange(preference);
    if (preference == advancedSearchPreference && advancedSearchPreference.isChecked()) {
        SpannableStringBuilder builder = new SpannableStringBuilder
                (getText(R.string.preference_advanced_search_message));
        Object[] spans = builder.getSpans(0, builder.length(), Object.class);
        for (Object span : spans) {
            int start = builder.getSpanStart(span);
            int end = builder.getSpanEnd(span);
            int flags = builder.getSpanFlags(span);
            builder.removeSpan(span);
            builder.setSpan(new TypefaceSpan("sans-serif-medium"), start, end, flags);
        }
        MessageDialog.create(this, builder, false);
    }
}
项目:My-Wallet-Android    文件:WalletUtils.java   
public static Editable formatAddress(final String address,
        final int groupSize, final int lineSize) {
    final SpannableStringBuilder builder = new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0; i < len; i += groupSize) {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);
        builder.setSpan(new TypefaceSpan("monospace"), builder.length()
                - part.length(), builder.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (end < len) {
            final boolean endOfLine = end % lineSize == 0;
            builder.append(endOfLine ? "\n" : Constants.THIN_SPACE);
        }
    }

    return builder;
}
项目:bither-android    文件:WalletUtils.java   
public static Editable formatHash(@Nullable final String prefix,
                                  @Nonnull final String address, final int groupSize,
                                  final int lineSize, final char groupSeparator) {
    final SpannableStringBuilder builder = prefix != null ? new SpannableStringBuilder(
            prefix) : new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0;
         i < len;
         i += groupSize) {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);
        builder.setSpan(new TypefaceSpan("monospace"), builder.length()
                        - part.length(), builder.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
        );
        if (end < len) {
            final boolean endOfLine = lineSize > 0 && end % lineSize == 0;
            builder.append(endOfLine ? '\n' : groupSeparator);
        }
    }

    return builder;
}
项目:Finanvita    文件:CurrencyFormatFragment.java   
private void updateFormat()
{
    final SpannableStringBuilder sb = new SpannableStringBuilder();
    sb.append("1").append(getGroupSeparator()).append("000");
    if (getDecimals() > 0)
        sb.append(getDecimalSeparator());

    if (getDecimals() == 2)
        sb.append("00");
    else if (getDecimals() == 1)
        sb.append("0");

    final SpannableStringBuilder ssb = new SpannableStringBuilder(getSymbol());
    ssb.setSpan(new TypefaceSpan("sans-serif-light"), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    final String symbolFormat = getSymbolFormat();
    if (symbolFormat.equalsIgnoreCase(Tables.Currencies.SymbolFormat.RIGHT_CLOSE))
        sb.append(ssb);
    else if (symbolFormat.equalsIgnoreCase(Tables.Currencies.SymbolFormat.LEFT_FAR))
        sb.insert(0, " ").insert(0, ssb);
    else if (symbolFormat.equalsIgnoreCase(Tables.Currencies.SymbolFormat.LEFT_CLOSE))
        sb.insert(0, ssb);
    else
        sb.append(" ").append(ssb);

    format_TV.setText(sb);
}
项目:Securecom-Messaging    文件:PassphrasePromptActivity.java   
private void initializeResources() {
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  getSupportActionBar().setCustomView(R.layout.light_centered_app_title);
  mitigateAndroidTilingBug();

  ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);
  passphraseText       = (EditText)    findViewById(R.id.passphrase_edit);
  SpannableString hint = new SpannableString(getString(R.string.PassphrasePromptActivity_enter_passphrase));

  hint.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  hint.setSpan(new ForegroundColorSpan(0x66000000), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  passphraseText.setHint(hint);
  okButton.setOnClickListener(new OkButtonClickListener());
  passphraseText.setOnEditorActionListener(new PassphraseActionListener());
  passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
                                   EditorInfo.IME_ACTION_DONE);
}
项目:tigatrapp-android    文件:TigaTagHandler.java   
@Override
public void handleTag(final boolean opening, final String tag, Editable output, final XMLReader xmlReader) {

    if (tag.equals("ul") || tag.equals("ol") || tag.equals("dd")) {
        if (opening) {
            mListParents.add(tag);
        } else mListParents.remove(tag);

        mListItemCount = 0;
    } else if (tag.equals("li") && !opening) {
        handleListTag(output);
    }
  else if(tag.equalsIgnoreCase("code")) {
      if(opening) {
          output.setSpan(new TypefaceSpan("monospace"), output.length(), output.length(), Spannable.SPAN_MARK_MARK);
      } else {
         Object obj = getLast(output, TypefaceSpan.class);
         int where = output.getSpanStart(obj);

         output.setSpan(new TypefaceSpan("monospace"), where, output.length(), 0);
      }
  }

}
项目:Securecom-Text    文件:PassphrasePromptActivity.java   
private void initializeResources() {
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  getSupportActionBar().setCustomView(R.layout.light_centered_app_title);
  mitigateAndroidTilingBug();

  ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);
  passphraseText       = (EditText)    findViewById(R.id.passphrase_edit);
  SpannableString hint = new SpannableString(getString(R.string.PassphrasePromptActivity_enter_passphrase));

  hint.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  hint.setSpan(new ForegroundColorSpan(0x66000000), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  passphraseText.setHint(hint);
  okButton.setOnClickListener(new OkButtonClickListener());
  passphraseText.setOnEditorActionListener(new PassphraseActionListener());
  passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
                                   EditorInfo.IME_ACTION_DONE);
}
项目:templecoin-android-wallet    文件:WalletUtils.java   
public static Editable formatHash(@Nullable final String prefix, @Nonnull final String address, final int groupSize, final int lineSize,
        final char groupSeparator)
{
    final SpannableStringBuilder builder = prefix != null ? new SpannableStringBuilder(prefix) : new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0; i < len; i += groupSize)
    {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);
        builder.setSpan(new TypefaceSpan("monospace"), builder.length() - part.length(), builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (end < len)
        {
            final boolean endOfLine = lineSize > 0 && end % lineSize == 0;
            builder.append(endOfLine ? '\n' : groupSeparator);
        }
    }

    return builder;
}
项目:countdown    文件:Utils.java   
/***
 * @param amPmFontSize - size of am/pm label (label removed is size is 0).
 * @return format string for 12 hours mode time
 */
public static CharSequence get12ModeFormat(int amPmFontSize) {
    String skeleton = "hma";
    String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
    // Remove the am/pm
    if (amPmFontSize <= 0) {
        pattern.replaceAll("a", "").trim();
    }
    // Replace spaces with "Hair Space"
    pattern = pattern.replaceAll(" ", "\u200A");
    // Build a spannable so that the am/pm will be formatted
    int amPmPos = pattern.indexOf('a');
    if (amPmPos == -1) {
        return pattern;
    }
    Spannable sp = new SpannableString(pattern);
    sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), amPmPos, amPmPos + 1,
            Spannable.SPAN_POINT_MARK);
    sp.setSpan(new AbsoluteSizeSpan(amPmFontSize), amPmPos, amPmPos + 1,
            Spannable.SPAN_POINT_MARK);
    sp.setSpan(new TypefaceSpan("sans-serif-condensed"), amPmPos, amPmPos + 1,
            Spannable.SPAN_POINT_MARK);
    return sp;
}
项目:PrepayCredit    文件:CustomTagHandler.java   
@Override
public void handleTag(final boolean opening, final String tag, Editable output, final XMLReader xmlReader) {

    if (tag.equals("ul") || tag.equals("ol") || tag.equals("dd")) {
        if (opening) {
            mListParents.add(tag);
        } else mListParents.remove(tag);

        mListItemCount = 0;
    } else if (tag.equals("li") && !opening) {
        handleListTag(output);
    } else if (tag.equalsIgnoreCase("code")) {
        if (opening) {
            output.setSpan(new TypefaceSpan("monospace"), output.length(), output.length(),
                    Spannable.SPAN_MARK_MARK);
        } else {
            Object obj = getLast(output, TypefaceSpan.class);
            int where = output.getSpanStart(obj);

            output.setSpan(new TypefaceSpan("monospace"), where, output.length(), 0);
        }
    }
}
项目:goldcoin-android    文件:WalletUtils.java   
public static Editable formatHash(final String prefix, final String address, final int groupSize, final int lineSize, final char groupSeparator)
{
    final SpannableStringBuilder builder = prefix != null ? new SpannableStringBuilder(prefix) : new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0; i < len; i += groupSize)
    {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);
        builder.setSpan(new TypefaceSpan("monospace"), builder.length() - part.length(), builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (end < len)
        {
            final boolean endOfLine = lineSize > 0 && end % lineSize == 0;
            builder.append(endOfLine ? '\n' : groupSeparator);
        }
    }

    return builder;
}
项目:SimpleWeatherForecast    文件: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);

    // 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();
}
项目:apps-android-wikipedia    文件:PageHeaderView.java   
private void updateText() {
    avPlayer.stop();

    SpannableStringBuilder builder = new SpannableStringBuilder(title);
    builder.setSpan(new TypefaceSpan("serif"), 0, title.length(),
            Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

    if (hasPronunciation()) {
        builder.append(" ");
        builder.append(pronunciationSpanned());
    }
    titleText.setMovementMethod(new LinkMovementMethod());
    titleText.setText(builder);

    if (hasSubtitle() || allowDescriptionEdit) {
        subtitleText.setMovementMethod(hasSubtitle() ? null : new LinkMovementMethod());
        subtitleText.setText(subtitleSpanned());
        subtitleText.setVisibility(VISIBLE);
    } else {
        subtitleText.setVisibility(INVISIBLE);
    }
}
项目:mobile-store    文件:Utils.java   
/**
 * Formats the app name using "sans-serif" and then appends the summary after a space with
 * "sans-serif-light". Doesn't mandate any font sizes or any other styles, that is up to the
 * {@link android.widget.TextView} which it ends up being displayed in.
 */
public static CharSequence formatAppNameAndSummary(String appName, String summary) {
    String toFormat = appName + ' ' + summary;
    CharacterStyle normal = new TypefaceSpan("sans-serif");
    CharacterStyle light = new TypefaceSpan("sans-serif-light");

    SpannableStringBuilder sb = new SpannableStringBuilder(toFormat);
    sb.setSpan(normal, 0, appName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    sb.setSpan(light, appName.length(), toFormat.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    return sb;
}
项目:SpanEZ    文件:SpanEZTest.java   
@Test
public void font_should_add_only_one_span() {
    spanBuilder.font(range, EZ.MONOSPACE)
               .apply();

    verify((SpanEZ) spanBuilder, times(1))
            .addSpan(isA(TargetRange.class), isA(TypefaceSpan.class));
}
项目:chromium-for-android-56-debug-video    文件:GeolocationSnackbarController.java   
/**
 * Shows the geolocation snackbar if it hasn't already been shown and the geolocation snackbar
 * is currently relevant: i.e. the default search engine is Google, location is enabled
 * for Chrome, the tab is not incognito, etc.
 *
 * @param snackbarManager The SnackbarManager used to show the snackbar.
 * @param view Any view that's attached to the view hierarchy.
 * @param isIncognito Whether the currently visible tab is incognito.
 * @param delayMs The delay in ms before the snackbar should be shown. This is intended to
 *                give the keyboard time to animate in.
 */
public static void maybeShowSnackbar(final SnackbarManager snackbarManager, View view,
        boolean isIncognito, int delayMs) {
    final Context context = view.getContext();
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) return;
    if (getGeolocationSnackbarShown(context)) return;

    // If in incognito mode, don't show the snackbar now, but maybe show it later.
    if (isIncognito) return;

    if (neverShowSnackbar(context)) {
        setGeolocationSnackbarShown(context);
        return;
    }

    Uri searchUri = Uri.parse(TemplateUrlService.getInstance().getUrlForSearchQuery("foo"));
    TypefaceSpan robotoMediumSpan = new TypefaceSpan("sans-serif-medium");
    String messageWithoutSpans = context.getResources().getString(
            R.string.omnibox_geolocation_disclosure, "<b>" + searchUri.getHost() + "</b>");
    SpannableString message = SpanApplier.applySpans(messageWithoutSpans,
            new SpanInfo("<b>", "</b>", robotoMediumSpan));
    String settings = context.getResources().getString(R.string.preferences);
    int durationMs = DeviceClassManager.isAccessibilityModeEnabled(view.getContext())
            ? ACCESSIBILITY_SNACKBAR_DURATION_MS : SNACKBAR_DURATION_MS;
    final GeolocationSnackbarController controller = new GeolocationSnackbarController();
    final Snackbar snackbar = Snackbar
            .make(message, controller, Snackbar.TYPE_ACTION, Snackbar.UMA_OMNIBOX_GEOLOCATION)
            .setAction(settings, view)
            .setSingleLine(false)
            .setDuration(durationMs);

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            snackbarManager.dismissSnackbars(controller);
            snackbarManager.showSnackbar(snackbar);
            setGeolocationSnackbarShown(context);
        }
    }, delayMs);
}
项目:chromium-for-android-56-debug-video    文件:ExpandablePreferenceGroup.java   
/**
 * Set the title for the preference group.
 * @param resourceId The resource id of the text to use.
 * @param count The number of entries the preference group contains.
 */
public void setGroupTitle(int resourceId, int count) {
    SpannableStringBuilder spannable =
            new SpannableStringBuilder(getContext().getResources().getString(resourceId));
    String prefCount = String.format(Locale.getDefault(), " - %d", count);
    spannable.append(prefCount);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),
                   0,
                   spannable.length() - prefCount.length(),
                   Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        spannable.setSpan(new TypefaceSpan("sans-serif-medium"),
                   0,
                   spannable.length() - prefCount.length(),
                   Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    // Color the first part of the title blue.
    ForegroundColorSpan blueSpan = new ForegroundColorSpan(
            ApiCompatibilityUtils.getColor(getContext().getResources(),
                    R.color.pref_accent_color));
    spannable.setSpan(blueSpan, 0, spannable.length() - prefCount.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    // Gray out the total count of items.
    int gray = ApiCompatibilityUtils.getColor(getContext().getResources(),
            R.color.expandable_group_dark_gray);
    spannable.setSpan(new ForegroundColorSpan(gray),
               spannable.length() - prefCount.length(),
               spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    setTitle(spannable);
}
项目:android-crond    文件:Crond.java   
public SpannableStringBuilder processCrontab() {
    SpannableStringBuilder ret = new SpannableStringBuilder();
    String hashedTab = "";
    try {
        MessageDigest messageDigest = MessageDigest.getInstance(HASH_ALGO);
        messageDigest.update(crontab.getBytes());
        hashedTab = Base64.encodeToString(messageDigest.digest(), Base64.DEFAULT).trim();
    }
    catch (NoSuchAlgorithmException e) {
        Log.e(TAG, String.format("Algorithm %s not found:", HASH_ALGO));
        e.printStackTrace();
    }
    if (!hashedTab.equals(sharedPrefs.getString(PREF_CRONTAB_HASH, ""))
            && !crontab.equals("")) {
        // only schedule when enabled
        if (sharedPrefs.getBoolean(PREF_ENABLED, false)) {
            IO.logToLogFile(context.getString(R.string.log_crontab_change_detected));
            scheduleCrontab();
        }
        // save in any case such that on installation the crontab is not "new"
        sharedPrefs.edit().putString(PREF_CRONTAB_HASH, hashedTab).apply();
    }
    if (crontab.equals("")) {
        return ret;
    }
    for (String line : crontab.split("\n")){
        ret.append(line + "\n",
                new TypefaceSpan("monospace"), Spanned.SPAN_COMPOSING);
        ret.append(describeLine(line));
    }
    return ret;
}
项目:aos-Video    文件:BrowserBySmb.java   
private void displayConnectionDescription() {
    final String description = getString(R.string.network_connected_as, mUser);
    final int userStart = description.indexOf(mUser);
    final int userEnd = userStart + mUser.length();
    final SpannableStringBuilder sb = new SpannableStringBuilder(description);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        sb.setSpan(new TypefaceSpan("sans-serif-light"), 0, description.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        sb.setSpan(new TypefaceSpan("sans-serif"), userStart, userEnd, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    }
    sb.setSpan(new StyleSpan(Typeface.BOLD), userStart, userEnd, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mButton.setText(sb);
}
项目:Slide-RSS    文件:SpoilerRobotoTextView.java   
/**
 * Sets the styling for string with code segments. <p/> The general process is to search for
 * <code>[[&lt;[</code> and <code>]&gt;]]</code> tokens to find the code fragments within the
 * escaped text. A <code>Spannable</code> is created which which breaks up the origin sequence
 * into non-code and code fragments, and applies a monospace font to the code fragments.
 *
 * @param sequence the Spannable generated from Html.fromHtml
 * @return the message with monospace font applied to code fragments
 */
private SpannableStringBuilder setCodeFont(SpannableStringBuilder sequence) {
    int start = 0;
    int end = 0;
    for (int i = 0; i < sequence.length(); i++) {
        if (sequence.charAt(i) == '[' && i < sequence.length() - 3) {
            if (sequence.charAt(i + 1) == '['
                    && sequence.charAt(i + 2) == '<'
                    && sequence.charAt(i + 3) == '[') {
                start = i;
            }
        } else if (sequence.charAt(i) == ']' && i < sequence.length() - 3) {
            if (sequence.charAt(i + 1) == '>'
                    && sequence.charAt(i + 2) == ']'
                    && sequence.charAt(i + 3) == ']') {
                end = i;
            }
        }

        if (end > start) {
            sequence.delete(end, end + 4);
            sequence.delete(start, start + 4);
            sequence.setSpan(new TypefaceSpan("monospace"), start, end - 4,
                    Spannable.SPAN_INCLUSIVE_INCLUSIVE);
            start = 0;
            end = 0;
            i = i - 4; // move back to compensate for removal of [[<[
        }
    }

    return sequence;
}
项目:HtmlCompat    文件:HtmlToSpannedConverter.java   
private void endFont(String tag, Editable text) {
    Font font = getLast(text, Font.class);
    if (font != null) {
        setSpanFromMark(tag, text, font, new TypefaceSpan(font.mFace));
    }
    Foreground foreground = getLast(text, Foreground.class);
    if (foreground != null) {
        setSpanFromMark(tag, text, foreground,
                new ForegroundColorSpan(foreground.mForegroundColor));
    }
}
项目:Exoplayer2Radio    文件:Tx3gDecoder.java   
@SuppressWarnings("ReferenceEquality")
private static void attachFontFamily(SpannableStringBuilder cueText, String fontFamily,
    String defaultFontFamily, int start, int end, int spanPriority) {
  if (fontFamily != defaultFontFamily) {
    cueText.setSpan(new TypefaceSpan(fontFamily), start, end,
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | spanPriority);
  }
}
项目:AndroidProjectsClient    文件:Formatter.java   
public static SpannableStringBuilder buildDiffSpan(@NonNull String diff) {
    final SpannableStringBuilder builder = new SpannableStringBuilder();

    int oldLength = 0;
    for(String line : diff.split("\n")) {
        oldLength = builder.length();
        if(line.startsWith("+")) {
            builder.append(line);
            builder.setSpan(new FullWidthBackgroundColorSpan(Color.parseColor("#8BC34A")),
                    oldLength, builder.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
            );
        } else if(line.startsWith("-")) {
            builder.append(line);
            builder.setSpan(new FullWidthBackgroundColorSpan(Color.parseColor("#F44336")),
                    oldLength, builder.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
            );
        } else {
            builder.append(line);
            builder.setSpan(new FullWidthBackgroundColorSpan(Color.parseColor("#9E9E9E")),
                    oldLength, builder.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
            );
        }
        builder.append("\n");
    }
    builder.setSpan(new TypefaceSpan("monospace"), 0, builder.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
    );
    return builder;
}