• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

app/23-Mar-2024-1,537950

gradle/wrapper/23-Mar-2024-76

README.mdD23-Mar-20244.2 KiB7456

build.gradleD23-Mar-20241.6 KiB6355

gradle.propertiesD23-Mar-2024730 1813

gradlewD23-Mar-20244.9 KiB161120

gradlew.batD23-Mar-20242.3 KiB9166

settings.gradleD23-Mar-202415 21

README.md

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