Spanner


Source link: https://github.com/neworld/spanner

This lib provides simple and fluent API for creating Android Spannable. Features:

  • Simple and fluent API
  • Helpers to create spans
  • Small method footprint (<200 methods, 28kb AAR package)

This library focuses on building spannable. If you prefer put full text first and then apply spans, take a look at another awesome library

Examples:

Spannable spannable = new Spanner()

.append("Original text\n\n")

.append("Big and blurry\n", Spans.sizePX(100))

.span("blurry", blur(5.0f, BlurMaskFilter.Blur.SOLID))

.append("big in DP\n", sizeDP(30))

.append("50% of original size\n", scaleSize(0.5f))

.append("bold\n", bold())

.append("italic\n", italic())

.append("bold and italic\n", boldItalic())

.append("custom typeface\n", font("sans-serif-black"))

.append("strike through\n", strikeThrough())

.append("underline\n", underline())

.append("background\n", background(Color.YELLOW))

.append("foreground\n", foreground(Color.RED))

.append("subscript\n", subscript())

.append("superscript\n", superscript())

.append(" \n", image(getResources().getDrawable(R.drawable.ic_android_16dp)))

.append("quite\n", quote())

.append("The quick brown fox jumps over the lazy dog\n", bold(), foreground(0xFF904f1c), Spans.quote())

.append("Custom\n", custom(new CustomSpan()))

.append("Click here\n", click(onClickListener))

.append("http://www.android.com\n", url("http://www.android.com"))

;

It looks like:

You can manipulate text in many more ways:

Spannable spannable = new Spanner("The quick brown fox jumps over the lazy dog")

.span("fox", foreground(Color.RED)) // search and span by given text

.replace("dog", "cat", strikeThrough()) // any number of spans

.insert(5, "foo", bold(), italic()) // any number of spans

.append("bar", underline());
 // any number of spans

If you need custom span, you need span builder:

//java 7 Spannable spannable = new Spanner("The quick brown fox jumps over the lazy dog")

.span("fox", custom(new SpanBuilder() {

@Override

public Object build() {

 return new StyleSpan(Typeface.ITALIC);

}

  
}
);

//java 8 Spannable spannable = new Spanner("The quick brown fox jumps over the lazy dog")

.span("fox", custom(() -> new StyleSpan(Typeface.ITALIC));

 //kotlin val spannable = Spanner("The quick brown fox jumps over the lazy dog")

.span("fox", custom {
 StyleSpan(Typeface.ITALIC) 
}
) 

Reference

Spans:

sizePx(int) background(int color) center()
sizeDP(int) foreground(int color) alignmentOpposite()
scaleSize(float) subscript() alignmentNormal()
bold() superscript() bullet(...)
italic() image(...) imageMargin(...)
boldItalic() click(listener) leadingMargin(...)
font(String) url(url) edit(...)
strikeThrough() custom(spanBuilder) emboss(...)
underline() quote() blur(...)
tabStop(where) appearance(...) locale(...)
suggestion(...)

Text manipulation:

Methods Description
append(text, spans...) appends text
replace(search, replace, spans...) search and replace text
span(search, spans...) search text and apply spans
insert(pos, text, spans...) instert given text in given position

How to use


 allprojects {

repositories {

 ...

 maven {
 url 'https://jitpack.io' 
}

}

  
}

 dependencies {

compile 'lt.neworld:spanner:v0.3.1'
  
}
 

License

Copyright 2017 Andrius Semionovas  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

String operators for RxJava.

advanced-textview is a companion app for Advanced Android TextView talk, demonstrating:

  • Animated CompoundDrawable
  • Text shadow
  • Custom font
  • Gradient text
  • Patterned text
  • HTML.fromHtml()
  • setFontFeatureSettings()
  • Styled string
  • AlignmentSpan
  • ClickableSpan
  • Rainbow span, animated
  • Lined paper
  • Emoji

Views and Drawable for animated GIFs in Android.

Bundled GIFLib via JNI is used to render frames. This way should be more efficient than WebView or Movie classes.
Animation starts automatically and run only if View with attached GifDrawable is visible.

Gradle plugin for Android which lets you use Java generics in your XML layouts.

droidicon provides over 1600 customizable icons, 25 ready-made social badges and more! droidicon makes it super easy to add icons and badges to your app. All of the social badges are already styled.

Just add them to your app! Or you can customize the icons however you want.

Helpstack provides mobile in-app support for your app users.

With HelpStack, you can:

  • Let users report issues within your app
  • Let users attach screenshots to their support requests
  • Receive Device and App Information automatically, along with the reported issue
  • Let users view your responses to their issues
  • Provide self-support by showing FAQ articles
  • Customise your HelpStack screen to blend with your app theme
  • Integrates with Zendesk, Desk.com and HappyFox. Even works with email if you don't have a help desk account.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes