Skip to content

Commit

Permalink
Support target sdk 31 (#256)
Browse files Browse the repository at this point in the history
* core: compileSdkVersion 31

* inappmessaging: targetSdkVersion 31

* early return

* Use if expression

* context.display?.cutout

* Revert "early return"

This reverts commit 6d521f214f7c9a0f2f9f5f2dcc0bb963a65eafc4.

* fix branch version to 30

* Use let

* Use setSystemBarsAppearance method

* Simplify setupWebView method

* Revert "context.display?.cutout"

This reverts commit eb18da941cb68a298d41426b29918dc5922f9eb8.

* Use DisplayManager

* Fix unused import

* Update changelog

* Update versions
  • Loading branch information
nkmrh authored Mar 30, 2024
1 parent f42cc51 commit 0ea8749
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 20 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@

| モジュール/プラグイン名 | Description | 最新のバージョン |
| :-- | :-- | :-- |
| core | イベントトラッキング機能を提供します。 | 2.24.0 |
| inappmessaging | アプリ内メッセージ機能を提供します。 | 2.18.0 |
| core | イベントトラッキング機能を提供します。 | 2.25.0 |
| inappmessaging | アプリ内メッセージ機能を提供します。 | 2.19.0 |
| notifications | プッシュ通知の受信および効果測定機能を提供します。 | 2.11.0 |
| variables | 設定値配信機能を提供します。 | 2.5.0 |
| visualtracking | ビジュアルトラッキング機能を提供します。| 2.9.0 |
| inbox | Push通知の送信履歴を取得する機能を提供します(β版)。 | 0.1.0 |
| Karte Gradle Plugin | ビジュアルトラッキング機能に必要なプラグインです。| 2.5.1 |

# Releases - xxxx.xx.xx

### Core 2.25.0
** 🔨CHANGED**
- targetSdkVersionを 29 -> 31 に変更しました。

### InAppMessaging 2.19.0
** 🔨CHANGED**
- targetSdkVersionを 29 -> 31 に変更しました。

# Releases - 2024.03.11

### Core 2.24.0
Expand Down
4 changes: 2 additions & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {

android {
namespace 'io.karte.android'
compileSdkVersion 29
compileSdkVersion 31

defaultConfig {
minSdkVersion 16
//noinspection OldTargetApi
targetSdkVersion 29
targetSdkVersion 31
buildConfigField "String", "LIB_VERSION", "\"$version\""

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/io/karte/android/tracking/AppInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,16 @@ private class Screen(context: Context) : Serializable {
private val height: Int

init {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val bounds = windowManager.currentWindowMetrics.bounds
val dp = context.resources.displayMetrics.density
width = (bounds.width() / dp).toInt()
height = (bounds.height() / dp).toInt()
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val metrics = DisplayMetrics()
@Suppress("DEPRECATION")
windowManager.defaultDisplay.getRealMetrics(metrics)
width = (metrics.widthPixels / metrics.density).toInt()
height = (metrics.heightPixels / metrics.density).toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ internal class DataStore private constructor(context: Context) {
else -> s to null
}
}.toMap())
persistable.id = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID))
val index = cursor.getColumnIndex(BaseColumns._ID)
persistable.id = cursor.getLong(index)
persistables.add(persistable)
instance.cache[persistable.id] = persistable
}
Expand Down
2 changes: 1 addition & 1 deletion core/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.24.0
2.25.0
4 changes: 2 additions & 2 deletions inappmessaging/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {

android {
namespace 'io.karte.android.inappmessaging'
compileSdkVersion 29
compileSdkVersion 31

defaultConfig {
minSdkVersion 16
//noinspection OldTargetApi
targetSdkVersion 29
targetSdkVersion 31
buildConfigField "String", "LIB_VERSION", "\"$version\""

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,14 @@ private class WebViewContainer(private val application: Application, private val
}

private fun setupWebView(url: String? = null) {
val targetUrl = url ?: InAppMessaging.self?.generateOverlayURL()
if (targetUrl == null) {
Logger.e(LOG_TAG, "Failed to construct overlay url.")
}
try {
_webView = IAMWebView(application, delegate)
_webView?.loadUrl(targetUrl)
val targetUrl = url ?: InAppMessaging.self?.generateOverlayURL()
if (targetUrl != null) {
_webView?.loadUrl(targetUrl)
} else {
Logger.e(LOG_TAG, "Failed to construct overlay url.")
}
} catch (e: PackageManager.NameNotFoundException) {
// WebViewアップデート中に初期化すると例外発生する可能性がある
// NOTE: https://stackoverflow.com/questions/29575313/namenotfoundexception-webview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.graphics.Color
import android.net.Uri
import android.net.http.SslError
import android.os.Build
import android.view.Display
import android.view.DisplayCutout
import android.view.KeyEvent
import android.view.WindowManager
Expand All @@ -38,6 +39,7 @@ import android.webkit.WebResourceResponse
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.core.hardware.display.DisplayManagerCompat
import io.karte.android.core.logger.Logger
import io.karte.android.inappmessaging.BuildConfig
import io.karte.android.utilities.asString
Expand Down Expand Up @@ -217,7 +219,6 @@ internal abstract class BaseWebView(context: Context) : WebView(context.applicat
Logger.d(LOG_TAG, "destroy")
super.destroy()
webChromeClient = null
webViewClient = null
}

private fun handleError(message: String, urlTriedToLoad: String?) {
Expand All @@ -238,12 +239,18 @@ internal abstract class BaseWebView(context: Context) : WebView(context.applicat
return null
}

val cutout: DisplayCutout = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val cutout: DisplayCutout? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
DisplayManagerCompat.getInstance(context).getDisplay(Display.DEFAULT_DISPLAY)?.cutout
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
@Suppress("DEPRECATION")
windowManager.defaultDisplay.cutout
} else {
rootWindowInsets.displayCutout
} ?: return null
}
if (cutout == null) {
return null
}

val scale = Resources.getSystem().displayMetrics.density
return SafeInsets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.view.Window
import android.view.WindowInsets
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.view.inputmethod.InputMethodManager.RESULT_HIDDEN
Expand All @@ -52,8 +53,10 @@ import org.json.JSONArray
import java.lang.ref.WeakReference

private const val LOG_TAG = "Karte.IAMView"
@Suppress("DEPRECATION")
private const val WINDOW_FLAGS_FOCUSED = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
@Suppress("DEPRECATION")
private const val WINDOW_FLAGS_UNFOCUSED = (
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
or WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Expand Down Expand Up @@ -93,7 +96,10 @@ internal open class WindowView(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING

/** StatusBarがContentViewに被っているか。Split Screen時に上画面であること. */
private val isStatusBarOverlaid: Boolean = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
private val isStatusBarOverlaid: Boolean = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
(contentView.rootWindowInsets?.getInsets(WindowInsets.Type.systemBars())?.top ?: -1) > 0
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@Suppress("DEPRECATION")
(contentView.rootWindowInsets?.systemWindowInsetTop ?: -1) > 0
} else {
// API 24未満はSplitScreen未対応のため、常にstatus barがある
Expand Down Expand Up @@ -143,7 +149,17 @@ internal open class WindowView(
// そのためこのケースでは、hideSoftInputFromWindow後にaddViewすることでz-orderをkeyboardより下にし、再度showSoftInputする。(hideSoftInputFromWindowの結果によって元々keyboardが表示されていたかどうかの判定ができる)
hideAndShowKeyboard()
}
params.systemUiVisibility = decorView.windowSystemUiVisibility

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
this.windowInsetsController?.setSystemBarsAppearance(
decorView.windowInsetsController?.systemBarsAppearance ?: 0,
decorView.windowInsetsController?.systemBarsAppearance ?: 0
)
} else {
@Suppress("DEPRECATION")
params.systemUiVisibility = decorView.windowSystemUiVisibility
}

val location = IntArray(2)
contentView.getLocationOnScreen(location)

Expand Down
2 changes: 1 addition & 1 deletion inappmessaging/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.18.0
2.19.0

0 comments on commit 0ea8749

Please sign in to comment.