Example usage for android.text SpannableString SpannableString

List of usage examples for android.text SpannableString SpannableString

Introduction

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

Prototype

public SpannableString(CharSequence source) 

Source Link

Document

For the backward compatibility reasons, this constructor copies all spans including android.text.NoCopySpan .

Usage

From source file:org.bobstuff.bobball.ActivityStateEnum.java

private void updateStatus(final GameState currGameState) {

    SpannableStringBuilder timeLeftStr = SpannableStringBuilder
            .valueOf(getString(R.string.timeLeftLabel, gameManager.timeLeft() / 10));

    SpannableStringBuilder livesStr = formatPerPlayer(getString(R.string.livesLabel), new playstat() {
        @Override//from w w  w  . ja  va  2 s .  co m
        public int call(Player p) {
            return p.getLives();
        }
    });
    SpannableStringBuilder scoreStr = formatPerPlayer(getString(R.string.scoreLabel), new playstat() {
        @Override
        public int call(Player p) {
            return p.getScore();
        }
    });

    SpannableStringBuilder clearedStr = formatPerPlayer(getString(R.string.areaClearedLabel), new playstat() {
        @Override
        public int call(Player p) {
            Grid grid = currGameState.getGrid();
            if (grid != null)
                return currGameState.getGrid().getPercentComplete(p.getPlayerId());
            else
                return 0;
        }
    });

    //display fps
    if (secretHandshake >= 3) {

        float fps = displayLoop.getFPS();
        int color = (fps < NUMBER_OF_FRAMES_PER_SECOND * 0.98f ? Color.RED : Color.GREEN);
        SpannableString s = new SpannableString(String.format(" FPS: %2.1f", fps));

        s.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        timeLeftStr.append(s);

        color = (gameManager.getUPS() < gameManager.NUMBER_OF_UPDATES_PER_SECOND * 0.98f ? Color.RED
                : Color.GREEN);
        s = new SpannableString(String.format(" UPS: %3.1f", gameManager.getUPS()));

        s.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        timeLeftStr.append(s);
    }

    statusTopleft.setText(timeLeftStr);
    statusTopright.setText(livesStr);
    statusBotleft.setText(scoreStr);
    statusBotright.setText(clearedStr);
}

From source file:com.coinblesk.client.utils.UIUtils.java

public static SpannableString toLargeSpannable(Context context, String amount, String currency,
        float sizeSpan) {
    final int amountLength = amount.length();
    SpannableString result = new SpannableString(new StringBuffer(amount + " " + currency));
    result.setSpan(new RelativeSizeSpan(sizeSpan), 0, amountLength, 0);
    result.setSpan(new ForegroundColorSpan(Color.WHITE), 0, amountLength, 0);
    result.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.colorAccent)), amountLength,
            result.length(), 0);/* w ww .  j  a v a 2  s.com*/
    return result;
}

From source file:com.fowlcorp.homebank4android.gui.AccountRecyclerAdapter.java

private Spannable colorText(String fieldName, String value) {
    Spannable span = new SpannableString(fieldName + value + getCurrency());
    span.setSpan(/*from   w ww  .  ja va  2  s  . c o  m*/
            new ForegroundColorSpan((value.charAt(0) == '-' ? Color.rgb(206, 92, 0) : Color.rgb(78, 154, 54))),
            fieldName.length(), fieldName.length() + value.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return span;
}

From source file:se.tmeit.app.ui.members.MemberInfoFragment.java

private void setTextWithPrefix(TextView textView, int prefixResId, String str) {
    String prefixStr = getString(prefixResId);
    SpannableString teamStr = new SpannableString(prefixStr + " " + str);
    teamStr.setSpan(new RelativeSizeSpan(0.8f), 0, prefixStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    int foregroundColor = ContextCompat.getColor(getContext(), R.color.insektionen);
    teamStr.setSpan(new ForegroundColorSpan(foregroundColor), 0, prefixStr.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    textView.setText(teamStr);/*w w  w  .j a va2s .c  o m*/
}

From source file:com.securecomcode.text.notifications.MessageNotifier.java

private static void appendPushNotificationState(Context context, MasterSecret masterSecret,
        NotificationState notificationState, Cursor cursor) {
    if (masterSecret != null)
        return;/*from   w  w  w  .j  a v a 2 s  .c  om*/

    PushDatabase.Reader reader = null;
    IncomingPushMessage message;

    try {
        reader = DatabaseFactory.getPushDatabase(context).readerFor(cursor);

        while ((message = reader.getNext()) != null) {
            Recipient recipient;

            try {
                recipient = RecipientFactory.getRecipientsFromString(context, message.getSource(), false)
                        .getPrimaryRecipient();
            } catch (RecipientFormattingException e) {
                Log.w("MessageNotifier", e);
                recipient = Recipient.getUnknownRecipient(context);
            }

            Recipients recipients = RecipientFactory.getRecipientsFromMessage(context, message, false);
            long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
            SpannableString body = new SpannableString(
                    context.getString(R.string.MessageNotifier_encrypted_message));
            body.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, body.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            notificationState
                    .addNotification(new NotificationItem(recipient, recipients, null, threadId, body, null));
        }
    } finally {
        if (reader != null)
            reader.close();
    }
}

From source file:com.timekeeping.app.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Crashlytics.start(this);
    mSystemUiHelper = new SystemUiHelper(this, SystemUiHelper.LEVEL_IMMERSIVE, 0);

    mSystemUiHelper.hide();//from  w w w . j  av a  2 s .  c  o  m
    setContentView(LAYOUT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
            && Build.VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
        View decorView = getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                // Note that system bars will only be "visible" if none of the
                // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    // The system bars are visible.
                    animToolActionBar(getStatusBarHeight());
                } else {
                    if (mFistTimeHide) {
                        mFistTimeHide = false;
                        return;
                    }
                    // The system bars are NOT visible.
                    animToolActionBar(0);
                }
            }
        });
    }

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    calcActionBarHeight();
    initDrawer();

    //Let all columns to equal.
    mGv = (GridView) findViewById(R.id.schedule_gv);
    int screenWidth = DeviceUtils.getScreenSize(this, 0).Width;
    if (Prefs.getInstance(getApplication()).isLastAListView()) {
        mGv.setColumnWidth(screenWidth / 2);
    } else {
        mGv.setColumnWidth(screenWidth / 3);
    }
    mGv.setOnScrollListener(this);

    //Init speech-framework.
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, 0x1);

    //Add new item.
    mAddNewV = findViewById(R.id.add_new_time_btn);
    mAddNewV.setOnClickListener(this);

    //Adapter for grid and dummy data.
    mAdp = new ItemsGridViewListAdapter();
    mGv.setAdapter(mAdp);
    refreshGrid();

    mGv.setOnItemLongClickListener(this);

    //Customized the title of ActionBar with a right font.
    SpannableString s = new SpannableString(getString(R.string.application_name));
    s.setSpan(new TypefaceSpan(this, Fonts.FONT_LIGHT), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    // Update the action bar title with the TypefaceSpan instance
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(s);
    }
}

