Home | History | Annotate | only in /developers/samples/android/ui/text/TextStyling-Java
Up to higher level directory
NameDateSize
app/21-Aug-2018
build.gradle21-Aug-20181.6K
gradle/21-Aug-2018
gradle.properties21-Aug-2018730
gradlew21-Aug-20184.9K
gradlew.bat21-Aug-20182.3K
README.md21-Aug-20184.2K
settings.gradle21-Aug-201815

README.md

      1 Text Styling
      2 ============
      3 This sample shows how to style text on Android using spans, in Java.
      4 
      5 Introduction
      6 ------------
      7 ## Features
      8 Parse 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.
     12 To update the text, modify the value of `R.string.display_text`.
     13 This 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
     16 The 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.
     17 To 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
     20 Text 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 
     23 Getting Started
     24 ---------------
     25 
     26 Clone this repository, enter the top level directory and run `./gradlew tasks`
     27 to get an overview of all the tasks available for this project.
     28 
     29 Some important tasks are:
     30 
     31 ```
     32 assembleDebug - Assembles all Debug builds.
     33 installDebug - Installs the Debug build.
     34 connectedAndroidTest - Installs and runs the tests for Debug build on connected
     35 devices.
     36 test - Run all unit tests.
     37 ```
     38 
     39 Screenshots
     40 -----------
     41 <img src="../screenshots/main_activity.png" width="30%" />
     42 
     43 Support
     44 -------
     45 - Stack Overflow: http://stackoverflow.com/questions/tagged/android-text
     46 
     47 If you've found an error in this sample, please file an issue:
     48 https://github.com/googlesamples/android-text/issues
     49 
     50 Patches are encouraged, and may be submitted by forking this project and
     51 submitting a pull request through GitHub.
     52 
     53 License
     54 --------
     55 ```
     56 Copyright 2018 The Android Open Source Project
     57 
     58 Licensed to the Apache Software Foundation (ASF) under one or more contributor
     59 license agreements. See the NOTICE file distributed with this work for
     60 additional information regarding copyright ownership. The ASF licenses this
     61 file to you under the Apache License, Version 2.0 (the "License"); you may not
     62 use this file except in compliance with the License. You may obtain a copy of
     63 the License at
     64 
     65    http://www.apache.org/licenses/LICENSE-2.0
     66 
     67 Unless required by applicable law or agreed to in writing, software
     68 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     69 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     70 License for the specific language governing permissions and limitations under
     71 the License.
     72 ```
     73 
     74