Skip to content

Commit 279a2de

Browse files
committed
Migrated ContextCompat to AppCompatResources to support API 16+ devices
1 parent 6ae2ea5 commit 279a2de

File tree

12 files changed

+27
-25
lines changed

12 files changed

+27
-25
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import android.widget.PopupMenu
2929
import android.widget.ToggleButton
3030
import androidx.appcompat.app.AlertDialog
3131
import androidx.appcompat.app.AppCompatActivity
32+
import androidx.appcompat.content.res.AppCompatResources
3233
import androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback
33-
import androidx.core.content.ContextCompat
3434
import androidx.core.content.FileProvider
3535
import org.wordpress.android.util.AppLog
3636
import org.wordpress.android.util.ImageUtils
@@ -339,7 +339,7 @@ open class MainActivity : AppCompatActivity(),
339339
aztec.visualEditor.setOverlay(predicate, 0, ColorDrawable(0x80000000.toInt()), Gravity.FILL)
340340
aztec.visualEditor.updateElementAttributes(predicate, attrs)
341341

342-
val progressDrawable = ContextCompat.getDrawable(this, android.R.drawable.progress_horizontal)!!
342+
val progressDrawable = AppCompatResources.getDrawable(this, android.R.drawable.progress_horizontal)!!
343343
// set the height of the progress bar to 2 (it's in dp since the drawable will be adjusted by the span)
344344
progressDrawable.setBounds(0, 0, 0, 4)
345345

@@ -361,7 +361,7 @@ open class MainActivity : AppCompatActivity(),
361361

362362
if (attrs.hasAttribute("video")) {
363363
attrs.removeAttribute(attrs.getIndex("video"))
364-
aztec.visualEditor.setOverlay(predicate, 0, ContextCompat.getDrawable(this, android.R.drawable.ic_media_play), Gravity.CENTER)
364+
aztec.visualEditor.setOverlay(predicate, 0, AppCompatResources.getDrawable(this, android.R.drawable.ic_media_play), Gravity.CENTER)
365365
}
366366

367367
aztec.visualEditor.updateElementAttributes(predicate, attrs)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ package org.wordpress.aztec
2323

2424
import android.content.Context
2525
import android.graphics.drawable.Drawable
26-
import androidx.core.content.ContextCompat
2726
import android.text.Editable
2827
import android.text.Spanned
28+
import androidx.appcompat.content.res.AppCompatResources
2929
import org.wordpress.aztec.plugins.IAztecPlugin
3030
import org.wordpress.aztec.plugins.html2visual.IHtmlTagHandler
3131
import org.wordpress.aztec.spans.AztecAudioSpan
@@ -58,7 +58,7 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
5858

5959
init {
6060
val styles = context.obtainStyledAttributes(R.styleable.AztecText)
61-
loadingDrawable = ContextCompat.getDrawable(context, styles.getResourceId(R.styleable.AztecText_drawableLoading, R.drawable.ic_image_loading))!!
61+
loadingDrawable = AppCompatResources.getDrawable(context, styles.getResourceId(R.styleable.AztecText_drawableLoading, R.drawable.ic_image_loading))!!
6262
styles.recycle()
6363
}
6464