From source file:org.catnut.util.CatnutUtils.java

/**
 * ?/*w w  w .  ja  v  a2  s . c o  m*/
 *
 * @param boundPx the icon' s rectangle bound, if zero, use the default
 */
public static SpannableString text2Emotion(Context context, String key, int boundPx) {
    SpannableString spannable = new SpannableString(key);
    InputStream inputStream = null;
    Drawable drawable = null;
    try {
        inputStream = context.getAssets().open(TweetImageSpan.EMOTIONS_DIR + TweetImageSpan.EMOTIONS.get(key));
        drawable = Drawable.createFromStream(inputStream, null);
    } catch (IOException e) {
        Log.e(TAG, "load emotion error!", e);
    } finally {
        closeIO(inputStream);
    }
    if (drawable != null) {
        if (boundPx == 0) {
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        } else {
            drawable.setBounds(0, 0, boundPx, boundPx);
        }
        ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
        spannable.setSpan(span, 0, key.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }
    return spannable;
}

From source file:com.jwetherell.quick_response_code.EncoderActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.btnshare:
        OnClickShare(null);/*from w  ww .  ja  v a  2s . co m*/
        return true;
    case android.R.id.home:
        onBackPressed();
        return true;
    case R.id.empty:
        Statistics.getInstance(EncoderActivity.this).click();
        View menuItemView = findViewById(R.id.empty);
        PopupMenu popupMenu = new PopupMenu(this, menuItemView);
        popupMenu.inflate(R.menu.menu_contextual_wps);
        for (int i = 0; i < popupMenu.getMenu().size(); i++) {
            MenuItem itemMenu = popupMenu.getMenu().getItem(i);
            SpannableString spanString = new SpannableString(
                    popupMenu.getMenu().getItem(i).getTitle().toString());
            spanString.setSpan(new ForegroundColorSpan(Color.BLACK), 0, spanString.length(), 0);
            itemMenu.setTitle(spanString);
        }
        popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                Statistics.getInstance(EncoderActivity.this).click();
                // TODO Auto-generated method stub
                switch (item.getItemId()) {
                case R.id.wps:
                    Statistics.getInstance(EncoderActivity.this).sendStatistics(TAGS.TAG_31);
                    Intent mIntent = new Intent(EncoderActivity.this, AVActivateWpsActivity.class);
                    mIntent.putExtra("is_5ghz", getIntent().getBooleanExtra("is_5ghz", false));
                    startActivity(mIntent);
                    break;

                default:
                    break;
                }

                return false;
            }
        });
        popupMenu.show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.barbrdo.app.activities.UserProfileActivity.java

@Override
void bindControls() {
    editTextPhone.addTextChangedListener(new PhoneNumberFormattingTextWatcher(editTextPhone));
    imageViewProfilePicture.setOnClickListener(this);
    textViewSearchRadius.setOnClickListener(this);
    textViewChangePassword.setOnClickListener(this);
    SpannableString content = new SpannableString(getString(R.string.change_password));
    content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
    textViewChangePassword.setText(content);

    getView(R.id.cv_password_change).setVisibility(View.GONE);
    textViewCancel.setOnClickListener(this);
    textViewUpgrade.setOnClickListener(this);
}

From source file:de.baumann.thema.Screen_Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.license) {

        SpannableString s;/*from   ww w .java  2 s.  c o  m*/

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            s = new SpannableString(Html.fromHtml(getString(R.string.about_text), Html.FROM_HTML_MODE_LEGACY));
        } else {
            //noinspection deprecation
            s = new SpannableString(Html.fromHtml(getString(R.string.about_text)));
        }
        Linkify.addLinks(s, Linkify.WEB_URLS);

        final AlertDialog d = new AlertDialog.Builder(Screen_Main.this).setTitle(R.string.about_title)
                .setMessage(s)
                .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).show();
        d.show();
        ((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    }

    if (id == R.id.changelog) {
        Uri uri = Uri.parse("https://github.com/scoute-dich/Blue-Minimal/blob/master/CHANGELOG.md"); // missing 'http://' will cause crashed
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }

    if (id == R.id.donate) {
        Uri uri = Uri
                .parse("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NP6TGYDYP9SHY"); // missing 'http://' will cause crashed
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }

    return super.onOptionsItemSelected(item);
}