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