Remove Build switches for Lollipop

This commit is contained in:
tzugen 2021-10-30 16:07:47 +02:00
parent 5fe1921ca5
commit bd23f54783
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
4 changed files with 10 additions and 46 deletions

View File

@ -1,9 +1,7 @@
package org.moire.ultrasonic.fragment
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Build
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
@ -109,10 +107,8 @@ internal class ServerRowAdapter(
}
// Set colors
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
icon?.setTint(ServerColor.getForegroundColor(context, setting?.color))
background?.setTint(ServerColor.getBackgroundColor(context, setting?.color))
}
icon?.setTint(ServerColor.getForegroundColor(context, setting?.color))
background?.setTint(ServerColor.getBackgroundColor(context, setting?.color))
// Set the final drawables
image?.setImageDrawable(icon)
@ -120,32 +116,16 @@ internal class ServerRowAdapter(
// Highlight the Active Server's row by changing its background
if (index == activeServerProvider.getActiveServer().index) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
layout?.background = ContextCompat.getDrawable(context, R.drawable.select_ripple)
} else {
layout?.setBackgroundResource(
Util.getResourceFromAttribute(context, R.attr.list_selector_holo_selected)
)
}
layout?.background = ContextCompat.getDrawable(context, R.drawable.select_ripple)
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
layout?.background = ContextCompat.getDrawable(context, R.drawable.default_ripple)
} else {
layout?.setBackgroundResource(
Util.getResourceFromAttribute(context, R.attr.list_selector_holo)
)
}
layout?.background = ContextCompat.getDrawable(context, R.drawable.default_ripple)
}
// Add the context menu for the row
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
serverMenu?.background = ContextCompat.getDrawable(
context,
R.drawable.select_ripple_circle
)
} else {
serverMenu?.setBackgroundColor(Color.TRANSPARENT)
}
serverMenu?.background = ContextCompat.getDrawable(
context,
R.drawable.select_ripple_circle
)
serverMenu?.setOnClickListener { view -> serverMenuClick(view, index) }

View File

@ -4,8 +4,6 @@ import android.content.Context
import android.media.AudioAttributes
import android.media.AudioManager
import android.media.AudioManager.OnAudioFocusChangeListener
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.media.AudioAttributesCompat
import androidx.media.AudioFocusRequestCompat
import androidx.media.AudioManagerCompat
@ -109,7 +107,6 @@ class AudioFocusHandler(private val context: Context) {
private var lowerFocus = false
// TODO: This can be removed if we switch to androidx.media2.player
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun getAudioAttributes(): AudioAttributes {
return AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)

View File

@ -10,11 +10,9 @@ package org.moire.ultrasonic.service
import android.content.Context
import android.content.Context.POWER_SERVICE
import android.content.Intent
import android.media.AudioManager
import android.media.MediaPlayer
import android.media.MediaPlayer.OnCompletionListener
import android.media.audiofx.AudioEffect
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.os.PowerManager
@ -447,12 +445,7 @@ class LocalMediaPlayer : KoinComponent {
}
private fun setAudioAttributes(player: MediaPlayer) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
player.setAudioAttributes(AudioFocusHandler.getAudioAttributes())
} else {
@Suppress("DEPRECATION")
player.setAudioStreamType(AudioManager.STREAM_MUSIC)
}
player.setAudioAttributes(AudioFocusHandler.getAudioAttributes())
}
@Suppress("ComplexCondition")

View File

@ -12,7 +12,6 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.media.AudioManager
import android.os.Build
import android.view.KeyEvent
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
@ -165,12 +164,7 @@ class MediaPlayerLifecycleSupport : KoinComponent {
}
}
val headsetIntentFilter: IntentFilter =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
IntentFilter(AudioManager.ACTION_HEADSET_PLUG)
} else {
IntentFilter(Intent.ACTION_HEADSET_PLUG)
}
val headsetIntentFilter = IntentFilter(AudioManager.ACTION_HEADSET_PLUG)
applicationContext().registerReceiver(headsetEventReceiver, headsetIntentFilter)
}