• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Text Styling
2============
3These samples shows how to style text on Android using spans, in [Java](https://github.com/googlesamples/android-text/tree/master/TextStyling-Java) and in [Kotlin](https://github.com/googlesamples/android-text/tree/master/TextStyling-Kotlin).
4
5
6Introduction
7------------
8The difference between [TextStyling-Java](https://github.com/googlesamples/android-text/tree/master/TextStyling-Java) and [TextStyling-Kotlin](https://github.com/googlesamples/android-text/tree/master/TextStyling-Kotlin) is only in the language. They have the same set of features, same class names and similar ways of testing the functionality.
9## Features
10Parse some hardcoded text and do the following:
11* Paragraphs starting with “> ” are transformed into quotes.
12* Text enclosed in “```” will be transformed into inline code block.
13* Lines starting with “+ ” or “* ” will be transformed into bullet points.
14To update the text, modify the value of `R.string.display_text`.
15This project is not meant to fully cover the markdown capabilities and has several limitations; for example, quotes do not support nesting other elements.
16
17## Implementation
18The text is parsed in the `Parser.parse` method and the spans are created in the `MarkdownBuilder.markdownToSpans` method.
19To see how to apply a span, check out `MarkdownBuilder.buildCodeBlockSpan`. To see how to apply multiple spans on the same string, see `MarkdownBuilder.buildQuoteSpan`. For examples of creating custom spans, see `BulletPointSpan`, `CodeBlockSpan` or `FontSpan`.
20
21## Testing
22Text parsing is tested with JUnit tests in `ParserTest`. Span building is tested via Android JUnit tests, in `MarkdownBuilderTest`.
23
24
25Getting Started
26---------------
27
28Clone this repository, enter the top level directory and run `./gradlew tasks`
29to get an overview of all the tasks available for this project.
30
31Some important tasks are:
32
33```
34assembleDebug - Assembles all Debug builds.
35installDebug - Installs the Debug build.
36connectedAndroidTest - Installs and runs the tests for Debug build on connected
37devices.
38test - Run all unit tests.
39```
40
41Screenshots
42-----------
43<img src="screenshots/main_activity.png" width="30%" />
44
45Support
46-------
47- Stack Overflow: http://stackoverflow.com/questions/tagged/android-text
48
49If you've found an error in this sample, please file an issue:
50https://github.com/googlesamples/android-text/issues
51
52Patches are encouraged, and may be submitted by forking this project and
53submitting a pull request through GitHub.
54
55License
56--------
57```
58Copyright 2018 The Android Open Source Project
59
60Licensed to the Apache Software Foundation (ASF) under one or more contributor
61license agreements. See the NOTICE file distributed with this work for
62additional information regarding copyright ownership. The ASF licenses this
63file to you under the Apache License, Version 2.0 (the "License"); you may not
64use this file except in compliance with the License. You may obtain a copy of
65the License at
66
67   http://www.apache.org/licenses/LICENSE-2.0
68
69Unless required by applicable law or agreed to in writing, software
70distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
71WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
72License for the specific language governing permissions and limitations under
73the License.
74```
75
76