@@ -124,7 +124,7 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
124124
LINE -> {
125125
if (opening) {
126126
// Add an extra newline above the line to prevent weird typing on the line above
127-
start(output, AztecHorizontalRuleSpan(context, ContextCompat.getDrawable(context, R.drawable.img_hr)!!,
127+
start(output, AztecHorizontalRuleSpan(context, AppCompatResources.getDrawable(context, R.drawable.img_hr)!!,
128128
nestingLevel, AztecAttributes(attributes)))
129129
output.append(Constants.MAGIC_CHAR)
130130
} else {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import android.widget.EditText
5454
import android.widget.Toast
5555
import androidx.annotation.DrawableRes
5656
import androidx.appcompat.app.AlertDialog
57+
import androidx.appcompat.content.res.AppCompatResources
5758
import androidx.appcompat.widget.AppCompatEditText
5859
import androidx.core.content.ContextCompat
5960
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
@@ -154,7 +155,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
154155
var watchersNestingLevel: Int = 0
155156

156157
private fun getPlaceholderDrawableFromResID(context: Context, @DrawableRes drawableId: Int, maxImageWidthForVisualEditor: Int): BitmapDrawable {
157-
val drawable = ContextCompat.getDrawable(context, drawableId)
158+
val drawable = AppCompatResources.getDrawable(context, drawableId)
158159
var bitmap: Bitmap
159160
if (drawable is BitmapDrawable) {
160161
bitmap = drawable.bitmap

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.wordpress.aztec.formatting
22

33
import android.graphics.drawable.Drawable
4-
import androidx.core.content.ContextCompat
54
import android.text.SpannableStringBuilder
65
import android.text.Spanned
76
import android.text.TextUtils
7+
import androidx.appcompat.content.res.AppCompatResources
88
import org.wordpress.aztec.AztecAttributes
99
import org.wordpress.aztec.AztecText
1010
import org.wordpress.aztec.AztecText.OnImageTappedListener
@@ -103,7 +103,7 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
103103

104104
val span = AztecHorizontalRuleSpan(
105105
editor.context,
106-
ContextCompat.getDrawable(editor.context, R.drawable.img_hr)!!,
106+
AppCompatResources.getDrawable(editor.context, R.drawable.img_hr)!!,
107107
nestingLevel,
108108
AztecAttributes(),
109109
editor

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package org.wordpress.aztec.spans
22

33
import android.content.Context
44
import android.graphics.drawable.Drawable
5-
import androidx.core.content.ContextCompat
65
import android.view.Gravity
6+
import androidx.appcompat.content.res.AppCompatResources
77
import org.wordpress.aztec.AztecAttributes
88
import org.wordpress.aztec.AztecText
99

@@ -16,7 +16,7 @@ class AztecAudioSpan(context: Context, drawable: Drawable?, override var nesting
1616
override val TAG: String = "audio"
1717

1818
init {
19-
setOverlay(0, ContextCompat.getDrawable(context, android.R.drawable.ic_lock_silent_mode_off), Gravity.CENTER)
19+
setOverlay(0, AppCompatResources.getDrawable(context, android.R.drawable.ic_lock_silent_mode_off), Gravity.CENTER)
2020
}
2121

2222
override fun onClick() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package org.wordpress.aztec.spans
22

33
import android.content.Context
44
import android.graphics.drawable.Drawable
5-
import androidx.core.content.ContextCompat
65
import android.view.Gravity
6+
import androidx.appcompat.content.res.AppCompatResources
77
import org.wordpress.aztec.AztecAttributes
88
import org.wordpress.aztec.AztecText
99

@@ -16,7 +16,7 @@ class AztecVideoSpan(context: Context, drawable: Drawable?, override var nesting
1616
override val TAG: String = "video"
1717

1818
init {
19-
setOverlay(0, ContextCompat.getDrawable(context, android.R.drawable.ic_media_play), Gravity.CENTER)
19+
setOverlay(0, AppCompatResources.getDrawable(context, android.R.drawable.ic_media_play), Gravity.CENTER)
2020
}
2121

2222
override fun onClick() {

wordpress-comments/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ android {
99
minSdkVersion 16
1010
targetSdkVersion 28
1111
versionName "1.0"
12+
vectorDrawables.useSupportLibrary = true
1213
}
1314

1415
buildTypes {

wordpress-comments/src/main/java/org/wordpress/aztec/plugins/wpcomments/HiddenGutenbergPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.wordpress.aztec.plugins.wpcomments
22

3-
import androidx.core.content.ContextCompat
43
import android.text.Editable
54
import android.text.Spannable
65
import android.text.style.CharacterStyle
6+
import androidx.appcompat.content.res.AppCompatResources
77
import org.wordpress.aztec.AztecText
88
import org.wordpress.aztec.Constants
99
import org.wordpress.aztec.plugins.IAztecPlugin
@@ -62,7 +62,7 @@ class HiddenGutenbergPlugin @JvmOverloads constructor(private val aztecText: Azt
6262
GutenbergInlineCommentSpan(
6363
text,
6464
aztecText.context,
65-
ContextCompat.getDrawable(aztecText.context, android.R.drawable.ic_menu_help)!!,
65+
AppCompatResources.getDrawable(aztecText.context, android.R.drawable.ic_menu_help)!!,
6666
nestingLevel
6767
),
6868
spanStart,

wordpress-comments/src/main/java/org/wordpress/aztec/plugins/wpcomments/WordPressCommentsPlugin.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.wordpress.aztec.plugins.wpcomments
22

3-
import androidx.core.content.ContextCompat
43
import android.text.Editable
54
import android.text.Spannable
65
import android.text.style.CharacterStyle
6+
import androidx.appcompat.content.res.AppCompatResources
77
import org.wordpress.aztec.AztecText
88
import org.wordpress.aztec.Constants
99
import org.wordpress.aztec.plugins.html2visual.IHtmlCommentHandler
@@ -41,7 +41,7 @@ class WordPressCommentsPlugin(private val visualEditor: AztecText) : IInlineSpan
4141
WordPressCommentSpan(
4242
text,
4343
visualEditor.context,
44-
ContextCompat.getDrawable(visualEditor.context, R.drawable.img_more)!!,
44+
AppCompatResources.getDrawable(visualEditor.context, R.drawable.img_more)!!,
4545
nestingLevel
4646
),
4747
spanStart,
@@ -57,7 +57,7 @@ class WordPressCommentsPlugin(private val visualEditor: AztecText) : IInlineSpan
5757
WordPressCommentSpan(
5858
text,
5959
visualEditor.context,
60-
ContextCompat.getDrawable(visualEditor.context, R.drawable.img_page)!!,
60+
AppCompatResources.getDrawable(visualEditor.context, R.drawable.img_page)!!,
6161
nestingLevel
6262
),
6363
spanStart,

wordpress-comments/src/main/java/org/wordpress/aztec/plugins/wpcomments/toolbar/MoreToolbarButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package org.wordpress.aztec.plugins.wpcomments.toolbar
22

3-
import androidx.core.content.ContextCompat
43
import android.text.SpannableStringBuilder
54
import android.text.Spanned
65
import android.view.KeyEvent
76
import android.view.LayoutInflater
87
import android.view.ViewGroup
98
import android.widget.ToggleButton
9+
import androidx.appcompat.content.res.AppCompatResources
1010
import org.wordpress.android.util.DeviceUtils
1111
import org.wordpress.aztec.AztecText
1212
import org.wordpress.aztec.Constants
@@ -31,7 +31,7 @@ class MoreToolbarButton(val visualEditor: AztecText) : IToolbarButton {
3131
val span = WordPressCommentSpan(
3232
WordPressCommentSpan.Comment.MORE.html,
3333
visualEditor.context,
34-
ContextCompat.getDrawable(visualEditor.context, R.drawable.img_more)!!,
34+
AppCompatResources.getDrawable(visualEditor.context, R.drawable.img_more)!!,
3535
nestingLevel,
3636
visualEditor
3737
)

0 commit comments

Comments
 (0)