Remove wallpaper blur effect

Never actually really worked
This commit is contained in:
MM20
2021-10-10 13:01:25 +02:00
parent 087d4fd455
commit dbc1444d7f
11 changed files with 5 additions and 332 deletions
@@ -1,9 +1,6 @@
package de.mm20.launcher2
import android.app.Application
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Bitmap
import androidx.appcompat.app.AppCompatDelegate
@@ -21,7 +18,6 @@ import de.mm20.launcher2.music.musicModule
import de.mm20.launcher2.preferences.LauncherPreferences
import de.mm20.launcher2.preferences.Themes
import de.mm20.launcher2.search.searchModule
import de.mm20.launcher2.ui.legacy.helper.WallpaperBlur
import de.mm20.launcher2.unitconverter.unitConverterModule
import de.mm20.launcher2.websites.websitesModule
import de.mm20.launcher2.widgets.widgetsModule
@@ -38,12 +34,9 @@ class LauncherApplication : Application(), CoroutineScope {
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + SupervisorJob()
var blurredWallpaper: Bitmap? = null
override fun onCreate() {
super.onCreate()
Debug()
instance = this
LauncherPreferences.initialize(this)
val theme = LauncherPreferences.instance.theme
@@ -55,9 +48,6 @@ class LauncherApplication : Application(), CoroutineScope {
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM //system
}
)
WallpaperBlur.requestBlur(this)
@Suppress("DEPRECATION") // We need to access the wallpaper directly to blur it
registerReceiver(WallpaperReceiver(), IntentFilter(Intent.ACTION_WALLPAPER_CHANGED))
startKoin {
androidLogger()
@@ -85,7 +75,6 @@ class LauncherApplication : Application(), CoroutineScope {
}
companion object {
lateinit var instance: LauncherApplication
val collator: Collator by lazy {
Collator.getInstance().apply { strength = Collator.SECONDARY }
@@ -99,10 +88,3 @@ object PermissionRequests {
const val LOCATION = 410
const val ALL = 666
}
class WallpaperReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) {
WallpaperBlur.requestBlur(context)
}
}
@@ -47,19 +47,6 @@ class PreferencesAppearanceFragment : PreferenceFragmentCompat() {
requireActivity().recreate()
true
}
if (WallpaperManager.getInstance(activity).wallpaperInfo != null) {
findPreference<Preference>("blur_cards")?.apply {
setSummary(R.string.preference_blur_cards_summary_lwp)
isEnabled = false
}
}
findPreference<Preference>("blur_cards")?.setOnPreferenceChangeListener { _, newValue ->
val newVal = newValue as? Boolean ?: return@setOnPreferenceChangeListener true
if (newVal && requireActivity().checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) {
ActivityCompat.requestPermissions(requireActivity(), arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 0)
}
true
}
findPreference<Preference>("wallpaper")?.setOnPreferenceClickListener {
requireContext().startActivity(Intent.createChooser(Intent(Intent.ACTION_SET_WALLPAPER), null))
@@ -13,16 +13,12 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import de.mm20.launcher2.LauncherApplication
import de.mm20.launcher2.R
import de.mm20.launcher2.ktx.castTo
import de.mm20.launcher2.ktx.dp
import de.mm20.launcher2.ktx.translate
import de.mm20.launcher2.preferences.CardBackground
import de.mm20.launcher2.preferences.LauncherPreferences
import de.mm20.launcher2.ui.legacy.helper.WallpaperBlur
import kotlinx.android.synthetic.main.fragment_card_settings.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -36,19 +32,10 @@ class PreferencesCardFragment : Fragment(R.layout.fragment_card_settings) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
previewCard.strokeOpacity = 0xFF
previewCardBlur.clipToOutline = true
previewCardBlur.outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline?) {
val radius = preferences.cardRadius
outline?.setRoundRect(0, 0, view.width, view.height, radius * dp)
}
}
val context = requireContext()
val previewCardBlur = previewCardBlur
val previewCard = previewCard
val prefFragment = PreferenesCardInnerFragment()
@@ -58,7 +45,6 @@ class PreferencesCardFragment : Fragment(R.layout.fragment_card_settings) {
it.setOnPreferenceChangeListener { pref, newValue ->
val value = newValue as Int
previewCard.radius = value * dp
previewCardBlur.invalidateOutline()
pref.summary = value.toString()
true
}
@@ -82,27 +68,6 @@ class PreferencesCardFragment : Fragment(R.layout.fragment_card_settings) {
true
}
}
findPreference<Preference>("blur_cards")?.let {
if (WallpaperManager.getInstance(requireContext()).wallpaperInfo != null) {
it.isEnabled = false
it.setSummary(R.string.preference_blur_cards_summary_lwp)
previewCardBlur.visibility = View.INVISIBLE
} else {
previewCardBlur.visibility = if (preferences.blurCards) {
View.VISIBLE
} else {
View.INVISIBLE
}
it.setOnPreferenceChangeListener { pref, newValue ->
previewCardBlur.visibility = if (newValue as Boolean) {
View.VISIBLE
} else {
View.INVISIBLE
}
true
}
}
}
findPreference<Preference>("card_background")?.let {
it.setOnPreferenceChangeListener { preference, newValue ->
val background = CardBackground.byValue(newValue as String)
@@ -137,49 +102,10 @@ class PreferencesCardFragment : Fragment(R.layout.fragment_card_settings) {
start()
}
if (preferences.blurCards && preferences.cardOpacity < 0xFF) {
lifecycleScope.launch {
val wallpaper = withContext(Dispatchers.IO) {
WallpaperBlur.getCachedBitmap(requireContext())
}
LauncherApplication.instance.blurredWallpaper = wallpaper
}
}
content.doOnNextLayout {
WallpaperManager.getInstance(requireContext()).setWallpaperOffsets(it.windowToken, 0.5f, 0.5f)
}
val activity = requireActivity()
lifecycleScope.launch {
val viewPosition = intArrayOf(0, 0)
val rect = Rect(0, 0, previewCardBlur.width, previewCardBlur.height)
val screen = Point()
activity.windowManager.defaultDisplay.getRealSize(screen)
previewCardBlur.getLocationOnScreen(viewPosition)
val file = File(requireContext().cacheDir, "wallpaper")
if (!file.exists()) return@launch
blurBitmap = withContext(Dispatchers.IO) {
val wallpaperWidth: Int
val wallpaperHeight: Int
val decoder = BitmapRegionDecoder
.newInstance(file.absolutePath, false)
wallpaperHeight = decoder.height
wallpaperWidth = decoder.width
if (wallpaperWidth >= screen.x && wallpaperHeight >= screen.y) {
val translateX = (wallpaperWidth - previewCardBlur.width) / 2f
val translateY = (wallpaperHeight - screen.y) / 2f + viewPosition[1]
rect.translate(translateX.roundToInt(),
translateY.roundToInt())
}
decoder.decodeRegion(rect, null)
}
previewCardBlur.setImageBitmap(blurBitmap)
}
}
override fun onStop() {
@@ -13,14 +13,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/previewCardBlur"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="16dp"
android:scaleType="centerCrop" />
<de.mm20.launcher2.ui.legacy.view.LauncherCardView
android:id="@+id/previewCard"
android:layout_width="match_parent"
@@ -24,12 +24,6 @@
app:min="0"
app:updatesContinuously="true" />
<SwitchPreference
app:key="blur_cards"
android:defaultValue="false"
app:summary="@string/preference_blur_cards_summary"
app:title="@string/preference_blur_cards" />
<ListPreference
app:key="card_background"
android:defaultValue="0"