{"id":22951854,"url":"https://github.com/fueled/snippety","last_synced_at":"2025-08-13T00:32:57.881Z","repository":{"id":60929949,"uuid":"92343196","full_name":"Fueled/snippety","owner":"Fueled","description":"A wrapper class on top of SpannableStringBuilder with utility methods for android and custom spans.","archived":false,"fork":false,"pushed_at":"2022-10-07T08:07:33.000Z","size":4898,"stargazers_count":50,"open_issues_count":0,"forks_count":3,"subscribers_count":19,"default_branch":"master","last_synced_at":"2023-05-15T06:50:18.405Z","etag":null,"topics":["snippety","span","spannablestring","spannablestringbuilder","spans","truss"],"latest_commit_sha":null,"homepage":"https://medium.com/fueled-android/style-your-text-using-snippety-9d205eb02fde","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Fueled.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-24T22:51:07.000Z","updated_at":"2023-03-15T05:03:03.000Z","dependencies_parsed_at":"2023-01-19T15:32:23.181Z","dependency_job_id":null,"html_url":"https://github.com/Fueled/snippety","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fueled%2Fsnippety","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fueled%2Fsnippety/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fueled%2Fsnippety/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fueled%2Fsnippety/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fueled","download_url":"https://codeload.github.com/Fueled/snippety/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229718664,"owners_count":18113553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["snippety","span","spannablestring","spannablestringbuilder","spans","truss"],"created_at":"2024-12-14T15:19:05.685Z","updated_at":"2024-12-14T15:19:06.281Z","avatar_url":"https://github.com/Fueled.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# snippety-android [![](https://jitpack.io/v/Fueled/snippety.svg)](https://jitpack.io/#Fueled/snippety)\n\nA wrapper class on top of `SpannableStringBuilder` with utility methods for android and custom spans.\nYou can trust [Snippety](./snippety/src/main/java/com/fueled/snippety/core/Snippety.java) and [Truss](./snippety/src/main/java/com/fueled/snippety/core/Truss.java) (by Jake Warton) to write cool text snippets which might be a pain in the neck otherwise.\n\n\u003cimg src=\"./README_images/ic_demo_screen.png\" width=\"274\" height=\"507\"/\u003e\u003cimg src=\"./README_images/ic_page_screen.png\" width=\"274\" height=\"507\"/\u003e\u003cimg src=\"./README_images/ic_html_screen.png\" width=\"274\" height=\"507\"/\u003e\n\n# Installation\n\nAdd the following to your root `build.gradle` at the end of repositories:\n\n```groovy\nallprojects {\n    repositories {\n        ...\n        maven { url \"https://jitpack.io\" }\n    }\n}\n```\n\nAdd the following dependency to your app `build.gradle`:\n\n```groovy\ndependencies {\n    compile 'com.github.fueled:snippety:{latest_version}'\n}\n```\n\n# How to use\n\n## Using Truss\n\n`Truss` returns a `CharSequence`. There are 2 ways of using it:\n\n1. Nested append : `pushSpan(Span)`, `append(String)` and `popSpan()`\n\n```java\nCharSequence text = new Truss()\n        .pushSpan(new BackgroundColorSpan(Color.RED))\n        .append(\"Hello Snippety\")\n        .popSpan()\n        .build();\n\n```\n\n2. Inline append : `append(String, Span)`\n\n```java\nCharSequence text = new Truss()\n        .append(\"Hello Snippety\", new BackgroundColorSpan(Color.RED))\n        .build();\n```\n\n## Using Snippety\n\n`Snippety` could be thought of as a collection of different span(s) which are anything but wrappers around the actual span(s).\n\n```java\nCharSequence text = new Truss()\n        .append(\"Hello Snippety\", new Snippety().backgroundColor(Color.RED))\n        .build();\n```\n\nYou can also add multiple span attributes at a time.\n\n```java\nCharSequence text = new Truss()\n        .append(\"Hello Snippety\", new Snippety().backgroundColor(Color.RED).textColor(Color.WHITE))\n        .build();\n```\n\n## Finally\n\nSet the `CharSequence` returned by Truss to your `TextView`.\n\n```java\ntextView.setText(new Truss()\n        .append(new Snippety().backgroundColor(Color.RED).textColor(Color.WHITE))\n        .build());\n```\n\nAttach `OnClickListener` to some text:\n\n```java\ntextView.setMovementMethod(LinkMovementMethod.getInstance());\ntextView.setText(new Truss()\n        .append(\"Click Me!\", new Snippety.OnClickListener() {\n                                @Override\n                                public void onClick() {\n                                    Toast.makeText(getContext(), \"Oooh it tickles!\", Toast.LENGTH_SHORT).show();\n                                }\n                            })\n        .build());\n```\n\n# Demo\n\nHere is how you can achieve the demo screenshot attached\n\n```java\ntextView.setText(new Truss()\n\n        .appendSelectiveln(\"With Snippety, you can use:\", \"Snippety\",\n             new Snippety().textColor(Color.RED))\n        .appendln()\n\n        .pushSpan(new Snippety().typeface(typeface)) // TextTypefaceSpan\n        .appendln(\"typeface for TypefaceSpan\")\n        .popSpan()\n\n        .appendln(\"fontStyle for StyleSpan\",\n             new Snippety().fontStyle(Snippety.FontStyle.BOLD))  //  StyleSpan\n\n        .appendln(\"fontStyle for Stylespan\",\n             new Snippety().fontStyle(Snippety.FontStyle.ITALIC))    //  StyleSpan\n\n        .appendln(\"textColor for ForegroundColorSpan\",\n             new Snippety().textColor(Color.MAGENTA))    //  ForegroundColorSpan\n\n        .appendln(\"backgroundColor for BackgroundColorSpan\",\n             new Snippety().backgroundColor(Color.YELLOW))   //  BackgroundColorSpan\n\n        .appendln(\"roundedBackgroundColor\\nfor RoundedBackgroundSpan\",\n             new Snippety().roundedBackgroundColor(Color.RED, Color.WHITE))  //  RoundedBackgroundSpan\n\n        .appendln(\"textSizeAbsolute for AbsoluteSizeSpan\",\n             new Snippety().textSizeAbsolute(textSize))  //  AbsoluteSizeSpan\n\n        .appendln(\"textSizeRelative for RelativeSizeSpan\",\n             new Snippety().textSizeRelative(1.2f))    //  RelativeSizeSpan\n\n        .appendln(\"textMultiColor for MultiColorSpan\",\n             new Snippety().textMultiColor(colorsRainbow))   //  MultiColorSpan\n\n        .appendln(\"underline for UnderlineSpan\",\n             new Snippety().underline()) //  UnderlineSpan\n\n        .append(\"image for ImageSpan\")\n        .appendln(new Snippety().image(drawable)) //  ImageSpan\n\n        .appendln(\"quote for QuoteSpan\",\n             new Snippety().quote(Color.RED))    //  QuoteSpan\n\n        .appendln(\"strikethrough for StrikethroughSpan\",\n             new Snippety().strikethrough()) //  StrikethroughSpan\n\n        .appendln(\"align for AlignmentSpan\",\n             new Snippety().align(Snippety.Indent.RIGHT))  //  AlignmentSpan\n\n        .appendln(\"url for URLSpan\",\n             new Snippety().url(\"http://developer.android.com\")) //  URLSpan\n\n        .appendln(\"addOnClickListener for ClickableSpan\",\n             new Snippety().textColor(Color.BLUE).addOnClickListener(new Snippety.OnClickListener() {\n                 @Override\n                 public void onClick() {\n                     Toast.makeText(getContext(), \"Thanks for stopping by!\", Toast.LENGTH_SHORT).show();\n                 }\n             })) //  ClickableSpan\n        .build();\n```\n\n# Snippety Snippets\n\nHere are some code snippets for `Snippety` spans (tongue twister :D)\n\n## Text Helper Spans\n\n- Typeface\n\n```java\nTypeface typeface = Typeface.createFromAsset(getContext().getAssets(), getString(R.string.font_sunshiney));\ntextView.setText(new Truss()\n        .append(\"Hello Snippety\", new Snippety().typeface(typeface))\n        .build());\n```\n\n- Font Style\n\n```java\ntextView.setText(new Truss()\n        .append(\"Hello Snippety\", new Snippety().fontStyle(Snippety.FontStyle.BOLD))\n        .build());\n```\n\n- Image Drawable\n\n```java\nDrawable drawable = ContextCompat.getDrawable(getContext(), R.mipmap.ic_launcher);\ntextView.setText(new Truss()\n        .append(new Snippety().image(drawable))\n        .build());\n```\n\n- Align\n\n```java\ntextView.setText(new Truss()\n        .append(\"Hello Snippety\", new Snippety().align(Snippety.Indent.RIGHT))\n        .build());\n```\n\n- Absolute Text Size\n\n```java\nint textSize = getResources().getDimensionPixelOffset(R.dimen.text_large);\ntextView.setText(new Truss()\n        .append(\"Hello Snippety\", new Snippety().textSizeAbsolute(textSize))\n        .build());\n```\n\n- Relative Text Size\n\n```java\ntextView.setText(new Truss()\n        .append(\"Hello Snippety\", new Snippety().textSizeRelative(1.2f))\n        .build());\n```\n\n- Background Color\n\n```java\ntextView.setText(new Truss()\n        .append(\"Hello Snippety\", new Snippety().backgroundColor(Color.RED))\n        .build());\n```\n\n- Rounded Background Color\n\n```java\ntextView.setText(new Truss()\n        .append(\"Hello Snippety\", new Snippety().roundedBackgroundColor(Color.RED, Color.WHITE))\n        .build());\n```\n\n- Text Color\n\n```java\ntextView.setText(new Truss()\n        .append(\"Hello Snippety\", new Snippety().textColor(Color.BLUE))\n        .build());\n```\n\n- Text Multi Color\n\n```java\nint[] colorsRainbow = getResources().getIntArray(R.array.rainbow);\ntextView.setText(new Truss()\n        .append(\"Hello Snippety\", new Snippety().textMultiColor(colorsRainbow))\n        .build());\n```\n\n## HTML Helper Spans\n\n- Ordered List\n\n```java\nint leadWidth = getResources().getDimensionPixelOffset(R.dimen.space_medium);\nint gapWidth = getResources().getDimensionPixelOffset(R.dimen.space_xlarge);\ntextView.setText(new Truss()\n        .appendln(\"Number One\", new Snippety().number(leadWidth, gapWidth, 1))\n        .appendln(\"Number Two\", new Snippety().number(leadWidth, gapWidth, 2))\n        .build());\n```\n\n- Unordered List\n\n```java\nint leadWidth = getResources().getDimensionPixelOffset(R.dimen.space_medium);\nint gapWidth = getResources().getDimensionPixelOffset(R.dimen.space_xlarge);\ntextView.setText(new Truss()\n        .appendln(\"Bullet One\", new Snippety().bullet(leadWidth, gapWidth))\n        .appendln(\"Bullet Two\", new Snippety().bullet(leadWidth, gapWidth))\n        .build());\n```\n\n- Custom Unordered List\n\n```java\nint leadWidth = getResources().getDimensionPixelOffset(R.dimen.space_medium);\nint gapWidth = getResources().getDimensionPixelOffset(R.dimen.space_xlarge);\ntextView.setText(new Truss()\n        .appendln(\"Custom Bullet One\", new Snippety().bullet(leadWidth, gapWidth, \"I.\"))\n        .appendln(\"Custom Bullet Two\", new Snippety().bullet(leadWidth, gapWidth, \"II.\"))\n        .build());\n```\n\n- Image Unordered List\n\n```java\nDrawable drawable = ContextCompat.getDrawable(getContext(), R.mipmap.ic_launcher);\nBitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_star_black_24dp);\nint padding = getResources().getDimensionPixelOffset(R.dimen.space_medium);\ntextView.setText(new Truss()\n        .appendln(\"Image Bullet One\", new Snippety().bullet(bitmap, padding))\n        .appendln(\"Image Bullet Two\", new Snippety().bullet(bitmap, padding))\n        .build());\n```\n\n- Horizontal Line\n\n```java\nint lineWidth = getResources().getDimensionPixelOffset(R.dimen.one_dp);\nint lineColor = ContextCompat.getColor(getContext(), R.color.grey_light);\ntextView.setText(new Truss()\n        .appendln(new Snippety().hr(lineWidth, lineColor))\n        .build());\n```\n\n# Reference\n\n- [JakeWharton/Truss.java](https://gist.github.com/JakeWharton/11274467)\n\n# License\n\n```\nCopyright 2017 Fueled\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffueled%2Fsnippety","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffueled%2Fsnippety","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffueled%2Fsnippety/lists"}