├── fixed-spans-sample ├── assets │ └── fonts │ │ ├── moonflowerfont.ttf │ │ └── font_readme.txt ├── res │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── drawable-xxxhdpi │ │ └── ic_launcher.png │ ├── values │ │ └── strings.xml │ └── layout │ │ └── main.xml ├── AndroidManifest.xml ├── pom.xml └── src │ └── com │ └── example │ └── fixedspans │ └── DemoActivity.java ├── .gitignore ├── fixed-spans ├── AndroidManifest.xml ├── res │ └── values │ │ └── attrs.xml ├── pom.xml └── src │ └── com │ └── chrisrenke │ └── fixedspans │ ├── JustifyingTextWatcher.java │ ├── MonospaceSpan.java │ ├── ShadowedCrossFadeSpan.java │ ├── TabularSpan.java │ ├── JustifyingTextView.java │ └── JustifySpan.java ├── README.md ├── pom.xml └── LICENSE.txt /fixed-spans-sample/assets/fonts/moonflowerfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChrisRenke/FixedSpans/HEAD/fixed-spans-sample/assets/fonts/moonflowerfont.ttf -------------------------------------------------------------------------------- /fixed-spans-sample/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChrisRenke/FixedSpans/HEAD/fixed-spans-sample/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /fixed-spans-sample/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChrisRenke/FixedSpans/HEAD/fixed-spans-sample/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /fixed-spans-sample/res/drawable-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChrisRenke/FixedSpans/HEAD/fixed-spans-sample/res/drawable-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse 2 | .classpath 3 | .project 4 | .settings/ 5 | 6 | # Intellij 7 | .idea/ 8 | *.iml 9 | *.iws 10 | 11 | # Mac 12 | .DS_Store 13 | 14 | # Maven 15 | log/ 16 | target/ -------------------------------------------------------------------------------- /fixed-spans/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | MonospaceSpan & TabularSpan 2 | =========================== 3 | 4 | Two simple spans to format any font in a monospace or tabular appearance. See [this little writeup](http://chrisrenke.com/spans/) for a thorough breakdown. 5 | 6 | ![MonospaceSpan](http://chrisrenke.com/assets/span_gif_mono.gif) 7 | 8 | ![TabularSpan](http://chrisrenke.com/assets/span_gif.gif) -------------------------------------------------------------------------------- /fixed-spans/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /fixed-spans-sample/assets/fonts/font_readme.txt: -------------------------------------------------------------------------------- 1 | FONT BY DENISE BENTULAN (c) 2013 2 | http://deathmunkey.deviantart.com 3 | http://www.dafont.com/denise-bentulan.d2156 4 | http://douxiegirl.com 5 | 6 | ----------------------------------------------------------------------------------------- 7 | 8 | Free for personal use ONLY. 9 | For commercial use, please email the designer at dnn.bntln@yahoo.com or contact@douxiegirl.com 10 | 11 | ----------------------------------------------------------------------------------------- 12 | 13 | PayPal donations are highly appreciated! 14 | these help me in a way through college. 15 | you may send them to my PayPal account, dnn.bntln@yahoo.com. 16 | 17 | thank you. 18 | 19 | ----------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /fixed-spans-sample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /fixed-spans/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.chrisrenke 9 | fixed-spans-parent 10 | 1.0-SNAPSHOT 11 | 12 | 13 | 14 | fixed-spans 15 | FixedSpans 16 | apklib 17 | 18 | 19 | 4.1.1.4 20 | 21 | 22 | 23 | 24 | com.google.android 25 | android 26 | ${platform.version} 27 | provided 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /fixed-spans-sample/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Fixed Spans 4 | 5 | Here\'s fixed spaced. 6 | Based on \'W\' or \'M\' 7 | Here\'s relative spaced. 8 | So\'s this one 9 | 10 | $29,011.11 11 | $51.78 12 | (555) 777-5555 13 | (111) 111-1111 14 | 192.168.1.1 15 | 16 | Actionbar title here 17 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 18 | 19 | 20 | -------------------------------------------------------------------------------- /fixed-spans-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.chrisrenke 9 | fixed-spans-parent 10 | 1.0-SNAPSHOT 11 | 12 | 13 | 14 | fixed-spans-sample 15 | FixedSpansSample 16 | apk 17 | 18 | 19 | UTF-8 20 | 4.1.1.4 21 | 3.6.0 22 | 23 | 24 | 25 | 26 | 27 | com.chrisrenke 28 | fixed-spans-parent 29 | ${project.version} 30 | 31 | 32 | 33 | com.google.android 34 | android 35 | ${platform.version} 36 | provided 37 | 38 | 39 | 40 | 41 | 42 | com.jayway.maven.plugins.android.generation2 43 | android-maven-plugin 44 | true 45 | 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-compiler-plugin 50 | 51 | 52 | 53 | org.apache.maven.plugins 54 | maven-checkstyle-plugin 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.chrisrenke 8 | fixed-spans-parent 9 | 1.0-SNAPSHOT 10 | pom 11 | 12 | FixedSpan (Parent) 13 | MonospaceSpan and TabularSpan 14 | 15 | 16 | fixed-spans 17 | fixed-spans-sample 18 | 19 | 20 | 21 | UTF-8 22 | 4.1.1.4 23 | 3.6.0 24 | 25 | 26 | 27 | 28 | com.google.android 29 | android 30 | ${platform.version} 31 | provided 32 | 33 | 34 | 35 | 36 | ${project.artifactId} 37 | 38 | 39 | 40 | com.jayway.maven.plugins.android.generation2 41 | android-maven-plugin 42 | ${android.plugin.version} 43 | true 44 | 45 | 46 | 47 | 48 | 49 | com.jayway.maven.plugins.android.generation2 50 | android-maven-plugin 51 | 52 | 53 | /Users/chrisrenke/Development/sdk/ 54 | 17 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /fixed-spans/src/com/chrisrenke/fixedspans/JustifyingTextWatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Chris Renke 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.chrisrenke.fixedspans; 18 | 19 | import android.text.Editable; 20 | import android.text.TextWatcher; 21 | import android.widget.TextView; 22 | 23 | import static com.chrisrenke.fixedspans.JustifySpan.Mode; 24 | import static com.chrisrenke.fixedspans.JustifySpan.Mode.ALL_CHARACTERS; 25 | import static com.chrisrenke.fixedspans.JustifySpan.Mode.WHITESPACE_ONLY; 26 | import static com.chrisrenke.fixedspans.JustifySpan.justify; 27 | 28 | public class JustifyingTextWatcher implements TextWatcher { 29 | 30 | public static JustifyingTextWatcher buildJustifier(TextView view, boolean justifyLastLine, 31 | float whitespaceWeight) { 32 | return new JustifyingTextWatcher(view, justifyLastLine, whitespaceWeight, ALL_CHARACTERS); 33 | } 34 | 35 | public static JustifyingTextWatcher buildJustifier(TextView view, boolean justifyLastLine) { 36 | return new JustifyingTextWatcher(view, justifyLastLine, -1f, WHITESPACE_ONLY); 37 | } 38 | 39 | private final TextView view; 40 | private final float whitespaceWeight; 41 | private final boolean justifyLastLine; 42 | private final Mode mode; 43 | 44 | private boolean ignoreNextPass; 45 | 46 | private JustifyingTextWatcher(TextView view, boolean justifyLastLine, float whitespaceWeight, 47 | Mode mode) { 48 | this.view = view; 49 | this.whitespaceWeight = whitespaceWeight; 50 | this.justifyLastLine = justifyLastLine; 51 | this.mode = mode; 52 | } 53 | 54 | @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { 55 | } 56 | 57 | @Override public void onTextChanged(CharSequence s, int start, int before, int count) { 58 | } 59 | 60 | @Override public void afterTextChanged(Editable s) { 61 | if (ignoreNextPass || s.toString().length() == 0) { 62 | ignoreNextPass = false; 63 | return; 64 | } 65 | ignoreNextPass = true; 66 | justify(view, justifyLastLine, whitespaceWeight, mode); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /fixed-spans/src/com/chrisrenke/fixedspans/MonospaceSpan.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Chris Renke 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.chrisrenke.fixedspans; 18 | 19 | import android.graphics.Canvas; 20 | import android.graphics.Paint; 21 | import android.text.style.ReplacementSpan; 22 | 23 | import static java.lang.Math.ceil; 24 | 25 | /** A {@link ReplacementSpan} that monospaces single-line text. */ 26 | public class MonospaceSpan extends ReplacementSpan { 27 | 28 | private static final String REFERENCE_CHARACTERS = "MW"; 29 | 30 | private final String relativeCharacters; 31 | 32 | /** 33 | * Set the {@code relativeMonospace} flag to true to monospace based on the widest character 34 | * in the content string; false will base the monospace on the widest width of 'M' or 'W'. 35 | */ 36 | public MonospaceSpan(boolean relativeMonospace) { 37 | this.relativeCharacters = relativeMonospace ? null : REFERENCE_CHARACTERS; 38 | } 39 | 40 | /** Use the widest character from {@code relativeCharacters} to determine monospace width. */ 41 | public MonospaceSpan(String relativeCharacters) { 42 | this.relativeCharacters = relativeCharacters; 43 | } 44 | 45 | public MonospaceSpan() { 46 | this.relativeCharacters = REFERENCE_CHARACTERS; 47 | } 48 | 49 | @Override 50 | public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { 51 | if (fm != null) paint.getFontMetricsInt(fm); 52 | return (int) ceil((end - start) * getMonoWidth(paint, text.subSequence(start, end))); 53 | } 54 | 55 | @Override 56 | public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, 57 | int bottom, Paint paint) { 58 | CharSequence actualText = text.subSequence(start, end); 59 | float monowidth = getMonoWidth(paint, actualText); 60 | for (int i = 0; i < actualText.length(); i++) { 61 | float textWidth = paint.measureText(actualText, i, i + 1); 62 | float halfFreeSpace = (textWidth - monowidth) / 2f; 63 | canvas.drawText(actualText, i, i + 1, x + (monowidth * i) - halfFreeSpace, y, paint); 64 | } 65 | } 66 | 67 | private float getMonoWidth(Paint paint, CharSequence text) { 68 | text = relativeCharacters == null ? text : relativeCharacters; 69 | float maxWidth = 0; 70 | for (int i = 0; i < text.length(); i++) { 71 | maxWidth = Math.max(paint.measureText(text, i, i + 1), maxWidth); 72 | } 73 | return maxWidth; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /fixed-spans/src/com/chrisrenke/fixedspans/ShadowedCrossFadeSpan.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Chris Renke 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.chrisrenke.fixedspans; 18 | 19 | import android.graphics.Color; 20 | import android.text.TextPaint; 21 | import android.text.style.CharacterStyle; 22 | 23 | import static android.graphics.Color.argb; 24 | import static android.graphics.Color.blue; 25 | import static android.graphics.Color.green; 26 | import static android.graphics.Color.red; 27 | 28 | public class ShadowedCrossFadeSpan extends CharacterStyle { 29 | 30 | private final int initialTextColor; 31 | private final int endTextColor; 32 | private final int initialShadowColor; 33 | private final int endShadowColor; 34 | private final int initialShadowOpacity; 35 | private final int endShadowOpacity; 36 | private final int shadowOffsetX; 37 | private final int shadowOffsetY; 38 | private final int shadowRadius; 39 | 40 | private int currentColor; 41 | private int currentShadowColor; 42 | private int currentShadowOpacity; 43 | 44 | public ShadowedCrossFadeSpan(int initialTextColor, int endTextColor, int shadowColor, 45 | int initialShadowOpacity, int endShadowOpacity, int shadowOffsetX, int shadowOffsetY, 46 | int shadowRadius) { 47 | this(initialTextColor, endTextColor, shadowColor, shadowColor, initialShadowOpacity, 48 | endShadowOpacity, shadowOffsetX, shadowOffsetY, shadowRadius); 49 | } 50 | 51 | public ShadowedCrossFadeSpan(int initialTextColor, int endTextColor, int initialShadowColor, 52 | int endShadowColor, int initialShadowOpacity, int endShadowOpacity, int shadowOffsetX, 53 | int shadowOffsetY, int shadowRadius) { 54 | this.initialTextColor = initialTextColor; 55 | this.endTextColor = endTextColor; 56 | this.initialShadowColor = initialShadowColor; 57 | this.endShadowColor = endShadowColor; 58 | this.initialShadowOpacity = initialShadowOpacity; 59 | this.endShadowOpacity = endShadowOpacity; 60 | this.shadowOffsetX = shadowOffsetX; 61 | this.shadowOffsetY = shadowOffsetY; 62 | this.shadowRadius = shadowRadius; 63 | 64 | // Set the span to the initial state. 65 | setParameter(0); 66 | } 67 | 68 | @Override public void updateDrawState(TextPaint tp) { 69 | tp.setColor(currentColor); 70 | tp.setShadowLayer(shadowRadius, shadowOffsetX, shadowOffsetY, argb(currentShadowOpacity, // 71 | red(currentShadowColor), green(currentShadowColor), blue(currentShadowColor))); 72 | } 73 | 74 | public void setParameter(float t) { 75 | currentShadowOpacity = param(initialShadowOpacity, endShadowOpacity, t); 76 | currentShadowColor = Color.rgb(param(red(initialShadowColor), red(endShadowColor), t), // 77 | param(green(initialShadowColor), green(endShadowColor), t), // 78 | param(blue(initialShadowColor), blue(endShadowColor), t)); 79 | currentColor = Color.rgb(param(red(initialTextColor), red(endTextColor), t), // 80 | param(green(initialTextColor), green(endTextColor), t), // 81 | param(blue(initialTextColor), blue(endTextColor), t)); 82 | } 83 | 84 | private static int param(int min, int max, float t) { 85 | return (int) ((max - min) * t) + min; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /fixed-spans/src/com/chrisrenke/fixedspans/TabularSpan.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Chris Renke 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.chrisrenke.fixedspans; 18 | 19 | import android.graphics.Canvas; 20 | import android.graphics.Paint; 21 | import android.text.style.ReplacementSpan; 22 | 23 | /** 24 | * Class to format spans of currencies with all numerals being the same width and all delimiters 25 | * being the same width (distinct from the numeral width). Other characters are their normal width. 26 | */ 27 | public class TabularSpan extends ReplacementSpan { 28 | private static final String DEFAULT_DELIMITER_CHARACTERS = ",."; 29 | private static final String DEFAULT_NUMERAL_CHARACTERS = "0123456789"; 30 | 31 | private final String delimiters; 32 | private final String numerals; 33 | 34 | public TabularSpan() { 35 | this.delimiters = DEFAULT_DELIMITER_CHARACTERS; 36 | this.numerals = DEFAULT_NUMERAL_CHARACTERS; 37 | } 38 | 39 | public TabularSpan(String delimiters, String numerals) { 40 | this.delimiters = delimiters; 41 | this.numerals = numerals; 42 | } 43 | 44 | @Override 45 | public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { 46 | if (fm != null) paint.getFontMetricsInt(fm); 47 | 48 | CharSequence actualText = text.subSequence(start, end); 49 | float numberWidth = getMaxCharacterWidth(paint, numerals); 50 | float delimiterWidth = getMaxCharacterWidth(paint, delimiters); 51 | float totalWidth = 0; 52 | 53 | for (int i = 0; i < actualText.length(); i++) { 54 | CharSequence character = actualText.subSequence(i, i + 1); 55 | if (delimiters.contains(character)) { 56 | totalWidth += delimiterWidth; 57 | } else if (numerals.contains(character)) { 58 | totalWidth += numberWidth; 59 | } else { 60 | totalWidth += paint.measureText(character, 0, 1); 61 | } 62 | } 63 | return (int) Math.ceil(totalWidth); 64 | } 65 | 66 | @Override 67 | public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, 68 | int bottom, Paint paint) { 69 | CharSequence actualText = text.subSequence(start, end); 70 | float numberWidth = getMaxCharacterWidth(paint, numerals); 71 | float delimiterWidth = getMaxCharacterWidth(paint, delimiters); 72 | 73 | for (int i = 0; i < actualText.length(); i++) { 74 | CharSequence character = actualText.subSequence(i, i + 1); 75 | float charWidth = paint.measureText(actualText, i, i + 1); 76 | float monoWidth; 77 | if (delimiters.contains(character)) { 78 | monoWidth = delimiterWidth; 79 | } else if (numerals.contains(character)) { 80 | monoWidth = numberWidth; 81 | } else { 82 | monoWidth = charWidth; 83 | } 84 | float halfFreeSpace = (monoWidth - charWidth) / 2f; 85 | canvas.drawText(actualText, i, i + 1, x + halfFreeSpace, y, paint); 86 | x += monoWidth; 87 | } 88 | } 89 | 90 | private static float getMaxCharacterWidth(Paint paint, CharSequence characters) { 91 | float maxWidth = 0; 92 | for (int i = 0; i < characters.length(); i++) { 93 | maxWidth = Math.max(paint.measureText(characters, i, i + 1), maxWidth); 94 | } 95 | return maxWidth; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /fixed-spans/src/com/chrisrenke/fixedspans/JustifyingTextView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Chris Renke 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.chrisrenke.fixedspans; 18 | 19 | import android.content.Context; 20 | import android.content.res.TypedArray; 21 | import android.util.AttributeSet; 22 | import android.widget.TextView; 23 | 24 | import static com.chrisrenke.fixedspans.JustifySpan.Mode; 25 | import static com.chrisrenke.fixedspans.JustifySpan.Mode.WHITESPACE_ONLY; 26 | import static com.chrisrenke.fixedspans.JustifySpan.justify; 27 | import static com.example.fixedspans.R.styleable; 28 | 29 | /** Thin extension of {@link TextView} that automatically justifies its text. */ 30 | public class JustifyingTextView extends TextView { 31 | 32 | private static final Mode DEF_MODE = WHITESPACE_ONLY; 33 | private static final boolean DEF_LAST_LINE = false; 34 | private static final float DEF_WEIGHT = 2f; 35 | 36 | private Mode mode; 37 | private boolean justifyLastLine; 38 | private float whitespaceWeight; 39 | 40 | public JustifyingTextView(Context context) { 41 | this(context, null); 42 | } 43 | 44 | public JustifyingTextView(Context context, AttributeSet attrs) { 45 | this(context, attrs, android.R.attr.textViewStyle); 46 | } 47 | 48 | public JustifyingTextView(Context context, AttributeSet attrs, int defStyle) { 49 | super(context, attrs, defStyle); 50 | TypedArray a = context.obtainStyledAttributes(attrs, styleable.JustifyingTextView, defStyle, 0); 51 | whitespaceWeight = getFloat(a, styleable.JustifyingTextView_whitespaceWeight, DEF_WEIGHT); 52 | mode = getEnum(a, styleable.JustifyingTextView_justifyMode, Mode.values(), DEF_MODE); 53 | justifyLastLine = getBoolean(a, styleable.JustifyingTextView_justifyLastLine, DEF_LAST_LINE); 54 | a.recycle(); 55 | justify(this, justifyLastLine, whitespaceWeight, mode); 56 | } 57 | 58 | @Override 59 | protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) { 60 | super.onTextChanged(text, start, lengthBefore, lengthAfter); 61 | justify(this, justifyLastLine, whitespaceWeight, mode); 62 | } 63 | 64 | @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { 65 | super.onSizeChanged(w, h, oldw, oldh); 66 | justify(this, justifyLastLine, whitespaceWeight, mode); 67 | } 68 | 69 | @Override public void setTextSize(float size) { 70 | super.setTextSize(size); 71 | justify(this, justifyLastLine, whitespaceWeight, mode); 72 | } 73 | 74 | @Override public void setTextSize(int unit, float size) { 75 | super.setTextSize(unit, size); 76 | justify(this, justifyLastLine, whitespaceWeight, mode); 77 | } 78 | 79 | @Override public void setTextAppearance(Context context, int resid) { 80 | super.setTextAppearance(context, resid); 81 | justify(this, justifyLastLine, whitespaceWeight, mode); 82 | } 83 | 84 | private static > E getEnum(TypedArray attributes, int styleableIndex, 85 | E[] values, E defValue) { 86 | int index = attributes.getInteger(styleableIndex, -1); 87 | if (index < 0) return defValue; 88 | return values[index]; 89 | } 90 | 91 | private static boolean getBoolean(TypedArray attributes, int styleableIndex, boolean defValue) { 92 | return attributes.getBoolean(styleableIndex, defValue); 93 | } 94 | 95 | private static float getFloat(TypedArray attributes, int styleableIndex, float defValue) { 96 | return attributes.getFloat(styleableIndex, defValue); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /fixed-spans-sample/src/com/example/fixedspans/DemoActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Chris Renke 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.fixedspans; 18 | 19 | import android.app.ActionBar; 20 | import android.app.Activity; 21 | import android.content.Context; 22 | import android.graphics.Paint; 23 | import android.graphics.Typeface; 24 | import android.os.Bundle; 25 | import android.text.SpannableString; 26 | import android.text.TextPaint; 27 | import android.text.style.CharacterStyle; 28 | import android.text.style.TypefaceSpan; 29 | import android.widget.SeekBar; 30 | import android.widget.TextView; 31 | import com.chrisrenke.fixedspans.MonospaceSpan; 32 | import com.chrisrenke.fixedspans.ShadowedCrossFadeSpan; 33 | import com.chrisrenke.fixedspans.TabularSpan; 34 | 35 | import static android.graphics.Color.BLACK; 36 | import static android.graphics.Color.WHITE; 37 | 38 | public class DemoActivity extends Activity { 39 | 40 | @Override 41 | public void onCreate(Bundle savedInstanceState) { 42 | super.onCreate(savedInstanceState); 43 | setContentView(com.example.fixedspans.R.layout.main); 44 | 45 | ActionBar actionBar = getActionBar(); 46 | SpannableString title = new SpannableString(getResources().getText(R.string.app_name)); 47 | title.setSpan(new MonospaceSpan(), 0, title.length(), 0); 48 | actionBar.setTitle(title); 49 | 50 | span(R.id.mono_0, new MonospaceSpan()); 51 | span(R.id.mono_1, new MonospaceSpan()); 52 | span(R.id.mono_2, new MonospaceSpan(true)); 53 | span(R.id.mono_3, new MonospaceSpan(true)); 54 | 55 | span(R.id.tabular_0, new MoonFlowerSpan(this)); 56 | span(R.id.tabular_0, new TabularSpan()); 57 | span(R.id.tabular_1, new MoonFlowerSpan(this)); 58 | span(R.id.tabular_1, new TabularSpan()); 59 | span(R.id.tabular_2, new MoonFlowerSpan(this)); 60 | span(R.id.tabular_2, new TabularSpan(" ()-", "0123456789")); 61 | span(R.id.tabular_3, new MoonFlowerSpan(this)); 62 | span(R.id.tabular_3, new TabularSpan(" ()-", "0123456789")); 63 | span(R.id.tabular_4, new MoonFlowerSpan(this)); 64 | span(R.id.tabular_4, new TabularSpan()); 65 | 66 | span(R.id.normal_0, new MoonFlowerSpan(this)); 67 | span(R.id.normal_1, new MoonFlowerSpan(this)); 68 | span(R.id.normal_2, new MoonFlowerSpan(this)); 69 | span(R.id.normal_3, new MoonFlowerSpan(this)); 70 | span(R.id.normal_4, new MoonFlowerSpan(this)); 71 | 72 | SeekBar seek = (SeekBar) findViewById(R.id.seek_bar); 73 | final ShadowedCrossFadeSpan span = 74 | new ShadowedCrossFadeSpan(WHITE, BLACK, BLACK, 200, 0, 0, 2, 6); 75 | final TextView fadetext = (TextView) findViewById(R.id.fade_0); 76 | seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 77 | @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 78 | span.setParameter((float) progress / (float) seekBar.getMax()); 79 | SpannableString spannableString = new SpannableString(fadetext.getText().toString()); 80 | spannableString.setSpan(span, 0, spannableString.length(), 0); 81 | fadetext.setText(spannableString); 82 | } 83 | 84 | @Override public void onStartTrackingTouch(SeekBar seekBar) { 85 | } 86 | 87 | @Override public void onStopTrackingTouch(SeekBar seekBar) { 88 | } 89 | }); 90 | span(R.id.fade_0, span); 91 | } 92 | 93 | private void span(int id, CharacterStyle span) { 94 | TextView view = (TextView) findViewById(id); 95 | SpannableString spannableString = new SpannableString(view.getText()); 96 | spannableString.setSpan(span, 0, spannableString.length(), 0); 97 | view.setText(spannableString); 98 | } 99 | 100 | public class MoonFlowerSpan extends TypefaceSpan { 101 | 102 | private static final String FONT_FAMILY = "sans-serif"; 103 | private final Context context; 104 | 105 | MoonFlowerSpan(Context context) { 106 | super(FONT_FAMILY); 107 | this.context = context; 108 | } 109 | 110 | @Override public void updateDrawState(TextPaint p) { 111 | applyCustomTypeface(p); 112 | } 113 | 114 | @Override public void updateMeasureState(TextPaint p) { 115 | applyCustomTypeface(p); 116 | } 117 | 118 | private void applyCustomTypeface(Paint paint) { 119 | paint.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/moonflowerfont.ttf")); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /fixed-spans-sample/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 17 | 18 | 24 | 25 | 31 | 32 | 38 | 39 | 45 | 46 | 51 | 52 | 58 | 66 | 74 | 82 | 90 | 98 | 99 | 100 | 106 | 114 | 122 | 130 | 138 | 146 | 147 | 148 | 149 | 150 | 159 | 160 | 168 | 169 | 176 | 177 | 186 | 187 | 196 | 197 | 198 | 208 | 209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /fixed-spans/src/com/chrisrenke/fixedspans/JustifySpan.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Chris Renke 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.chrisrenke.fixedspans; 18 | 19 | import android.graphics.Canvas; 20 | import android.graphics.Color; 21 | import android.graphics.Paint; 22 | import android.text.Layout; 23 | import android.text.SpannableString; 24 | import android.text.SpannableStringBuilder; 25 | import android.text.TextPaint; 26 | import android.text.style.ReplacementSpan; 27 | import android.view.ViewTreeObserver; 28 | import android.widget.TextView; 29 | 30 | import static com.chrisrenke.fixedspans.JustifySpan.Mode.ALL_CHARACTERS; 31 | import static com.chrisrenke.fixedspans.JustifySpan.Mode.WHITESPACE_ONLY; 32 | import static java.lang.Character.isWhitespace; 33 | 34 | /** 35 | * Justifies a line of text relative to the given width (assumed to be the width of the view). 36 | * If using outside of a singleline context, use {@link JustifySpan#justify(TextView, 37 | * boolean, float)} or {@link JustifySpan#justify(android.widget.TextView, boolean)} to 38 | * handle all the hard work for you. 39 | */ 40 | public class JustifySpan extends ReplacementSpan { 41 | 42 | /** Justifies the given {@code textView} with weighted all character justification. */ 43 | public static void justify(final TextView textView, final boolean justifyLastLine, 44 | final float whitespaceWeight) { 45 | justify(textView, justifyLastLine, whitespaceWeight, ALL_CHARACTERS); 46 | } 47 | 48 | /** Justifies the given {@code textView} with whitespace justification. */ 49 | public static void justify(final TextView textView, final boolean justifyLastLine) { 50 | justify(textView, justifyLastLine, 1f, ALL_CHARACTERS); 51 | } 52 | 53 | public static enum Mode {WHITESPACE_ONLY, ALL_CHARACTERS} 54 | 55 | private final float lineWidth; 56 | private final float whitespaceWeight; 57 | 58 | public JustifySpan(float lineWidth) { 59 | this(lineWidth, -1); 60 | } 61 | 62 | public JustifySpan(float lineWidth, float whitespaceWeight) { 63 | this.lineWidth = lineWidth; 64 | this.whitespaceWeight = whitespaceWeight; 65 | } 66 | 67 | /** Since this span justifies text, it will always take the full line width. */ 68 | @Override 69 | public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { 70 | return (int) lineWidth; 71 | } 72 | 73 | @Override 74 | public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, 75 | int bottom, Paint paint) { 76 | CharSequence actualText = text.subSequence(start, end); 77 | 78 | // Prune trailing whitespace characters from line 79 | if (Character.isWhitespace(actualText.charAt(actualText.length() - 1))) { 80 | actualText = actualText.subSequence(0, actualText.length() - 1); 81 | } 82 | 83 | float textWidth = paint.measureText(actualText, 0, actualText.length()); 84 | float differenceWidth = lineWidth - textWidth; 85 | 86 | // If there's no available space, draw the text as usual. 87 | if (differenceWidth <= 0) { 88 | canvas.drawText(text, start, end, x, y, paint); 89 | return; 90 | } 91 | 92 | int whitespaceCharacters = 0; 93 | for (int i = 0; i < actualText.length(); i++) { 94 | if (isWhitespace(actualText.charAt(i))) whitespaceCharacters++; 95 | } 96 | 97 | if (whitespaceWeight > 0) { 98 | drawTextOmniSpacing(canvas, text, start, end, x, y, paint, actualText, differenceWidth, 99 | whitespaceCharacters); 100 | } else { 101 | drawTextWhitespace(canvas, text, start, end, x, y, paint, actualText, differenceWidth, 102 | whitespaceCharacters); 103 | } 104 | } 105 | 106 | /** 107 | * Draws the given sequence of text onto the canvas with additional width given to whitespace 108 | * characters; non-whitespace characters will be drawn normally. 109 | */ 110 | private void drawTextWhitespace(Canvas canvas, CharSequence text, int start, int end, float x, 111 | int y, Paint paint, CharSequence actualText, float differenceWidth, 112 | int whitespaceCharacters) { 113 | 114 | ((TextPaint) paint).bgColor = Color.RED; 115 | float addPerWhitespace = differenceWidth / (float) whitespaceCharacters; 116 | 117 | for (int i = 0; i < actualText.length(); i++) { 118 | float characterWidth = paint.measureText(actualText, i, i + 1); 119 | canvas.drawText(actualText, i, i + 1, x, y, paint); 120 | x += characterWidth; 121 | if (isWhitespace(actualText.charAt(i))) x += addPerWhitespace; 122 | } 123 | } 124 | 125 | /** 126 | * Draws the given sequence of text onto the canvas with additional spacing placed around every 127 | * character, with more or less space given to whitespace characters based on the strength of 128 | * this span's {@code whitespaceWeight}. 129 | */ 130 | private void drawTextOmniSpacing(Canvas canvas, CharSequence text, int start, int end, float x, 131 | int y, Paint paint, CharSequence actualText, float differenceWidth, 132 | int whitespaceCharacters) { 133 | int nonWhitespaceCharacters = actualText.length() - whitespaceCharacters; 134 | 135 | float addPerCharacter = 136 | differenceWidth / ((whitespaceCharacters * whitespaceWeight) + nonWhitespaceCharacters); 137 | float halfAddPerCharacter = addPerCharacter / 2f; 138 | 139 | for (int i = 0; i < actualText.length(); i++) { 140 | float characterWidth = paint.measureText(actualText, i, i + 1); 141 | float characterPadding = isWhitespace(actualText.charAt(i)) // 142 | ? halfAddPerCharacter * whitespaceWeight // 143 | : halfAddPerCharacter; 144 | 145 | x += characterPadding; 146 | canvas.drawText(actualText, i, i + 1, x, y, paint); 147 | x += characterPadding + characterWidth; 148 | } 149 | } 150 | 151 | /** Internal method to be started from the two sister justify() methods or package members. */ 152 | static void justify(final TextView textView, final boolean justifyLastLine, 153 | final float whitespaceWeight, final Mode mode) { 154 | ViewTreeObserver vto = textView.getViewTreeObserver(); 155 | vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 156 | public void onGlobalLayout() { 157 | ViewTreeObserver obs = textView.getViewTreeObserver(); 158 | obs.removeGlobalOnLayoutListener(this); 159 | doJustify(textView, justifyLastLine, whitespaceWeight, mode); 160 | } 161 | }); 162 | } 163 | 164 | private static void doJustify(TextView textView, boolean justifyLastLine, float whitespaceWeight, 165 | Mode mode) { 166 | Layout layout = textView.getLayout(); 167 | 168 | // If layout is null, we can't do anything, abort abort abort. 169 | if (layout == null) return; 170 | 171 | int lines = layout.getLineCount(); 172 | SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); 173 | for (int line = 0; line < lines; line++) { 174 | CharSequence lineText = 175 | layout.getText().subSequence(layout.getLineStart(line), layout.getLineEnd(line)); 176 | 177 | // If justifyLastLine is false, don't format the last line at all 178 | if (lines > 1 && line == lines - 1 && !justifyLastLine) { 179 | spannableStringBuilder.append(lineText); 180 | } else { 181 | SpannableString spannableString = new SpannableString(lineText); 182 | int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight(); 183 | JustifySpan span = mode == WHITESPACE_ONLY // 184 | ? new JustifySpan(width) // 185 | : new JustifySpan(width, whitespaceWeight); 186 | spannableString.setSpan(span, 0, spannableString.length(), 0); 187 | spannableStringBuilder.append(spannableString); 188 | } 189 | 190 | // Add a manual newline or bad stuff happens as a result of replacement span. 191 | spannableStringBuilder.append(line != lines - 1 ? "\n" : ""); 192 | } 193 | 194 | // Update textView with new charsequence 195 | textView.setText(spannableStringBuilder.subSequence(0, spannableStringBuilder.length())); 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | Copyright 2014 Chris Renke 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. --------------------------------------------------------------------------------