From dbc1444d7f76ef3e522c437b05dd9aa0807b480b Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sun, 10 Oct 2021 13:01:25 +0200 Subject: [PATCH] Remove wallpaper blur effect Never actually really worked --- .../de/mm20/launcher2/LauncherApplication.kt | 18 ---- .../fragment/PreferencesAppearanceFragment.kt | 13 --- .../fragment/PreferencesCardFragment.kt | 74 -------------- .../res/layout/fragment_card_settings.xml | 8 -- app/src/main/res/xml/preferences_cards.xml | 6 -- i18n/src/main/res/values-de/strings.xml | 3 - i18n/src/main/res/values/strings.xml | 3 - .../ui/legacy/activity/LauncherActivity.kt | 21 +--- .../ui/legacy/helper/WallpaperBlur.kt | 91 ------------------ .../mm20/launcher2/ui/legacy/view/BlurView.kt | 96 ------------------- ui/src/main/res/layout/activity_launcher.xml | 4 +- 11 files changed, 5 insertions(+), 332 deletions(-) delete mode 100644 ui/src/main/java/de/mm20/launcher2/ui/legacy/helper/WallpaperBlur.kt delete mode 100644 ui/src/main/java/de/mm20/launcher2/ui/legacy/view/BlurView.kt diff --git a/app/src/main/java/de/mm20/launcher2/LauncherApplication.kt b/app/src/main/java/de/mm20/launcher2/LauncherApplication.kt index aeb8a681..a6ebd991 100644 --- a/app/src/main/java/de/mm20/launcher2/LauncherApplication.kt +++ b/app/src/main/java/de/mm20/launcher2/LauncherApplication.kt @@ -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) - } - -} \ No newline at end of file diff --git a/app/src/main/java/de/mm20/launcher2/fragment/PreferencesAppearanceFragment.kt b/app/src/main/java/de/mm20/launcher2/fragment/PreferencesAppearanceFragment.kt index e3b5054c..640dcaa2 100644 --- a/app/src/main/java/de/mm20/launcher2/fragment/PreferencesAppearanceFragment.kt +++ b/app/src/main/java/de/mm20/launcher2/fragment/PreferencesAppearanceFragment.kt @@ -47,19 +47,6 @@ class PreferencesAppearanceFragment : PreferenceFragmentCompat() { requireActivity().recreate() true } - if (WallpaperManager.getInstance(activity).wallpaperInfo != null) { - findPreference("blur_cards")?.apply { - setSummary(R.string.preference_blur_cards_summary_lwp) - isEnabled = false - } - } - findPreference("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("wallpaper")?.setOnPreferenceClickListener { requireContext().startActivity(Intent.createChooser(Intent(Intent.ACTION_SET_WALLPAPER), null)) diff --git a/app/src/main/java/de/mm20/launcher2/fragment/PreferencesCardFragment.kt b/app/src/main/java/de/mm20/launcher2/fragment/PreferencesCardFragment.kt index 38371b77..7564bfc3 100644 --- a/app/src/main/java/de/mm20/launcher2/fragment/PreferencesCardFragment.kt +++ b/app/src/main/java/de/mm20/launcher2/fragment/PreferencesCardFragment.kt @@ -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("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("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() { diff --git a/app/src/main/res/layout/fragment_card_settings.xml b/app/src/main/res/layout/fragment_card_settings.xml index bbcab1cf..d492d631 100644 --- a/app/src/main/res/layout/fragment_card_settings.xml +++ b/app/src/main/res/layout/fragment_card_settings.xml @@ -13,14 +13,6 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> - - - - - Websuchen-Shortcuts Websuchen bearbeiten Ort - Unschärfeeffekt - Hintergrund hinter Karten unscharf darstellen - Nicht mit Live-Hintergründen kompatibel Google YouTube Google Play diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 81692533..6e157b85 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -183,9 +183,6 @@ Web search shortcuts Edit web searches Location - Blur effect - Blur wallpaper behind translucent cards - Not compatible with live wallpapers Google YouTube Google Play diff --git a/ui/src/main/java/de/mm20/launcher2/ui/legacy/activity/LauncherActivity.kt b/ui/src/main/java/de/mm20/launcher2/ui/legacy/activity/LauncherActivity.kt index aa37015d..a741249c 100644 --- a/ui/src/main/java/de/mm20/launcher2/ui/legacy/activity/LauncherActivity.kt +++ b/ui/src/main/java/de/mm20/launcher2/ui/legacy/activity/LauncherActivity.kt @@ -59,7 +59,6 @@ import de.mm20.launcher2.transition.OneShotLayoutTransition import de.mm20.launcher2.ui.R import de.mm20.launcher2.ui.legacy.component.EditFavoritesView import de.mm20.launcher2.ui.legacy.component.WidgetView -import de.mm20.launcher2.ui.legacy.helper.WallpaperBlur import de.mm20.launcher2.ui.legacy.search.SearchGridView import de.mm20.launcher2.ui.legacy.widget.LauncherWidget import de.mm20.launcher2.weather.WeatherViewModel @@ -208,7 +207,9 @@ class LauncherActivity : AppCompatActivity() { overlayView = rootView.overlay - + if (LauncherPreferences.instance.dimWallpaper) { + dimWallpaper.setBackgroundColor(getColor(R.color.wallpaper_dim)) + } scrollContainer.layoutTransition.enableTransitionType(LayoutTransition.CHANGING) searchContainer.layoutTransition.enableTransitionType(LayoutTransition.CHANGING) @@ -221,12 +222,6 @@ class LauncherActivity : AppCompatActivity() { adjustWidgetSpace() } initWidgets() - if (preferences.blurCards && preferences.cardOpacity < 0xFF) { - container.viewTreeObserver.addOnPreDrawListener { - blurView.invalidate() - true - } - } scrollView.setOnTouchListener(scrollViewOnTouchListener) scrollView.setOnScrollChangeListener { _: NestedScrollView?, _: Int, scrollY: Int, _: Int, oldScrollY: Int -> when { @@ -608,14 +603,6 @@ class LauncherActivity : AppCompatActivity() { override fun onStart() { super.onStart() - if (preferences.blurCards && preferences.cardOpacity < 0xFF) { - lifecycleScope.launch { - val wallpaper = withContext(Dispatchers.IO) { - WallpaperBlur.getCachedBitmap(this@LauncherActivity) - } - WallpaperBlur.blurredWallpaper = wallpaper - } - } preferences.doOnPreferenceChange("is_light_wallpaper", action = themeListener) widgetHost.startListening() } @@ -627,8 +614,6 @@ class LauncherActivity : AppCompatActivity() { override fun onStop() { super.onStop() - WallpaperBlur.blurredWallpaper?.takeIf { !it.isRecycled }?.recycle() - WallpaperBlur.blurredWallpaper = null try { widgetHost.stopListening() } catch (e: NullPointerException) { diff --git a/ui/src/main/java/de/mm20/launcher2/ui/legacy/helper/WallpaperBlur.kt b/ui/src/main/java/de/mm20/launcher2/ui/legacy/helper/WallpaperBlur.kt deleted file mode 100644 index b56596e8..00000000 --- a/ui/src/main/java/de/mm20/launcher2/ui/legacy/helper/WallpaperBlur.kt +++ /dev/null @@ -1,91 +0,0 @@ -package de.mm20.launcher2.ui.legacy.helper - -import android.Manifest -import android.app.WallpaperManager -import android.content.Context -import android.content.pm.PackageManager -import android.graphics.Bitmap -import android.graphics.BitmapFactory -import android.os.Build -import androidx.core.content.ContextCompat -import androidx.core.graphics.drawable.toBitmap -import com.bumptech.glide.Glide -import com.bumptech.glide.request.RequestOptions -import com.bumptech.glide.request.target.SimpleTarget -import com.bumptech.glide.request.transition.Transition -import de.mm20.launcher2.ktx.dp -import de.mm20.launcher2.preferences.LauncherPreferences -import jp.wasabeef.glide.transformations.BlurTransformation -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import java.io.File -import java.io.FileOutputStream - - -object WallpaperBlur { - fun requestBlur(context: Context) { - val wm = WallpaperManager.getInstance(context) - val lastId = context.getSharedPreferences("wallpaper", Context.MODE_PRIVATE) - .getInt("last_wallpaper_id", 0) - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || wm.getWallpaperId(WallpaperManager.FLAG_SYSTEM) != lastId) { - blurredWallpaper?.takeIf { !it.isRecycled }?.recycle() - blurredWallpaper = null - File(context.cacheDir, "wallpaper").takeIf { it.exists() }?.delete() - if (wm.wallpaperInfo != null) return - if (ContextCompat.checkSelfPermission( - context, - Manifest.permission.READ_EXTERNAL_STORAGE - ) != PackageManager.PERMISSION_GRANTED - ) return - val wallpaper = wm.drawable.toBitmap() - Glide.with(context) - .asBitmap() - .load(wallpaper) - .apply( - RequestOptions.bitmapTransform( - BlurTransformation( - (20 * context.dp).toInt(), - 1 - ) - ) - ) - .into(object : SimpleTarget() { - override fun onResourceReady( - resource: Bitmap, - transition: Transition? - ) { - GlobalScope.launch { - withContext(Dispatchers.IO) { - val out = FileOutputStream(File(context.cacheDir, "wallpaper")) - resource.compress(Bitmap.CompressFormat.PNG, 100, out) - out.close() - context.getSharedPreferences("wallpaper", Context.MODE_PRIVATE) - .edit() - .putInt( - "last_wallpaper_id", wm.getWallpaperId( - WallpaperManager.FLAG_SYSTEM - ) - ) - .apply() - - if (LauncherPreferences.instance.blurCards && LauncherPreferences.instance.cardOpacity < 0xFF) { - blurredWallpaper = resource - } else { - resource.recycle() - } - } - } - } - - }) - } - } - - fun getCachedBitmap(context: Context): Bitmap? { - return BitmapFactory.decodeFile(File(context.cacheDir, "wallpaper").absolutePath) - } - - var blurredWallpaper: Bitmap? = null -} diff --git a/ui/src/main/java/de/mm20/launcher2/ui/legacy/view/BlurView.kt b/ui/src/main/java/de/mm20/launcher2/ui/legacy/view/BlurView.kt deleted file mode 100644 index ac82e2ca..00000000 --- a/ui/src/main/java/de/mm20/launcher2/ui/legacy/view/BlurView.kt +++ /dev/null @@ -1,96 +0,0 @@ -package de.mm20.launcher2.ui.legacy.view - -import android.content.Context -import android.graphics.* -import android.util.AttributeSet -import android.view.View -import android.view.ViewGroup -import androidx.core.content.ContextCompat -import androidx.core.graphics.toRect -import androidx.core.view.isVisible -import androidx.core.view.iterator -import de.mm20.launcher2.ktx.copyTo -import de.mm20.launcher2.ktx.scale -import de.mm20.launcher2.ktx.toRectF -import de.mm20.launcher2.ktx.translate -import de.mm20.launcher2.preferences.LauncherPreferences -import de.mm20.launcher2.ui.R -import kotlin.math.min - -class BlurView : View { - - private val globalRect = Rect() - private val blurPaint = Paint().apply { xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) } - private val maskPaint = Paint().apply { color = Color.BLACK } - private val viewRect = RectF() - private val wallpaperRect = RectF() - private val windowRect = Rect() - - private val dimWallpaper = LauncherPreferences.instance.dimWallpaper - private val dimPaint = Paint().apply { color = ContextCompat.getColor(context, R.color.wallpaper_dim) } - - constructor(context: Context) : super(context) - constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) - constructor(context: Context, attrs: AttributeSet?, defStyleRes: Int) : super(context, attrs, defStyleRes) - - override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) - /*val blurredWallpaper = LauncherApplication.instance.blurredWallpaper - blurredWallpaper ?: return drawWallpaperDim(canvas) - if (blurredWallpaper.isRecycled) return drawWallpaperDim(canvas) - val parent = parent as? ViewGroup ?: return drawWallpaperDim(canvas) - drawMasks(parent, canvas) - getGlobalVisibleRect(globalRect) - globalRect.toRectF(viewRect) - getWindowVisibleDisplayFrame(windowRect) - /*canvas.drawBitmap(blurredWallpaper, - -(blurredWallpaper.width - viewRect.width()) / 2f, - -(blurredWallpaper.height - viewRect.height()) / 2f, - blurPaint)*/ - if (blurredWallpaper.width >= width && blurredWallpaper.height >= height) { - viewRect.copyTo(wallpaperRect) - wallpaperRect.translate((blurredWallpaper.width - wallpaperRect.width()) / 2f, (blurredWallpaper.height - wallpaperRect.height()) / 2f) - } else { - val scale = min(blurredWallpaper.width / width.toFloat(), blurredWallpaper.height / height.toFloat()) - viewRect.copyTo(wallpaperRect) - wallpaperRect.scale(scale) - wallpaperRect.translate((blurredWallpaper.width - wallpaperRect.width()) / 2, (blurredWallpaper.height - wallpaperRect.height()) / 2) - } - if (viewRect.top > 0f) { - wallpaperRect.translate(0f, viewRect.top) - } - canvas.drawBitmap(blurredWallpaper, wallpaperRect.toRect(), viewRect, blurPaint) - drawWallpaperDim(canvas)*/ - } - - private fun drawWallpaperDim(canvas: Canvas) { - if (dimWallpaper) { - canvas.drawRect(Rect(0, 0, canvas.width, canvas.height), dimPaint) - } - } - - private var viewBounds = RectF() - - private fun drawMasks(parent: ViewGroup, canvas: Canvas) { - loop@ for (view in parent.iterator()) { - when { - !view.isVisible || view.alpha == 0f -> { - } - view is LauncherCardView -> { - if (view.backgroundOpacity == 0 || view.backgroundOpacity == 0xFF) { - continue@loop - } - if (!view.getGlobalVisibleRect(globalRect)) continue@loop - globalRect.toRectF(viewBounds) - if (viewRect.top > 0f) { - viewBounds.translate(0f, -viewRect.top) - } - canvas.drawRoundRect(viewBounds, view.radius, view.radius, maskPaint) - } - view is ViewGroup -> { - drawMasks(view, canvas) - } - } - } - } -} \ No newline at end of file diff --git a/ui/src/main/res/layout/activity_launcher.xml b/ui/src/main/res/layout/activity_launcher.xml index bb960221..27059102 100644 --- a/ui/src/main/res/layout/activity_launcher.xml +++ b/ui/src/main/res/layout/activity_launcher.xml @@ -7,8 +7,8 @@ android:layout_height="match_parent" android:clipChildren="false"> -