Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ToastCompat compatible with Android SDK 30 #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions toasthandler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ publish {
}

android {
compileSdkVersion 29
compileSdkVersion 30
buildToolsVersion "29.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ class ToastCompat(context: Context, private val toast: Toast) : Toast(context) {
toast.setText(s)
}

override fun setView(view: View) {
override fun setView(view: View?) {
toast.view = view
setContextCompat(view, ToastContextWrapper(view.context))
if (view != null) {
setContextCompat(view, ToastContextWrapper(view.context))
}
}

override fun getHorizontalMargin(): Float {
Expand All @@ -65,12 +67,12 @@ class ToastCompat(context: Context, private val toast: Toast) : Toast(context) {
return toast.yOffset
}

override fun getView(): View {
override fun getView(): View? {
return toast.view
}

private fun setContextCompat(view: View, context: Context) {
if (Build.VERSION.SDK_INT == 25) {
private fun setContextCompat(view: View?, context: Context) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1 && view != null) {
try {
val field = View::class.java.getDeclaredField("mContext")
field.isAccessible = true
Expand Down