FastTextView


Source link: https://github.com/lsjwzh/FastTextView

FastTextView

FastTextView is faster than Android TextView. FastTextView use StaticLayout to render Spanned String, so it support most features of Android TextView.

Inspired by : https://engineering.instagram.com/improving-comment-rendering-on-android-a77d5db3d82e

Features

1.Faster measuring

2.More flexibility

3.Support Stroke Text (More accurate method to measure stroke text and italic text)

4.Correct Ellipsis handle with ImageSpan

FastTextView vs Android TextView

Rendering a SpannableString of 389 chars with ClickableSpan and ImageSpan. Call 'onMeasure'?'onDraw' 1000 times. Here are the test results on MI MAX (Android 6.0.1):

D/FastTextLayoutView: FastTextLayoutView onMeasure cost:0 D/FastTextView: FastTextView onMeasure cost:1 D/TestTextView: TestTextView measure cost:104 D/FastTextLayoutView: FastTextLayoutView onDraw cost:271 D/FastTextView: FastTextView onDraw cost:250 D/TestTextView: TestTextView onDraw cost:249 

You can see FastTextView's 'onMeasure' almost no time consuming.

Basic Usage

repositories {

  ...
  jcenter()
  ... 
}
  dependencies {

  ...
  compile 'com.lsjwzh.widget:FastTextView:1.1.5'
  ... 
}
 

java code


 FastTextView fastTextView = (FastTextView) mRootView.findViewById(R.id.fast_tv2);

  fastTextView.setText(spannableString);
 

Advance Usage

Use Layout directly

java code


 TextPaint textPaint = new TextPaint();

  textPaint.setAntiAlias(true);

  textPaint.setColor(Color.WHITE);

  float textSize = TypedValue.applyDimension(

 TypedValue.COMPLEX_UNIT_SP, 20, getResources().getDisplayMetrics());

  textPaint.setTextSize(textSize);

  FastTextLayoutView fastTextLayoutView = (FastTextLayoutView) mRootView.findViewById(R.id.fast_tv);

  int width = Layout.getDesiredWidth(spannableStringBuilder, textPaint);

StaticLayout layout = new StaticLayout(spannableStringBuilder, textPaint,

 Math.min(width, getResources().getDisplayMetrics().widthPixels), Layout.Alignment.ALIGN_NORMAL,

 1.0f, 0.0f, true);

  fastTextLayoutView.setTextLayout(layout);
 

Single Line Stroke Text

java code


 ... ...
  StrokeSpan strokeSpan = new StrokeSpan(Color.BLUE, Color.YELLOW, 20);

  spannableStringBuilder.setSpan(strokeSpan, 0, spannableStringBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

  FastTextView fastTextView = (FastTextView) mRootView.findViewById(R.id.fast_tv2);

  fastTextView.setText(spannableStringBuilder);
 

Read More


  ReadMoreTextView readMoreTextView = (ReadMoreTextView) mRootView.findViewById(R.id.readmore_tv);

  readMoreTextView.setText(spannableStringBuilder);

  readMoreTextView.setCustomEllipsisSpan(new ReadMoreTextView.EllipsisSpan("  Read More"));

  readMoreTextView.setCustomCollapseSpan(new ReadMoreTextView.EllipsisSpan("  Collapse"));
 

TODO List

1.Layout Cache (For List Scene)

2.ColorState background

3.ReadMore

4.Ellipsis

5.AutoSize

License

Copyright 2017 lsjwzh  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

Android Color picker is a custom image or drawable color picker. It is very easy to use and customize. It tracks the color changes continuously on moving picker and also tracks color changes on tap of color picker.

Gorgeous Android Time and Date picker library inspired by the Timely app.

The ExpandableConstraintLayout presents itself as a wrapper around Google's ConstraintLayout with the small feature of toggling (expansion/collapse).

ChartProgressBar is an android library to build a bar chart with progress bar style.

Country gives a list of countries with all their flags.

A circular seekbar for Android, with a control knob! (for the lack of a better word).

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