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
targetSdk = 34
versionCode = 4
versionName = "1.0.4"
versionName = "1.0.3"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

View File

@ -9,7 +9,6 @@ import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import android.view.View
import android.webkit.MimeTypeMap
import android.widget.AdapterView
import androidx.activity.result.contract.ActivityResultContracts
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.PreferenceUtil
import com.ray650128.floatingwindow.view.ValueEditor
import java.io.File
class SettingActivity : AppCompatActivity() {
@ -54,16 +52,15 @@ class SettingActivity : AppCompatActivity() {
private val galleryLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
val data = result.data
val returnUri = data?.data ?: return@registerForActivityResult
imageUri = saveImageToCache(returnUri)
imageUri = data?.data
Glide.with(this).load(imageUri).into(binding.imgPreview)
FloatingWindowHelperUtils.setIcon(windowIcon, Uri.parse(imageUri))
FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
//workingCheckItemAdapter.setImageUri(currentPosition, currentUri)
//checkPassButton()
}
}
private var imageUri: String? = null
private var imageUri: Uri? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -75,7 +72,7 @@ class SettingActivity : AppCompatActivity() {
yOffset = PreferenceUtil.yOffset
windowGravity = FloatingWindowHelperUtils.GravityType.fromInt(PreferenceUtil.gravity)
windowIcon = FloatingWindowHelperUtils.IconType.fromInt(PreferenceUtil.icon)
if (!PreferenceUtil.iconPath.isNullOrEmpty()) {
imageUri = if (PreferenceUtil.iconPath.isNullOrEmpty()) null else {
Uri.parse(PreferenceUtil.iconPath)
}
@ -97,7 +94,7 @@ 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))
FloatingWindowHelperUtils.setIcon(windowIcon, imageUri)
if (windowIcon == FloatingWindowHelperUtils.IconType.CUSTOM) {
imgPreview.isVisible = true
btnPickPhoto.isVisible = true
@ -208,7 +205,7 @@ class SettingActivity : AppCompatActivity() {
PreferenceUtil.yOffset = yOffset
PreferenceUtil.gravity = windowGravity.type
PreferenceUtil.icon = windowIcon.value
PreferenceUtil.iconPath = imageUri
PreferenceUtil.iconPath = imageUri?.toString()
finish()
}
@ -233,23 +230,4 @@ class SettingActivity : AppCompatActivity() {
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI)
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
}
}