├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── bunk3r │ │ └── spanez │ │ └── sample │ │ └── MainActivity.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ └── java │ │ └── com │ │ └── bunk3r │ │ └── spanez │ │ ├── SpanEZ.java │ │ ├── api │ │ ├── ContentEZ.java │ │ ├── EZ.java │ │ ├── Locator.java │ │ └── StyleEZ.java │ │ ├── callbacks │ │ └── OnSpanClickListener.java │ │ ├── locators │ │ ├── Paragraph.java │ │ ├── Range.java │ │ └── Word.java │ │ ├── models │ │ ├── P.java │ │ ├── ParagraphLocator.java │ │ └── TargetRange.java │ │ └── spans │ │ └── ClickableSpanEZ.java │ └── test │ └── java │ └── com │ └── bunk3r │ └── spanez │ ├── SpanEZTest.java │ ├── locators │ ├── ParagraphTest.java │ ├── RangeTest.java │ └── WordTest.java │ ├── models │ └── TargetRangeTest.java │ └── spans │ └── ClickableSpanEZTest.java ├── settings.gradle └── sonar-project.properties /.gitignore: -------------------------------------------------------------------------------- 1 | # NDK 2 | .externalNativeBuild/ 3 | 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # Files for the ART/Dalvik VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # Generated files 15 | bin/ 16 | gen/ 17 | out/ 18 | 19 | # Gradle files 20 | .gradle/ 21 | build/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Log Files 30 | *.log 31 | 32 | # Android Studio Navigation editor temp files 33 | .navigation/ 34 | 35 | # Android Studio captures folder 36 | captures/ 37 | 38 | # Intellij 39 | *.iml 40 | .idea/ 41 | 42 | # Keystore files 43 | *.jks 44 | >>>>>>> origin/master 45 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | jdk: oraclejdk8 3 | sudo: false 4 | 5 | android: 6 | components: 7 | - tools 8 | - android-25 9 | - build-tools-25.0.2 10 | - platform-tools 11 | - extra-android-m2repository 12 | 13 | before_cache: 14 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 15 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 16 | - rm -fr $HOME/.sonar/cache 17 | 18 | cache: 19 | directories: 20 | - $HOME/.gradle/caches/ 21 | - $HOME/.gradle/wrapper/ 22 | - $HOME/.android/build-cache 23 | - $HOME/.sonar/cache 24 | - $HOME/.m2 25 | 26 | env: 27 | global: 28 | - secure: Ad76+gWNzIJYv+UKIaMxk+Cj2tXSMr88JgSsNaLxk3wiAs4xnknpWdIxoDqpkt6SkvYts2/27dM0bus7LkI6+Ude9ObkxExMkkFmSQwMs3nmsP6f3zUGxUiS0vfjM60u3Zn/yPtbm4N5LX48ufRpfHZfHXgeS+4JUHkWdzE6HL8ywxSQ6AM3CiEO/SS0+HROJq8uPcDng/WcB6LZW/GupHBTPXwKQEmHjZjFiDmlFjV3wX1bjPkaydsJLf0+Llxg7eAkD4t/dpTjrzZQkYZDjmx0eN/zD8gch+HioeuOU6ox9mk2wZRZVmPp6duMnAXJySSSpbKmhOCrf7FsZ6hxKzgfk9Duvz4OdIRW/zc8GboDx+1oHttbLCF8Pj8K7Rmd+gJMzhpvcKHZJb0eV0zAfC669I2ljCjIlffVliyDKPtD9YgyskG2EkkNSkAIo88KBJ0V/RzNxB5rBEn8fSXLorUwLjDQxog4Dqlh8XWt89xmmvvJj3dwz+L5xDnmRKIizTK/ovxDulfpGzQF0GD/qgF9UdHfghhsr7zhsQFaogaztiuvjKGd4+bC9fkfgzvftT3vvCp/Teorcq48ts/m09DuuS7CtxFk9RegFSmf0gPfaRIfkRttdZBbzjCIHEe9GFr+6aiVMgw20zeqOKLoSGy7Xl7YyCb3w/WiyrJls9w= 29 | - secure: tZt10m2kLImdwEWxRVKrHBE/6cVV2nOh737bc+HwBnATw7QDe+esYsHcNGWHhfAfHpyolkvdkPnoNp+mow9j7hgGIaOqpru7P5lf+5lu1Rf/rqDmaB+W8xjNA7x88g0EOihauy7IZ7Q/5gfbMlO2kYUvxqrOdOp0x/SbuAPH1AjW9B0ZC0fNxcsI3ENn+jJF80MKnEWJC12Bpp2+wjDqSVGqOtAqz1u04If15+TvIlnSGc5CNw2MyALyzXfz/qG/y1HpIdWEPSZLqT+907ZhnlEshNec7lMh2DlwHuUUcsCLAE7emfWBRdifaVAtOqrD5d7QEsJzpk8tOddbt5JfrBplic4KCQ7y4qcS9rBtdX30BpS/Oeb44RdRh87og126iLsJ2ROYR3+eItIV1d/ndkJJ007Z0oVF0jSc6iaiLOP8gjcqkQ+pdlAUu9uQr7NPma+MvMDco+A2gJymUSIefl0S8Pkx+RPmBs5Usf+Gzp3T7ieXbxdOTUJfpx+jbkU4/wNOx939UtkbhzMM3ulkEzjUhmV9vBto98WkF3MCEDH0UY2tHSadTqFS5OnCECembjGL/0AnqpfodTkxEkTBAPTkVakbqUpdta89MFmOXk0Qc/jY1bFAsxkRKeT5BbiQORmUInVxHu7NFkc+pN/ZkZN32T+4Tnh+XDS4jixl/iE= 30 | 31 | addons: 32 | sonarqube: 33 | branches: 34 | - master 35 | - development 36 | 37 | before_script: 38 | - chmod +x gradlew 39 | 40 | script: 41 | - ./gradlew build jacocoTestReport --continue 42 | 43 | after_success: 44 | - sonar-scanner 45 | - bash <(curl -s https://codecov.io/bash) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Deprecated if using Kotlin 2 | -------- 3 | If you are using Kotlin on your project, use [SpanK](https://github.com/yombunker/SpanK) instead (you can think of it as the the newest version of this library, but is meant for Kotlin only). Is better suited for Kotlin, plus has some nice quality of life inprovements that this library doesn't include just because of how verbose it would be. Please check it out and hope you enjoy it. 4 | 5 | SpanEZ 6 | ============ 7 | 8 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/yombunker/SpanEZ/blob/master/LICENSE) 9 | [![Build status](https://travis-ci.org/yombunker/SpanEZ.svg?branch=master)](https://travis-ci.org/yombunker/SpanEZ) 10 | [![Download](https://api.bintray.com/packages/yombunker/maven/spanez/images/download.svg) ](https://bintray.com/yombunker/maven/spanez/_latestVersion) 11 | 12 | Complete abstraction from the Spannable API. Forget about all the boiler plate code and all the 13 | [Object what][1] nonsense that you have to deal with when working with Spannable. 14 | 15 | * Eliminate `setSpan` calls by using all the provided methods trough the `StyleEZ` interface. 16 | * Chain multiple spans with a fluent style 17 | * By using both the `ContentEZ` and `StyleEZ` interface it removes unnecessary methods from the autocomplete form, and thus it removes clutter. 18 | * Allows different ways of adding content (String, String Resource and Formatted String) 19 | * By default it does [INCLUSIVE_INCLUSIVE][2] to all the spans 20 | * After calling any of the inclusive/exclusive methods, all the next methods will be using that flag until apply is called or another flag is used 21 | * You can create your own locator by extending the Locator interface 22 | 23 | How to use 24 | -------- 25 | 26 | Let's start with the easiest example, you need just one Span in your content 27 | 28 | ```java 29 | public class MainActivity extends AppCompatActivity { 30 | private TextView sample; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | 37 | sample = (TextView) findViewById(R.id.sample_text); 38 | SpanEZ.from(sample) // 1. pass the target TextView 39 | .withContent(R.string.lorem_ipsum) // 2. pass the content 40 | .style(Word.findAll("ipsum dolor"), BOLD | UNDERLINE) // 3. chain styles (optional) 41 | .apply(); // 4. apply 42 | } 43 | } 44 | ``` 45 | 46 | Now, let's go to the big leagues, you can get this and even more, and just with a couple of lines: 47 | 48 | ![Alt text](http://i63.tinypic.com/izcms4.png "Demo app screenshot") 49 | 50 | ```java 51 | public class MainActivity extends AppCompatActivity { 52 | private TextView sample; 53 | 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | setContentView(R.layout.activity_main); 58 | 59 | sample = (TextView) findViewById(R.id.sample_text); 60 | SpanEZ.from(sample) 61 | .withContent(R.string.lorem_ipsum) 62 | .absoluteSize(Range.from(0, 5), 20) 63 | .absoluteSizeDP(Range.from(6, 10), 34) 64 | .exclusive() 65 | .backgroundColor(Word.findFirst("ipsum dolor"), R.color.colorPrimary) 66 | .backgroundColor(Range.from(30, 50), R.color.colorPrimaryDark) 67 | .foregroundColor(Range.from(45, 100), R.color.colorAccent) 68 | .inclusiveExclusive() 69 | .style(Word.findAll("ipsum"), BOLD | UNDERLINE) 70 | .style(Word.findFirst("ipsum"), ITALIC | STRIKETHROUGH) 71 | .link(Word.findFirst("ut ultricies dolor molestie eget. Aliquam scelerisque, elit sit amet faucibus tincidunt"), "http://www.google.com") 72 | .clickable(Word.findFirst("Mauris in lacus at nulla consectetur dapibus. Sed accumsan sapien nec nisi mattis pulvinar."), new OnSpanClickListener() { 73 | @Override 74 | public void onSpanClick(String spanContent) { 75 | Toast.makeText(MainActivity.this, spanContent, Toast.LENGTH_SHORT).show(); 76 | } 77 | }) 78 | .inclusive() 79 | .quote(Paragraph.containing("Lorem")) 80 | .scaleX(Range.from(60, 80), 2) 81 | .apply(); // Calling the apply method is the only one that MUST be done in UIThread 82 | } 83 | } 84 | ``` 85 | 86 | Download 87 | -------- 88 | 89 | ```groovy 90 | dependencies { 91 | implementation 'com.bunk3r:spanez:2.x.x' 92 | } 93 | ``` 94 | 95 | License 96 | ------- 97 | 98 | Copyright 2017 Jorge Aguilar 99 | 100 | Licensed under the Apache License, Version 2.0 (the "License"); 101 | you may not use this file except in compliance with the License. 102 | You may obtain a copy of the License at 103 | 104 | http://www.apache.org/licenses/LICENSE-2.0 105 | 106 | Unless required by applicable law or agreed to in writing, software 107 | distributed under the License is distributed on an "AS IS" BASIS, 108 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 109 | See the License for the specific language governing permissions and 110 | limitations under the License. 111 | 112 | 113 | [1]: https://developer.android.com/reference/android/text/Spannable.html#setSpan(java.lang.Object, int, int, int) 114 | [2]: https://developer.android.com/reference/android/text/Spanned.html#SPAN_INCLUSIVE_INCLUSIVE 115 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion projectCompileSdk 5 | buildToolsVersion projectBuildTools 6 | defaultConfig { 7 | applicationId "com.bunk3r.spanez.sample" 8 | minSdkVersion minSdk 9 | targetSdkVersion targetSdk 10 | versionCode projectVersionCode 11 | versionName projectVersionName 12 | } 13 | 14 | buildTypes { 15 | release { 16 | minifyEnabled true 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile project(':library') 24 | compile 'com.android.support:appcompat-v7:25.1.0' 25 | } 26 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\joragu\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/bunk3r/spanez/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.TextView; 6 | import android.widget.Toast; 7 | 8 | import com.bunk3r.spanez.SpanEZ; 9 | import com.bunk3r.spanez.callbacks.OnSpanClickListener; 10 | import com.bunk3r.spanez.locators.Paragraph; 11 | import com.bunk3r.spanez.locators.Range; 12 | import com.bunk3r.spanez.locators.Word; 13 | 14 | import static com.bunk3r.spanez.api.EZ.BOLD; 15 | import static com.bunk3r.spanez.api.EZ.ITALIC; 16 | import static com.bunk3r.spanez.api.EZ.STRIKETHROUGH; 17 | import static com.bunk3r.spanez.api.EZ.UNDERLINE; 18 | 19 | public class MainActivity extends AppCompatActivity { 20 | private TextView sample; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_main); 26 | 27 | sample = (TextView) findViewById(R.id.sample_text); 28 | } 29 | 30 | @Override 31 | protected void onResume() { 32 | super.onResume(); 33 | 34 | SpanEZ.withTextView(sample) 35 | .withContent(R.string.lorem_ipsum) 36 | .absoluteSize(Range.from(0, 5), 20) 37 | .absoluteSizeDP(Range.from(6, 10), 34) 38 | .exclusive() 39 | .backgroundColor(Word.findFirst("ipsum dolor"), R.color.colorPrimary) 40 | .backgroundColor(Range.from(30, 50), R.color.colorPrimaryDark) 41 | .foregroundColor(Range.from(45, 100), R.color.colorAccent) 42 | .inclusiveExclusive() 43 | .style(Word.findAll("ipsum"), BOLD | UNDERLINE) 44 | .style(Word.findFirst("ipsum"), ITALIC | STRIKETHROUGH) 45 | .link(Word.findFirst("ut ultricies dolor molestie eget"), "http://www.google.com") 46 | .clickable(Word.findFirst("Mauris in lacus at nulla"), new OnSpanClickListener() { 47 | @Override 48 | public void onSpanClick(String spanContent) { 49 | Toast.makeText(MainActivity.this, spanContent, Toast.LENGTH_SHORT) 50 | .show(); 51 | } 52 | }) 53 | .inclusive() 54 | .quote(Paragraph.containing("Lorem")) 55 | .scaleX(Range.from(60, 80), 2) 56 | .apply(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yombunker/SpanEZ/df3acbad54049c6bb094f7fd847793af5d4831a0/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yombunker/SpanEZ/df3acbad54049c6bb094f7fd847793af5d4831a0/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yombunker/SpanEZ/df3acbad54049c6bb094f7fd847793af5d4831a0/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yombunker/SpanEZ/df3acbad54049c6bb094f7fd847793af5d4831a0/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yombunker/SpanEZ/df3acbad54049c6bb094f7fd847793af5d4831a0/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SpanEZ 3 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt est id eros pharetra eleifend. Vivamus porttitor accumsan quam, et mattis tortor fermentum quis. Quisque ut ipsum tellus. Quisque suscipit diam ut augue egestas, vel tempus nisi euismod. Curabitur accumsan molestie nisl, ut ultricies dolor molestie eget. Aliquam scelerisque, elit sit amet faucibus tincidunt, tortor purus interdum sapien, eu suscipit lorem dolor mattis libero. Morbi ut urna tempor, auctor lorem vitae, bibendum nibh. Nullam ut massa id arcu efficitur cursus. Mauris in lacus at nulla consectetur dapibus. Sed accumsan sapien nec nisi mattis pulvinar. 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | ext { 4 | projectCompileSdk = 25 5 | projectBuildTools = "25.0.2" 6 | minSdk = 17 7 | targetSdk = 25 8 | 9 | projectVersionCode = 3 10 | projectVersionName = "2.0.1" 11 | } 12 | 13 | buildscript { 14 | repositories { 15 | jcenter() 16 | } 17 | dependencies { 18 | classpath 'com.android.tools.build:gradle:2.2.3' 19 | classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1' 20 | } 21 | } 22 | 23 | allprojects { 24 | repositories { 25 | jcenter() 26 | } 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # suppress inspection "UnusedProperty" for whole file 2 | 3 | # Project-wide Gradle settings. 4 | 5 | # IDE (e.g. Android Studio) users: 6 | # Gradle settings configured through the IDE *will override* 7 | # any settings specified in this file. 8 | 9 | # For more details on how to configure your build environment visit 10 | # http://www.gradle.org/docs/current/userguide/build_environment.html 11 | 12 | # Specifies the JVM arguments used for the daemon process. 13 | # The setting is particularly useful for tweaking memory settings. 14 | # suppress inspection "UnusedProperty" 15 | org.gradle.jvmargs=-Xmx2048m 16 | 17 | # When configured, Gradle will run in incubating parallel mode. 18 | # This option should only be used with decoupled projects. More details, visit 19 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 20 | org.gradle.parallel=true 21 | org.gradle.daemon=true 22 | 23 | #Enable build cache 24 | android.enableBuildCache=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yombunker/SpanEZ/df3acbad54049c6bb094f7fd847793af5d4831a0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'jacoco-android' 3 | 4 | //noinspection GroovyMissingReturnStatement 5 | android { 6 | compileSdkVersion projectCompileSdk 7 | buildToolsVersion projectBuildTools 8 | 9 | defaultConfig { 10 | minSdkVersion minSdk 11 | targetSdkVersion targetSdk 12 | versionCode projectVersionCode 13 | versionName projectVersionName 14 | } 15 | 16 | testOptions { 17 | unitTests.returnDefaultValues = true 18 | } 19 | } 20 | 21 | dependencies { 22 | compile 'com.android.support:appcompat-v7:25.1.0' 23 | 24 | testCompile 'junit:junit:4.12' 25 | testCompile 'org.assertj:assertj-core:3.6.1' 26 | testCompile 'org.mockito:mockito-core:2.6.3' 27 | } -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\joragu\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/SpanEZ.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.Typeface; 6 | import android.support.annotation.ColorRes; 7 | import android.support.annotation.FloatRange; 8 | import android.support.annotation.IntRange; 9 | import android.support.annotation.NonNull; 10 | import android.support.annotation.StringRes; 11 | import android.support.annotation.StyleRes; 12 | import android.support.annotation.UiThread; 13 | import android.support.annotation.VisibleForTesting; 14 | import android.support.v4.content.ContextCompat; 15 | import android.text.Layout; 16 | import android.text.SpannableString; 17 | import android.text.Spanned; 18 | import android.text.method.LinkMovementMethod; 19 | import android.text.style.AbsoluteSizeSpan; 20 | import android.text.style.AlignmentSpan; 21 | import android.text.style.BackgroundColorSpan; 22 | import android.text.style.ClickableSpan; 23 | import android.text.style.ForegroundColorSpan; 24 | import android.text.style.LocaleSpan; 25 | import android.text.style.QuoteSpan; 26 | import android.text.style.RelativeSizeSpan; 27 | import android.text.style.ScaleXSpan; 28 | import android.text.style.StrikethroughSpan; 29 | import android.text.style.StyleSpan; 30 | import android.text.style.SubscriptSpan; 31 | import android.text.style.SuperscriptSpan; 32 | import android.text.style.TextAppearanceSpan; 33 | import android.text.style.TypefaceSpan; 34 | import android.text.style.URLSpan; 35 | import android.text.style.UnderlineSpan; 36 | import android.widget.TextView; 37 | 38 | import com.bunk3r.spanez.api.ContentEZ; 39 | import com.bunk3r.spanez.api.EZ; 40 | import com.bunk3r.spanez.api.Locator; 41 | import com.bunk3r.spanez.api.StyleEZ; 42 | import com.bunk3r.spanez.callbacks.OnSpanClickListener; 43 | import com.bunk3r.spanez.models.ParagraphLocator; 44 | import com.bunk3r.spanez.models.TargetRange; 45 | import com.bunk3r.spanez.spans.ClickableSpanEZ; 46 | 47 | import java.util.Locale; 48 | 49 | import static com.bunk3r.spanez.api.EZ.BOLD; 50 | import static com.bunk3r.spanez.api.EZ.ITALIC; 51 | import static com.bunk3r.spanez.api.EZ.STRIKETHROUGH; 52 | import static com.bunk3r.spanez.api.EZ.SUBSCRIPT; 53 | import static com.bunk3r.spanez.api.EZ.SUPERSCRIPT; 54 | import static com.bunk3r.spanez.api.EZ.UNDERLINE; 55 | 56 | /** 57 | * Part of SpanEZ 58 | * Created by joragu on 1/12/2017. 59 | */ 60 | 61 | public class SpanEZ implements ContentEZ, StyleEZ { 62 | private static final int RESOURCE_NOT_SET = -1; 63 | 64 | private final TextView target; 65 | private final Context context; 66 | private final Resources resources; 67 | 68 | private int spanFlags = Spanned.SPAN_INCLUSIVE_INCLUSIVE; 69 | private String content; 70 | private SpannableString spannableContent; 71 | 72 | /** 73 | * This is the starting place, once the target has been selected you can apply all the changes 74 | * to that target. 75 | * 76 | * @param target The View were the string is located 77 | * @return an SpanEZ instance were you can apply all the different span styles 78 | */ 79 | public static ContentEZ withTextView(TextView target) { 80 | return new SpanEZ(target); 81 | } 82 | 83 | private SpanEZ(@NonNull TextView targetView) { 84 | target = targetView; 85 | context = target.getContext(); 86 | resources = target.getResources(); 87 | } 88 | 89 | @Override 90 | public StyleEZ withCurrentContent() { 91 | CharSequence currentText = target.getText(); 92 | if (currentText instanceof SpannableString) { 93 | spannableContent = (SpannableString) currentText; 94 | content = spannableContent.toString(); 95 | } else { 96 | content = currentText.toString(); 97 | spannableContent = new SpannableString(content); 98 | } 99 | return this; 100 | } 101 | 102 | @Override 103 | public StyleEZ withContent(String text) { 104 | content = text; 105 | spannableContent = new SpannableString(content); 106 | return this; 107 | } 108 | 109 | @Override 110 | public StyleEZ withContent(@StringRes int textResId) { 111 | String text = resources.getString(textResId); 112 | return withContent(text); 113 | } 114 | 115 | @Override 116 | public StyleEZ withFormattedContent(@StringRes int textResId, @NonNull Object... args) { 117 | String text = resources.getString(textResId, args); 118 | return withContent(text); 119 | } 120 | 121 | @Override 122 | public StyleEZ inclusive() { 123 | spanFlags = Spanned.SPAN_INCLUSIVE_INCLUSIVE; 124 | return this; 125 | } 126 | 127 | @Override 128 | public StyleEZ inclusiveExclusive() { 129 | spanFlags = Spanned.SPAN_INCLUSIVE_EXCLUSIVE; 130 | return this; 131 | } 132 | 133 | @Override 134 | public StyleEZ exclusiveInclusive() { 135 | spanFlags = Spanned.SPAN_EXCLUSIVE_INCLUSIVE; 136 | return this; 137 | } 138 | 139 | @Override 140 | public StyleEZ exclusive() { 141 | spanFlags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; 142 | return this; 143 | } 144 | 145 | @Override 146 | public StyleEZ style(@NonNull Locator locator, @EZ.STYLE int styles) { 147 | if (isFlagSet(styles, BOLD)) { 148 | bold(locator); 149 | } 150 | 151 | if (isFlagSet(styles, ITALIC)) { 152 | italic(locator); 153 | } 154 | 155 | if (isFlagSet(styles, UNDERLINE)) { 156 | underline(locator); 157 | } 158 | 159 | if (isFlagSet(styles, STRIKETHROUGH)) { 160 | strikethrough(locator); 161 | } 162 | 163 | if (isFlagSet(styles, SUBSCRIPT)) { 164 | subscript(locator); 165 | } 166 | 167 | if (isFlagSet(styles, SUPERSCRIPT)) { 168 | superscript(locator); 169 | } 170 | return this; 171 | } 172 | 173 | /** 174 | * Applies a {@code Bold} style to all the {@code Character} within the given range. Or throws 175 | * and {@code IndexOutOfBoundsException} if the range provided is outside the content bounds. 176 | * 177 | * @param locator range were the span will be applied to 178 | */ 179 | private void bold(@NonNull Locator locator) { 180 | StyleSpan bold = new StyleSpan(Typeface.BOLD); 181 | addMultipleSpan(locator, bold); 182 | } 183 | 184 | /** 185 | * Applies an {@code Italic} style to all the {@code Character} within the given range. Or throws 186 | * and {@code IndexOutOfBoundsException} if the range provided is outside the content bounds. 187 | * 188 | * @param locator range were the span will be applied to 189 | */ 190 | private void italic(@NonNull Locator locator) { 191 | StyleSpan italic = new StyleSpan(Typeface.ITALIC); 192 | addMultipleSpan(locator, italic); 193 | } 194 | 195 | /** 196 | * Applies a {@code Underline} style to all the {@code Character} within the given range. Or throws 197 | * and {@code IndexOutOfBoundsException} if the range provided is outside the content bounds. 198 | * 199 | * @param locator range were the span will be applied to 200 | */ 201 | private void underline(@NonNull Locator locator) { 202 | UnderlineSpan underline = new UnderlineSpan(); 203 | addMultipleSpan(locator, underline); 204 | } 205 | 206 | /** 207 | * Applies an {@code Strikethrough} style (Meaning that it crosses all text with a horizontal line) 208 | * to all the {@code Character} within the given range. Or throws and {@code IndexOutOfBoundsException} 209 | * if the range provided is outside the content bounds. 210 | * 211 | * @param locator range were the span will be applied to 212 | */ 213 | private void strikethrough(@NonNull Locator locator) { 214 | StrikethroughSpan strikethroughSpan = new StrikethroughSpan(); 215 | addMultipleSpan(locator, strikethroughSpan); 216 | } 217 | 218 | /** 219 | * Applies a {@code Subscript} style to all the {@code Character} within the given range. Or throws 220 | * and {@code IndexOutOfBoundsException} if the range provided is outside the content bounds. 221 | * 222 | * @param locator range were the span will be applied to 223 | */ 224 | private void subscript(@NonNull Locator locator) { 225 | SubscriptSpan subscriptSpan = new SubscriptSpan(); 226 | addMultipleSpan(locator, subscriptSpan); 227 | } 228 | 229 | /** 230 | * Applies a {@code Superscript} style to all the {@code Character} within the given range. Or throws 231 | * and {@code IndexOutOfBoundsException} if the range provided is outside the content bounds. 232 | * 233 | * @param locator range were the span will be applied to 234 | */ 235 | private void superscript(@NonNull Locator locator) { 236 | SuperscriptSpan superscriptSpan = new SuperscriptSpan(); 237 | addMultipleSpan(locator, superscriptSpan); 238 | } 239 | 240 | @Override 241 | public StyleEZ clickable(@NonNull Locator locator, @NonNull OnSpanClickListener spanClick) { 242 | for (TargetRange targetRange : locator.locate(content)) { 243 | ClickableSpan clickSpan = ClickableSpanEZ.from(spanClick, 244 | content.substring(targetRange.getStart(), 245 | targetRange 246 | .getEnd() + 1)); 247 | target.setMovementMethod(new LinkMovementMethod()); 248 | addSpan(targetRange, clickSpan); 249 | } 250 | return this; 251 | } 252 | 253 | @Override 254 | public StyleEZ foregroundColor(@NonNull Locator locator, @ColorRes int fgColorResId) { 255 | final int fgColor = ContextCompat.getColor(context, fgColorResId); 256 | ForegroundColorSpan fgColorSpan = new ForegroundColorSpan(fgColor); 257 | addMultipleSpan(locator, fgColorSpan); 258 | return this; 259 | } 260 | 261 | @Override 262 | public StyleEZ backgroundColor(@NonNull Locator locator, @ColorRes int bgColorResId) { 263 | final int bgColor = ContextCompat.getColor(context, bgColorResId); 264 | BackgroundColorSpan bgColorSpan = new BackgroundColorSpan(bgColor); 265 | addMultipleSpan(locator, bgColorSpan); 266 | return this; 267 | } 268 | 269 | @Override 270 | public StyleEZ quote(@NonNull ParagraphLocator paragraph) { 271 | return quote(paragraph, RESOURCE_NOT_SET); 272 | } 273 | 274 | @Override 275 | public StyleEZ quote(@NonNull ParagraphLocator paragraph, @ColorRes int quoteColorResId) { 276 | final QuoteSpan quoteSpan; 277 | if (quoteColorResId == RESOURCE_NOT_SET) { 278 | quoteSpan = new QuoteSpan(); 279 | } else { 280 | final int quoteColor = ContextCompat.getColor(context, quoteColorResId); 281 | quoteSpan = new QuoteSpan(quoteColor); 282 | } 283 | 284 | addMultipleSpan(paragraph, quoteSpan); 285 | return this; 286 | } 287 | 288 | @Override 289 | public StyleEZ alignCenter(@NonNull ParagraphLocator paragraph) { 290 | AlignmentSpan centerSpan = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER); 291 | addMultipleSpan(paragraph, centerSpan); 292 | return this; 293 | } 294 | 295 | @Override 296 | public StyleEZ alignEnd(@NonNull ParagraphLocator paragraph) { 297 | AlignmentSpan oppositeSpan = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE); 298 | addMultipleSpan(paragraph, oppositeSpan); 299 | return this; 300 | } 301 | 302 | @Override 303 | public StyleEZ alignStart(@NonNull ParagraphLocator paragraph) { 304 | AlignmentSpan normalSpan = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_NORMAL); 305 | addMultipleSpan(paragraph, normalSpan); 306 | return this; 307 | } 308 | 309 | @Override 310 | public StyleEZ link(@NonNull Locator locator, @NonNull String url) { 311 | URLSpan urlSpan = new URLSpan(url); 312 | addMultipleSpan(locator, urlSpan); 313 | return this; 314 | } 315 | 316 | @Override 317 | public StyleEZ font(@NonNull Locator locator, @NonNull @EZ.FontFamily String fontFamily) { 318 | TypefaceSpan typefaceSpan = new TypefaceSpan(fontFamily); 319 | addMultipleSpan(locator, typefaceSpan); 320 | return this; 321 | } 322 | 323 | @Override 324 | public StyleEZ appearance(@NonNull Locator locator, @StyleRes int appearance) { 325 | TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(context, appearance); 326 | addMultipleSpan(locator, textAppearanceSpan); 327 | return this; 328 | } 329 | 330 | @Override 331 | public StyleEZ locale(@NonNull Locator locator, @NonNull Locale locale) { 332 | LocaleSpan localeSpan = new LocaleSpan(locale); 333 | addMultipleSpan(locator, localeSpan); 334 | return this; 335 | } 336 | 337 | @Override 338 | public StyleEZ scaleX(@NonNull Locator locator, @FloatRange(from = 0.f) float proportion) { 339 | ScaleXSpan scaleXSpan = new ScaleXSpan(proportion); 340 | addMultipleSpan(locator, scaleXSpan); 341 | return this; 342 | } 343 | 344 | @Override 345 | public StyleEZ relativeSize(@NonNull Locator locator, @FloatRange(from = 0.f) float proportion) { 346 | RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(proportion); 347 | addMultipleSpan(locator, relativeSizeSpan); 348 | return this; 349 | } 350 | 351 | @Override 352 | public StyleEZ absoluteSize(@NonNull Locator locator, @IntRange(from = 1) int pixels) { 353 | AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(pixels); 354 | addMultipleSpan(locator, absoluteSizeSpan); 355 | return this; 356 | } 357 | 358 | @Override 359 | public StyleEZ absoluteSizeDP(@NonNull Locator locator, @IntRange(from = 1) int dips) { 360 | AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(dips, true); 361 | addMultipleSpan(locator, absoluteSizeSpan); 362 | return this; 363 | } 364 | 365 | @Override 366 | @UiThread 367 | public void apply() { 368 | target.setText(spannableContent); 369 | } 370 | 371 | /** 372 | * Applies the given {@code span} to the specified ranges 373 | * 374 | * @param locator the locator to be used to decide were to apply this span 375 | * @param span the span to be applied 376 | */ 377 | private void addMultipleSpan(@NonNull Locator locator, @NonNull Object span) { 378 | for (TargetRange targetRange : locator.locate(content)) { 379 | addSpan(targetRange, span); 380 | } 381 | } 382 | 383 | /** 384 | * Applies the given {@code span} to the specified range from 385 | * 386 | * @param targetRange the range were the span will be applied to 387 | * @param span the span to be applied 388 | */ 389 | @SuppressWarnings("WeakerAccess") 390 | @VisibleForTesting 391 | protected void addSpan(@NonNull TargetRange targetRange, @NonNull Object span) { 392 | final int start = targetRange.getStart(); 393 | final int end = targetRange.getEnd(); 394 | // Added 1 to the span, because it seems that internally it does exclusive range 395 | spannableContent.setSpan(span, start, end + 1, spanFlags); 396 | } 397 | 398 | 399 | private boolean isFlagSet(@EZ.STYLE int flag, int flagToVerify) { 400 | return (flag & flagToVerify) == flagToVerify; 401 | } 402 | 403 | } 404 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/api/ContentEZ.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.api; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.support.annotation.StringRes; 5 | 6 | /** 7 | * Part of SpanEZ 8 | * Created by joragu on 1/13/2017. 9 | */ 10 | 11 | @SuppressWarnings({"WeakerAccess", 12 | "unused"}) 13 | public interface ContentEZ { 14 | /** 15 | * If you want to keep the content of the {@code target} 16 | * NOTE: Currently it only works if the content is a SpannableString, otherwise it will be taken 17 | * as a normal String. 18 | * 19 | * @return the same instance of the object so that chaining is possible 20 | */ 21 | StyleEZ withCurrentContent(); 22 | 23 | /** 24 | * If you want to set the starting content of the {@code target} from a {@code String} 25 | * 26 | * @param text the text that will be set as the content of the (@code target) 27 | * @return the same instance of the object so that chaining is possible 28 | */ 29 | StyleEZ withContent(String text); 30 | 31 | /** 32 | * If you want to set the starting content of the {@code target} from a String resource id 33 | * 34 | * @param textResId the {@code R.string.*} id of the string that will be used 35 | * @return the same instance of the object so that chaining is possible 36 | */ 37 | StyleEZ withContent(@StringRes int textResId); 38 | 39 | /** 40 | * If you want to set the starting content of the {@code target} from a String resource id, that 41 | * has format, and you need to pass down the arguments for that format 42 | * 43 | * @param textResId the {@code R.string.*} id of the string that will be used 44 | * @param args the arguments that will be pass to the format of the {@code String} 45 | * @return the same instance of the object so that chaining is possible 46 | */ 47 | StyleEZ withFormattedContent(@StringRes int textResId, @NonNull Object... args); 48 | } 49 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/api/EZ.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.api; 2 | 3 | import android.support.annotation.IntDef; 4 | import android.support.annotation.StringDef; 5 | 6 | import java.lang.annotation.Retention; 7 | 8 | import static java.lang.annotation.RetentionPolicy.SOURCE; 9 | 10 | /** 11 | * Part of SpanEZ 12 | * Created by Jorge Aguilar on 1/20/2017. 13 | */ 14 | 15 | @SuppressWarnings("WeakerAccess") 16 | public final class EZ { 17 | public static final int BOLD = 1; 18 | public static final int ITALIC = 1 << 1; 19 | public static final int UNDERLINE = 1 << 2; 20 | public static final int STRIKETHROUGH = 1 << 3; 21 | public static final int SUBSCRIPT = 1 << 4; 22 | public static final int SUPERSCRIPT = 1 << 5; 23 | 24 | @Retention(SOURCE) 25 | @IntDef(flag = true, value = {BOLD, 26 | ITALIC, 27 | UNDERLINE, 28 | STRIKETHROUGH, 29 | SUBSCRIPT, 30 | SUPERSCRIPT}) 31 | public @interface STYLE {} 32 | 33 | public static final String MONOSPACE = "monospace"; 34 | public static final String SERIF = "serif"; 35 | public static final String SANS_SERIF = "sans-serif"; 36 | public static final String SANS_SERIF_LIGHT = "sans-serif-light"; 37 | public static final String SANS_SERIF_CONDENSED = "sans-serif-condensed"; 38 | 39 | 40 | @Retention(SOURCE) 41 | @StringDef(value = {MONOSPACE, 42 | SERIF, 43 | SANS_SERIF, 44 | SANS_SERIF_LIGHT, 45 | SANS_SERIF_CONDENSED}) 46 | public @interface FontFamily {} 47 | } 48 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/api/Locator.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.api; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | import com.bunk3r.spanez.models.TargetRange; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Part of SpanEZ 11 | * Created by joragu on 1/12/2017. 12 | */ 13 | 14 | public interface Locator { 15 | /** 16 | * Returns a list of ranges where the target(s) were located 17 | * 18 | * @param content the content were to look for the target(s) 19 | * @return a list of ranges were the target was found, will be empty if not found 20 | */ 21 | @NonNull 22 | List locate(@NonNull String content); 23 | } 24 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/api/StyleEZ.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.api; 2 | 3 | import android.support.annotation.ColorRes; 4 | import android.support.annotation.FloatRange; 5 | import android.support.annotation.IntRange; 6 | import android.support.annotation.NonNull; 7 | import android.support.annotation.StyleRes; 8 | import android.support.annotation.UiThread; 9 | 10 | import com.bunk3r.spanez.callbacks.OnSpanClickListener; 11 | import com.bunk3r.spanez.models.ParagraphLocator; 12 | 13 | import java.util.Locale; 14 | 15 | /** 16 | * Part of SpanEZ 17 | * Created by joragu on 1/13/2017. 18 | */ 19 | @SuppressWarnings({"unused", 20 | "WeakerAccess"}) 21 | public interface StyleEZ { 22 | /** 23 | * Every call after this will set the {@code Span} to be {@code Inclusive} in both sides, this 24 | * means that if text is added within that range the new text will keep the same format. 25 | * 26 | * @return the same instance of the object so that chaining is possible 27 | */ 28 | StyleEZ inclusive(); 29 | 30 | /** 31 | * Every call after this will set the {@code Span} to be {@code Exclusive} in both sides, this 32 | * means that if text is added within that range, excluding the last character the new 33 | * text will keep the same format. 34 | * 35 | * @return the same instance of the object so that chaining is possible 36 | */ 37 | StyleEZ inclusiveExclusive(); 38 | 39 | /** 40 | * Every call after this will set the {@code Span} to be {@code Exclusive} in both sides, this 41 | * means that if text is added within that range, excluding the first character the new 42 | * text will keep the same format. 43 | * 44 | * @return the same instance of the object so that chaining is possible 45 | */ 46 | StyleEZ exclusiveInclusive(); 47 | 48 | /** 49 | * Every call after this will set the {@code Span} to be {@code Exclusive} in both sides, this 50 | * means that if text is added within that range, excluding the first and last character the new 51 | * text will keep the same format. 52 | * 53 | * @return the same instance of the object so that chaining is possible 54 | */ 55 | StyleEZ exclusive(); 56 | 57 | /** 58 | * Applies all the {@code styles} to the {@code Character} within the given range. Or throws 59 | * and {@code IllegalArgumentException} if the range provided is outside the content bounds. 60 | * 61 | * @param locator the locator to be used to decide were to apply this style 62 | * @param styles all the styles to be applied, this are in form of a flag 63 | * ex. BOLD | ITALIC | UNDERLINE 64 | * @return the same instance of the object so that chaining is possible 65 | */ 66 | StyleEZ style(@NonNull Locator locator, @EZ.STYLE int styles); 67 | 68 | /** 69 | * Changes the {@code ForegroundColor} of all the {@code Character} within the given range. Or throws 70 | * and {@code IllegalArgumentException} if the range provided is outside the content bounds. 71 | * 72 | * @param locator the locator to be used to decide were to apply this style 73 | * @param fgColorResId the color to use for the {@code Char} 74 | * @return the same instance of the object so that chaining is possible 75 | */ 76 | StyleEZ foregroundColor(@NonNull Locator locator, @ColorRes int fgColorResId); 77 | 78 | /** 79 | * Changes the {@code BackgroundColor} of all the {@code Character} within the given range. Or throws 80 | * and {@code IllegalArgumentException} if the range provided is outside the content bounds. 81 | * 82 | * @param locator the locator to be used to decide were to apply this style 83 | * @param bgColorResId the color to use for the {@code BackgroundColor} 84 | * @return the same instance of the object so that chaining is possible 85 | */ 86 | StyleEZ backgroundColor(@NonNull Locator locator, @ColorRes int bgColorResId); 87 | 88 | /** 89 | * Adds an {@code OnClickListener} to all the {@code Character} within the given range. Or throws 90 | * and {@code IllegalArgumentException} if the range provided is outside the content bounds. 91 | * 92 | * @param locator the locator to be used to decide were to apply this style 93 | * @param spanClick the callback to call whenever the span it is clicked 94 | * @return the same instance of the object so that chaining is possible 95 | */ 96 | StyleEZ clickable(@NonNull Locator locator, @NonNull OnSpanClickListener spanClick); 97 | 98 | /** 99 | * Styles the paragraph where all the {@code Character} within the given range exist. Or throws 100 | * and {@code IllegalArgumentException} if the range provided is outside the content bounds. 101 | * 102 | * @param paragraph the locator to be used to decide were to apply this style 103 | * @return the same instance of the object so that chaining is possible 104 | */ 105 | StyleEZ quote(@NonNull ParagraphLocator paragraph); 106 | 107 | /** 108 | * Styles the paragraph (with the selected {@code quoteColorResId}) where all the {@code Character} 109 | * within the given range exist. Or throws and {@code IllegalArgumentException} if the range 110 | * provided is outside the content bounds. 111 | * 112 | * @param paragraph the locator to be used to decide were to apply this style 113 | * @param quoteColorResId the color to use for the paragraph marker 114 | * @return the same instance of the object so that chaining is possible 115 | */ 116 | StyleEZ quote(@NonNull ParagraphLocator paragraph, @ColorRes int quoteColorResId); 117 | 118 | /** 119 | * Modifies the gravity of the paragraph to be Center align, this is applied to the location of 120 | * where the {@code Character} within the given range are located. Or throws and 121 | * {@code IllegalArgumentException} if the range provided is outside the content bounds. 122 | * 123 | * @param paragraph the locator to be used to decide were to apply this style 124 | * @return the same instance of the object so that chaining is possible 125 | */ 126 | StyleEZ alignCenter(@NonNull ParagraphLocator paragraph); 127 | 128 | /** 129 | * Modifies the gravity of the paragraph to be Right align for LTR locales, and to be Left align 130 | * for RTL locales, this is applied to the location of where the {@code Character} within the 131 | * given range are located. Or throws and {@code IllegalArgumentException} if the range provided 132 | * is outside the content bounds. 133 | * 134 | * @param paragraph the locator to be used to decide were to apply this style 135 | * @return the same instance of the object so that chaining is possible 136 | */ 137 | StyleEZ alignEnd(@NonNull ParagraphLocator paragraph); 138 | 139 | /** 140 | * Modifies the gravity of the paragraph to be Left align for LTR locales, and to be Right align 141 | * for RTL locales, this is applied to the location of where the {@code Character} within the 142 | * given range are located. Or throws and {@code IllegalArgumentException} if the range provided 143 | * is outside the content bounds. 144 | * 145 | * @param paragraph the locator to be used to decide were to apply this style 146 | * @return the same instance of the object so that chaining is possible 147 | */ 148 | StyleEZ alignStart(@NonNull ParagraphLocator paragraph); 149 | 150 | /** 151 | * Applies a {@code Link} style to all the {@code Character} within the given range. Or throws 152 | * and {@code IllegalArgumentException} if the range provided is outside the content bounds. If 153 | * clicked an Intent to open the link will be fired. 154 | * 155 | * @param locator the locator to be used to decide were to apply this style 156 | * @param url the Url that will be applied to the {@code Char} 157 | * @return the same instance of the object so that chaining is possible 158 | */ 159 | StyleEZ link(@NonNull Locator locator, @NonNull String url); 160 | 161 | /** 162 | * Changes the font family to be used for the {@code Character} within the given range. Or throws 163 | * and {@code IllegalArgumentException} if the range provided is outside the content bounds. 164 | * 165 | * @param locator the locator to be used to decide were to apply this style 166 | * @param fontFamily the font family to be use 167 | * @return the same instance of the object so that chaining is possible 168 | */ 169 | StyleEZ font(@NonNull Locator locator, @NonNull @EZ.FontFamily String fontFamily); 170 | 171 | /** 172 | * Applies the defined style to the {@code Character} within the given range. Or throws 173 | * and {@code IllegalArgumentException} if the range provided is outside the content bounds. 174 | * 175 | * @param locator the locator to be used to decide were to apply this style 176 | * @param appearance the style resource to be used 177 | * @return the same instance of the object so that chaining is possible 178 | */ 179 | StyleEZ appearance(@NonNull Locator locator, @StyleRes int appearance); 180 | 181 | /** 182 | * Applies a different {@code locale} to the {@code Character} within the given range. Or throws 183 | * and {@code IllegalArgumentException} if the range provided is outside the content bounds. 184 | * 185 | * @param locator the locator to be used to decide were to apply this style 186 | * @param locale the locale to be use 187 | * @return the same instance of the object so that chaining is possible 188 | */ 189 | StyleEZ locale(@NonNull Locator locator, @NonNull Locale locale); 190 | 191 | /** 192 | * Applies a scale factor to the width of the {@code Character} within the given range. Or throws 193 | * and {@code IllegalArgumentException} if the range provided is outside the content bounds. 194 | * 195 | * @param locator the locator to be used to decide were to apply this style 196 | * @param proportion the factor to be used by the scaling 197 | * @return the same instance of the object so that chaining is possible 198 | */ 199 | StyleEZ scaleX(@NonNull Locator locator, @FloatRange(from = 0.f) float proportion); 200 | 201 | /** 202 | * Changes the size of the {@code String} relative to the {@code TextSize} applied to the 203 | * {@code Character} within the given range. Or throws and {@code IllegalArgumentException} if 204 | * the range provided is outside the content bounds. 205 | * 206 | * @param locator the locator to be used to decide were to apply this style 207 | * @param proportion the factor to be used by the scaling 208 | * @return the same instance of the object so that chaining is possible 209 | */ 210 | StyleEZ relativeSize(@NonNull Locator locator, @FloatRange(from = 0.f) float proportion); 211 | 212 | /** 213 | * Changes the size of the {@code Character} within the given range to be exactly {@code pixels}Px. 214 | * Or throws and {@code IllegalArgumentException} if the range provided is outside the content bounds. 215 | * 216 | * @param locator the locator to be used to decide were to apply this style 217 | * @param pixels the size in pixels that will be applied to the {@code String} 218 | * @return the same instance of the object so that chaining is possible 219 | */ 220 | StyleEZ absoluteSize(@NonNull Locator locator, @IntRange(from = 1) int pixels); 221 | 222 | /** 223 | * Changes the size of the {@code Character} within the given range to be exactly {@code dips}DP. 224 | * Or throws and {@code IllegalArgumentException} if the range provided is outside the content bounds. 225 | * 226 | * @param locator the locator to be used to decide were to apply this style 227 | * @param dips the size in density independent pixels that will be applied to the {@code Char} 228 | * @return the same instance of the object so that chaining is possible 229 | */ 230 | StyleEZ absoluteSizeDP(@NonNull Locator locator, @IntRange(from = 1) int dips); 231 | 232 | /** 233 | * Applies all the previous modifications to the {@code target} 234 | */ 235 | @UiThread 236 | void apply(); 237 | } 238 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/callbacks/OnSpanClickListener.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.callbacks; 2 | 3 | /** 4 | * Part of SpanEZ 5 | * Created by joragu on 1/1/2017. 6 | */ 7 | 8 | @SuppressWarnings({"WeakerAccess", 9 | "unused"}) 10 | public interface OnSpanClickListener { 11 | void onSpanClick(String spanContent); 12 | } 13 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/locators/Paragraph.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.locators; 2 | 3 | import android.support.annotation.IntRange; 4 | import android.support.annotation.NonNull; 5 | 6 | import com.bunk3r.spanez.models.P; 7 | import com.bunk3r.spanez.models.ParagraphLocator; 8 | import com.bunk3r.spanez.models.TargetRange; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * Part of SpanEZ 15 | * Created by joragu on 1/12/2017. 16 | */ 17 | @SuppressWarnings({"WeakerAccess", 18 | "unused"}) 19 | public final class Paragraph extends ParagraphLocator { 20 | private final boolean byNumber; 21 | private int paragraphNumber; 22 | private String excerpt; 23 | 24 | public static Paragraph number(@IntRange(from = 1) int paragraphNumber) { 25 | return new Paragraph(paragraphNumber); 26 | } 27 | 28 | public static Paragraph containing(@NonNull String excerpt) { 29 | return new Paragraph(excerpt); 30 | } 31 | 32 | private Paragraph(@IntRange(from = 1) int paragraphNumber) { 33 | this.byNumber = true; 34 | this.paragraphNumber = paragraphNumber; 35 | } 36 | 37 | private Paragraph(@NonNull String excerpt) { 38 | this.byNumber = false; 39 | this.excerpt = excerpt; 40 | } 41 | 42 | @NonNull 43 | @Override 44 | public List locate(@NonNull String content) { 45 | List

