Skip to content

Commit 37ce634

Browse files
committed
Merge remote-tracking branch 'origin/develop' into issue/accessible-formatting-toolbar
2 parents 1918ffe + 75c0b6c commit 37ce634

File tree

12 files changed

+110
-131
lines changed

12 files changed

+110
-131
lines changed

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [1.3.36](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.3.36)
4+
### Changed
5+
- Implement start and reversed in lists
6+
- Allow preformatted background alpha and tidying to be set from child classes
7+
38
## [1.3.35](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.3.35)
49
### Changed
510
- Update Glide version to 4.10.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ repositories {
105105
```
106106
```gradle
107107
dependencies {
108-
api ('com.github.wordpress-mobile.WordPress-Aztec-Android:aztec:v1.3.35')
108+
api ('com.github.wordpress-mobile.WordPress-Aztec-Android:aztec:v1.3.36')
109109
}
110110
```
111111

app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,46 @@ open class MainActivity : AppCompatActivity(),
9191
private val UNDERLINE = "<u style=\"color:lime\">Underline</u><br>"
9292
private val STRIKETHROUGH = "<s style=\"color:#ff666666\" class=\"test\">Strikethrough</s><br>" // <s> or <strike> or <del>
9393
private val ORDERED = "<ol style=\"color:green\"><li>Ordered</li><li>should have color</li></ol>"
94+
private val ORDERED_WITH_START = "<h4>Start in 10 List:</h4>" +
95+
"<ol start=\"10\">\n" +
96+
" <li>Ten</li>\n" +
97+
" <li>Eleven</li>\n" +
98+
" <li>Twelve</li>\n" +
99+
"</ol>"
100+
private val ORDERED_REVERSED = "<h4>Reversed List:</h4>" +
101+
"<ol reversed>\n" +
102+
" <li>Three</li>\n" +
103+
" <li>Two</li>\n" +
104+
" <li>One</li>\n" +
105+
"</ol>"
106+
private val ORDERED_REVERSED_WITH_START = "<h4>Reversed Start in 10 List:</h4>" +
107+
"<ol reversed start=\"10\">\n" +
108+
" <li>Ten</li>\n" +
109+
" <li>Nine</li>\n" +
110+
" <li>Eight</li>\n" +
111+
"</ol>"
112+
private val ORDERED_REVERSED_NEGATIVE_WITH_START = "<h4>Reversed Start in 1 List:</h4>" +
113+
"<ol reversed start=\"1\">\n" +
114+
" <li>One</li>\n" +
115+
" <li>Zero</li>\n" +
116+
" <li>Minus One</li>\n" +
117+
"</ol>"
118+
private val ORDERED_REVERSED_WITH_START_IDENT = "<h4>Reversed Start in 6 List:</h4>" +
119+
"<ol reversed>" +
120+
" <li>Six</li>" +
121+
" <li>Five</li>" +
122+
" <li>Four</li>" +
123+
" <li>Three</li>" +
124+
" <li>Two</li>" +
125+
" <li>One<ol>" +
126+
" <li>One</li>" +
127+
" <li>Two</li>" +
128+
" <li>Three</li>" +
129+
" <li>Four</li>" +
130+
" <li>Five</li>" +
131+
" <li>Six</li>" +
132+
" <li>Seven</li> " +
133+
" </ol></li></ol>"
94134
private val LINE = "<hr />"
95135
private val UNORDERED = "<ul><li style=\"color:darkred\">Unordered</li><li>Should not have color</li></ul>"
96136
private val QUOTE = "<blockquote>Quote</blockquote>"
@@ -147,6 +187,11 @@ open class MainActivity : AppCompatActivity(),
147187
UNDERLINE +
148188
STRIKETHROUGH +
149189
ORDERED +
190+
ORDERED_WITH_START +
191+
ORDERED_REVERSED +
192+
ORDERED_REVERSED_WITH_START +
193+
ORDERED_REVERSED_NEGATIVE_WITH_START +
194+
ORDERED_REVERSED_WITH_START_IDENT +
150195
LINE +
151196
UNORDERED +
152197
QUOTE +

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class AztecParser @JvmOverloads constructor(val plugins: List<IAztecPlugin> = li
7575
return spanned
7676
}
7777

78-
fun fromHtml(source: String, context: Context): Spanned {
79-
val tidySource = tidy(source)
78+
fun fromHtml(source: String, context: Context, shouldSkipTidying: Boolean = false): Spanned {
79+
val tidySource = if (shouldSkipTidying) source else tidy(source)
8080

8181
val spanned = SpannableStringBuilder(Html.fromHtml(tidySource,
8282
AztecTagHandler(context, plugins), context, plugins, ignoredTags))
@@ -90,7 +90,8 @@ class AztecParser @JvmOverloads constructor(val plugins: List<IAztecPlugin> = li
9090
return spanned
9191
}
9292

93-
fun toHtml(text: Spanned, withCursor: Boolean = false): String {
93+
@JvmOverloads
94+
fun toHtml(text: Spanned, withCursor: Boolean = false, shouldSkipTidying: Boolean = false): String {
9495
val out = StringBuilder()
9596

9697
val data = SpannableStringBuilder(text)
@@ -107,7 +108,8 @@ class AztecParser @JvmOverloads constructor(val plugins: List<IAztecPlugin> = li
107108
}
108109

109110
withinHtml(out, data)
110-
val html = postprocessHtml(tidy(out.toString()))
111+
val tidyOut = if (shouldSkipTidying) out.toString() else tidy(out.toString())
112+
val html = postprocessHtml(tidyOut)
111113
return html
112114
}
113115

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

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.annotation.SuppressLint
2121
import android.content.ClipData
2222
import android.content.ClipboardManager
2323
import android.content.Context
24+
import android.content.res.TypedArray
2425
import android.graphics.Bitmap
2526
import android.graphics.Canvas
2627
import android.graphics.drawable.BitmapDrawable
@@ -48,8 +49,6 @@ import android.view.MotionEvent
4849
import android.view.View
4950
import android.view.WindowManager
5051
import android.view.inputmethod.BaseInputConnection
51-
import android.view.inputmethod.EditorInfo
52-
import android.view.inputmethod.InputConnection
5352
import android.widget.CheckBox
5453
import android.widget.EditText
5554
import android.widget.Toast
@@ -72,7 +71,6 @@ import org.wordpress.aztec.handlers.ListHandler
7271
import org.wordpress.aztec.handlers.ListItemHandler
7372
import org.wordpress.aztec.handlers.PreformatHandler
7473
import org.wordpress.aztec.handlers.QuoteHandler
75-
import org.wordpress.aztec.ime.EditorInfoUtils
7674
import org.wordpress.aztec.plugins.IAztecPlugin
7775
import org.wordpress.aztec.plugins.IToolbarButton
7876
import org.wordpress.aztec.source.Format
@@ -121,7 +119,6 @@ import org.wordpress.aztec.watchers.event.text.BeforeTextChangedEventData
121119
import org.wordpress.aztec.watchers.event.text.OnTextChangedEventData
122120
import org.wordpress.aztec.watchers.event.text.TextWatcherEvent
123121
import org.xml.sax.Attributes
124-
import java.lang.ref.WeakReference
125122
import java.security.MessageDigest
126123
import java.security.NoSuchAlgorithmException
127124
import java.util.ArrayList
@@ -296,9 +293,6 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
296293

297294
private var focusOnVisible = true
298295

299-
var inputConnectionRef: WeakReference<InputConnection>? = null
300-
var inputConnectionEditorInfo: EditorInfo? = null
301-
302296
interface OnSelectionChangedListener {
303297
fun onSelectionChanged(selStart: Int, selEnd: Int)
304298
}
@@ -417,7 +411,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
417411
BlockFormatter.HeaderStyle(verticalHeadingMargin),
418412
BlockFormatter.PreformatStyle(
419413
styles.getColor(R.styleable.AztecText_preformatBackground, 0),
420-
styles.getFraction(R.styleable.AztecText_preformatBackgroundAlpha, 1, 1, 0f),
414+
getPreformatBackgroundAlpha(styles),
421415
styles.getColor(R.styleable.AztecText_preformatColor, 0),
422416
verticalParagraphMargin)
423417
)
@@ -670,43 +664,10 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
670664
}
671665
}
672666

673-
override fun onCreateInputConnection(outAttrs: EditorInfo) : InputConnection {
674-
// limiting the reuseInputConnection fix for Anroid 8.0.0 for now
675-
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
676-
return handleReuseInputConnection(outAttrs)
677-
}
678-
679-
return super.onCreateInputConnection(outAttrs)
680-
}
681-
682-
private fun handleReuseInputConnection(outAttrs: EditorInfo) : InputConnection {
683-
// initialize inputConnectionEditorInfo
684-
if (inputConnectionEditorInfo == null) {
685-
inputConnectionEditorInfo = outAttrs
686-
}
687-
688-
// now init the InputConnection, or replace if EditorInfo contains anything different
689-
if (inputConnectionRef?.get() == null || !EditorInfoUtils.areEditorInfosTheSame(outAttrs, inputConnectionEditorInfo!!)) {
690-
// we have a new InputConnection to create, save the new EditorInfo data and create it
691-
// we make a copy of the parameters being received, because super.onCreateInputConnection may make changes
692-
// to EditorInfo params being sent to it, and we want to preserve the same data we received in order
693-
// to compare.
694-
// (see https://android.googlesource.com/platform/frameworks/base/+/jb-mr0-release/core/java/android/widget/
695-
// TextView.java#5404)
696-
inputConnectionEditorInfo = EditorInfoUtils.copyEditorInfo(outAttrs)
697-
val localInputConnection = super.onCreateInputConnection(outAttrs)
698-
if (localInputConnection == null) {
699-
// in case super returns null, let's just observe the base implementation, no need to make
700-
// an InputConnectionWrapper of a null target
701-
return localInputConnection
702-
}
703-
// if non null, wrap the new InputConnection around our wrapper (used for logging purposes only)
704-
//inputConnection = AztecTextInputConnectionWrapper(localInputConnection, this)
705-
inputConnectionRef = WeakReference(localInputConnection)
706-
}
707-
708-
// return the existing inputConnection
709-
return inputConnectionRef?.get()!!
667+
// We are exposing this method in order to allow subclasses to set their own alpha value
668+
// for preformatted background
669+
open fun getPreformatBackgroundAlpha(styles: TypedArray): Float {
670+
return styles.getFraction(R.styleable.AztecText_preformatBackgroundAlpha, 1, 1, 0f)
710671
}
711672

712673
override fun onRestoreInstanceState(state: Parcelable?) {
@@ -1144,6 +1105,10 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
11441105
}
11451106
}
11461107

1108+
open fun shouldSkipTidying(): Boolean {
1109+
return false
1110+
}
1111+
11471112
override fun afterTextChanged(text: Editable) {
11481113
if (isTextChangedListenerDisabled()) {
11491114
subWatcherNestingLevel()
@@ -1192,7 +1157,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
11921157

11931158
var cleanSource = CleaningUtils.cleanNestedBoldTags(source)
11941159
cleanSource = Format.removeSourceEditorFormatting(cleanSource, isInCalypsoMode, isInGutenbergMode)
1195-
builder.append(parser.fromHtml(cleanSource, context))
1160+
builder.append(parser.fromHtml(cleanSource, context, shouldSkipTidying()))
11961161

11971162
Format.preProcessSpannedText(builder, isInCalypsoMode)
11981163

@@ -1357,7 +1322,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
13571322

13581323
Format.postProcessSpannedText(output, isInCalypsoMode)
13591324

1360-
return EndOfBufferMarkerAdder.removeEndOfTextMarker(parser.toHtml(output, withCursorTag))
1325+
return EndOfBufferMarkerAdder.removeEndOfTextMarker(parser.toHtml(output, withCursorTag, shouldSkipTidying()))
13611326
}
13621327

13631328
// default behavior returns formatted HTML from this text
@@ -1559,13 +1524,14 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
15591524
deleteInlineStyleFromTheBeginning()
15601525
}
15611526
}
1562-
// Fix for crash when pasting text on Samsung Devices running Android 8.
1563-
// Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/8827
1527+
// Fix for crash when pasting text on Samsung Devices running Android 7 & 8.
1528+
// Android 7 Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/10872
1529+
// Android 8 Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/8827
15641530
clipboardIdentifier -> {
1565-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Build.VERSION.SDK_INT < 28
1531+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && Build.VERSION.SDK_INT < Build.VERSION_CODES.P
15661532
&& Build.MANUFACTURER.toLowerCase().equals("samsung")) {
15671533
// Nope return true
1568-
Toast.makeText(context, R.string.samsung_disabled_custom_clipboard, Toast.LENGTH_LONG).show()
1534+
Toast.makeText(context, context.getString(R.string.samsung_disabled_custom_clipboard, Build.VERSION.RELEASE), Toast.LENGTH_LONG).show()
15691535
} else {
15701536
return super.onTextContextMenuItem(id)
15711537
}

aztec/src/main/kotlin/org/wordpress/aztec/ime/EditorInfoUtils.kt

Lines changed: 0 additions & 55 deletions
This file was deleted.

aztec/src/main/kotlin/org/wordpress/aztec/plugins/CssUnderlinePlugin.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ class CssUnderlinePlugin : ISpanPostprocessor, ISpanPreprocessor {
4141
if (hiddenSpan.TAG == SPAN_TAG) {
4242
val parentStyle = hiddenSpan.attributes.getValue(CssStyleFormatter.STYLE_ATTRIBUTE)
4343
val childStyle = calypsoUnderlineSpan.attributes.getValue(CssStyleFormatter.STYLE_ATTRIBUTE)
44-
if (parentStyle != null && childStyle != null) {
45-
hiddenSpan.attributes.setValue(CssStyleFormatter.STYLE_ATTRIBUTE, CssStyleFormatter.mergeStyleAttributes(parentStyle, childStyle))
46-
}
44+
hiddenSpan.attributes.setValue(CssStyleFormatter.STYLE_ATTRIBUTE, CssStyleFormatter.mergeStyleAttributes(parentStyle, childStyle))
4745

4846
// remove the extra child span
4947
spannable.removeSpan(calypsoUnderlineSpan)

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecListSpan.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class AztecListSpan(override var nestingLevel: Int,
3434
}
3535
}
3636

37-
fun getIndexOfProcessedLine(text: CharSequence, end: Int): Int {
37+
fun getIndexOfProcessedLine(text: CharSequence, end: Int): Int? {
3838
val spanStart = (text as Spanned).getSpanStart(this)
3939
val spanEnd = text.getSpanEnd(this)
4040

@@ -44,7 +44,7 @@ abstract class AztecListSpan(override var nestingLevel: Int,
4444
val hasSublist = listText.getSpans(end - spanStart - 1, end - spanStart, AztecListSpan::class.java)
4545
.any { it.nestingLevel > nestingLevel }
4646
if (hasSublist) {
47-
return -1
47+
return null
4848
}
4949
}
5050

@@ -55,7 +55,7 @@ abstract class AztecListSpan(override var nestingLevel: Int,
5555
.any { it.nestingLevel == nestingLevel + 1 && listText.getSpanStart(it) == startOfLine }
5656

5757
if (!isValidListItem) {
58-
return -1
58+
return null
5959
}
6060

6161
// count the list item spans up to the current line with the expected nesting level => item number
@@ -65,6 +65,17 @@ abstract class AztecListSpan(override var nestingLevel: Int,
6565
.size
6666
}
6767

68+
fun getNumberOfItemsInProcessedLine(text: CharSequence): Int {
69+
val spanStart = (text as Spanned).getSpanStart(this)
70+
val spanEnd = text.getSpanEnd(this)
71+
72+
val listText = text.subSequence(spanStart, spanEnd) as Spanned
73+
74+
return listText.getSpans(0, listText.length, AztecListItemSpan::class.java)
75+
.filter { it.nestingLevel == nestingLevel + 1 }
76+
.size
77+
}
78+
6879
fun nestingDepth(text: Spanned, index: Int, nextIndex: Int): Int {
6980
val finalNextIndex = if (nextIndex > text.length) index else nextIndex
7081
return IAztecNestable.getNestingLevelAt(text, index, finalNextIndex)

0 commit comments

Comments
 (0)