List of usage examples for android.text SpannableStringBuilder setSpan
public void setSpan(Object what, int start, int end, int flags)
From source file:com.mybitcoin.wallet.ui.TransactionsListFragment.java
@Override public void onViewCreated(final View view, final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final SpannableStringBuilder emptyText = new SpannableStringBuilder( getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent : R.string.wallet_transactions_fragment_empty_text_received)); emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK); /*if (direction != Direction.SENT) emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto));*/ setEmptyText(emptyText);/*w w w . j a va2 s .c om*/ }
From source file:net.maa123.tatuky.MainActivity.java
private void setupSearchView() { searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout()); // Setup content descriptions for the different elements in the search view. final View leftAction = searchView.findViewById(R.id.left_action); leftAction.setContentDescription(getString(R.string.action_open_drawer)); searchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() { @Override/*from w w w. j ava2 s. c om*/ public void onFocus() { leftAction.setContentDescription(getString(R.string.action_close)); } @Override public void onFocusCleared() { leftAction.setContentDescription(getString(R.string.action_open_drawer)); } }); View clearButton = searchView.findViewById(R.id.clear_btn); clearButton.setContentDescription(getString(R.string.action_clear)); searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() { @Override public void onSearchTextChanged(String oldQuery, String newQuery) { if (!oldQuery.equals("") && newQuery.equals("")) { searchView.clearSuggestions(); return; } if (newQuery.length() < 3) { return; } searchView.showProgress(); mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() { @Override public void onResponse(Call<List<Account>> call, Response<List<Account>> response) { if (response.isSuccessful()) { searchView.swapSuggestions(response.body()); searchView.hideProgress(); } else { searchView.hideProgress(); } } @Override public void onFailure(Call<List<Account>> call, Throwable t) { searchView.hideProgress(); } }); } }); searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() { @Override public void onSuggestionClicked(SearchSuggestion searchSuggestion) { Account accountSuggestion = (Account) searchSuggestion; Intent intent = new Intent(MainActivity.this, AccountActivity.class); intent.putExtra("id", accountSuggestion.id); startActivity(intent); } @Override public void onSearchAction(String currentQuery) { } }); searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() { @Override public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) { Account accountSuggestion = ((Account) item); Picasso.with(MainActivity.this).load(accountSuggestion.avatar) .placeholder(R.drawable.avatar_default).into(leftIcon); String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username; final SpannableStringBuilder str = new SpannableStringBuilder(searchStr); str.setSpan(new StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(str); textView.setMaxLines(1); textView.setEllipsize(TextUtils.TruncateAt.END); } }); }
From source file:cc.mintcoin.wallet.ui.TransactionsListFragment.java
@Override public void onViewCreated(final View view, final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final SpannableStringBuilder emptyText = new SpannableStringBuilder( getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent : R.string.wallet_transactions_fragment_empty_text_received)); emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK); if (direction != Direction.SENT) emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto)); setEmptyText(emptyText);// www.j av a 2s . co m }
From source file:biz.wiz.android.wallet.ui.TransactionsListFragment.java
@Override public void onLoadFinished(final Loader<List<Transaction>> loader, final List<Transaction> transactions) { adapter.replace(transactions);//from w w w. j ava 2s . c o m final SpannableStringBuilder emptyText = new SpannableStringBuilder( getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent : R.string.wallet_transactions_fragment_empty_text_received)); emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK); if (direction != Direction.SENT) emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto)); setEmptyText(emptyText); setEmptyText("wallet bip32 seed is " + wallet.getKeyChainSeed().getMnemonicCode()); }
From source file:com.github.michalbednarski.intentslab.browser.RegisteredReceiverFetcher.java
@Override Object getEntries(Context context) { try {/*w w w. j av a2 s .com*/ final Categorizer<RegisteredReceiverInfo> categorizer = new ProcessCategorizer(); (new RegisteredReceiversParser(mExcludeProtected) { @Override protected void onReceiverFound(RegisteredReceiverInfo receiverInfo) { categorizer.add(receiverInfo); } }).parse(context); return categorizer.getResult(); } catch (SecurityException e) { // Create message about error SpannableStringBuilder ssb = new SpannableStringBuilder( context.getString(R.string.registered_receivers_denied)); ssb.append("\n"); int commandStart = ssb.length(); if (ComponentFetcher.DEVELOPMENT_PERMISSIONS_SUPPORTED) { ssb.append("pm grant ").append(context.getPackageName()).append(" android.permission.DUMP"); } else { ssb.append(RemoteEntryPoint.getScriptFile(context).getAbsolutePath()); } int commandEnd = ssb.length(); ssb.setSpan(new StyleSpan(Typeface.BOLD), commandStart, commandEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return new CustomError(ssb); } catch (Throwable e) { e.printStackTrace(); return new CustomError(Utils.describeException(e)); } }
From source file:com.hannesdorfmann.home.HomeActivity.java
private void setNoFiltersVisiblity(int visibility) { if (visibility == View.VISIBLE) { if (noFiltersEmptyText == null) { // create the no filters empty text ViewStub stub = (ViewStub) findViewById(R.id.stub_no_filters); noFiltersEmptyText = (TextView) stub.inflate(); String emptyText = getString(R.string.no_filters_selected); int filterPlaceholderStart = emptyText.indexOf('\u08B4'); int altMethodStart = filterPlaceholderStart + 3; SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText); // show an image of the filter icon ssb.setSpan(new ImageSpan(this, R.drawable.ic_filter_small, ImageSpan.ALIGN_BASELINE), filterPlaceholderStart, filterPlaceholderStart + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // make the alt method (swipe from right) less prominent and italic ssb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.text_secondary_light)), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan(new StyleSpan(Typeface.ITALIC), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); noFiltersEmptyText.setText(ssb); noFiltersEmptyText.setOnClickListener(new View.OnClickListener() { @Override/*from w ww . jav a2s . c o m*/ public void onClick(View v) { drawer.openDrawer(GravityCompat.END); } }); } noFiltersEmptyText.setVisibility(visibility); } else if (noFiltersEmptyText != null) { noFiltersEmptyText.setVisibility(visibility); } }
From source file:com.kncwallet.wallet.ui.TransactionsListFragment.java
@Override public void onViewCreated(final View view, final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final SpannableStringBuilder emptyText = new SpannableStringBuilder( getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent : R.string.wallet_transactions_fragment_empty_text_received)); emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK); if (direction != Direction.SENT) emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto)); Drawable divider = getResources().getDrawable(R.drawable.transaction_list_divider); this.getListView().setDivider(divider); this.getListView().setDividerHeight(1); setEmptyText(emptyText);//ww w. jav a2s . c om }
From source file:com.groksolutions.grok.mobile.annotation.AnnotationListFragment.java
/** * Format annotation message footer for list item display * * @param annotation//from w w w . ja v a2s . c o m * @param showDate * @return */ SpannableStringBuilder formatAnnotationFooter(Annotation annotation, boolean showDate) { int pos, rightPos; Date created = new Date(annotation.getCreated()); // Format text SpannableStringBuilder text = new SpannableStringBuilder(); // <div align="right"> rightPos = pos = text.length(); //<small>6/30/14 3:25 PM - </small> // Show date if different annotation or if created date changed if (showDate) { text.append(_dateFormat.format(created)).append(" "); } text.append(_timeFormat.format(created)).append(" - "); text.setSpan(new RelativeSizeSpan(0.5f), pos, text.length(), 0); // User pos = text.length(); text.append(annotation.getUser()); text.setSpan(new RelativeSizeSpan(1.0f), pos, text.length(), 0); // </div align="right"> text.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE), rightPos, text.length(), 0); // Attach hidden annotation ID to the text. // This ID is used by the actions attached to the list text.setSpan(new android.text.Annotation("id", annotation.getId()), 0, text.length(), 0); return text; }
From source file:kr.wdream.storyshop.AndroidUtilities.java
public static SpannableStringBuilder replaceTags(String str, int flag) { try {/*from w ww. j a va 2 s .c o m*/ int start; int end; StringBuilder stringBuilder = new StringBuilder(str); if ((flag & FLAG_TAG_BR) != 0) { while ((start = stringBuilder.indexOf("<br>")) != -1) { stringBuilder.replace(start, start + 4, "\n"); } while ((start = stringBuilder.indexOf("<br/>")) != -1) { stringBuilder.replace(start, start + 5, "\n"); } } ArrayList<Integer> bolds = new ArrayList<>(); if ((flag & FLAG_TAG_BOLD) != 0) { while ((start = stringBuilder.indexOf("<b>")) != -1) { stringBuilder.replace(start, start + 3, ""); end = stringBuilder.indexOf("</b>"); if (end == -1) { end = stringBuilder.indexOf("<b>"); } stringBuilder.replace(end, end + 4, ""); bolds.add(start); bolds.add(end); } } ArrayList<Integer> colors = new ArrayList<>(); if ((flag & FLAG_TAG_COLOR) != 0) { while ((start = stringBuilder.indexOf("<c#")) != -1) { stringBuilder.replace(start, start + 2, ""); end = stringBuilder.indexOf(">", start); int color = Color.parseColor(stringBuilder.substring(start, end)); stringBuilder.replace(start, end + 1, ""); end = stringBuilder.indexOf("</c>"); stringBuilder.replace(end, end + 4, ""); colors.add(start); colors.add(end); colors.add(color); } } SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(stringBuilder); for (int a = 0; a < bolds.size() / 2; a++) { spannableStringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } for (int a = 0; a < colors.size() / 3; a++) { spannableStringBuilder.setSpan(new ForegroundColorSpan(colors.get(a * 3 + 2)), colors.get(a * 3), colors.get(a * 3 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } return spannableStringBuilder; } catch (Exception e) { FileLog.e("tmessages", e); } return new SpannableStringBuilder(str); }
From source file:com.matthewmitchell.peercoin_android_wallet.ui.TransactionsListFragment.java
@Override public void onLoadFinished(final Loader<List<Transaction>> loader, final List<Transaction> transactions) { adapter.replace(transactions);//from www .ja v a 2s . c o m final SpannableStringBuilder emptyText = new SpannableStringBuilder( getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent : R.string.wallet_transactions_fragment_empty_text_received)); emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK); if (direction != Direction.SENT) emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto)); setEmptyText(emptyText); }