Skip to content

Commit 7a3ac1c

Browse files
authored
Merge pull request #239 from wordpress-mobile/issue/238-add-underline-format
Issue/238 add underline format
2 parents c372d6d + c91a730 commit 7a3ac1c

File tree

11 files changed

+174
-27
lines changed

11 files changed

+174
-27
lines changed

aztec/src/main/java/org/wordpress/aztec/Html.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ private void handleEndTag(String tag) {
613613
} else if (tag.equalsIgnoreCase("a")) {
614614
end(spannableStringBuilder, TextFormat.FORMAT_LINK);
615615
} else if (tag.equalsIgnoreCase("u")) {
616-
end(spannableStringBuilder, TextFormat.FORMAT_UNDERLINED);
616+
end(spannableStringBuilder, TextFormat.FORMAT_UNDERLINE);
617617
} else if (tag.equalsIgnoreCase("sup")) {
618618
end(spannableStringBuilder, TextFormat.FORMAT_SUPERSCRIPT);
619619
} else if (tag.equalsIgnoreCase("sub")) {
@@ -678,7 +678,7 @@ private static void end(SpannableStringBuilder text, TextFormat textFormat) {
678678
newSpan = new AztecStyleSpan(Typeface.ITALIC, Html.stringifyAttributes(marker.attributes).toString());
679679
}
680680
break;
681-
case FORMAT_UNDERLINED:
681+
case FORMAT_UNDERLINE:
682682
marker = (AttributedMarker) getLast(text, Underline.class);
683683
if (marker != null) {
684684
newSpan = new AztecUnderlineSpan(Html.stringifyAttributes(marker.attributes).toString());

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ class AztecText : EditText, TextWatcher {
410410
TextFormat.FORMAT_HEADING_6 -> lineBlockFormatter.applyHeading(textFormat)
411411
TextFormat.FORMAT_BOLD -> inlineFormatter.toggleBold()
412412
TextFormat.FORMAT_ITALIC -> inlineFormatter.toggleItalic()
413+
TextFormat.FORMAT_UNDERLINE -> inlineFormatter.toggleUnderline()
413414
TextFormat.FORMAT_STRIKETHROUGH -> inlineFormatter.toggleStrikethrough()
414415
TextFormat.FORMAT_UNORDERED_LIST -> blockFormatter.toggleUnorderedList()
415416
TextFormat.FORMAT_ORDERED_LIST -> blockFormatter.toggleOrderedList()
@@ -434,7 +435,7 @@ class AztecText : EditText, TextWatcher {
434435
TextFormat.FORMAT_HEADING_6 -> return lineBlockFormatter.containsHeading(format, selStart, selEnd)
435436
TextFormat.FORMAT_BOLD -> return inlineFormatter.containsInlineStyle(TextFormat.FORMAT_BOLD, selStart, selEnd)
436437
TextFormat.FORMAT_ITALIC -> return inlineFormatter.containsInlineStyle(TextFormat.FORMAT_ITALIC, selStart, selEnd)
437-
TextFormat.FORMAT_UNDERLINED -> return inlineFormatter.containsInlineStyle(TextFormat.FORMAT_UNDERLINED, selStart, selEnd)
438+
TextFormat.FORMAT_UNDERLINE -> return inlineFormatter.containsInlineStyle(TextFormat.FORMAT_UNDERLINE, selStart, selEnd)
438439
TextFormat.FORMAT_STRIKETHROUGH -> return inlineFormatter.containsInlineStyle(TextFormat.FORMAT_STRIKETHROUGH, selStart, selEnd)
439440
TextFormat.FORMAT_UNORDERED_LIST -> return blockFormatter.containsList(TextFormat.FORMAT_UNORDERED_LIST, selStart, selEnd)
440441
TextFormat.FORMAT_ORDERED_LIST -> return blockFormatter.containsList(TextFormat.FORMAT_ORDERED_LIST, selStart, selEnd)
@@ -719,7 +720,7 @@ class AztecText : EditText, TextWatcher {
719720
inlineFormatter.removeInlineStyle(TextFormat.FORMAT_BOLD, start, end)
720721
inlineFormatter.removeInlineStyle(TextFormat.FORMAT_ITALIC, start, end)
721722
inlineFormatter.removeInlineStyle(TextFormat.FORMAT_STRIKETHROUGH, start, end)
722-
inlineFormatter.removeInlineStyle(TextFormat.FORMAT_UNDERLINED, start, end)
723+
inlineFormatter.removeInlineStyle(TextFormat.FORMAT_UNDERLINE, start, end)
723724
inlineFormatter.removeInlineStyle(TextFormat.FORMAT_CODE, start, end)
724725
}
725726

aztec/src/main/kotlin/org/wordpress/aztec/TextFormat.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ enum class TextFormat {
1212
FORMAT_HEADING_6,
1313
FORMAT_BOLD,
1414
FORMAT_ITALIC,
15-
FORMAT_UNDERLINED,
15+
FORMAT_UNDERLINE,
1616
FORMAT_STRIKETHROUGH,
1717
FORMAT_UNORDERED_LIST,
1818
FORMAT_ORDERED_LIST,

aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, val headerSty
3535
}
3636
}
3737

38-
fun toggleUnderline() {
39-
if (!containsInlineStyle(TextFormat.FORMAT_UNDERLINED)) {
40-
applyInlineStyle(TextFormat.FORMAT_UNDERLINED)
41-
} else {
42-
removeInlineStyle(TextFormat.FORMAT_UNDERLINED)
43-
}
44-
}
45-
4638
fun toggleStrikethrough() {
4739
if (!containsInlineStyle(TextFormat.FORMAT_STRIKETHROUGH)) {
4840
applyInlineStyle(TextFormat.FORMAT_STRIKETHROUGH)
@@ -51,6 +43,14 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, val headerSty
5143
}
5244
}
5345

46+
fun toggleUnderline() {
47+
if (!containsInlineStyle(TextFormat.FORMAT_UNDERLINE)) {
48+
applyInlineStyle(TextFormat.FORMAT_UNDERLINE)
49+
} else {
50+
removeInlineStyle(TextFormat.FORMAT_UNDERLINE)
51+
}
52+
}
53+
5454
fun toggleCode() {
5555
if (!containsInlineStyle(TextFormat.FORMAT_CODE)) {
5656
applyInlineStyle(TextFormat.FORMAT_CODE)
@@ -106,6 +106,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, val headerSty
106106
TextFormat.FORMAT_BOLD,
107107
TextFormat.FORMAT_ITALIC,
108108
TextFormat.FORMAT_STRIKETHROUGH,
109+
TextFormat.FORMAT_UNDERLINE,
109110
TextFormat.FORMAT_CODE -> if (!editor.contains(item, textChangedEvent.inputStart, textChangedEvent.inputEnd)) {
110111
applyInlineStyle(item, textChangedEvent.inputStart, textChangedEvent.inputEnd)
111112
}
@@ -136,6 +137,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, val headerSty
136137
TextFormat.FORMAT_BOLD,
137138
TextFormat.FORMAT_ITALIC,
138139
TextFormat.FORMAT_STRIKETHROUGH,
140+
TextFormat.FORMAT_UNDERLINE,
139141
TextFormat.FORMAT_CODE -> removeInlineStyle(it, newStart, end)
140142
else -> {
141143
//do nothing
@@ -356,7 +358,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, val headerSty
356358
TextFormat.FORMAT_BOLD -> return AztecStyleSpan(Typeface.BOLD)
357359
TextFormat.FORMAT_ITALIC -> return AztecStyleSpan(Typeface.ITALIC)
358360
TextFormat.FORMAT_STRIKETHROUGH -> return AztecStrikethroughSpan()
359-
TextFormat.FORMAT_UNDERLINED -> return AztecUnderlineSpan()
361+
TextFormat.FORMAT_UNDERLINE -> return AztecUnderlineSpan()
360362
TextFormat.FORMAT_CODE -> return AztecCodeSpan(codeStyle)
361363
else -> return AztecStyleSpan(Typeface.NORMAL)
362364
}

aztec/src/main/kotlin/org/wordpress/aztec/toolbar/ToolbarAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum class ToolbarAction constructor(val buttonId: Int, val actionType: ToolbarA
1313
BOLD(R.id.format_bar_button_bold, ToolbarActionType.INLINE_STYLE, TextFormat.FORMAT_BOLD),
1414
ITALIC(R.id.format_bar_button_italic, ToolbarActionType.INLINE_STYLE, TextFormat.FORMAT_ITALIC),
1515
STRIKETHROUGH(R.id.format_bar_button_strikethrough, ToolbarActionType.INLINE_STYLE, TextFormat.FORMAT_STRIKETHROUGH),
16+
UNDERLINE(R.id.format_bar_button_underline, ToolbarActionType.INLINE_STYLE, TextFormat.FORMAT_UNDERLINE),
1617
UNORDERED_LIST(R.id.format_bar_button_ul, ToolbarActionType.BLOCK_STYLE, TextFormat.FORMAT_UNORDERED_LIST),
1718
ORDERED_LIST(R.id.format_bar_button_ol, ToolbarActionType.BLOCK_STYLE, TextFormat.FORMAT_ORDERED_LIST),
1819
QUOTE(R.id.format_bar_button_quote, ToolbarActionType.BLOCK_STYLE, TextFormat.FORMAT_QUOTE),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:height="44dp"
6+
android:width="44dp"
7+
android:viewportHeight="44"
8+
android:viewportWidth="44" >
9+
10+
<!-- @color/grey_darken_20 -->
11+
<path
12+
android:fillColor="#ff4f748e"
13+
android:pathData="M14,29v2h16v-2H14z M28,13v8c0,3.3-2.7,6-6,6s-6-2.7-6-6v-8h3v8c0,1.6,1.4,3,3,3s3-1.4,3-3v-8H28z" >
14+
</path>
15+
16+
</vector>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:height="44dp"
6+
android:width="44dp"
7+
android:viewportHeight="44"
8+
android:viewportWidth="44" >
9+
10+
<!-- @color/grey_lighten_20 -->
11+
<path
12+
android:fillColor="#ffc8d7e1"
13+
android:pathData="M14,29v2h16v-2H14z M28,13v8c0,3.3-2.7,6-6,6s-6-2.7-6-6v-8h3v8c0,1.6,1.4,3,3,3s3-1.4,3-3v-8H28z" >
14+
</path>
15+
16+
</vector>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:height="44dp"
6+
android:width="44dp"
7+
android:viewportHeight="44"
8+
android:viewportWidth="44" >
9+
10+
<!-- @color/blue_wordpress -->
11+
<path
12+
android:fillColor="#ff0087be"
13+
android:pathData="M14,29v2h16v-2H14z M28,13v8c0,3.3-2.7,6-6,6s-6-2.7-6-6v-8h3v8c0,1.6,1.4,3,3,3s3-1.4,3-3v-8H28z" >
14+
</path>
15+
16+
</vector>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<selector
4+
xmlns:android="http://schemas.android.com/apk/res/android" >
5+
6+
<item android:drawable="@drawable/format_bar_button_underline_disabled" android:state_enabled="false" />
7+
<item android:drawable="@drawable/format_bar_button_underline_highlighted" android:state_checked="true" />
8+
<item android:drawable="@drawable/format_bar_button_underline_highlighted" android:state_pressed="true" />
9+
<item android:drawable="@drawable/format_bar_button_underline_highlighted" android:state_focused="true" />
10+
<item android:drawable="@drawable/format_bar_button_underline" />
11+
12+
</selector>

aztec/src/main/res/layout/aztec_format_bar.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@
8585
style="@style/FormatBarButton" >
8686
</org.wordpress.aztec.toolbar.RippleToggleButton>
8787

88+
<org.wordpress.aztec.toolbar.RippleToggleButton
89+
android:id="@+id/format_bar_button_underline"
90+
android:background="@drawable/format_bar_button_underline_selector"
91+
android:contentDescription="@string/format_bar_description_underline"
92+
android:layout_height="fill_parent"
93+
android:layout_width="wrap_content"
94+
style="@style/FormatBarButton" >
95+
</org.wordpress.aztec.toolbar.RippleToggleButton>
96+
8897
<org.wordpress.aztec.toolbar.RippleToggleButton
8998
android:id="@+id/format_bar_button_quote"
9099
android:background="@drawable/format_bar_button_quote_selector"

0 commit comments

Comments
 (0)