mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-11 06:44:00 +00:00
Use RikkaX layoutinflater
This commit is contained in:
@@ -353,6 +353,7 @@ dependencies {
|
||||
androidTestImplementation "androidx.annotation:annotation:${ANDROID_X_VERSION}"
|
||||
implementation 'com.github.ChickenHook:RestrictionBypass:2.2'
|
||||
implementation 'dev.rikka.tools.refine:runtime:3.1.1'
|
||||
implementation 'dev.rikka.rikkax.layoutinflater:layoutinflater:1.2.0'
|
||||
|
||||
implementation "androidx.compose.ui:ui:$compose_version"
|
||||
implementation "androidx.compose.ui:ui-tooling:$compose_version"
|
||||
|
||||
@@ -1,43 +1,12 @@
|
||||
package app.lawnchair
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import app.lawnchair.font.FontManager
|
||||
import com.android.launcher3.BubbleTextView
|
||||
import com.android.launcher3.views.DoubleShadowBubbleTextView
|
||||
import rikka.layoutinflater.view.LayoutInflaterFactory
|
||||
|
||||
class LawnchairLayoutFactory(context: Context) : LayoutInflater.Factory2 {
|
||||
class LawnchairLayoutFactory(context: Context) : LayoutInflaterFactory() {
|
||||
|
||||
private val fontManager by lazy { FontManager.INSTANCE.get(context) }
|
||||
private val constructorMap = mapOf<String, (Context, AttributeSet) -> View>(
|
||||
"Button" to ::Button,
|
||||
"TextView" to ::TextView,
|
||||
BubbleTextView::class.java.name to ::BubbleTextView,
|
||||
DoubleShadowBubbleTextView::class.java.name to ::DoubleShadowBubbleTextView,
|
||||
)
|
||||
|
||||
override fun onCreateView(
|
||||
parent: View?,
|
||||
name: String,
|
||||
context: Context,
|
||||
attrs: AttributeSet
|
||||
): View? {
|
||||
val view = constructorMap[name]?.let { it(context, attrs) }
|
||||
if (view is TextView) {
|
||||
try {
|
||||
fontManager.overrideFont(view, attrs)
|
||||
} catch (e: Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
return view
|
||||
}
|
||||
|
||||
override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
|
||||
return onCreateView(null, name, context, attrs)
|
||||
init {
|
||||
addOnViewCreatedListener(FontManager.INSTANCE.get(context).onViewCreatedListener)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import app.lawnchair.util.runOnMainThread
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.util.MainThreadInitializedObject
|
||||
import kotlinx.coroutines.launch
|
||||
import rikka.layoutinflater.view.LayoutInflaterFactory.OnViewCreatedListener
|
||||
|
||||
class FontManager private constructor(private val context: Context) {
|
||||
|
||||
@@ -20,6 +21,11 @@ class FontManager private constructor(private val context: Context) {
|
||||
|
||||
private val specMap = createFontMap()
|
||||
|
||||
val onViewCreatedListener = OnViewCreatedListener { view, _, _, _, attrs ->
|
||||
if (view !is TextView) return@OnViewCreatedListener
|
||||
overrideFont(view, attrs)
|
||||
}
|
||||
|
||||
private fun createFontMap(): Map<Int, FontSpec> {
|
||||
val sansSerif = Typeface.SANS_SERIF
|
||||
val sansSerifMedium = Typeface.create("sans-serif-medium", Typeface.NORMAL)
|
||||
|
||||
Reference in New Issue
Block a user