List of usage examples for android.text SpannableStringBuilder SpannableStringBuilder
public SpannableStringBuilder(CharSequence text)
From source file:org.mozilla.gecko.home.HistoryPanel.java
/** * Make Span that is clickable, italicized, and underlined * between the string markers <code>FORMAT_S1</code> and * <code>FORMAT_S2</code>./*from w w w. j a va 2s.co m*/ * * @param text String to format * @return formatted SpannableStringBuilder, or null if there * is not any text to format. */ private SpannableStringBuilder formatHintText(String text) { // Set formatting as marked by string placeholders. final int underlineStart = text.indexOf(FORMAT_S1); final int underlineEnd = text.indexOf(FORMAT_S2); // Check that there is text to be formatted. if (underlineStart >= underlineEnd) { return null; } final SpannableStringBuilder ssb = new SpannableStringBuilder(text); // Set italicization. ssb.setSpan(new StyleSpan(Typeface.ITALIC), 0, ssb.length(), 0); // Set clickable text. final ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View widget) { Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.HOMESCREEN, "hint-private-browsing"); try { final JSONObject json = new JSONObject(); json.put("type", "Menu:Open"); EventDispatcher.getInstance().dispatchEvent(json, null); } catch (JSONException e) { Log.e(LOGTAG, "Error forming JSON for Private Browsing contextual hint", e); } } }; ssb.setSpan(clickableSpan, 0, text.length(), 0); // Remove underlining set by ClickableSpan. final UnderlineSpan noUnderlineSpan = new UnderlineSpan() { @Override public void updateDrawState(TextPaint textPaint) { textPaint.setUnderlineText(false); } }; ssb.setSpan(noUnderlineSpan, 0, text.length(), 0); // Add underlining for "Private Browsing". ssb.setSpan(new UnderlineSpan(), underlineStart, underlineEnd, 0); ssb.delete(underlineEnd, underlineEnd + FORMAT_S2.length()); ssb.delete(underlineStart, underlineStart + FORMAT_S1.length()); return ssb; }
From source file:com.github.irshulx.Components.InputExtensions.java
public CustomEditText getNewEditTextInst(final String hint, CharSequence text) { final CustomEditText editText = new CustomEditText( new ContextThemeWrapper(this.editorCore.getContext(), R.style.WysiwygEditText)); addEditableStyling(editText);/* w ww .ja va2 s .co m*/ editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); if (hint != null) { editText.setHint(hint); } if (text != null) { setText(editText, text); } /** * create tag for the editor */ EditorControl editorTag = editorCore.createTag(EditorType.INPUT); editorTag.textSettings = new TextSettings(this.DEFAULT_TEXT_COLOR); editText.setTag(editorTag); editText.setBackgroundDrawable( ContextCompat.getDrawable(this.editorCore.getContext(), R.drawable.invisible_edit_text)); editText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { return editorCore.onKey(v, keyCode, event, editText); } }); editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { editText.clearFocus(); } else { editorCore.setActiveView(v); } } }); editText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { String text = Html.toHtml(editText.getText()); Object tag = editText.getTag(R.id.control_tag); if (s.length() == 0 && tag != null) editText.setHint(tag.toString()); if (s.length() > 0) { /* * if user had pressed enter, replace it with br */ for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == '\n') { CharSequence subChars = s.subSequence(0, i); SpannableStringBuilder ssb = new SpannableStringBuilder(subChars); text = Html.toHtml(ssb); if (text.length() > 0) setText(editText, text); if (i + 1 == s.length()) { s.clear(); } int index = editorCore.getParentView().indexOfChild(editText); /* if the index was 0, set the placeholder to empty, behaviour happens when the user just press enter */ if (index == 0) { editText.setHint(null); editText.setTag(R.id.control_tag, hint); } int position = index + 1; CharSequence newText = null; SpannableStringBuilder editable = new SpannableStringBuilder(); int lastIndex = s.length(); int nextIndex = i + 1; if (nextIndex < lastIndex) { newText = s.subSequence(nextIndex, lastIndex); for (int j = 0; j < newText.length(); j++) { editable.append(newText.charAt(j)); if (newText.charAt(j) == '\n') { editable.append('\n'); } } } insertEditText(position, hint, editable); break; } } } if (editorCore.getEditorListener() != null) { editorCore.getEditorListener().onTextChanged(editText, s); } } }); if (this.lineSpacing != -1) { setLineSpacing(editText, this.lineSpacing); } return editText; }
From source file:com.heath_bar.tvdb.EpisodeDetails.java
/** Populate the GUI with the data we've found */ public void PopulateStuff(TvEpisode theEpisode) { // Set Title/*from www. j av a 2s. co m*/ TextView textview = (TextView) findViewById(R.id.title); textview.setVisibility(View.VISIBLE); textview.setText(theEpisode.getSeason() + "x" + String.format("%02d", theEpisode.getNumber()) + " " + theEpisode.getName()); // Set Thumb if (theEpisode.getImage() != null && (theEpisode.getImage().getBitmap() == null || theEpisode.getImage().getUrl().equals(""))) { // do nothin } else { imageId = theEpisode.getImage().getId(); ImageButton banner = (ImageButton) findViewById(R.id.episode_thumb); banner.setImageBitmap(theEpisode.getImage().getBitmap()); banner.setVisibility(View.VISIBLE); banner.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { shareImage(); } }); } // Overview textview = (TextView) findViewById(R.id.overview_header); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.overview); textview.setVisibility(View.VISIBLE); textview.setText(theEpisode.getOverview()); // Director textview = (TextView) findViewById(R.id.director_header); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.director); textview.setVisibility(View.VISIBLE); textview.setText(theEpisode.getDirector()); // Writer textview = (TextView) findViewById(R.id.writer_header); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.writer); textview.setVisibility(View.VISIBLE); textview.setText(theEpisode.getWriter()); // Rating textview = (TextView) findViewById(R.id.rating_header); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.rating); textview.setVisibility(View.VISIBLE); textview.setText(theEpisode.getRating() + " / 10"); // First Aired textview = (TextView) findViewById(R.id.first_aired_header); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.first_aired); textview.setVisibility(View.VISIBLE); textview.setText(DateUtil.toString(theEpisode.getAirDate())); // Guest Stars textview = (TextView) findViewById(R.id.guest_stars_header); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.guest_stars); textview.setVisibility(View.VISIBLE); textview.setText(theEpisode.getGuestStars()); textview = (TextView) findViewById(R.id.imdb_link); textview.setVisibility(View.VISIBLE); final String imdbId = theEpisode.getIMDB(); if (imdbId != "") { SpannableStringBuilder ssb = new SpannableStringBuilder(getResources().getString(R.string.imdb)); ssb.setSpan(new NonUnderlinedClickableSpan(getResources().getString(R.string.imdb)) { @Override public void onClick(View v) { Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.imdb.com/title/" + imdbId)); startActivity(myIntent); } }, 0, ssb.length(), 0); ssb.setSpan(new TextAppearanceSpan(this, R.style.episode_link), 0, ssb.length(), 0); // Set the style of the text textview.setText(ssb, BufferType.SPANNABLE); textview.setMovementMethod(LinkMovementMethod.getInstance()); } }
From source file:com.hippo.ehviewer.ui.scene.GalleryListScene.java
private void setSearchBarHint(Context context, SearchBar searchBar) { Resources resources = context.getResources(); Drawable searchImage = DrawableManager.getDrawable(context, R.drawable.v_magnify_x24); SpannableStringBuilder ssb = new SpannableStringBuilder(" "); ssb.append(resources.getString(//from w w w.java 2 s . c o m EhUrl.SITE_EX == Settings.getGallerySite() ? R.string.gallery_list_search_bar_hint_exhentai : R.string.gallery_list_search_bar_hint_e_hentai)); int textSize = (int) (searchBar.getEditTextTextSize() * 1.25); if (searchImage != null) { searchImage.setBounds(0, 0, textSize, textSize); ssb.setSpan(new ImageSpan(searchImage), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } searchBar.setEditTextHint(ssb); }
From source file:io.github.hidroh.materialistic.widget.StoryView.java
private Spannable decorateUpdated() { SpannableStringBuilder sb = new SpannableStringBuilder("*"); sb.setSpan(new AsteriskSpan(getContext()), sb.length() - 1, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return sb;/* www. j ava 2 s . co m*/ }
From source file:midian.baselib.widget.PagerSlidingTabStrip.java
private void addRightIcon(TextView tab, int i, boolean isUp) { String text = pager.getAdapter().getPageTitle(i).toString() + " "; SpannableStringBuilder str = new SpannableStringBuilder(text + "[icon]"); // ?Drawable? Drawable d = getResources().getDrawable(isUp ? R.drawable.icon_tap_up : R.drawable.icon_tap_down); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); // ImageSpan/*w ww. ja va 2 s . c o m*/ ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE); str.setSpan(span, text.length(), text.length() + "[icon]".length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); tab.setText(str); }
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);//w w w . 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); setEmptyText("wallet bip32 seed is " + wallet.getKeyChainSeed().getMnemonicCode()); }
From source file:com.mybitcoin.wallet.ui.RequestCoinsFragment.java
private void updateView() { if (!isResumed()) return;//from w w w. j a v a 2s . co m final String bitcoinRequest = determineBitcoinRequestStr(true); final byte[] paymentRequest = determinePaymentRequest(true); // update qr-code final int size = (int) (256 * getResources().getDisplayMetrics().density); final String qrContent; if (config.getQrPaymentRequestEnabled()) qrContent = "BITCOIN:-" + Qr.encodeBinary(paymentRequest); else qrContent = bitcoinRequest; qrCodeBitmap = Qr.bitmap(qrContent, size); qrView.setImageBitmap(qrCodeBitmap); // update nfc ndef message final boolean nfcSuccess = Nfc.publishMimeObject(nfcManager, activity, PaymentProtocol.MIMETYPE_PAYMENTREQUEST, paymentRequest, false); // update initiate request message final SpannableStringBuilder initiateText = new SpannableStringBuilder( getString(R.string.request_coins_fragment_initiate_request_qr)); if (nfcSuccess) initiateText.append(' ').append(getString(R.string.request_coins_fragment_initiate_request_nfc)); initiateRequestView.setText(initiateText); // focus linking final int activeAmountViewId = amountCalculatorLink.activeTextView().getId(); acceptBluetoothPaymentView.setNextFocusUpId(activeAmountViewId); }
From source file:com.rimbit.android_wallet.ui.RequestCoinsFragment.java
private void updateView() { if (!isResumed()) return;/*from w w w. j a v a 2 s . co m*/ final String rimbitRequest = determineRimbitRequestStr(true); final byte[] paymentRequest = determinePaymentRequest(true); // update qr-code final int size = (int) (256 * getResources().getDisplayMetrics().density); final String qrContent; if (config.getQrPaymentRequestEnabled()) qrContent = "Rimbit:-" + Qr.encodeBinary(paymentRequest); else qrContent = rimbitRequest; qrCodeBitmap = Qr.bitmap(qrContent, size); qrView.setImageBitmap(qrCodeBitmap); // update nfc ndef message final boolean nfcSuccess = Nfc.publishMimeObject(nfcManager, activity, PaymentProtocol.MIMETYPE_PAYMENTREQUEST, paymentRequest); // update initiate request message final SpannableStringBuilder initiateText = new SpannableStringBuilder( getString(R.string.request_coins_fragment_initiate_request_qr)); if (nfcSuccess) initiateText.append(' ').append(getString(R.string.request_coins_fragment_initiate_request_nfc)); initiateRequestView.setText(initiateText); // focus linking final int activeAmountViewId = amountCalculatorLink.activeTextView().getId(); acceptBluetoothPaymentView.setNextFocusUpId(activeAmountViewId); }
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 w w w.j a v a2s .c om 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); }