Remove Build switches for Lollipop
This commit is contained in:
parent
5fe1921ca5
commit
bd23f54783
|
@ -1,9 +1,7 @@
|
||||||
package org.moire.ultrasonic.fragment
|
package org.moire.ultrasonic.fragment
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Build
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
@ -109,10 +107,8 @@ internal class ServerRowAdapter(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set colors
|
// Set colors
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
icon?.setTint(ServerColor.getForegroundColor(context, setting?.color))
|
icon?.setTint(ServerColor.getForegroundColor(context, setting?.color))
|
||||||
background?.setTint(ServerColor.getBackgroundColor(context, setting?.color))
|
background?.setTint(ServerColor.getBackgroundColor(context, setting?.color))
|
||||||
}
|
|
||||||
|
|
||||||
// Set the final drawables
|
// Set the final drawables
|
||||||
image?.setImageDrawable(icon)
|
image?.setImageDrawable(icon)
|
||||||
|
@ -120,32 +116,16 @@ internal class ServerRowAdapter(
|
||||||
|
|
||||||
// Highlight the Active Server's row by changing its background
|
// Highlight the Active Server's row by changing its background
|
||||||
if (index == activeServerProvider.getActiveServer().index) {
|
if (index == activeServerProvider.getActiveServer().index) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
layout?.background = ContextCompat.getDrawable(context, R.drawable.select_ripple)
|
layout?.background = ContextCompat.getDrawable(context, R.drawable.select_ripple)
|
||||||
} else {
|
} else {
|
||||||
layout?.setBackgroundResource(
|
|
||||||
Util.getResourceFromAttribute(context, R.attr.list_selector_holo_selected)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
layout?.background = ContextCompat.getDrawable(context, R.drawable.default_ripple)
|
layout?.background = ContextCompat.getDrawable(context, R.drawable.default_ripple)
|
||||||
} else {
|
|
||||||
layout?.setBackgroundResource(
|
|
||||||
Util.getResourceFromAttribute(context, R.attr.list_selector_holo)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the context menu for the row
|
// Add the context menu for the row
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
serverMenu?.background = ContextCompat.getDrawable(
|
serverMenu?.background = ContextCompat.getDrawable(
|
||||||
context,
|
context,
|
||||||
R.drawable.select_ripple_circle
|
R.drawable.select_ripple_circle
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
serverMenu?.setBackgroundColor(Color.TRANSPARENT)
|
|
||||||
}
|
|
||||||
|
|
||||||
serverMenu?.setOnClickListener { view -> serverMenuClick(view, index) }
|
serverMenu?.setOnClickListener { view -> serverMenuClick(view, index) }
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@ import android.content.Context
|
||||||
import android.media.AudioAttributes
|
import android.media.AudioAttributes
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.media.AudioManager.OnAudioFocusChangeListener
|
import android.media.AudioManager.OnAudioFocusChangeListener
|
||||||
import android.os.Build
|
|
||||||
import androidx.annotation.RequiresApi
|
|
||||||
import androidx.media.AudioAttributesCompat
|
import androidx.media.AudioAttributesCompat
|
||||||
import androidx.media.AudioFocusRequestCompat
|
import androidx.media.AudioFocusRequestCompat
|
||||||
import androidx.media.AudioManagerCompat
|
import androidx.media.AudioManagerCompat
|
||||||
|
@ -109,7 +107,6 @@ class AudioFocusHandler(private val context: Context) {
|
||||||
private var lowerFocus = false
|
private var lowerFocus = false
|
||||||
|
|
||||||
// TODO: This can be removed if we switch to androidx.media2.player
|
// TODO: This can be removed if we switch to androidx.media2.player
|
||||||
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
fun getAudioAttributes(): AudioAttributes {
|
fun getAudioAttributes(): AudioAttributes {
|
||||||
return AudioAttributes.Builder()
|
return AudioAttributes.Builder()
|
||||||
.setUsage(AudioAttributes.USAGE_MEDIA)
|
.setUsage(AudioAttributes.USAGE_MEDIA)
|
||||||
|
|
|
@ -10,11 +10,9 @@ package org.moire.ultrasonic.service
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Context.POWER_SERVICE
|
import android.content.Context.POWER_SERVICE
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.media.AudioManager
|
|
||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
import android.media.MediaPlayer.OnCompletionListener
|
import android.media.MediaPlayer.OnCompletionListener
|
||||||
import android.media.audiofx.AudioEffect
|
import android.media.audiofx.AudioEffect
|
||||||
import android.os.Build
|
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
|
@ -447,12 +445,7 @@ class LocalMediaPlayer : KoinComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setAudioAttributes(player: MediaPlayer) {
|
private fun setAudioAttributes(player: MediaPlayer) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
player.setAudioAttributes(AudioFocusHandler.getAudioAttributes())
|
player.setAudioAttributes(AudioFocusHandler.getAudioAttributes())
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
player.setAudioStreamType(AudioManager.STREAM_MUSIC)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("ComplexCondition")
|
@Suppress("ComplexCondition")
|
||||||
|
|
|
@ -12,7 +12,6 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.os.Build
|
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
|
@ -165,12 +164,7 @@ class MediaPlayerLifecycleSupport : KoinComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val headsetIntentFilter: IntentFilter =
|
val headsetIntentFilter = IntentFilter(AudioManager.ACTION_HEADSET_PLUG)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
IntentFilter(AudioManager.ACTION_HEADSET_PLUG)
|
|
||||||
} else {
|
|
||||||
IntentFilter(Intent.ACTION_HEADSET_PLUG)
|
|
||||||
}
|
|
||||||
|
|
||||||
applicationContext().registerReceiver(headsetEventReceiver, headsetIntentFilter)
|
applicationContext().registerReceiver(headsetEventReceiver, headsetIntentFilter)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue