Search in sources :

Example 26 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project Conversations by siacs.

the class MessageAdapter method displayHeartMessage.

private void displayHeartMessage(final ViewHolder viewHolder, final String body) {
    if (viewHolder.download_button != null) {
        viewHolder.download_button.setVisibility(View.GONE);
    }
    viewHolder.image.setVisibility(View.GONE);
    viewHolder.messageBody.setVisibility(View.VISIBLE);
    viewHolder.messageBody.setIncludeFontPadding(false);
    Spannable span = new SpannableString(body);
    span.setSpan(new RelativeSizeSpan(4.0f), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    span.setSpan(new ForegroundColorSpan(activity.getWarningTextColor()), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    viewHolder.messageBody.setText(span);
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) Spannable(android.text.Spannable)

Example 27 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project android-app by spark.

the class TinkerFragment method showInstructions.

private void showInstructions() {
    View instructions = Ui.findView(this, R.id.tinker_instructions);
    // set cyan on "D7" text
    TextView instructions3 = Ui.findView(instructions, R.id.tinker_instructions_3);
    String d7 = "D7";
    String instructions3Text = getString(R.string.tinker_instructions_3);
    int idx = instructions3Text.indexOf(d7);
    int cyan = getResources().getColor(R.color.cyan);
    Spannable str = (Spannable) instructions3.getText();
    str.setSpan(new ForegroundColorSpan(cyan), idx, idx + d7.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    // set visible and then set it to disappear when we're done. and then
    // never show up again.
    instructions.setVisibility(View.VISIBLE);
    instructions.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            v.setVisibility(View.GONE);
            TinkerPrefs.getInstance().setVisited(true);
        }
    });
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) Spannable(android.text.Spannable)

Example 28 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project platform_frameworks_base by android.

the class FlashlightTile method handleUpdateState.

@Override
protected void handleUpdateState(BooleanState state, Object arg) {
    state.label = mHost.getContext().getString(R.string.quick_settings_flashlight_label);
    if (!mFlashlightController.isAvailable()) {
        Drawable icon = mHost.getContext().getDrawable(R.drawable.ic_signal_flashlight_disable).mutate();
        final int disabledColor = mHost.getContext().getColor(R.color.qs_tile_tint_unavailable);
        icon.setTint(disabledColor);
        state.icon = new DrawableIcon(icon);
        state.label = new SpannableStringBuilder().append(state.label, new ForegroundColorSpan(disabledColor), SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
        state.contentDescription = mContext.getString(R.string.accessibility_quick_settings_flashlight_unavailable);
        return;
    }
    if (arg instanceof Boolean) {
        boolean value = (Boolean) arg;
        if (value == state.value) {
            return;
        }
        state.value = value;
    } else {
        state.value = mFlashlightController.isEnabled();
    }
    final AnimationIcon icon = state.value ? mEnable : mDisable;
    state.icon = icon;
    state.contentDescription = mContext.getString(R.string.quick_settings_flashlight_label);
    state.minimalAccessibilityClassName = state.expandedAccessibilityClassName = Switch.class.getName();
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Drawable(android.graphics.drawable.Drawable) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 29 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project platform_frameworks_base by android.

the class CustomTile method handleUpdateState.

@Override
protected void handleUpdateState(State state, Object arg) {
    int tileState = mTile.getState();
    if (mServiceManager.hasPendingBind()) {
        tileState = Tile.STATE_UNAVAILABLE;
    }
    Drawable drawable;
    try {
        drawable = mTile.getIcon().loadDrawable(mContext);
    } catch (Exception e) {
        Log.w(TAG, "Invalid icon, forcing into unavailable state");
        tileState = Tile.STATE_UNAVAILABLE;
        drawable = mDefaultIcon.loadDrawable(mContext);
    }
    int color = mContext.getColor(getColor(tileState));
    drawable.setTint(color);
    state.icon = new DrawableIcon(drawable);
    state.label = mTile.getLabel();
    if (tileState == Tile.STATE_UNAVAILABLE) {
        state.label = new SpannableStringBuilder().append(state.label, new ForegroundColorSpan(color), SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
    }
    if (mTile.getContentDescription() != null) {
        state.contentDescription = mTile.getContentDescription();
    } else {
        state.contentDescription = state.label;
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Drawable(android.graphics.drawable.Drawable) RemoteException(android.os.RemoteException) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 30 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project platform_frameworks_base by android.

the class RestrictedLockUtils method setMenuItemAsDisabledByAdmin.

/**
     * Set the menu item as disabled by admin by adding a restricted padlock at the end of the
     * text and set the click listener which will send an intent to show the admin support details
     * dialog. If the admin is null, remove the padlock and disabled color span. When the admin is
     * null, we also set the OnMenuItemClickListener to null, so if you want to set a custom
     * OnMenuItemClickListener, set it after calling this method.
     */
public static void setMenuItemAsDisabledByAdmin(final Context context, final MenuItem item, final EnforcedAdmin admin) {
    SpannableStringBuilder sb = new SpannableStringBuilder(item.getTitle());
    removeExistingRestrictedSpans(sb);
    if (admin != null) {
        final int disabledColor = context.getColor(R.color.disabled_text_color);
        sb.setSpan(new ForegroundColorSpan(disabledColor), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ImageSpan image = new RestrictedLockImageSpan(context);
        sb.append(" ", image, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                sendShowAdminSupportDetailsIntent(context, admin);
                return true;
            }
        });
    } else {
        item.setOnMenuItemClickListener(null);
    }
    item.setTitle(sb);
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) MenuItem(android.view.MenuItem) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Aggregations

ForegroundColorSpan (android.text.style.ForegroundColorSpan)152 SpannableStringBuilder (android.text.SpannableStringBuilder)56 SpannableString (android.text.SpannableString)48 StyleSpan (android.text.style.StyleSpan)25 TextView (android.widget.TextView)24 ImageSpan (android.text.style.ImageSpan)23 RelativeSizeSpan (android.text.style.RelativeSizeSpan)21 View (android.view.View)21 Spannable (android.text.Spannable)20 BackgroundColorSpan (android.text.style.BackgroundColorSpan)18 TypefaceSpan (android.text.style.TypefaceSpan)16 StrikethroughSpan (android.text.style.StrikethroughSpan)14 UnderlineSpan (android.text.style.UnderlineSpan)13 Drawable (android.graphics.drawable.Drawable)12 EditText (android.widget.EditText)11 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)10 CharacterStyle (android.text.style.CharacterStyle)10 SuperscriptSpan (android.text.style.SuperscriptSpan)8 LinearLayout (android.widget.LinearLayout)8 URLSpan (android.text.style.URLSpan)7