List of usage examples for android.text SpannableString SpannableString
public SpannableString(CharSequence source)
From source file:com.flowzr.activity.MainActivity.java
private void setMyTabText(Tab tab, String text) { SpannableString s = new SpannableString(text); s.setSpan(new TypefaceSpan("sans-serif"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); tab.setText(s);/* w w w.j ava 2 s . com*/ }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java
private CharSequence getStyledSuggestedWord(final SuggestedWords suggestedWords, final int indexInSuggestedWords) { if (indexInSuggestedWords >= suggestedWords.size()) { return null; }/*from ww w . j a va 2s .c o m*/ final String word = suggestedWords.getLabel(indexInSuggestedWords); // TODO: don't use the index to decide whether this is the auto-correction/typed word, as // this is brittle final boolean isAutoCorrection = suggestedWords.mWillAutoCorrect && indexInSuggestedWords == SuggestedWords.INDEX_OF_AUTO_CORRECTION; final boolean isTypedWordValid = suggestedWords.mTypedWordValid && indexInSuggestedWords == SuggestedWords.INDEX_OF_TYPED_WORD; if (!isAutoCorrection && !isTypedWordValid) { return word; } final int len = word.length(); final Spannable spannedWord = new SpannableString(word); final int options = mSuggestionStripOptions; if ((isAutoCorrection && (options & AUTO_CORRECT_BOLD) != 0) || (isTypedWordValid && (options & VALID_TYPED_WORD_BOLD) != 0)) { spannedWord.setSpan(BOLD_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } if (isAutoCorrection && (options & AUTO_CORRECT_UNDERLINE) != 0) { spannedWord.setSpan(UNDERLINE_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } return spannedWord; }
From source file:com.coinblesk.client.utils.UIUtils.java
public static SpannableString toLargeSpannable(Context context, String amount, String currency) { final int amountLength = amount.length(); SpannableString result = new SpannableString(new StringBuffer(amount + " " + currency)); result.setSpan(new RelativeSizeSpan(2), 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 w w . j a v a 2s . c o m*/ return result; }
From source file:org.rm3l.ddwrt.tiles.syslog.StatusSyslogTile.java
@Override public void onLoadFinished(@NotNull Loader<NVRAMInfo> loader, @Nullable NVRAMInfo data) { //Set tiles// w ww .j a v a 2s . c o m Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data); layout.findViewById(R.id.tile_status_router_syslog_header_loading_view).setVisibility(View.GONE); layout.findViewById(R.id.tile_status_router_syslog_content_loading_view).setVisibility(View.GONE); layout.findViewById(R.id.tile_status_router_syslog_state).setVisibility(View.VISIBLE); layout.findViewById(R.id.tile_status_router_syslog_content).setVisibility(View.VISIBLE); if (data == null) { data = new NVRAMInfo().setException(new DDWRTNoDataException("No Data!")); } @NotNull final TextView errorPlaceHolderView = (TextView) this.layout .findViewById(R.id.tile_status_router_syslog_error); @Nullable final Exception exception = data.getException(); if (!(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { if (exception == null) { errorPlaceHolderView.setVisibility(View.GONE); } final String syslogdEnabledPropertyValue = data.getProperty(SYSLOGD_ENABLE); final boolean isSyslogEnabled = "1".equals(syslogdEnabledPropertyValue); final TextView syslogState = (TextView) this.layout.findViewById(R.id.tile_status_router_syslog_state); final View syslogContentView = this.layout.findViewById(R.id.tile_status_router_syslog_content); final EditText filterEditText = (EditText) this.layout .findViewById(R.id.tile_status_router_syslog_filter); syslogState.setText( syslogdEnabledPropertyValue == null ? "-" : (isSyslogEnabled ? "Enabled" : "Disabled")); syslogState.setVisibility(mDisplayStatus ? View.VISIBLE : View.GONE); final TextView logTextView = (TextView) syslogContentView; if (isSyslogEnabled) { //Highlight textToFind for new log lines final String newSyslog = data.getProperty(SYSLOG, EMPTY_STRING); //Hide container if no data at all (no existing data, and incoming data is empty too) final View scrollView = layout.findViewById(R.id.tile_status_router_syslog_content_scrollview); //noinspection ConstantConditions Spanned newSyslogSpan = new SpannableString(newSyslog); final SharedPreferences sharedPreferences = this.mParentFragmentPreferences; final String existingSearch = sharedPreferences != null ? sharedPreferences.getString(getFormattedPrefKey(LAST_SEARCH), null) : null; if (!isNullOrEmpty(existingSearch)) { if (isNullOrEmpty(filterEditText.getText().toString())) { filterEditText.setText(existingSearch); } if (!isNullOrEmpty(newSyslog)) { //noinspection ConstantConditions newSyslogSpan = findAndHighlightOutput(newSyslog, existingSearch); } } // if (!(isNullOrEmpty(existingSearch) || isNullOrEmpty(newSyslog))) { // filterEditText.setText(existingSearch); // //noinspection ConstantConditions // newSyslogSpan = findAndHighlightOutput(newSyslog, existingSearch); // } if (isNullOrEmpty(logTextView.getText().toString()) && isNullOrEmpty(newSyslog)) { scrollView.setVisibility(View.INVISIBLE); } else { scrollView.setVisibility(View.VISIBLE); logTextView.setMovementMethod(new ScrollingMovementMethod()); logTextView.append( new SpannableStringBuilder().append(Html.fromHtml("<br/>")).append(newSyslogSpan)); } filterEditText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (filterEditText.getRight() - filterEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { //Reset everything filterEditText.setText(EMPTY_STRING); //this will trigger the TextWatcher, thus disabling the "Find" button //Highlight text in textview final String currentText = logTextView.getText().toString(); logTextView.setText(currentText.replaceAll(SLASH_FONT_HTML, EMPTY_STRING) .replaceAll(FONT_COLOR_YELLOW_HTML, EMPTY_STRING)); if (sharedPreferences != null) { final SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING); editor.apply(); } return true; } } return false; } }); filterEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { final String textToFind = filterEditText.getText().toString(); if (isNullOrEmpty(textToFind)) { //extra-check, even though we can be pretty sure the button is enabled only if textToFind is present return true; } if (sharedPreferences != null) { if (textToFind.equalsIgnoreCase(existingSearch)) { //No need to go further as this is already the string we are looking for return true; } final SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(getFormattedPrefKey(LAST_SEARCH), textToFind); editor.apply(); } //Highlight text in textview final String currentText = logTextView.getText().toString(); logTextView.setText( findAndHighlightOutput(currentText.replaceAll(SLASH_FONT_HTML, EMPTY_STRING) .replaceAll(FONT_COLOR_YELLOW_HTML, EMPTY_STRING), textToFind)); return true; } return false; } }); } } if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { //noinspection ThrowableResultOfMethodCallIgnored final Throwable rootCause = Throwables.getRootCause(exception); errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null")); final Context parentContext = this.mParentFragmentActivity; errorPlaceHolderView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { //noinspection ThrowableResultOfMethodCallIgnored if (rootCause != null) { Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show(); } } }); errorPlaceHolderView.setVisibility(View.VISIBLE); } doneWithLoaderInstance(this, loader, R.id.tile_status_router_syslog_togglebutton_title, R.id.tile_status_router_syslog_togglebutton); Log.d(LOG_TAG, "onLoadFinished(): done loading!"); }
From source file:com.grepsound.fragments.MyProfileFragment.java
@Override public void onRequestSuccess(User profile) { mProfile = profile;//from w ww . ja v a 2 s .c om mImgLoader.DisplayImage(profile.getLargeAvatarUrl(), mUserCover); mName.setText(profile.getUsername()); mSpannableString = new SpannableString(profile.getUsername()); mFollowers.setCounter(Integer.parseInt(profile.getFollowersCount())); mFollowing.setCounter(Integer.parseInt(profile.getFollowingCount())); mCity.setText(profile.getCity()); }
From source file:io.vit.vitio.Settings.SettingsActivity.java
@Override protected void onResume() { super.onResume(); toolbar.setBackgroundColor(getResources().getColor(R.color.darkgray)); SpannableString s = new SpannableString("SETTINGS"); s.setSpan(myTheme.getMyThemeTypeFaceSpan(), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); getSupportActionBar().setTitle(s);/*w w w . j av a2 s . c o m*/ }
From source file:org.fdroid.enigtext.notifications.MessageNotifier.java
private static NotificationState constructNotificationState(Context context, MasterSecret masterSecret, Cursor cursor) {/* w ww . ja v a 2 s . c o m*/ NotificationState notificationState = new NotificationState(); MessageRecord record; MmsSmsDatabase.Reader reader; if (masterSecret == null) reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor); else reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor, masterSecret); while ((record = reader.getNext()) != null) { Recipient recipient = record.getIndividualRecipient(); Recipients recipients = record.getRecipients(); long threadId = record.getThreadId(); SpannableString body = record.getDisplayBody(); Uri image = null; // XXXX This is so fucked up. FIX ME! if (body.toString().equals(context.getString(R.string.MessageDisplayHelper_decrypting_please_wait))) { 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, threadId, body, image)); } reader.close(); return notificationState; }
From source file:de.baumann.thema.FragmentWallpaper.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.color) { ColorPickerDialogBuilder.with(getActivity()).initialColor(0xff2196f3).setTitle(R.string.custom) .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER).density(9) .setPositiveButton(R.string.yes, new ColorPickerClickListener() { @Override/*from w w w . j av a 2 s.c om*/ public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) { try { WallpaperManager wm = WallpaperManager.getInstance(getActivity()); // Create 1x1 bitmap to store the color Bitmap bmp = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Make a canvas with which we can draw to the bitmap Canvas canvas = new Canvas(bmp); // Fill with color and save canvas.drawColor(selectedColor); canvas.save(); wm.setBitmap(bmp); bmp.recycle(); Snackbar.make(imgHeader, R.string.applying, Snackbar.LENGTH_LONG).show(); } catch (IOException e) { // oh lord! } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).build().show(); return false; } if (id == R.id.help) { SpannableString s; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { s = new SpannableString( Html.fromHtml(getString(R.string.help_wallpaper), Html.FROM_HTML_MODE_LEGACY)); } else { //noinspection deprecation s = new SpannableString(Html.fromHtml(getString(R.string.help_wallpaper))); } Linkify.addLinks(s, Linkify.WEB_URLS); final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.title_wallpaper).setMessage(s) .setPositiveButton(getString(R.string.yes), null); dialog.show(); return false; } return super.onOptionsItemSelected(item); }
From source file:io.github.hidroh.materialistic.data.HackerNewsItem.java
@NonNull private SpannableString createAuthorSpannable(boolean authorLink) { SpannableString bySpannable = new SpannableString(AUTHOR_SEPARATOR + by); if (!authorLink) { return bySpannable; }// w ww.jav a 2 s. c om bySpannable.setSpan(new StyleSpan(Typeface.BOLD), AUTHOR_SEPARATOR.length(), bySpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View view) { view.getContext() .startActivity(new Intent(Intent.ACTION_VIEW).setData(AppUtils.createUserUri(getBy()))); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; bySpannable.setSpan(clickableSpan, AUTHOR_SEPARATOR.length(), bySpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return bySpannable; }
From source file:com.just.agentweb.AgentWebUtils.java
static void show(View parent, CharSequence text, int duration, @ColorInt int textColor, @ColorInt int bgColor, CharSequence actionText, @ColorInt int actionTextColor, View.OnClickListener listener) { SpannableString spannableString = new SpannableString(text); ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor); spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration)); Snackbar snackbar = snackbarWeakReference.get(); View view = snackbar.getView(); view.setBackgroundColor(bgColor);/*from w w w . j a v a 2 s . c om*/ if (actionText != null && actionText.length() > 0 && listener != null) { snackbar.setActionTextColor(actionTextColor); snackbar.setAction(actionText, listener); } snackbar.show(); }