diff --git a/app/build.gradle b/app/build.gradle index 223661b..00252cc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -62,7 +62,7 @@ android { dependencies { implementation 'androidx.core:core-ktx:1.12.0' implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'com.google.android.material:material:1.12.0' + implementation 'com.google.android.material:material:1.13.0-alpha13' implementation 'androidx.constraintlayout:constraintlayout:2.2.1' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.2.1' diff --git a/app/src/main/java/partisan/weforge/xyz/pulse/PopupWindow.kt b/app/src/main/java/partisan/weforge/xyz/pulse/PopupWindow.kt index d5f4aa1..f60b03f 100644 --- a/app/src/main/java/partisan/weforge/xyz/pulse/PopupWindow.kt +++ b/app/src/main/java/partisan/weforge/xyz/pulse/PopupWindow.kt @@ -3,6 +3,7 @@ package partisan.weforge.xyz.pulse import android.Manifest import android.content.Context import android.content.Intent +import android.graphics.Color import android.graphics.PixelFormat import android.media.AudioManager import android.net.Uri @@ -14,19 +15,29 @@ import android.widget.TextView import android.animation.ObjectAnimator import android.widget.ProgressBar import androidx.annotation.RequiresPermission +import androidx.core.content.res.use +import com.google.android.material.card.MaterialCardView import java.lang.ref.WeakReference import java.util.* import kotlin.concurrent.timerTask +import android.util.Log +import android.content.res.ColorStateList +import com.google.android.material.color.DynamicColors +import com.google.android.material.color.utilities.MaterialDynamicColors +import com.google.android.material.color.MaterialColors class PopupWindow( ctx: Context, private val service: WeakReference?, ) { - private val themedCtx = ContextThemeWrapper(ctx, R.style.Theme_Pulse) + private val themedCtx = DynamicColors.wrapContextIfAvailable( + ContextThemeWrapper(ctx, R.style.Theme_Pulse) + ) private val prefs = Preferences(themedCtx) private val windowManager = themedCtx.getSystemService(WindowManager::class.java) private val audioManager = themedCtx.getSystemService(AudioManager::class.java) - private val view = LayoutInflater.from(themedCtx).inflate(R.layout.popup, null) + private val inflater = LayoutInflater.from(themedCtx) + private val view = inflater.inflate(R.layout.popup, null) private val layoutParams = WindowManager.LayoutParams().apply { format = PixelFormat.TRANSLUCENT flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE @@ -43,6 +54,9 @@ class PopupWindow( cancel() service?.get()?.placeCallUnmodified() } + + // This is utterly stupid, but it works + applyResolvedColors(view) } fun preview() { @@ -137,5 +151,33 @@ class PopupWindow( fun cancel() { timer?.cancel() remove() + } + + private fun applyResolvedColors(view: android.view.View) { + val attrSurface = com.google.android.material.R.attr.colorSurface + val attrOnSurface = com.google.android.material.R.attr.colorOnSurface + val attrPrimary = com.google.android.material.R.attr.colorPrimaryVariant + + try { + themedCtx.obtainStyledAttributes(intArrayOf(attrSurface, attrOnSurface, attrPrimary)).use { ta -> + val surface = ta.getColor(0, Color.LTGRAY) + val onSurface = ta.getColor(1, Color.DKGRAY) + val primary = ta.getColor(2, Color.DKGRAY) + + (view as? MaterialCardView)?.setCardBackgroundColor(surface) + view.findViewById(R.id.description)?.setTextColor(onSurface) + + view.findViewById(R.id.progress)?.let { bar -> + bar.progressTintList = ColorStateList.valueOf(primary) + bar.progressBackgroundTintList = ColorStateList.valueOf( + primary and 0x00FFFFFF or (0x40 shl 24) + ) + } + + view.invalidate() + } + } catch (e: Exception) { + Log.e("PopupTheme", "Color resolution error: ${e.message}", e) + } } } diff --git a/app/src/main/res/layout/popup.xml b/app/src/main/res/layout/popup.xml index 1b46631..1031757 100644 --- a/app/src/main/res/layout/popup.xml +++ b/app/src/main/res/layout/popup.xml @@ -7,8 +7,7 @@ android:layout_height="wrap_content" app:cardCornerRadius="24dp" app:cardElevation="4dp" - app:cardBackgroundColor="?attr/colorSurface" - android:background="@android:color/white"> + app:cardBackgroundColor="?attr/colorSurface"> + style="@android:style/Widget.ProgressBar.Horizontal"/>