Well, if it works it ain't stupid (material you fix for popup)
This commit is contained in:
parent
64efa8c15e
commit
1850641fdb
3 changed files with 47 additions and 8 deletions
|
@ -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'
|
||||
|
|
|
@ -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<CallRedirectionService>?,
|
||||
) {
|
||||
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<TextView>(R.id.description)?.setTextColor(onSurface)
|
||||
|
||||
view.findViewById<ProgressBar>(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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -20,7 +19,6 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:textColor="?attr/colorOnSurface"
|
||||
android:textSize="16sp"
|
||||
android:textAppearance="?attr/textAppearanceBodyMedium"
|
||||
android:textAlignment="center"
|
||||
|
@ -35,7 +33,6 @@
|
|||
android:layout_marginBottom="8dp"
|
||||
android:indeterminate="false"
|
||||
android:max="100"
|
||||
style="@android:style/Widget.ProgressBar.Horizontal"
|
||||
android:progressDrawable="@drawable/progress_drawable"/>
|
||||
style="@android:style/Widget.ProgressBar.Horizontal"/>
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue