app: upgrade to android 12

Add preliminary compat for android 12 [API 31]. More changes may be
needed as time goes on, but its close enough to platform stability
to the point where its needed.
This commit is contained in:
OxygenCobalt 2021-07-29 10:49:18 -06:00
parent cd0167405e
commit ec4ca16658
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 20 additions and 25 deletions

View file

@ -4,7 +4,7 @@ apply plugin: "kotlin-kapt"
apply plugin: "androidx.navigation.safeargs.kotlin" apply plugin: "androidx.navigation.safeargs.kotlin"
android { android {
compileSdkVersion 30 compileSdkVersion 31
buildToolsVersion "30.0.3" buildToolsVersion "30.0.3"
defaultConfig { defaultConfig {
@ -13,7 +13,7 @@ android {
versionCode 7 versionCode 7
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 30 targetSdkVersion 31
buildFeatures { buildFeatures {
dataBinding true dataBinding true

View file

@ -31,17 +31,11 @@ class PlaybackNotification private constructor(
mediaToken: MediaSessionCompat.Token mediaToken: MediaSessionCompat.Token
) : NotificationCompat.Builder(context, CHANNEL_ID), PlaybackStateManager.Callback { ) : NotificationCompat.Builder(context, CHANNEL_ID), PlaybackStateManager.Callback {
init { init {
val mainActivityIntent = PendingIntent.getActivity(
context, REQUEST_CODE,
Intent(context, MainActivity::class.java),
PendingIntent.FLAG_UPDATE_CURRENT
)
setSmallIcon(R.drawable.ic_song) setSmallIcon(R.drawable.ic_song)
setCategory(NotificationCompat.CATEGORY_SERVICE) setCategory(NotificationCompat.CATEGORY_SERVICE)
setShowWhen(false) setShowWhen(false)
setSilent(true) setSilent(true)
setContentIntent(mainActivityIntent) setContentIntent(newPendingIntent(context, Intent(context, MainActivity::class.java)))
setVisibility(NotificationCompat.VISIBILITY_PUBLIC) setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
addAction(buildLoopAction(context, LoopMode.NONE)) addAction(buildLoopAction(context, LoopMode.NONE))
@ -158,15 +152,23 @@ class PlaybackNotification private constructor(
): NotificationCompat.Action { ): NotificationCompat.Action {
val action = NotificationCompat.Action.Builder( val action = NotificationCompat.Action.Builder(
iconRes, actionName, iconRes, actionName,
PendingIntent.getBroadcast( newPendingIntent(context, Intent(actionName))
context, REQUEST_CODE,
Intent(actionName), PendingIntent.FLAG_UPDATE_CURRENT,
)
) )
return action.build() return action.build()
} }
private fun newPendingIntent(context: Context, intent: Intent): PendingIntent {
return PendingIntent.getBroadcast(
context, REQUEST_CODE, intent,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_IMMUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
)
}
companion object { companion object {
const val CHANNEL_ID = "CHANNEL_AUXIO_PLAYBACK" const val CHANNEL_ID = "CHANNEL_AUXIO_PLAYBACK"
const val NOTIFICATION_ID = 0xA0A0 const val NOTIFICATION_ID = 0xA0A0

View file

@ -5,7 +5,6 @@ import android.content.Context
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.content.res.Configuration import android.content.res.Configuration
import android.content.res.Resources import android.content.res.Resources
import android.graphics.Point
import android.graphics.drawable.AnimatedVectorDrawable import android.graphics.drawable.AnimatedVectorDrawable
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
@ -235,25 +234,19 @@ fun Activity.isIrregularLandscape(): Boolean {
* @return If the system bars are on the bottom, false if no. * @return If the system bars are on the bottom, false if no.
*/ */
private fun isSystemBarOnBottom(activity: Activity): Boolean { private fun isSystemBarOnBottom(activity: Activity): Boolean {
val realPoint = Point()
val metrics = DisplayMetrics() val metrics = DisplayMetrics()
var width = 0 var width: Int
var height = 0 var height: Int
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity.display?.let { display ->
display.getRealSize(realPoint)
activity.windowManager.currentWindowMetrics.bounds.also { activity.windowManager.currentWindowMetrics.bounds.also {
width = it.width() width = it.width()
height = it.height() height = it.height()
} }
}
} else { } else {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
activity.getSystemServiceSafe(WindowManager::class).apply { activity.getSystemServiceSafe(WindowManager::class).apply {
defaultDisplay.getRealSize(realPoint)
defaultDisplay.getMetrics(metrics) defaultDisplay.getMetrics(metrics)
width = metrics.widthPixels width = metrics.widthPixels