Compare commits

..

No commits in common. "9e00d69d35675b161ba92f81b4132d5b65c2341a" and "2eebb63122e2404e7f79e7ac2571e01d248c57f6" have entirely different histories.

2 changed files with 7 additions and 29 deletions

View File

@ -12,7 +12,7 @@ android {
minSdk = 24 minSdk = 24
targetSdk = 34 targetSdk = 34
versionCode = 4 versionCode = 4
versionName = "1.0.4" versionName = "1.0.3"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@ -9,7 +9,6 @@ import android.os.Bundle
import android.provider.MediaStore import android.provider.MediaStore
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.webkit.MimeTypeMap
import android.widget.AdapterView 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
@ -21,7 +20,6 @@ import com.ray650128.floatingwindow.utils.DensityUtil
import com.ray650128.floatingwindow.utils.FloatingWindowHelperUtils import com.ray650128.floatingwindow.utils.FloatingWindowHelperUtils
import com.ray650128.floatingwindow.utils.PreferenceUtil import com.ray650128.floatingwindow.utils.PreferenceUtil
import com.ray650128.floatingwindow.view.ValueEditor import com.ray650128.floatingwindow.view.ValueEditor
import java.io.File
class SettingActivity : AppCompatActivity() { class SettingActivity : AppCompatActivity() {
@ -54,16 +52,15 @@ class SettingActivity : AppCompatActivity() {
private val galleryLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> private val galleryLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) { if (result.resultCode == Activity.RESULT_OK) {
val data = result.data val data = result.data
val returnUri = data?.data ?: return@registerForActivityResult imageUri = data?.data
imageUri = saveImageToCache(returnUri)
Glide.with(this).load(imageUri).into(binding.imgPreview) Glide.with(this).load(imageUri).into(binding.imgPreview)
FloatingWindowHelperUtils.setIcon(windowIcon, Uri.parse(imageUri)) FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
//workingCheckItemAdapter.setImageUri(currentPosition, currentUri) //workingCheckItemAdapter.setImageUri(currentPosition, currentUri)
//checkPassButton() //checkPassButton()
} }
} }
private var imageUri: String? = null private var imageUri: Uri? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -75,7 +72,7 @@ class SettingActivity : AppCompatActivity() {
yOffset = PreferenceUtil.yOffset yOffset = PreferenceUtil.yOffset
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()) { imageUri = if (PreferenceUtil.iconPath.isNullOrEmpty()) null else {
Uri.parse(PreferenceUtil.iconPath) Uri.parse(PreferenceUtil.iconPath)
} }
@ -97,7 +94,7 @@ 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)) 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
@ -208,7 +205,7 @@ class SettingActivity : AppCompatActivity() {
PreferenceUtil.yOffset = yOffset PreferenceUtil.yOffset = yOffset
PreferenceUtil.gravity = windowGravity.type PreferenceUtil.gravity = windowGravity.type
PreferenceUtil.icon = windowIcon.value PreferenceUtil.icon = windowIcon.value
PreferenceUtil.iconPath = imageUri PreferenceUtil.iconPath = imageUri?.toString()
finish() finish()
} }
@ -233,23 +230,4 @@ class SettingActivity : AppCompatActivity() {
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI) val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI)
galleryLauncher.launch(intent) galleryLauncher.launch(intent)
} }
private fun saveImageToCache(uri: Uri?): String? {
if (uri == null) return null
val inputStream = contentResolver.openInputStream(uri)
inputStream?.use { input ->
val extension = getFileExtension(uri.toString())
val outputFile = File(cacheDir, "custom.$extension")
outputFile.outputStream().use { output ->
input.copyTo(output)
}
return outputFile.absolutePath
}
return null
}
private fun getFileExtension(uri: String): String {
return MimeTypeMap.getSingleton().getExtensionFromMimeType(contentResolver.getType(Uri.parse(uri)))
?: "jpg" // Default extension
}
} }