paragraphs = splitIntoParagraphs(content); 46 | return byNumber ? locateByNumber(paragraphs) : locateByContent(paragraphs); 47 | } 48 | 49 | @NonNull 50 | private List locateByNumber(@NonNull List

paragraphs) { 51 | List ranges = new ArrayList<>(1); 52 | if (paragraphs.size() >= paragraphNumber) { 53 | P paragraph = paragraphs.get(paragraphNumber - 1); 54 | ranges.add(TargetRange.from(paragraph.getStart(), paragraph.getEnd())); 55 | } 56 | return ranges; 57 | } 58 | 59 | @NonNull 60 | private List locateByContent(@NonNull List

paragraphs) { 61 | List ranges = new ArrayList<>(); 62 | if (excerpt.isEmpty()) { 63 | return ranges; 64 | } 65 | 66 | for (P paragraph : paragraphs) { 67 | if (paragraph.getContent().contains(excerpt)) { 68 | ranges.add(TargetRange.from(paragraph.getStart(), paragraph.getEnd())); 69 | } 70 | } 71 | return ranges; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/locators/Range.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.locators; 2 | 3 | import android.support.annotation.IntRange; 4 | import android.support.annotation.NonNull; 5 | 6 | import com.bunk3r.spanez.api.Locator; 7 | import com.bunk3r.spanez.models.TargetRange; 8 | 9 | import java.util.ArrayList; 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | /** 14 | * Part of SpanEZ 15 | * Created by joragu on 1/12/2017. 16 | */ 17 | 18 | @SuppressWarnings("WeakerAccess") 19 | public final class Range implements Locator { 20 | private final TargetRange targetRange; 21 | private final List ranges = new ArrayList<>(1); 22 | private final List empty = Collections.emptyList(); 23 | 24 | public static Range from(@IntRange(from = 0) int start, @IntRange(from = 0) int end) { 25 | if (end < start) { 26 | throw new IllegalArgumentException("The end of the targetRange shouldn't be before the start"); 27 | } 28 | 29 | return new Range(start, end); 30 | } 31 | 32 | private Range(int start, int end) { 33 | targetRange = TargetRange.from(start, end); 34 | ranges.add(targetRange); 35 | } 36 | 37 | @NonNull 38 | @Override 39 | public List locate(@NonNull String content) { 40 | final int contentLength = content.length(); 41 | return (targetRange.getStart() < contentLength && targetRange.getEnd() < contentLength) 42 | ? ranges 43 | : empty; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/locators/Word.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.locators; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | import com.bunk3r.spanez.api.Locator; 6 | import com.bunk3r.spanez.models.TargetRange; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * Part of SpanEZ 13 | * Created by joragu on 1/12/2017. 14 | */ 15 | 16 | @SuppressWarnings("WeakerAccess") 17 | public final class Word implements Locator { 18 | private static final int NOT_FOUND = -1; 19 | 20 | private final String snippet; 21 | private final boolean findAllOccurrences; 22 | 23 | public static Word findFirst(@NonNull String word) { 24 | return new Word(word, false); 25 | } 26 | 27 | public static Word findAll(@NonNull String word) { 28 | return new Word(word, true); 29 | } 30 | 31 | private Word(@NonNull String snippet, boolean findAllOccurrences) { 32 | this.snippet = snippet; 33 | this.findAllOccurrences = findAllOccurrences; 34 | } 35 | 36 | @NonNull 37 | @Override 38 | public List locate(@NonNull String content) { 39 | List ranges = new ArrayList<>(); 40 | if (snippet.isEmpty()) { 41 | return ranges; 42 | } 43 | 44 | int startingIndex = 0; 45 | int wordLength = snippet.length() - 1; 46 | 47 | do { 48 | int wordIndex = content.indexOf(snippet, startingIndex); 49 | if (wordIndex != NOT_FOUND) { 50 | ranges.add(TargetRange.from(wordIndex, wordIndex + wordLength)); 51 | } else { 52 | break; 53 | } 54 | startingIndex = wordIndex + 1; 55 | } while (findAllOccurrences); 56 | 57 | return ranges; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/models/P.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.models; 2 | 3 | /** 4 | * Part of SpanEZ 5 | * Created by Jorge Aguilar on 1/21/2017. 6 | * 7 | * This defines the content of a Paragraph 8 | */ 9 | public class P { 10 | private final String content; 11 | private final int startIndex; 12 | private final int endIndex; 13 | 14 | P(String fullContent, int startIndex, int endIndex) { 15 | this.content = fullContent.substring(startIndex, endIndex); 16 | this.startIndex = startIndex; 17 | this.endIndex = fullContent.length() != endIndex ? endIndex : endIndex - 1; 18 | } 19 | 20 | public String getContent() { 21 | return content; 22 | } 23 | 24 | public int getStart() { 25 | return startIndex; 26 | } 27 | 28 | public int getEnd() { 29 | return endIndex; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/models/ParagraphLocator.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.models; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | import com.bunk3r.spanez.api.Locator; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * Part of SpanEZ 12 | * Created by joragu on 1/12/2017. 13 | *

14 | * This is just to specify that this locator should return a paragraph 15 | */ 16 | @SuppressWarnings("WeakerAccess") 17 | public abstract class ParagraphLocator implements Locator { 18 | private static final int NOT_FOUND = -1; 19 | 20 | /** 21 | * Splits the content by new line character (\n), any empty paragraph is ignored 22 | * 23 | * @param content the full content to split into paragraphs 24 | * @return a list of {@code P} that contains all the paragraphs 25 | */ 26 | @NonNull 27 | protected List

splitIntoParagraphs(@NonNull String content) { 28 | List

paragraphs = new ArrayList<>(); 29 | int startPosition = 0; 30 | int newLinePosition; 31 | 32 | do { 33 | newLinePosition = content.indexOf('\n', startPosition); 34 | int paragraphEnd = newLinePosition != NOT_FOUND ? newLinePosition : content.length(); 35 | if (paragraphEnd - startPosition > 0) { 36 | P paragraph = new P(content, startPosition, paragraphEnd); 37 | paragraphs.add(paragraph); 38 | } 39 | startPosition = newLinePosition + 1; 40 | } while (newLinePosition != NOT_FOUND); 41 | 42 | return paragraphs; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/models/TargetRange.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.models; 2 | 3 | import android.support.annotation.IntRange; 4 | 5 | /** 6 | * Part of SpanEZ 7 | * Created by joragu on 1/12/2017. 8 | */ 9 | public final class TargetRange { 10 | @IntRange(from = 0) 11 | private final int start; 12 | 13 | @IntRange(from = 0) 14 | private final int end; 15 | 16 | public static TargetRange from(@IntRange(from = 0) int start, @IntRange(from = 0) int end) { 17 | if (end < start) { 18 | throw new IllegalArgumentException("The end of the range shouldn't be before the start"); 19 | } 20 | 21 | return new TargetRange(start, end); 22 | } 23 | 24 | private TargetRange(@IntRange(from = 0) int start, @IntRange(from = 0) int end) { 25 | this.start = start; 26 | this.end = end; 27 | } 28 | 29 | @IntRange(from = 0) 30 | public int getStart() { 31 | return start; 32 | } 33 | 34 | @IntRange(from = 0) 35 | public int getEnd() { 36 | return end; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "TargetRange{" + "start=" + start + ", end=" + end + '}'; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object o) { 46 | if (this == o) { 47 | return true; 48 | } 49 | 50 | if (!(o instanceof TargetRange)) { 51 | return false; 52 | } 53 | 54 | TargetRange that = (TargetRange) o; 55 | return start == that.start && end == that.end; 56 | 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | int result = 31; 62 | result *= start; 63 | result += end; 64 | return result; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /library/src/main/java/com/bunk3r/spanez/spans/ClickableSpanEZ.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.spans; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.text.style.ClickableSpan; 5 | import android.view.View; 6 | 7 | import com.bunk3r.spanez.callbacks.OnSpanClickListener; 8 | 9 | /** 10 | * Part of SpanEZ 11 | * Created by joragu on 1/1/2017. 12 | */ 13 | 14 | public final class ClickableSpanEZ extends ClickableSpan { 15 | private final OnSpanClickListener spanClickListener; 16 | private final String text; 17 | 18 | @NonNull 19 | public static ClickableSpan from(@NonNull OnSpanClickListener onSpanClickListener, @NonNull String content) { 20 | return new ClickableSpanEZ(onSpanClickListener, content); 21 | } 22 | 23 | private ClickableSpanEZ(@NonNull OnSpanClickListener onSpanClickListener, @NonNull String content) { 24 | super(); 25 | spanClickListener = onSpanClickListener; 26 | text = content; 27 | } 28 | 29 | @Override 30 | public void onClick(View widget) { 31 | spanClickListener.onSpanClick(text); 32 | } 33 | } -------------------------------------------------------------------------------- /library/src/test/java/com/bunk3r/spanez/SpanEZTest.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez; 2 | 3 | import android.text.method.LinkMovementMethod; 4 | import android.text.style.AbsoluteSizeSpan; 5 | import android.text.style.AlignmentSpan; 6 | import android.text.style.ClickableSpan; 7 | import android.text.style.LocaleSpan; 8 | import android.text.style.RelativeSizeSpan; 9 | import android.text.style.ScaleXSpan; 10 | import android.text.style.StrikethroughSpan; 11 | import android.text.style.StyleSpan; 12 | import android.text.style.SubscriptSpan; 13 | import android.text.style.SuperscriptSpan; 14 | import android.text.style.TextAppearanceSpan; 15 | import android.text.style.TypefaceSpan; 16 | import android.text.style.URLSpan; 17 | import android.text.style.UnderlineSpan; 18 | import android.widget.TextView; 19 | 20 | import com.bunk3r.spanez.api.EZ; 21 | import com.bunk3r.spanez.api.StyleEZ; 22 | import com.bunk3r.spanez.callbacks.OnSpanClickListener; 23 | import com.bunk3r.spanez.locators.Paragraph; 24 | import com.bunk3r.spanez.locators.Range; 25 | import com.bunk3r.spanez.models.TargetRange; 26 | 27 | import org.junit.Before; 28 | import org.junit.Test; 29 | import org.junit.runner.RunWith; 30 | import org.mockito.ArgumentCaptor; 31 | import org.mockito.Mock; 32 | import org.mockito.junit.MockitoJUnitRunner; 33 | 34 | import java.util.Locale; 35 | 36 | import static org.mockito.ArgumentMatchers.anyString; 37 | import static org.mockito.ArgumentMatchers.isA; 38 | import static org.mockito.Mockito.only; 39 | import static org.mockito.Mockito.spy; 40 | import static org.mockito.Mockito.times; 41 | import static org.mockito.Mockito.verify; 42 | 43 | /** 44 | * Part of SpanEZ 45 | * Created by Jorge Aguilar on 1/21/2017. 46 | */ 47 | @RunWith(MockitoJUnitRunner.class) 48 | public class SpanEZTest { 49 | private static final int INTEGER_ARG = 1; 50 | @Mock 51 | private TextView mockTextView; 52 | 53 | @Mock 54 | private OnSpanClickListener spanClickListener; 55 | 56 | private Paragraph paragraph; 57 | private Range range; 58 | private StyleEZ spanBuilder; 59 | 60 | @Before 61 | public void setUp() throws Exception { 62 | spanBuilder = SpanEZ.withTextView(mockTextView) 63 | .withContent("This is a dummy content"); 64 | spanBuilder = spy(spanBuilder); 65 | 66 | int start = 1; 67 | int end = 5; 68 | range = Range.from(start, end); 69 | paragraph = Paragraph.number(1); 70 | } 71 | 72 | @Test 73 | public void bold_should_add_only_one_span() { 74 | spanBuilder.style(range, EZ.BOLD) 75 | .apply(); 76 | 77 | verify((SpanEZ) spanBuilder, times(1)) 78 | .addSpan(isA(TargetRange.class), isA(StyleSpan.class)); 79 | } 80 | 81 | @Test 82 | public void italic_should_add_only_one_span() { 83 | spanBuilder.style(range, EZ.ITALIC) 84 | .apply(); 85 | 86 | verify((SpanEZ) spanBuilder, times(1)) 87 | .addSpan(isA(TargetRange.class), isA(StyleSpan.class)); 88 | } 89 | 90 | @Test 91 | public void underline_should_add_only_one_span() { 92 | spanBuilder.style(range, EZ.UNDERLINE) 93 | .apply(); 94 | 95 | verify((SpanEZ) spanBuilder, times(1)) 96 | .addSpan(isA(TargetRange.class), isA(UnderlineSpan.class)); 97 | } 98 | 99 | @Test 100 | public void strikethrough_should_add_only_one_span() { 101 | spanBuilder.style(range, EZ.STRIKETHROUGH) 102 | .apply(); 103 | 104 | verify((SpanEZ) spanBuilder, times(1)) 105 | .addSpan(isA(TargetRange.class), isA(StrikethroughSpan.class)); 106 | } 107 | 108 | @Test 109 | public void subscript_should_add_only_one_span() { 110 | spanBuilder.style(range, EZ.SUBSCRIPT) 111 | .apply(); 112 | 113 | verify((SpanEZ) spanBuilder, times(1)) 114 | .addSpan(isA(TargetRange.class), isA(SubscriptSpan.class)); 115 | } 116 | 117 | @Test 118 | public void superscript_should_add_only_one_span() { 119 | spanBuilder.style(range, EZ.SUPERSCRIPT) 120 | .apply(); 121 | 122 | verify((SpanEZ) spanBuilder, times(1)) 123 | .addSpan(isA(TargetRange.class), isA(SuperscriptSpan.class)); 124 | } 125 | 126 | @Test 127 | public void link_should_add_only_one_span() { 128 | spanBuilder.link(range, "") 129 | .apply(); 130 | 131 | verify((SpanEZ) spanBuilder, times(1)) 132 | .addSpan(isA(TargetRange.class), isA(URLSpan.class)); 133 | } 134 | 135 | @Test 136 | public void font_should_add_only_one_span() { 137 | spanBuilder.font(range, EZ.MONOSPACE) 138 | .apply(); 139 | 140 | verify((SpanEZ) spanBuilder, times(1)) 141 | .addSpan(isA(TargetRange.class), isA(TypefaceSpan.class)); 142 | } 143 | 144 | @SuppressWarnings("ResourceType") 145 | @Test 146 | public void appearance_should_add_only_one_span() { 147 | spanBuilder.appearance(range, INTEGER_ARG) 148 | .apply(); 149 | 150 | verify((SpanEZ) spanBuilder, times(1)) 151 | .addSpan(isA(TargetRange.class), isA(TextAppearanceSpan.class)); 152 | } 153 | 154 | @Test 155 | public void locale_should_add_only_one_span() { 156 | spanBuilder.locale(range, Locale.US) 157 | .apply(); 158 | 159 | verify((SpanEZ) spanBuilder, times(1)) 160 | .addSpan(isA(TargetRange.class), isA(LocaleSpan.class)); 161 | } 162 | 163 | @Test 164 | public void scale_x_should_add_only_one_span() { 165 | spanBuilder.scaleX(range, INTEGER_ARG) 166 | .apply(); 167 | 168 | verify((SpanEZ) spanBuilder, times(1)) 169 | .addSpan(isA(TargetRange.class), isA(ScaleXSpan.class)); 170 | } 171 | 172 | @Test 173 | public void relative_size_should_add_only_one_span() { 174 | spanBuilder.relativeSize(range, INTEGER_ARG) 175 | .apply(); 176 | 177 | verify((SpanEZ) spanBuilder, times(1)) 178 | .addSpan(isA(TargetRange.class), isA(RelativeSizeSpan.class)); 179 | } 180 | 181 | @Test 182 | public void absolute_size_should_add_only_one_span() { 183 | spanBuilder.absoluteSize(range, INTEGER_ARG) 184 | .apply(); 185 | 186 | verify((SpanEZ) spanBuilder, times(1)) 187 | .addSpan(isA(TargetRange.class), isA(AbsoluteSizeSpan.class)); 188 | } 189 | 190 | @Test 191 | public void absolute_size_pixel_independent_should_add_only_one_span() { 192 | spanBuilder.absoluteSizeDP(range, INTEGER_ARG) 193 | .apply(); 194 | 195 | verify((SpanEZ) spanBuilder, times(1)) 196 | .addSpan(isA(TargetRange.class), isA(AbsoluteSizeSpan.class)); 197 | } 198 | 199 | @Test 200 | public void click_should_add_only_one_span() { 201 | spanBuilder.clickable(range, spanClickListener) 202 | .apply(); 203 | 204 | verify(mockTextView, times(1)) 205 | .setMovementMethod(isA(LinkMovementMethod.class)); 206 | 207 | verify((SpanEZ) spanBuilder, times(1)) 208 | .addSpan(isA(TargetRange.class), isA(ClickableSpan.class)); 209 | } 210 | 211 | @Test 212 | public void clicking_on_a_click_span_triggers_callback() { 213 | spanBuilder.clickable(range, spanClickListener) 214 | .apply(); 215 | 216 | ArgumentCaptor captor = ArgumentCaptor.forClass(ClickableSpan.class); 217 | verify((SpanEZ) spanBuilder, times(1)) 218 | .addSpan(isA(TargetRange.class), captor.capture()); 219 | 220 | captor.getValue().onClick(mockTextView); 221 | 222 | verify(spanClickListener, only()) 223 | .onSpanClick(anyString()); 224 | } 225 | 226 | @Test 227 | public void align_start_should_add_only_one_span() { 228 | spanBuilder.alignStart(paragraph) 229 | .apply(); 230 | 231 | verify((SpanEZ) spanBuilder, times(1)) 232 | .addSpan(isA(TargetRange.class), isA(AlignmentSpan.class)); 233 | } 234 | 235 | @Test 236 | public void align_center_should_add_only_one_span() { 237 | spanBuilder.alignCenter(paragraph) 238 | .apply(); 239 | 240 | verify((SpanEZ) spanBuilder, times(1)) 241 | .addSpan(isA(TargetRange.class), isA(AlignmentSpan.class)); 242 | } 243 | 244 | @Test 245 | public void align_end_should_add_only_one_span() { 246 | spanBuilder.alignEnd(paragraph) 247 | .apply(); 248 | 249 | verify((SpanEZ) spanBuilder, times(1)) 250 | .addSpan(isA(TargetRange.class), isA(AlignmentSpan.class)); 251 | } 252 | } -------------------------------------------------------------------------------- /library/src/test/java/com/bunk3r/spanez/locators/ParagraphTest.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.locators; 2 | 3 | import com.bunk3r.spanez.models.TargetRange; 4 | 5 | import org.junit.Test; 6 | 7 | import java.util.List; 8 | 9 | import static org.assertj.core.api.Java6Assertions.assertThat; 10 | 11 | /** 12 | * Part of SpanEZ 13 | * Created by joragu on 1/13/2017. 14 | */ 15 | public class ParagraphTest { 16 | private static final int FIRST_PARAGRAPH = 1; 17 | private static final int MIDDLE_PARAGRAPH = 2; 18 | private static final int LAST_PARAGRAPH = 3; 19 | private static final int NOT_EXISTENT_PARAGRAPH = 4; 20 | 21 | private static final String EMPTY_EXCERPT = ""; 22 | private static final String PARAGRAPH_EXCERPT = "paragraph"; 23 | private static final String NOT_EXISTENT_EXCERPT = "random"; 24 | private static final String FIRST_PARAGRAPH_CONTENT = "First paragraph"; 25 | private static final String SECOND_PARAGRAPH_CONTENT = "Second paragraph"; 26 | private static final String THIRD_PARAGRAPH_CONTENT = "Third paragraph"; 27 | private static final String EMPTY_CONTENT = ""; 28 | private static final String NEW_LINES_CONTENT = "\n\n\n\n"; 29 | private static final String SINGLE_PARAGRAPH_CONTENT = NEW_LINES_CONTENT + FIRST_PARAGRAPH_CONTENT + NEW_LINES_CONTENT; 30 | private static final String MULTIPLE_PARAGRAPHS_CONTENT = FIRST_PARAGRAPH_CONTENT + "\n" + SECOND_PARAGRAPH_CONTENT + "\n" + THIRD_PARAGRAPH_CONTENT; 31 | 32 | private static final TargetRange FIRST_PARAGRAPH_RANGE = TargetRange.from(0, 15); 33 | private static final TargetRange SECOND_PARAGRAPH_RANGE = TargetRange.from(16, 32); 34 | private static final TargetRange THIRD_PARAGRAPH_RANGE = TargetRange.from(33, 47); 35 | 36 | @Test 37 | public void find_by_number_when_content_is_empty() { 38 | Paragraph paragraph = Paragraph.number(FIRST_PARAGRAPH); 39 | List results = paragraph.locate(EMPTY_CONTENT); 40 | assertThat(results).isEmpty(); 41 | } 42 | 43 | @Test 44 | public void find_by_number_when_content_is_new_lines() { 45 | Paragraph paragraph = Paragraph.number(FIRST_PARAGRAPH); 46 | List results = paragraph.locate(NEW_LINES_CONTENT); 47 | assertThat(results).isEmpty(); 48 | } 49 | 50 | @Test 51 | public void find_by_number_when_empty_paragraphs_exist() { 52 | Paragraph paragraph = Paragraph.number(FIRST_PARAGRAPH); 53 | List results = paragraph.locate(SINGLE_PARAGRAPH_CONTENT); 54 | 55 | int startIndex = 4; 56 | int endIndex = startIndex + FIRST_PARAGRAPH_CONTENT.length(); 57 | TargetRange expectedResult = TargetRange.from(startIndex, endIndex); 58 | assertThat(results).hasSize(1) 59 | .containsOnly(expectedResult); 60 | } 61 | 62 | @Test 63 | public void find_by_number_when_paragraph_does_exist_at_start() { 64 | Paragraph paragraph = Paragraph.number(FIRST_PARAGRAPH); 65 | List results = paragraph.locate(MULTIPLE_PARAGRAPHS_CONTENT); 66 | 67 | assertThat(results).hasSize(1) 68 | .containsOnly(FIRST_PARAGRAPH_RANGE); 69 | } 70 | 71 | @Test 72 | public void find_by_number_when_paragraph_does_exist_at_center() { 73 | Paragraph paragraph = Paragraph.number(MIDDLE_PARAGRAPH); 74 | List results = paragraph.locate(MULTIPLE_PARAGRAPHS_CONTENT); 75 | 76 | assertThat(results).hasSize(1) 77 | .containsOnly(SECOND_PARAGRAPH_RANGE); 78 | } 79 | 80 | @Test 81 | public void find_by_number_when_paragraph_does_exist_at_end() { 82 | Paragraph paragraph = Paragraph.number(LAST_PARAGRAPH); 83 | List results = paragraph.locate(MULTIPLE_PARAGRAPHS_CONTENT); 84 | 85 | assertThat(results).hasSize(1) 86 | .containsOnly(THIRD_PARAGRAPH_RANGE); 87 | } 88 | 89 | @Test 90 | public void find_by_number_when_paragraph_does_not_exist() { 91 | Paragraph paragraph = Paragraph.number(NOT_EXISTENT_PARAGRAPH); 92 | List results = paragraph.locate(MULTIPLE_PARAGRAPHS_CONTENT); 93 | assertThat(results).isEmpty(); 94 | } 95 | 96 | @Test 97 | public void find_by_content_when_content_is_empty() { 98 | Paragraph paragraph = Paragraph.containing(PARAGRAPH_EXCERPT); 99 | List results = paragraph.locate(EMPTY_CONTENT); 100 | assertThat(results).isEmpty(); 101 | } 102 | 103 | @Test 104 | public void find_by_content_when_content_is_new_lines() { 105 | Paragraph paragraph = Paragraph.containing(PARAGRAPH_EXCERPT); 106 | List results = paragraph.locate(NEW_LINES_CONTENT); 107 | assertThat(results).isEmpty(); 108 | } 109 | 110 | @Test 111 | public void find_by_content_when_excerpt_is_empty() { 112 | Paragraph paragraph = Paragraph.containing(EMPTY_EXCERPT); 113 | List results = paragraph.locate(MULTIPLE_PARAGRAPHS_CONTENT); 114 | assertThat(results).isEmpty(); 115 | } 116 | 117 | @Test 118 | public void find_by_content_when_empty_paragraphs_exist() { 119 | Paragraph paragraph = Paragraph.containing(PARAGRAPH_EXCERPT); 120 | List results = paragraph.locate(SINGLE_PARAGRAPH_CONTENT); 121 | 122 | int startIndex = 4; 123 | int endIndex = startIndex + FIRST_PARAGRAPH_CONTENT.length(); 124 | TargetRange expectedResult = TargetRange.from(startIndex, endIndex); 125 | assertThat(results).hasSize(1) 126 | .containsOnly(expectedResult); 127 | } 128 | 129 | @Test 130 | public void find_by_content_when_excerpt_not_present_in_content() { 131 | Paragraph paragraph = Paragraph.containing(NOT_EXISTENT_EXCERPT); 132 | List results = paragraph.locate(MULTIPLE_PARAGRAPHS_CONTENT); 133 | assertThat(results).isEmpty(); 134 | } 135 | 136 | @Test 137 | public void find_by_content_when_paragraph_does_exist_at_start() { 138 | Paragraph paragraph = Paragraph.containing(FIRST_PARAGRAPH_CONTENT); 139 | List results = paragraph.locate(MULTIPLE_PARAGRAPHS_CONTENT); 140 | 141 | assertThat(results).hasSize(1) 142 | .containsOnly(FIRST_PARAGRAPH_RANGE); 143 | } 144 | 145 | @Test 146 | public void find_by_content_when_paragraph_does_exist_at_center() { 147 | Paragraph paragraph = Paragraph.containing(SECOND_PARAGRAPH_CONTENT); 148 | List results = paragraph.locate(MULTIPLE_PARAGRAPHS_CONTENT); 149 | 150 | assertThat(results).hasSize(1) 151 | .containsOnly(SECOND_PARAGRAPH_RANGE); 152 | } 153 | 154 | @Test 155 | public void find_by_content_when_paragraph_does_exist_at_end() { 156 | Paragraph paragraph = Paragraph.containing(THIRD_PARAGRAPH_CONTENT); 157 | List results = paragraph.locate(MULTIPLE_PARAGRAPHS_CONTENT); 158 | 159 | assertThat(results).hasSize(1) 160 | .containsOnly(THIRD_PARAGRAPH_RANGE); 161 | } 162 | 163 | @Test 164 | public void find_by_content_when_multiple_paragraphs_exist() { 165 | Paragraph paragraph = Paragraph.containing(PARAGRAPH_EXCERPT); 166 | List results = paragraph.locate(MULTIPLE_PARAGRAPHS_CONTENT); 167 | 168 | assertThat(results).hasSize(3) 169 | .containsOnly(FIRST_PARAGRAPH_RANGE, 170 | SECOND_PARAGRAPH_RANGE, 171 | THIRD_PARAGRAPH_RANGE); 172 | } 173 | } -------------------------------------------------------------------------------- /library/src/test/java/com/bunk3r/spanez/locators/RangeTest.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.locators; 2 | 3 | import com.bunk3r.spanez.models.TargetRange; 4 | 5 | import org.junit.Test; 6 | 7 | import java.util.List; 8 | 9 | import static org.assertj.core.api.Java6Assertions.assertThat; 10 | 11 | /** 12 | * Part of SpanEZ 13 | * Created by joragu on 1/13/2017. 14 | */ 15 | public class RangeTest { 16 | private static final String CONTENT = "This is a text where the range fits"; 17 | private static final int RANGE_START = 0; 18 | private static final int RANGE_END = 10; 19 | private static final int RANGE_OUTSIDE_CONTENT = 100; 20 | 21 | @Test 22 | public void valid_range() { 23 | Range range = Range.from(RANGE_START, RANGE_END); 24 | assertThat(range).isNotNull(); 25 | } 26 | 27 | @Test(expected = IllegalArgumentException.class) 28 | public void exception_thrown_when_range_is_invalid() { 29 | Range.from(RANGE_END, RANGE_START); 30 | } 31 | 32 | @Test 33 | public void range_should_not_change() { 34 | Range range = Range.from(RANGE_START, RANGE_END); 35 | List results = range.locate(CONTENT); 36 | 37 | TargetRange expectedResult = TargetRange.from(RANGE_START, RANGE_END); 38 | assertThat(results).hasSize(1) 39 | .containsOnly(expectedResult); 40 | } 41 | 42 | @Test 43 | public void do_not_a_range_if_end_range_outside_content() { 44 | Range range = Range.from(RANGE_START, RANGE_OUTSIDE_CONTENT); 45 | List results = range.locate(CONTENT); 46 | assertThat(results).isEmpty(); 47 | } 48 | 49 | @Test 50 | public void do_not_a_range_if_start_range_outside_content() { 51 | Range range = Range.from(RANGE_OUTSIDE_CONTENT, RANGE_OUTSIDE_CONTENT); 52 | List results = range.locate(CONTENT); 53 | assertThat(results).isEmpty(); 54 | } 55 | } -------------------------------------------------------------------------------- /library/src/test/java/com/bunk3r/spanez/locators/WordTest.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.locators; 2 | 3 | import com.bunk3r.spanez.models.TargetRange; 4 | 5 | import org.junit.Test; 6 | 7 | import java.util.List; 8 | 9 | import static org.assertj.core.api.Java6Assertions.assertThat; 10 | 11 | /** 12 | * Part of SpanEZ 13 | * Created by joragu on 1/13/2017. 14 | */ 15 | public class WordTest { 16 | private static final String EMPTY_WORD = ""; 17 | private static final String FIRST_WORD = "start"; 18 | private static final String MIDDLE_WORD = "middle"; 19 | private static final String LAST_WORD = "end"; 20 | private static final String WORD_NOT_IN_CONTENT = "blah blah"; 21 | private static final String UNIQUE_CONTENT = FIRST_WORD + MIDDLE_WORD + LAST_WORD; 22 | private static final String REPEATED_CONTENT = FIRST_WORD + MIDDLE_WORD + MIDDLE_WORD + MIDDLE_WORD + LAST_WORD; 23 | 24 | private static final TargetRange FIRST_WORD_RANGE = TargetRange.from(0, 4); 25 | private static final TargetRange MIDDLE_WORD_RANGE = TargetRange.from(5, 10); 26 | private static final TargetRange LAST_WORD_RANGE = TargetRange.from(11, 13); 27 | private static final TargetRange REPEATED_MIDDLE_WORD_RANGE_1 = TargetRange.from(5, 10); 28 | private static final TargetRange REPEATED_MIDDLE_WORD_RANGE_2 = TargetRange.from(11, 16); 29 | private static final TargetRange REPEATED_MIDDLE_WORD_RANGE_3 = TargetRange.from(17, 22); 30 | 31 | @Test 32 | public void find_first_occurrence_when_only_one_exist_at_start() { 33 | Word wordLocator = Word.findFirst(FIRST_WORD); 34 | List results = wordLocator.locate(UNIQUE_CONTENT); 35 | 36 | assertThat(results).hasSize(1) 37 | .containsOnly(FIRST_WORD_RANGE); 38 | } 39 | 40 | @Test 41 | public void find_first_occurrence_when_only_one_exist_at_center() { 42 | Word wordLocator = Word.findFirst(MIDDLE_WORD); 43 | List results = wordLocator.locate(UNIQUE_CONTENT); 44 | 45 | assertThat(results).hasSize(1) 46 | .containsOnly(MIDDLE_WORD_RANGE); 47 | } 48 | 49 | @Test 50 | public void find_first_occurrence_when_only_one_exist_at_end() { 51 | Word wordLocator = Word.findFirst(LAST_WORD); 52 | List results = wordLocator.locate(UNIQUE_CONTENT); 53 | 54 | assertThat(results).hasSize(1) 55 | .containsOnly(LAST_WORD_RANGE); 56 | } 57 | 58 | @Test 59 | public void find_first_occurrence_when_multiple_exist() { 60 | Word wordLocator = Word.findFirst(MIDDLE_WORD); 61 | List results = wordLocator.locate(REPEATED_CONTENT); 62 | 63 | assertThat(results).hasSize(1) 64 | .containsOnly(REPEATED_MIDDLE_WORD_RANGE_1); 65 | } 66 | 67 | @Test 68 | public void find_first_when_it_does_not_exist_in_content() { 69 | Word wordLocator = Word.findFirst(WORD_NOT_IN_CONTENT); 70 | List results = wordLocator.locate(UNIQUE_CONTENT); 71 | assertThat(results).isEmpty(); 72 | } 73 | 74 | @Test 75 | public void find_first_when_word_is_empty() { 76 | Word wordLocator = Word.findFirst(EMPTY_WORD); 77 | List results = wordLocator.locate(UNIQUE_CONTENT); 78 | assertThat(results).isEmpty(); 79 | } 80 | 81 | @Test 82 | public void find_all_occurrence_when_only_one_exist_at_start() { 83 | Word wordLocator = Word.findAll(FIRST_WORD); 84 | List results = wordLocator.locate(UNIQUE_CONTENT); 85 | 86 | assertThat(results).hasSize(1) 87 | .containsOnly(FIRST_WORD_RANGE); 88 | } 89 | 90 | @Test 91 | public void find_all_occurrence_when_only_one_exist_at_end() { 92 | Word wordLocator = Word.findAll(LAST_WORD); 93 | List results = wordLocator.locate(UNIQUE_CONTENT); 94 | 95 | assertThat(results).hasSize(1) 96 | .containsOnly(LAST_WORD_RANGE); 97 | } 98 | 99 | @Test 100 | public void find_all_occurrence_when_multiple_exist() { 101 | Word wordLocator = Word.findAll(MIDDLE_WORD); 102 | List results = wordLocator.locate(REPEATED_CONTENT); 103 | 104 | assertThat(results).hasSize(3) 105 | .containsOnly(REPEATED_MIDDLE_WORD_RANGE_1, 106 | REPEATED_MIDDLE_WORD_RANGE_2, 107 | REPEATED_MIDDLE_WORD_RANGE_3); 108 | } 109 | 110 | @Test 111 | public void find_all_when_it_does_not_exist_in_content() { 112 | Word wordLocator = Word.findAll(WORD_NOT_IN_CONTENT); 113 | List results = wordLocator.locate(UNIQUE_CONTENT); 114 | assertThat(results).isEmpty(); 115 | } 116 | 117 | @Test 118 | public void find_all_when_word_is_empty() { 119 | Word wordLocator = Word.findAll(EMPTY_WORD); 120 | List results = wordLocator.locate(UNIQUE_CONTENT); 121 | assertThat(results).isEmpty(); 122 | } 123 | } -------------------------------------------------------------------------------- /library/src/test/java/com/bunk3r/spanez/models/TargetRangeTest.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.models; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.assertj.core.api.Java6Assertions.assertThat; 6 | 7 | /** 8 | * Part of SpanEZ 9 | * Created by joragu on 1/13/2017. 10 | */ 11 | public class TargetRangeTest { 12 | private static final int RANGE_ZERO = 0; 13 | private static final int RANGE_ONE = 1; 14 | private static final int RANGE_FIVE = 5; 15 | private static final int RANGE_TEN = 10; 16 | 17 | @Test 18 | public void valid_range() { 19 | TargetRange targetRange = TargetRange.from(RANGE_ZERO, RANGE_TEN); 20 | assertThat(targetRange).isNotNull(); 21 | } 22 | 23 | @Test(expected = IllegalArgumentException.class) 24 | public void exception_thrown_when_range_is_invalid() { 25 | TargetRange.from(RANGE_TEN, RANGE_ZERO); 26 | } 27 | 28 | @Test 29 | public void hashcode_must_match() { 30 | TargetRange targetRange = TargetRange.from(RANGE_ONE, RANGE_FIVE); 31 | final int hashCode = targetRange.hashCode(); 32 | 33 | int expectedResult = 36; 34 | assertThat(hashCode).isEqualTo(expectedResult); 35 | } 36 | 37 | @Test 38 | public void hashcode_must_not_match() { 39 | TargetRange targetRange = TargetRange.from(RANGE_ONE, RANGE_FIVE); 40 | final int hashCode = targetRange.hashCode(); 41 | 42 | TargetRange otherRange = TargetRange.from(RANGE_ZERO, RANGE_TEN); 43 | assertThat(hashCode).isNotEqualTo(otherRange.hashCode()); 44 | } 45 | 46 | @Test 47 | public void target_range_must_be_equal() { 48 | TargetRange targetRange = TargetRange.from(RANGE_ZERO, RANGE_TEN); 49 | 50 | TargetRange expectedResult = TargetRange.from(RANGE_ZERO, RANGE_TEN); 51 | assertThat(targetRange).isEqualTo(expectedResult); 52 | } 53 | 54 | 55 | @Test 56 | public void target_range_compare_same_instance() { 57 | TargetRange targetRange = TargetRange.from(RANGE_ZERO, RANGE_TEN); 58 | 59 | assertThat(targetRange).isEqualTo(targetRange); 60 | } 61 | 62 | @Test 63 | public void target_range_must_not_be_equal() { 64 | TargetRange targetRange = TargetRange.from(RANGE_ZERO, RANGE_TEN); 65 | 66 | TargetRange expectedResult = TargetRange.from(RANGE_ONE, RANGE_FIVE); 67 | assertThat(targetRange).isNotEqualTo(expectedResult); 68 | } 69 | 70 | @Test 71 | public void target_range_start_must_not_be_equal() { 72 | TargetRange targetRange = TargetRange.from(RANGE_ZERO, RANGE_TEN); 73 | 74 | TargetRange expectedResult = TargetRange.from(RANGE_ONE, RANGE_TEN); 75 | assertThat(targetRange).isNotEqualTo(expectedResult); 76 | } 77 | 78 | @Test 79 | public void target_range_must_not_be_equal_they_are_different_types() { 80 | TargetRange targetRange = TargetRange.from(RANGE_ZERO, RANGE_TEN); 81 | assertThat(targetRange).isNotEqualTo("a different object type"); 82 | } 83 | 84 | @Test 85 | public void target_range_end_must_not_be_equal() { 86 | TargetRange targetRange = TargetRange.from(RANGE_ZERO, RANGE_TEN); 87 | 88 | TargetRange expectedResult = TargetRange.from(RANGE_ZERO, RANGE_FIVE); 89 | assertThat(targetRange).isNotEqualTo(expectedResult); 90 | } 91 | 92 | @Test 93 | public void getters_are_just_for_read_only() { 94 | TargetRange targetRange = TargetRange.from(RANGE_ZERO, RANGE_TEN); 95 | 96 | assertThat(targetRange.getStart()).isEqualTo(RANGE_ZERO); 97 | assertThat(targetRange.getEnd()).isEqualTo(RANGE_TEN); 98 | } 99 | 100 | @Test 101 | public void validating_target_range_to_string() { 102 | TargetRange targetRange = TargetRange.from(RANGE_ZERO, RANGE_TEN); 103 | 104 | assertThat(targetRange).hasToString("TargetRange{" + "start=" + RANGE_ZERO + ", end=" + RANGE_TEN + '}'); 105 | } 106 | } -------------------------------------------------------------------------------- /library/src/test/java/com/bunk3r/spanez/spans/ClickableSpanEZTest.java: -------------------------------------------------------------------------------- 1 | package com.bunk3r.spanez.spans; 2 | 3 | import android.text.style.ClickableSpan; 4 | 5 | import com.bunk3r.spanez.callbacks.OnSpanClickListener; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.mockito.Mock; 10 | import org.mockito.junit.MockitoJUnitRunner; 11 | 12 | import static org.mockito.Mockito.times; 13 | import static org.mockito.Mockito.verify; 14 | 15 | /** 16 | * Part of SpanEZ 17 | * Created by joragu on 1/17/2017. 18 | */ 19 | @RunWith(MockitoJUnitRunner.class) 20 | public class ClickableSpanEZTest { 21 | private static final String FAKE_CONTENT = "Dummy Content"; 22 | 23 | @Mock 24 | private OnSpanClickListener mockListener; 25 | 26 | @Test 27 | public void clicking_the_span_trigger_the_callback() { 28 | ClickableSpan clickableSpanEZ = ClickableSpanEZ.from(mockListener, FAKE_CONTENT); 29 | 30 | clickableSpanEZ.onClick(null); 31 | verify(mockListener, times(1)).onSpanClick(FAKE_CONTENT); 32 | } 33 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':library' 2 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | # suppress inspection "UnusedProperty" for whole file 2 | 3 | # Branches in which sonarQube will be run 4 | sonar.branch=master 5 | 6 | # must be unique in a given SonarQube instance 7 | sonar.projectKey=com.bunk3r:spanez 8 | # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. 9 | sonar.projectName=SpanEz 10 | sonar.projectVersion=2.0.1 11 | 12 | # Encoding of the source code. Default is default system encoding 13 | sonar.language=java 14 | sonar.sourceEncoding=UTF-8 15 | 16 | # Modules to be included in the report 17 | sonar.modules=library 18 | 19 | # Java compatibility version 20 | sonar.java.source=1.7 21 | 22 | # path to source and binaries for the code 23 | sonar.sources=src/main/java 24 | sonar.java.binaries=build/intermediates/classes/release 25 | 26 | # path to source and binaries for the tests 27 | sonar.tests=src/test/java 28 | sonar.java.test.binaries=build/intermediates/classes/test/release 29 | 30 | # path to the jacoco coverage report 31 | sonar.jacoco.reportPaths=build/jacoco/testReleaseUnitTest.exec --------------------------------------------------------------------------------