@@ -21,6 +21,7 @@ import android.annotation.SuppressLint
2121import android.content.ClipData
2222import android.content.ClipboardManager
2323import android.content.Context
24+ import android.content.res.TypedArray
2425import android.graphics.Bitmap
2526import android.graphics.Canvas
2627import android.graphics.drawable.BitmapDrawable
@@ -48,8 +49,6 @@ import android.view.MotionEvent
4849import android.view.View
4950import android.view.WindowManager
5051import android.view.inputmethod.BaseInputConnection
51- import android.view.inputmethod.EditorInfo
52- import android.view.inputmethod.InputConnection
5352import android.widget.CheckBox
5453import android.widget.EditText
5554import android.widget.Toast
@@ -72,7 +71,6 @@ import org.wordpress.aztec.handlers.ListHandler
7271import org.wordpress.aztec.handlers.ListItemHandler
7372import org.wordpress.aztec.handlers.PreformatHandler
7473import org.wordpress.aztec.handlers.QuoteHandler
75- import org.wordpress.aztec.ime.EditorInfoUtils
7674import org.wordpress.aztec.plugins.IAztecPlugin
7775import org.wordpress.aztec.plugins.IToolbarButton
7876import org.wordpress.aztec.source.Format
@@ -121,7 +119,6 @@ import org.wordpress.aztec.watchers.event.text.BeforeTextChangedEventData
121119import org.wordpress.aztec.watchers.event.text.OnTextChangedEventData
122120import org.wordpress.aztec.watchers.event.text.TextWatcherEvent
123121import org.xml.sax.Attributes
124- import java.lang.ref.WeakReference
125122import java.security.MessageDigest
126123import java.security.NoSuchAlgorithmException
127124import 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 }
0 commit comments