Commit b818b158 by 王佳洋

悬浮窗内存泄漏尝试修复

parent 19f73ce3
...@@ -109,9 +109,9 @@ class PlayerFloatHelper { ...@@ -109,9 +109,9 @@ class PlayerFloatHelper {
} }
fun removeView(context: Context) { fun removeView(context: Context) {
if (TextUtils.isEmpty(showingPageName) || showingPageName != context::class.qualifiedName) { // if (TextUtils.isEmpty(showingPageName) || showingPageName != context::class.qualifiedName) {
return // return
} // }
mPlayerFloatView?.visibility = View.GONE mPlayerFloatView?.visibility = View.GONE
wm?.removeViewImmediate(mPlayerFloatView) wm?.removeViewImmediate(mPlayerFloatView)
showingPageName = "" showingPageName = ""
......
package com.ydl.media.view package com.ydl.media.view
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Application
import android.content.Context import android.content.Context
import android.text.TextUtils import android.text.TextUtils
import android.view.MotionEvent import android.view.MotionEvent
...@@ -20,22 +21,22 @@ import java.util.concurrent.CopyOnWriteArraySet ...@@ -20,22 +21,22 @@ import java.util.concurrent.CopyOnWriteArraySet
import kotlin.math.abs import kotlin.math.abs
class PlayerFloatView(private val ctx: Context) : FrameLayout(ctx) { class PlayerFloatView(ctx: Context) : FrameLayout(ctx.applicationContext) {
private var mTouchDownX: Float = 0.toFloat() private var mTouchDownX: Float = 0.toFloat()
private var mTouchDownY: Float = 0.toFloat() private var mTouchDownY: Float = 0.toFloat()
private var mTouchX: Float = 0.toFloat() private var mTouchX: Float = 0.toFloat()
private var mTouchY: Float = 0.toFloat() private var mTouchY: Float = 0.toFloat()
private val mTouchSlop: Int = (ViewConfiguration.get(ctx).scaledTouchSlop + 8) * 3 private val mTouchSlop: Int = (ViewConfiguration.get(context).scaledTouchSlop + 8) * 3
private val mWindowManager: WindowManager = ctx.getSystemService(Context.WINDOW_SERVICE) as WindowManager private val mWindowManager: WindowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
//全局变量,用以保存悬浮窗口的属性 //全局变量,用以保存悬浮窗口的属性
var mFloatViewParams = WindowManager.LayoutParams() var mFloatViewParams = WindowManager.LayoutParams()
private var mListeners: CopyOnWriteArraySet<FloatViewPlayListener> = CopyOnWriteArraySet() private var mListeners: CopyOnWriteArraySet<FloatViewPlayListener> = CopyOnWriteArraySet()
private var mStateChangeListener: OnPlayerEventListener? = null private var mStateChangeListener: OnPlayerEventListener? = null
private val mStatusBarHeight: Int = StatusBarUtil.getStatusBarHeight(ctx) private val mStatusBarHeight: Int = StatusBarUtil.getStatusBarHeight(context)
fun resetLayoutParams() { fun resetLayoutParams() {
...@@ -46,7 +47,7 @@ class PlayerFloatView(private val ctx: Context) : FrameLayout(ctx) { ...@@ -46,7 +47,7 @@ class PlayerFloatView(private val ctx: Context) : FrameLayout(ctx) {
View.inflate(context, R.layout.item_playing_float_btn, this) View.inflate(context, R.layout.item_playing_float_btn, this)
resetFloatView() resetFloatView()
if (!TextUtils.isEmpty(AudioPlayer.get().playMusic?.coverPath)) { if (!TextUtils.isEmpty(AudioPlayer.get().playMusic?.coverPath)) {
GlideApp.with(context.applicationContext) GlideApp.with(context)
.load(AudioPlayer.get().playMusic?.coverPath) .load(AudioPlayer.get().playMusic?.coverPath)
.transform(GlideRoundTransform(context, 4)) .transform(GlideRoundTransform(context, 4))
.error(R.drawable.ico_play_float_pic) .error(R.drawable.ico_play_float_pic)
...@@ -61,7 +62,7 @@ class PlayerFloatView(private val ctx: Context) : FrameLayout(ctx) { ...@@ -61,7 +62,7 @@ class PlayerFloatView(private val ctx: Context) : FrameLayout(ctx) {
mListeners.forEach { mListeners.forEach {
it.onPauseClick() it.onPauseClick()
} }
PlayerFloatHelper.removeView(ctx) PlayerFloatHelper.removeView(context)
PlayerFloatHelper.playTempData.clear() PlayerFloatHelper.playTempData.clear()
AudioPlayer.get().resetPlayer() AudioPlayer.get().resetPlayer()
} }
...@@ -135,7 +136,7 @@ class PlayerFloatView(private val ctx: Context) : FrameLayout(ctx) { ...@@ -135,7 +136,7 @@ class PlayerFloatView(private val ctx: Context) : FrameLayout(ctx) {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
fun resetFloatView() { fun resetFloatView() {
if (!TextUtils.isEmpty(AudioPlayer.get().playMusic?.coverPath)) { if (!TextUtils.isEmpty(AudioPlayer.get().playMusic?.coverPath)) {
GlideApp.with(context.applicationContext) GlideApp.with(context)
.load(AudioPlayer.get().playMusic?.coverPath) .load(AudioPlayer.get().playMusic?.coverPath)
.transform(GlideRoundTransform(context, 4)) .transform(GlideRoundTransform(context, 4))
.error(R.drawable.ico_play_float_pic) .error(R.drawable.ico_play_float_pic)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment