Java Code Examples for android.text.style.TypefaceSpan

The following are top voted examples for showing how to use android.text.style.TypefaceSpan. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Cable-Android   File: PassphrasePromptActivity.java   View source code 7 votes vote down vote up
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);
}
 
Example 2
Project: PeSanKita-android   File: PassphrasePromptActivity.java   View source code 6 votes vote down vote up
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);
}
 
Example 3
Project: My-Android-Base-Code   File: HtmlTagHandler.java   View source code 6 votes vote down vote up
@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);
        }
    }

}
 
Example 4
Project: mvvm-template   File: PreTagHandler.java   View source code 6 votes vote down vote up
@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);
    }
}
 
Example 5
Project: revolution-irc   File: UserAutoRunCommandHelper.java   View source code 6 votes vote down vote up
@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();
}
 
Example 6
Project: xwallet   File: WalletUtils.java   View source code 6 votes vote down vote up
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;
}
 
Example 7
Project: okwallet   File: SampleActivity.java   View source code 6 votes vote down vote up
@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();
        }
    }
}
 
Example 8
Project: okwallet   File: WalletUtils.java   View source code 6 votes vote down vote up
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;
}
 
Example 9
Project: ScribaNotesApp   File: Html.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 10
Project: TextSecure   File: PassphrasePromptActivity.java   View source code 6 votes vote down vote up
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);
}
 
Example 11
Project: Vafrinn   File: ExpandablePreferenceGroup.java   View source code 6 votes vote down vote up
/**
 * 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);
}
 
Example 12
Project: chaincloud-v   File: BitcoinUtil.java   View source code 6 votes vote down vote up
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;
}
 
Example 13
Project: ombuds-android   File: WalletUtils.java   View source code 6 votes vote down vote up
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;
}
 
Example 14
Project: TextSecureSMP   File: PassphrasePromptActivity.java   View source code 6 votes vote down vote up
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);
}
 
Example 15
Project: Silence   File: PassphrasePromptActivity.java   View source code 6 votes vote down vote up
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);
}
 
Example 16
Project: transistor   File: Tx3gDecoderTest.java   View source code 6 votes vote down vote up
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);
}
 
Example 17
Project: transistor   File: Tx3gDecoderTest.java   View source code 6 votes vote down vote up
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);
}
 
Example 18
Project: Dashchan   File: InterfaceFragment.java   View source code 6 votes vote down vote up
@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);
	}
}
 
Example 19
Project: My-Wallet-Android   File: WalletUtils.java   View source code 6 votes vote down vote up
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;
}
 
Example 20
Project: bither-android   File: WalletUtils.java   View source code 6 votes vote down vote up
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;
}
 
Example 21
Project: Finanvita   File: CurrencyFormatFragment.java   View source code 6 votes vote down vote up
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);
}
 
Example 22
Project: Securecom-Messaging   File: PassphrasePromptActivity.java   View source code 6 votes vote down vote up
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);
}
 
Example 23
Project: tigatrapp-android   File: TigaTagHandler.java   View source code 6 votes vote down vote up
@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);
	  }
  }
	
}
 
Example 24
Project: Securecom-Text   File: PassphrasePromptActivity.java   View source code 6 votes vote down vote up
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);
}
 
Example 25
Project: templecoin-android-wallet   File: WalletUtils.java   View source code 6 votes vote down vote up
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;
}
 
Example 26
Project: countdown   File: Utils.java   View source code 6 votes vote down vote up
/***
 * @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;
}
 
Example 27
Project: PrepayCredit   File: CustomTagHandler.java   View source code 6 votes vote down vote up
@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);
        }
    }
}
 
Example 28
Project: goldcoin-android   File: WalletUtils.java   View source code 6 votes vote down vote up
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;
}
 
Example 29
Project: SimpleWeatherForecast   File: MainActivity.java   View source code 6 votes vote down vote up
@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();
}
 
Example 30
Project: apps-android-wikipedia   File: PageHeaderView.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 31
Project: mobile-store   File: Utils.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 32
Project: SpanEZ   File: SpanEZTest.java   View source code 5 votes vote down vote up
@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));
}
 
Example 33
Project: chromium-for-android-56-debug-video   File: GeolocationSnackbarController.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 34
Project: chromium-for-android-56-debug-video   File: ExpandablePreferenceGroup.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 35
Project: android-crond   File: Crond.java   View source code 5 votes vote down vote up
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;
}
 
Example 36
Project: aos-Video   File: BrowserBySmb.java   View source code 5 votes vote down vote up
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);
}
 
Example 37
Project: Slide-RSS   File: SpoilerRobotoTextView.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 38
Project: HtmlCompat   File: HtmlToSpannedConverter.java   View source code 5 votes vote down vote up
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));
    }
}
 
Example 39
Project: Exoplayer2Radio   File: Tx3gDecoder.java   View source code 5 votes vote down vote up
@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);
  }
}
 
Example 40
Project: AndroidProjectsClient   File: Formatter.java   View source code 5 votes vote down vote up
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;
}