Version 1.0.4: 徹底修復自訂圖片導致懸浮窗閃退的問題
This commit is contained in:
parent
9e00d69d35
commit
83d188f21e
@ -50,8 +50,4 @@ dependencies {
|
|||||||
|
|
||||||
// EasyWindow
|
// EasyWindow
|
||||||
implementation("com.github.getActivity:EasyWindow:10.2")
|
implementation("com.github.getActivity:EasyWindow:10.2")
|
||||||
|
|
||||||
// Glide
|
|
||||||
implementation("com.github.bumptech.glide:glide:4.15.1")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -3,6 +3,7 @@ package com.ray650128.floatingwindow.ui
|
|||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@ -14,7 +15,6 @@ import android.widget.AdapterView
|
|||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.bumptech.glide.Glide
|
|
||||||
import com.ray650128.floatingwindow.databinding.ActivitySettingBinding
|
import com.ray650128.floatingwindow.databinding.ActivitySettingBinding
|
||||||
import com.ray650128.floatingwindow.dp
|
import com.ray650128.floatingwindow.dp
|
||||||
import com.ray650128.floatingwindow.utils.DensityUtil
|
import com.ray650128.floatingwindow.utils.DensityUtil
|
||||||
@ -56,8 +56,10 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
val data = result.data
|
val data = result.data
|
||||||
val returnUri = data?.data ?: return@registerForActivityResult
|
val returnUri = data?.data ?: return@registerForActivityResult
|
||||||
imageUri = saveImageToCache(returnUri)
|
imageUri = saveImageToCache(returnUri)
|
||||||
Glide.with(this).load(imageUri).into(binding.imgPreview)
|
Log.d(TAG, "imageUri=$imageUri")
|
||||||
FloatingWindowHelperUtils.setIcon(windowIcon, Uri.parse(imageUri))
|
val bitmap = BitmapFactory.decodeFile(imageUri)
|
||||||
|
binding.imgPreview.setImageBitmap(bitmap)
|
||||||
|
FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
|
||||||
//workingCheckItemAdapter.setImageUri(currentPosition, currentUri)
|
//workingCheckItemAdapter.setImageUri(currentPosition, currentUri)
|
||||||
//checkPassButton()
|
//checkPassButton()
|
||||||
}
|
}
|
||||||
@ -76,7 +78,7 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
windowGravity = FloatingWindowHelperUtils.GravityType.fromInt(PreferenceUtil.gravity)
|
windowGravity = FloatingWindowHelperUtils.GravityType.fromInt(PreferenceUtil.gravity)
|
||||||
windowIcon = FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon)
|
windowIcon = FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon)
|
||||||
if (!PreferenceUtil.iconPath.isNullOrEmpty()) {
|
if (!PreferenceUtil.iconPath.isNullOrEmpty()) {
|
||||||
Uri.parse(PreferenceUtil.iconPath)
|
imageUri = PreferenceUtil.iconPath
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.apply {
|
binding.apply {
|
||||||
@ -97,7 +99,9 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
windowIcon = FloatingWindowHelperUtils.IconType.fromIndex(position)
|
windowIcon = FloatingWindowHelperUtils.IconType.fromIndex(position)
|
||||||
FloatingWindowHelperUtils.setIcon(windowIcon, Uri.parse(imageUri))
|
if (imageUri != null) {
|
||||||
|
FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
|
||||||
|
}
|
||||||
if (windowIcon == FloatingWindowHelperUtils.IconType.CUSTOM) {
|
if (windowIcon == FloatingWindowHelperUtils.IconType.CUSTOM) {
|
||||||
imgPreview.isVisible = true
|
imgPreview.isVisible = true
|
||||||
btnPickPhoto.isVisible = true
|
btnPickPhoto.isVisible = true
|
||||||
@ -192,13 +196,15 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (imageUri != null) {
|
if (imageUri != null) {
|
||||||
Glide.with(this@SettingActivity).load(imageUri).into(imgPreview)
|
val bitmap = BitmapFactory.decodeFile(imageUri)
|
||||||
|
imgPreview.setImageBitmap(bitmap)
|
||||||
}
|
}
|
||||||
|
|
||||||
btnPickPhoto.setOnClickListener {
|
btnPickPhoto.setOnClickListener {
|
||||||
requestPermission.launch(
|
requestPermission.launch(
|
||||||
arrayOf(
|
arrayOf(
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.READ_MEDIA_IMAGES
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
|
Manifest.permission.READ_MEDIA_IMAGES
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -222,7 +228,7 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
)
|
)
|
||||||
FloatingWindowHelperUtils.setIcon(
|
FloatingWindowHelperUtils.setIcon(
|
||||||
FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon),
|
FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon),
|
||||||
Uri.parse(PreferenceUtil.iconPath)
|
PreferenceUtil.iconPath
|
||||||
)
|
)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
@ -252,4 +258,8 @@ class SettingActivity : AppCompatActivity() {
|
|||||||
return MimeTypeMap.getSingleton().getExtensionFromMimeType(contentResolver.getType(Uri.parse(uri)))
|
return MimeTypeMap.getSingleton().getExtensionFromMimeType(contentResolver.getType(Uri.parse(uri)))
|
||||||
?: "jpg" // Default extension
|
?: "jpg" // Default extension
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TAG = SettingActivity::class.java.simpleName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
package com.ray650128.floatingwindow.utils
|
package com.ray650128.floatingwindow.utils
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.drawable.BitmapDrawable
|
import android.graphics.drawable.BitmapDrawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@ -10,6 +11,7 @@ import android.view.WindowManager
|
|||||||
import com.hjq.window.EasyWindow
|
import com.hjq.window.EasyWindow
|
||||||
import com.ray650128.floatingwindow.MyApp
|
import com.ray650128.floatingwindow.MyApp
|
||||||
import com.ray650128.floatingwindow.R
|
import com.ray650128.floatingwindow.R
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
object FloatingWindowHelperUtils {
|
object FloatingWindowHelperUtils {
|
||||||
|
|
||||||
@ -38,10 +40,17 @@ object FloatingWindowHelperUtils {
|
|||||||
if (PreferenceUtil.iconPath.isNullOrEmpty()) {
|
if (PreferenceUtil.iconPath.isNullOrEmpty()) {
|
||||||
setImageDrawable(android.R.id.icon, windowIcon.value)
|
setImageDrawable(android.R.id.icon, windowIcon.value)
|
||||||
} else {
|
} else {
|
||||||
val uri = Uri.parse(PreferenceUtil.iconPath)
|
val iconPath = PreferenceUtil.iconPath
|
||||||
val bitmap = BitmapFactory.decodeStream(MyApp.appContext.contentResolver.openInputStream(uri))
|
if (iconPath?.contains("/data/user/0/com.ray650128.floatingwindow/cache/") == true) {
|
||||||
val drawable = BitmapDrawable(MyApp.appContext.resources, bitmap)
|
val bitmap = BitmapFactory.decodeFile(iconPath)
|
||||||
setImageDrawable(android.R.id.icon, drawable)
|
val drawable = BitmapDrawable(MyApp.appContext.resources, bitmap)
|
||||||
|
setImageDrawable(android.R.id.icon, drawable)
|
||||||
|
} else {
|
||||||
|
val uri = Uri.parse(PreferenceUtil.iconPath)
|
||||||
|
val bitmap = BitmapFactory.decodeStream(MyApp.appContext.contentResolver.openInputStream(uri))
|
||||||
|
val drawable = BitmapDrawable(MyApp.appContext.resources, bitmap)
|
||||||
|
setImageDrawable(android.R.id.icon, drawable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setImageDrawable(android.R.id.icon, windowIcon.value)
|
setImageDrawable(android.R.id.icon, windowIcon.value)
|
||||||
@ -129,6 +138,21 @@ object FloatingWindowHelperUtils {
|
|||||||
window.update()
|
window.update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setIcon(value: IconType, inputUri: String? = null) {
|
||||||
|
if (value == IconType.CUSTOM) {
|
||||||
|
if (inputUri == null) {
|
||||||
|
window.setImageDrawable(android.R.id.icon, value.value)
|
||||||
|
} else {
|
||||||
|
val bitmap = BitmapFactory.decodeFile(inputUri)
|
||||||
|
val drawable = BitmapDrawable(MyApp.appContext.resources, bitmap)
|
||||||
|
window.setImageDrawable(android.R.id.icon, drawable)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
window.setImageDrawable(android.R.id.icon, value.value)
|
||||||
|
}
|
||||||
|
window.update()
|
||||||
|
}
|
||||||
|
|
||||||
enum class GravityType(val type: Int) {
|
enum class GravityType(val type: Int) {
|
||||||
TOP_LEFT(0),
|
TOP_LEFT(0),
|
||||||
BOTTOM_LEFT(1),
|
BOTTOM_LEFT(1),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user