List of usage examples for android.text SpannableStringBuilder SpannableStringBuilder
public SpannableStringBuilder(CharSequence text)
From source file:com.taobao.weex.dom.WXTextDomObject.java
/** * Update layout according to {@link #mText} and span * @param width the specified width.//from ww w .j ava 2 s. co m * @param forceWidth If true, force the text width to the specified width, otherwise, text width * may equals to or be smaller than the specified width. * @param previousLayout the result of previous layout, could be null. */ private @NonNull Layout createLayout(float width, boolean forceWidth, @Nullable Layout previousLayout) { float textWidth; textWidth = getTextWidth(mTextPaint, width, forceWidth); Layout layout; if (!FloatUtil.floatsEqual(previousWidth, textWidth) || previousLayout == null) { boolean forceRtl = false; Object direction = getStyles().get(Constants.Name.DIRECTION); if (direction != null && "text".equals(mType)) { forceRtl = direction.equals(Constants.Name.RTL); } layout = StaticLayoutProxy.create(spanned, mTextPaint, (int) Math.ceil(textWidth), Layout.Alignment.ALIGN_NORMAL, 1, 0, false, forceRtl); } else { layout = previousLayout; } if (mNumberOfLines != UNSET && mNumberOfLines > 0 && mNumberOfLines < layout.getLineCount()) { int lastLineStart, lastLineEnd; lastLineStart = layout.getLineStart(mNumberOfLines - 1); lastLineEnd = layout.getLineEnd(mNumberOfLines - 1); if (lastLineStart < lastLineEnd) { SpannableStringBuilder builder = null; if (lastLineStart > 0) { builder = new SpannableStringBuilder(spanned.subSequence(0, lastLineStart)); } else { builder = new SpannableStringBuilder(); } Editable lastLine = new SpannableStringBuilder(spanned.subSequence(lastLineStart, lastLineEnd)); builder.append(truncate(lastLine, mTextPaint, (int) Math.ceil(textWidth), textOverflow)); adjustSpansRange(spanned, builder); spanned = builder; return new StaticLayout(spanned, mTextPaint, (int) Math.ceil(textWidth), Layout.Alignment.ALIGN_NORMAL, 1, 0, false); } } return layout; }
From source file:com.jculb.wallet.ui.RequestCoinsFragment.java
private void updateView() { if (!isResumed()) return;// w ww. ja v a 2s. c o 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 = "DEFCOIN:-" + 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:us.phyxsi.gameshelf.ui.HomeActivity.java
private void setNoResultsEmptyTextVisibility(int visibility) { if (visibility == View.VISIBLE) { if (noResultsEmptyText == null) { // create the no results empty text ViewStub stub = (ViewStub) findViewById(R.id.stub_no_results); noResultsEmptyText = (TextView) stub.inflate(); String emptyText = getString(R.string.no_results_found); int addPlaceholderStart = emptyText.indexOf('\u08B4'); int altMethodStart = addPlaceholderStart + 3; SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText); // show an image of the add icon ssb.setSpan(new ImageSpan(this, R.drawable.ic_add_small, ImageSpan.ALIGN_BASELINE), addPlaceholderStart, addPlaceholderStart + 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); noResultsEmptyText.setText(ssb); }//w ww . j a v a2s . com noResultsEmptyText.setVisibility(visibility); } else if (noResultsEmptyText != null) { noResultsEmptyText.setVisibility(visibility); } }
From source file:de.jdellay.wallet.ui.RequestCoinsFragment.java
private void updateView() { if (!isResumed()) return;// w w w.jav a2s .c om 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 = "CCNCOIN:-" + 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.hamradiocoin.wallet.ui.RequestCoinsFragment.java
private void updateView() { if (!isResumed()) return;//from ww w. ja va2s .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 = CoinDefinition.coinURIScheme.toUpperCase() + ":-" + 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); // 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.amitupadhyay.aboutexample.ui.widget.CollapsingTitleLayout.java
private void createLayoutPreM(int width, float lineSpacingAdd) { layout = new StaticLayout(displayText, paint, width - titleInsetStart - titleInsetEnd, Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingAdd, true); lineCount = layout.getLineCount();//from w ww .j av a 2 s . c o m if (lineCount > maxLines) { // if it exceeds our max number of lines then truncate the text & recreate the layout int endIndex = layout.getLineEnd(maxLines - 1) - 2; // minus 2 chars for the ellipse displayText = new SpannableStringBuilder(title.subSequence(0, endIndex) + ""); layout = new StaticLayout(displayText, paint, width - titleInsetStart - titleInsetEnd, Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingAdd, true); lineCount = maxLines; } }
From source file:de.schildbach.litecoinwallet.ui.RequestCoinsFragment.java
private void updateView() { if (!isResumed()) return;//from w w w . j av a 2s . co m final String request = determineRequestStr(true); // update qr code final int size = (int) (256 * getResources().getDisplayMetrics().density); qrCodeBitmap = Qr.bitmap(request, size); qrView.setImageBitmap(qrCodeBitmap); // update ndef message final boolean nfcSuccess = Nfc.publishUri(nfcManager, getActivity(), request); // 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); // update bluetooth message final boolean serviceRunning = application.isServiceRunning(AcceptBluetoothService.class); bluetoothEnabledView.setVisibility( bluetoothAdapter != null && bluetoothAdapter.isEnabled() && serviceRunning ? View.VISIBLE : View.GONE); }
From source file:com.heath_bar.tvdb.SeriesOverview.java
/** Populate the interface with the data pulled from the webz */ private void PopulateStuff(TvSeries seriesInfo) { if (seriesInfo == null) { Toast.makeText(getApplicationContext(), "Something bad happened. No data was found.", Toast.LENGTH_SHORT).show(); return;/* ww w .j av a 2 s . c om*/ } // Set title getSupportActionBar().setTitle(seriesInfo.getName()); // Hide/Activate the favorites button if (seriesInfo.isFavorite(getApplicationContext())) { Button b = (Button) findViewById(R.id.btn_add_to_favorites); b.setVisibility(View.GONE); } else { Button b = (Button) findViewById(R.id.btn_add_to_favorites); b.setVisibility(View.VISIBLE); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Button b = (Button) findViewById(R.id.btn_add_to_favorites); b.setVisibility(View.GONE); addToFavorites(); } }); } // Set the banner ImageView imageView = (ImageView) findViewById(R.id.series_banner); imageView.setImageBitmap(seriesInfo.getImage().getBitmap()); imageView.setVisibility(View.VISIBLE); final String seriesName = seriesInfo.getName(); imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { shareImage(); } }); // Set the banner link TextView textview = (TextView) findViewById(R.id.banner_listing_link); textview.setTextColor(getResources().getColor(R.color.tvdb_green)); textview.setVisibility(View.VISIBLE); textview.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getApplicationContext(), BannerListing.class); i.putExtra("seriesId", seriesId); i.putExtra("seriesName", seriesName); startActivity(i); } }); // Set air info textview = (TextView) findViewById(R.id.airs_header); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.last_episode); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.next_episode); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.series_air_info); StringBuffer sb = new StringBuffer(); sb.append(seriesInfo.getAirDay()); if (!seriesInfo.getAirTime().equals("")) sb.append(" at " + seriesInfo.getAirTime()); if (!seriesInfo.getNetwork().equals("")) sb.append(" on " + seriesInfo.getNetwork()); textview.setText(sb.toString()); textview.setVisibility(View.VISIBLE); // Set actors textview = (TextView) findViewById(R.id.starring); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.series_actors); textview.setVisibility(View.VISIBLE); SpannableStringBuilder text = tagsBuilder(seriesInfo.getActors(), "|"); textview.setText(text, BufferType.SPANNABLE); textview.setMovementMethod(LinkMovementMethod.getInstance()); // Set rating textview = (TextView) findViewById(R.id.rating_header); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.rating); textview.setText(seriesInfo.getRating() + " / 10"); textview.setVisibility(View.VISIBLE); // Set genre textview = (TextView) findViewById(R.id.genre_header); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.genre); textview.setText(StringUtil.commafy(seriesInfo.getGenre())); textview.setVisibility(View.VISIBLE); // Set runtime textview = (TextView) findViewById(R.id.runtime_header); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.runtime); textview.setText(seriesInfo.getRuntime() + " minutes"); textview.setVisibility(View.VISIBLE); // Set overview textview = (TextView) findViewById(R.id.overview_header); textview.setVisibility(View.VISIBLE); textview = (TextView) findViewById(R.id.overview); textview.setText(seriesInfo.getOverview()); textview.setVisibility(View.VISIBLE); // Show Seasons header textview = (TextView) findViewById(R.id.seasons_header); textview.setVisibility(View.VISIBLE); // IMDB Link textview = (TextView) findViewById(R.id.imdb_link); textview.setVisibility(View.VISIBLE); final String imdbId = seriesInfo.getIMDB(); 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.heath_bar.tvdb.EpisodeDetails.java
/** Update the GUI with the specified rating */ private void setUserRatingTextView(int rating) { TextView ratingTextView = (TextView) findViewById(R.id.rating); String communityRatingText = myEpisode.getRating() + " / 10"; String ratingTextA = communityRatingText + " ("; String ratingTextB = (rating == 0) ? "rate" : String.valueOf(rating); String ratingTextC = ")"; int start = ratingTextA.length(); int end = ratingTextA.length() + ratingTextB.length(); SpannableStringBuilder ssb = new SpannableStringBuilder(ratingTextA + ratingTextB + ratingTextC); ssb.setSpan(new NonUnderlinedClickableSpan() { @Override//from www . ja v a 2 s . c o m public void onClick(View v) { showRatingDialog(); } }, start, end, 0); ssb.setSpan(new TextAppearanceSpan(getApplicationContext(), R.style.episode_link), start, end, 0); // Set the style of the text ratingTextView.setText(ssb, BufferType.SPANNABLE); ratingTextView.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:de.langerhans.wallet.ui.RequestCoinsFragment.java
private void updateView() { if (!isResumed()) return;//from www. ja v a 2 s . c om final String bitcoinRequest = determineBitcoinRequestStr(true); byte[] paymentRequest; try { paymentRequest = determinePaymentRequest(true); oldRequest = paymentRequest; } catch (IllegalArgumentException e) { paymentRequest = oldRequest; } // update qr-code final int size = (int) (256 * getResources().getDisplayMetrics().density); final String qrContent; if (config.getQrPaymentRequestEnabled()) qrContent = "DOGECOIN:-" + 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, com.google.dogecoin.protocols.payments.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); }