List of usage examples for android.text SpannableString SpannableString
public SpannableString(CharSequence source)
From source file:com.bt.heliniumstudentapp.SettingsActivity.java
private void setTitles() { final Spannable prefGeneral = new SpannableString(getString(R.string.general)); final Spannable prefCustomization = new SpannableString(getString(R.string.customization)); final Spannable prefSchedule = new SpannableString(getString(R.string.schedule)); final Spannable prefGrades = new SpannableString(getString(R.string.grades)); final Spannable prefUpdate = new SpannableString(getString(R.string.updates)); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { prefGeneral.setSpan(// w ww. j a va2 s . c om new ForegroundColorSpan(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)), 0, prefGeneral.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefCustomization.setSpan( new ForegroundColorSpan(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)), 0, prefCustomization.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefSchedule.setSpan( new ForegroundColorSpan(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)), 0, prefSchedule.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefGrades.setSpan( new ForegroundColorSpan(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)), 0, prefGrades.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefUpdate.setSpan( new ForegroundColorSpan(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)), 0, prefUpdate.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { prefGeneral.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.dark_grey_dark)), 0, prefGeneral.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefCustomization.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.dark_grey_dark)), 0, prefCustomization.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefSchedule.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.dark_grey_dark)), 0, prefSchedule.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefGrades.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.dark_grey_dark)), 0, prefGrades.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefUpdate.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.dark_grey_dark)), 0, prefUpdate.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } findPreference("pref_general").setTitle(prefGeneral); findPreference("pref_customization").setTitle(prefCustomization); findPreference("pref_schedule").setTitle(prefSchedule); findPreference("pref_grades").setTitle(prefGrades); findPreference("pref_updates").setTitle(prefUpdate); }
From source file:com.app.blockydemo.ui.fragment.ScriptFragment.java
private void updateActionModeTitle() { int numberOfSelectedItems = adapter.getAmountOfCheckedItems(); String completeTitle;// w w w . j a v a 2s. c o m switch ((Integer) actionMode.getTag()) { case ACTION_MODE_COPY: completeTitle = getResources().getQuantityString(R.plurals.number_of_bricks_to_copy, numberOfSelectedItems, numberOfSelectedItems); break; case ACTION_MODE_DELETE: completeTitle = getResources().getQuantityString(R.plurals.number_of_bricks_to_delete, numberOfSelectedItems, numberOfSelectedItems); break; default: throw new IllegalArgumentException("Wrong or unhandled tag in ActionMode."); } int indexOfNumber = completeTitle.indexOf(' ') + 1; Spannable completeSpannedTitle = new SpannableString(completeTitle); completeSpannedTitle.setSpan( new ForegroundColorSpan(getResources().getColor(R.color.actionbar_title_color)), indexOfNumber, indexOfNumber + String.valueOf(numberOfSelectedItems).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); actionMode.setTitle(completeSpannedTitle); }
From source file:com.taobao.weex.dom.WXTextDomObject.java
/** * Update {@link #spanned} according to the give charSequence and styles * @param text the give raw text.//w ww . ja va 2 s.c o m * @return an Spanned contains text and spans */ protected @NonNull Spanned createSpanned(String text) { if (!TextUtils.isEmpty(text)) { SpannableString spannable = new SpannableString(text); updateSpannable(spannable, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return spannable; } return new SpannableString(""); }
From source file:com.csipsimple.service.SipNotifications.java
protected static CharSequence buildTickerMessage(Context context, String address, String body) { String displayAddress = address; StringBuilder buf = new StringBuilder( displayAddress == null ? "" : displayAddress.replace('\n', ' ').replace('\r', ' ')); buf.append(':').append(' '); int offset = buf.length(); if (!TextUtils.isEmpty(body)) { body = body.replace('\n', ' ').replace('\r', ' '); buf.append(body);/*from www . ja v a 2 s. c o m*/ } SpannableString spanText = new SpannableString(buf.toString()); spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, offset, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spanText; }
From source file:com.aegiswallet.actions.MainActivity.java
@Override public void setTitle(CharSequence title) { SpannableString s = new SpannableString(title); s.setSpan(new CustomTypefaceSpan(this, "regular.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //getActionBar().setTitle(s); mTitle = s;/* ww w .j a v a 2s. c om*/ }
From source file:org.catrobat.catroid.ui.fragment.AddBrickFragment.java
public void onBrickChecked() { if (actionMode == null) { return;//from w w w.j a v a2 s .c om } int numberOfSelectedItems = adapter.getAmountOfCheckedItems(); if (numberOfSelectedItems == 0) { actionMode.setTitle(actionModeTitle); } else { String appendix = multipleItemAppendixActionMode; if (numberOfSelectedItems == 1) { appendix = singleItemAppendixActionMode; } String numberOfItems = Integer.toString(numberOfSelectedItems); String completeTitle = actionModeTitle + " " + numberOfItems + " " + appendix; int titleLength = actionModeTitle.length(); Spannable completeSpannedTitle = new SpannableString(completeTitle); completeSpannedTitle.setSpan( new ForegroundColorSpan(getResources().getColor(R.color.actionbar_title_color)), titleLength + 1, titleLength + (1 + numberOfItems.length()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); actionMode.setTitle(completeSpannedTitle); } }
From source file:com.heath_bar.tvdb.SeriesOverview.java
/** Populate the GUI with the episode information */ private void PopulateStuffPartTwo() { // Populate the next/last episodes TvEpisode last = episodeList.getLastAired(); TvEpisode next = episodeList.getNextAired(); SpannableString text = null;//from w ww . j a v a 2s . c om TextView richTextView = (TextView) findViewById(R.id.last_episode); if (last == null) { text = new SpannableString("Last Episode: unknown"); } else { text = new SpannableString( "Last Episode: " + last.getName() + " (" + DateUtil.toString(last.getAirDate()) + ")"); NonUnderlinedClickableSpan clickableSpan = new NonUnderlinedClickableSpan() { @Override public void onClick(View view) { episodeListener.onClick(view); } }; int start = 14; int end = start + last.getName().length(); text.setSpan(clickableSpan, start, end, 0); text.setSpan(new TextAppearanceSpan(this, R.style.episode_link), start, end, 0); text.setSpan(new AbsoluteSizeSpan((int) textSize, true), 0, text.length(), 0); richTextView.setId(last.getId()); richTextView.setMovementMethod(LinkMovementMethod.getInstance()); } richTextView.setText(text, BufferType.SPANNABLE); text = null; richTextView = (TextView) findViewById(R.id.next_episode); if (seriesInfo != null && seriesInfo.getStatus() != null && !seriesInfo.getStatus().equals("Ended")) { if (next == null) { text = new SpannableString("Next Episode: unknown"); } else { text = new SpannableString( "Next Episode: " + next.getName() + " (" + DateUtil.toString(next.getAirDate()) + ")"); NonUnderlinedClickableSpan clickableSpan = new NonUnderlinedClickableSpan() { @Override public void onClick(View view) { episodeListener.onClick(view); } }; int start = 14; int end = start + next.getName().length(); text.setSpan(clickableSpan, start, end, 0); text.setSpan(new TextAppearanceSpan(this, R.style.episode_link), start, end, 0); text.setSpan(new AbsoluteSizeSpan((int) textSize, true), 0, text.length(), 0); richTextView.setId(next.getId()); richTextView.setMovementMethod(LinkMovementMethod.getInstance()); } richTextView.setText(text, BufferType.SPANNABLE); } }
From source file:android.melbournehistorymap.MapsActivity.java
/** * Manipulates the map once available.// w w w.j a v a 2s. c om * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; spinner = (ProgressBar) findViewById(R.id.prograssSpinner); //check if permission has been granted if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Permission has already been granted return; } mMap.setMyLocationEnabled(true); mMap.getUiSettings().setZoomControlsEnabled(false); double lat; double lng; final int radius; int zoom; lat = Double.parseDouble(CurrLat); lng = Double.parseDouble(CurrLong); //build current location LatLng currentLocation = new LatLng(lat, lng); final LatLng realLocation = currentLocation; if (MELBOURNE.contains(currentLocation)) { mMap.getUiSettings().setMyLocationButtonEnabled(true); zoom = 17; } else { mMap.getUiSettings().setMyLocationButtonEnabled(false); lat = -37.81161508043379; lng = 144.9647320434451; zoom = 15; currentLocation = new LatLng(lat, lng); } mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLocation, 13)); CameraPosition cameraPosition = new CameraPosition.Builder().target(currentLocation) // Sets the center of the map to location user .zoom(zoom) // Sets the zoom .bearing(0) // Sets the orientation of the camera to east .tilt(25) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder //Animate user to map location, if in Melbourne or outside of Melbourne bounds mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), new GoogleMap.CancelableCallback() { @Override public void onFinish() { updateMap(); } @Override public void onCancel() { } }); final TextView placeTitle = (TextView) findViewById(R.id.placeTitle); final TextView placeVic = (TextView) findViewById(R.id.placeVic); final TextView expPlaceTitle = (TextView) findViewById(R.id.expPlaceTitle); final TextView expPlaceVic = (TextView) findViewById(R.id.expPlaceVic); final TextView expPlaceDescription = (TextView) findViewById(R.id.placeDescription); final TextView wikiLicense = (TextView) findViewById(R.id.wikiLicense); final TextView expPlaceDistance = (TextView) findViewById(R.id.expPlaceDistance); final RelativeLayout tile = (RelativeLayout) findViewById(R.id.tile); final TextView fab = (TextView) findViewById(R.id.fab); final RelativeLayout distanceCont = (RelativeLayout) findViewById(R.id.distanceContainer); // String license = "Text is available under the <a rel=\"license\" href=\"//en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License\">Creative Commons Attribution-ShareAlike License</a><a rel=\"license\" href=\"//creativecommons.org/licenses/by-sa/3.0/\" style=\"display:none;\"></a>;\n" + // "additional terms may apply."; // wikiLicense.setText(Html.fromHtml(license)); // wikiLicense.setMovementMethod(LinkMovementMethod.getInstance()); //Marker click mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { String title = marker.getTitle(); mMap.setPadding(0, 0, 0, 620); //set clicked marker to full opacity marker.setAlpha(1f); //set previous marker back to partial opac (if there is a prevMarker if (dirtyMarker == 1) { prevMarker.setAlpha(0.6f); } prevMarker = marker; dirtyMarker = 1; //Set DB helper DBHelper myDBHelper = new DBHelper(MapsActivity.this, WikiAPI.DB_NAME, null, WikiAPI.VERSION); //Only search for Wiki API requests if no place article returned. // ** //Open DB as readable only. SQLiteDatabase db = myDBHelper.getReadableDatabase(); //Set the query String dbFriendlyName = title.replace("\'", "\'\'"); //Limit by 1 rows Cursor cursor = db.query(DBHelper.TABLE_NAME, null, "PLACE_NAME = '" + dbFriendlyName + "'", null, null, null, null, "1"); //move through each row returned in the query results while (cursor.moveToNext()) { String place_ID = cursor.getString(cursor.getColumnIndex("PLACE_ID")); String placeName = cursor.getString(cursor.getColumnIndex("PLACE_NAME")); String placeLoc = cursor.getString(cursor.getColumnIndex("PLACE_LOCATION")); String placeArticle = cursor.getString(cursor.getColumnIndex("ARTICLE")); String placeLat = cursor.getString(cursor.getColumnIndex("LAT")); String placeLng = cursor.getString(cursor.getColumnIndex("LNG")); //Get Google Place photos //Source: https://developers.google.com/places/android-api/photos final String placeId = place_ID; Places.GeoDataApi.getPlacePhotos(mGoogleApiClient, placeId) .setResultCallback(new ResultCallback<PlacePhotoMetadataResult>() { @Override public void onResult(PlacePhotoMetadataResult photos) { if (!photos.getStatus().isSuccess()) { return; } ImageView mImageView = (ImageView) findViewById(R.id.imageView); ImageView mImageViewExpanded = (ImageView) findViewById(R.id.headerImage); TextView txtAttribute = (TextView) findViewById(R.id.photoAttribute); TextView expTxtAttribute = (TextView) findViewById(R.id.expPhotoAttribute); PlacePhotoMetadataBuffer photoMetadataBuffer = photos.getPhotoMetadata(); if (photoMetadataBuffer.getCount() > 0) { // Display the first bitmap in an ImageView in the size of the view photoMetadataBuffer.get(0).getScaledPhoto(mGoogleApiClient, 600, 200) .setResultCallback(mDisplayPhotoResultCallback); //get photo attributions PlacePhotoMetadata photo = photoMetadataBuffer.get(0); CharSequence attribution = photo.getAttributions(); if (attribution != null) { txtAttribute.setText(Html.fromHtml(String.valueOf(attribution))); expTxtAttribute.setText(Html.fromHtml(String.valueOf(attribution))); //http://stackoverflow.com/questions/4303160/how-can-i-make-links-in-fromhtml-clickable-android txtAttribute.setMovementMethod(LinkMovementMethod.getInstance()); expTxtAttribute.setMovementMethod(LinkMovementMethod.getInstance()); } else { txtAttribute.setText(" "); expTxtAttribute.setText(" "); } } else { //Reset image view as no photo was identified mImageView.setImageResource(android.R.color.transparent); mImageViewExpanded.setImageResource(android.R.color.transparent); txtAttribute.setText(R.string.no_photos); expTxtAttribute.setText(R.string.no_photos); } photoMetadataBuffer.release(); } }); LatLng destLocation = new LatLng(Double.parseDouble(placeLat), Double.parseDouble(placeLng)); //Work out distance between current location and place location //Source Library: https://github.com/googlemaps/android-maps-utils double distance = SphericalUtil.computeDistanceBetween(realLocation, destLocation); distance = Math.round(distance); distance = distance * 0.001; String strDistance = String.valueOf(distance); String[] arrDistance = strDistance.split("\\."); String unit = "km"; if (arrDistance[0] == "0") { unit = "m"; strDistance = arrDistance[1]; } else { strDistance = arrDistance[0] + "." + arrDistance[1].substring(0, 1); } placeArticle = placeArticle .replaceAll("(<div class=\"thumb t).*\\s.*\\s.*\\s.*\\s.*\\s<\\/div>\\s<\\/div>", " "); Spannable noUnderlineMessage = new SpannableString(Html.fromHtml(placeArticle)); //http://stackoverflow.com/questions/4096851/remove-underline-from-links-in-textview-android for (URLSpan u : noUnderlineMessage.getSpans(0, noUnderlineMessage.length(), URLSpan.class)) { noUnderlineMessage.setSpan(new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, noUnderlineMessage.getSpanStart(u), noUnderlineMessage.getSpanEnd(u), 0); } placeArticle = String.valueOf(noUnderlineMessage); placeArticle = placeArticle.replaceAll("(\\[\\d\\])", " "); placeTitle.setText(placeName); expPlaceTitle.setText(placeName); placeVic.setText(placeLoc); expPlaceVic.setText(placeLoc); expPlaceDescription.setText(placeArticle); if (MELBOURNE.contains(realLocation)) { expPlaceDistance.setText("Distance: " + strDistance + unit); distanceCont.setVisibility(View.VISIBLE); } } tile.setVisibility(View.VISIBLE); fab.setVisibility(View.VISIBLE); //Set to true to not show default behaviour. return false; } }); mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { @Override public void onMapClick(LatLng latLng) { int viewStatus = tile.getVisibility(); if (viewStatus == View.VISIBLE) { tile.setVisibility(View.INVISIBLE); fab.setVisibility(View.INVISIBLE); //set previous marker back to partial opac (if there is a prevMarker if (dirtyMarker == 1) { prevMarker.setAlpha(0.6f); } } mMap.setPadding(0, 0, 0, 0); } }); FloatingActionButton shareIcon = (FloatingActionButton) findViewById(R.id.shareIcon); shareIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //https://www.google.com.au/maps/place/Federation+Square/@-37.8179789,144.9668635,15z //Build implicit intent by triggering a SENDTO action, which will capture applications that allow for messages //that allow for messages to be sent to a specific user with data //http://developer.android.com/reference/android/content/Intent.html#ACTION_SENDTO Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); //Build SMS String encodedPlace = "empty"; try { encodedPlace = URLEncoder.encode(String.valueOf(expPlaceTitle.getText()), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(expPlaceTitle.getText()) + " \n\nhttps://www.google.com.au/maps/place/" + encodedPlace); Intent sms = Intent.createChooser(intent, null); startActivity(sms); } }); TextView fullArticle = (TextView) findViewById(R.id.fullArticle); fullArticle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String wikiPlace = WikiPlace.getName(String.valueOf(expPlaceTitle.getText())); String url = "https://en.wikipedia.org/wiki/" + wikiPlace; Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(browserIntent); } }); }
From source file:org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder.java
private Spanned getTitleStringByFriends(int stringRes, int stringResMulti, ParcelableUser[] sources, Object[] targets) {/*from w w w . j a va2s . c o m*/ if (sources == null || sources.length == 0) return null; final Context context = adapter.getContext(); final Resources resources = context.getResources(); final Configuration configuration = resources.getConfiguration(); final UserColorNameManager manager = adapter.getUserColorNameManager(); final boolean nameFirst = adapter.isNameFirst(); final SpannableString firstSourceName = new SpannableString( manager.getDisplayName(sources[0], nameFirst, false)); firstSourceName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstSourceName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); final String displayName; final Object target = targets[0]; if (target instanceof ParcelableUser) { displayName = manager.getDisplayName((ParcelableUser) target, nameFirst, false); } else if (target instanceof ParcelableStatus) { displayName = manager.getDisplayName((ParcelableStatus) target, nameFirst, false); } else { throw new IllegalArgumentException(); } final SpannableString firstTargetName = new SpannableString(displayName); firstTargetName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstTargetName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (sources.length == 1) { final String format = context.getString(stringRes); return SpanFormatter.format(configuration.locale, format, firstSourceName, firstTargetName); } else if (sources.length == 2) { final String format = context.getString(stringResMulti); final SpannableString secondSourceName = new SpannableString( manager.getDisplayName(sources[1], nameFirst, false)); secondSourceName.setSpan(new StyleSpan(Typeface.BOLD), 0, secondSourceName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return SpanFormatter.format(configuration.locale, format, firstSourceName, secondSourceName, firstTargetName); } else { final int othersCount = sources.length - 1; final SpannableString nOthers = new SpannableString( resources.getQuantityString(R.plurals.N_others, othersCount, othersCount)); nOthers.setSpan(new StyleSpan(Typeface.BOLD), 0, nOthers.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); final String format = context.getString(stringResMulti); return SpanFormatter.format(configuration.locale, format, firstSourceName, nOthers, firstTargetName); } }
From source file:com.example.lowviscam.GalleryActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_search: return true; case R.id.action_about: // 1. Instantiate an AlertDialog.Builder with its constructor AlertDialog.Builder builder = new AlertDialog.Builder(this); // 2. Chain together various setter methods to set the dialog characteristics String aboutString = getResources().getString(R.string.dialog_message); String titleString = getResources().getString(R.string.dialog_title); SpannableString sa = new SpannableString(aboutString); SpannableString st = new SpannableString(titleString); sa.setSpan(new TypefaceSpan(this, "APHont-Regular_q15c.otf"), 0, sa.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); st.setSpan(new TypefaceSpan(this, "APHont-Bold_q15c.otf"), 0, st.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setMessage(sa).setTitle(st).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked OK button }/*from w w w . jav a2s.c o m*/ }); ; // 3. Get the AlertDialog from create() AlertDialog dialog = builder.create(); dialog.show(); return true; default: return super.onOptionsItemSelected(item); } }