Skip to content

Commit

Permalink
Add support stroke color and width in dock search
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSluffy authored and nulldrf committed Aug 24, 2024
1 parent cadac07 commit 22bbef7
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 11 deletions.
2 changes: 2 additions & 0 deletions lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
<!-- Accent color and color picker -->
<string name="colors">Colors</string>
<string name="accent_color">Accent color</string>
<string name="stroke_color">Stroke color</string>

<string name="swatches">Swatches</string>

Expand Down Expand Up @@ -529,6 +530,7 @@
<string name="hotseat_mode_google_search">Google Search bar</string>

<string name="search_background_transparency">Opacity</string>
<string name="stroke_width">Stroke</string>
<string name="corner_radius_label">Corner radius</string>
<string name="apply_accent_color_label">Apply accent color</string>
<string name="search_provider">Search provider</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class PreferenceManager private constructor(private val context: Context) : Base
val drawerThemedIcons = BoolPref("drawer_themed_icons", false, recreate)
val hotseatQsbCornerRadius = FloatPref("pref_hotseatQsbCornerRadius", 1F, recreate)
val searchBackgroundHotseatTransparency = IntPref("pref_searchHotseatTranparency", 0, recreate)

val searchStrokeWidth = FloatPref("pref_searchStrokeWidth", 1F, recreate)
val enableWallpaperBlur = BoolPref("pref_enableWallpaperBlur", false, recreate)
val wallpaperBlur = IntPref("pref_wallpaperBlur", 25, recreate)
val wallpaperBlurFactorThreshold = IntPref("pref_wallpaperBlurFactor", 25, recreate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ class PreferenceManager2 private constructor(private val context: Context) : Pre
onSet = { reloadHelper.restart() },
)

val strokeColorStyle = preference(
key = stringPreferencesKey(name = "stroke_color"),
parse = ColorOption::fromString,
save = ColorOption::toString,
onSet = { reloadHelper.restart() },
defaultValue = ColorOption.fromString(context.getString(R.string.config_default_accent_color)),
)

val notificationDotColor = preference(
key = stringPreferencesKey(name = "notification_dot_color"),
parse = ColorOption::fromString,
Expand Down
34 changes: 31 additions & 3 deletions lawnchair/src/app/lawnchair/qsb/LawnQsbLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.Paint
import android.graphics.drawable.LayerDrawable
import android.graphics.drawable.PaintDrawable
import android.util.AttributeSet
import android.widget.FrameLayout
Expand All @@ -27,6 +29,7 @@ import app.lawnchair.qsb.providers.Google
import app.lawnchair.qsb.providers.GoogleGo
import app.lawnchair.qsb.providers.PixelSearch
import app.lawnchair.qsb.providers.QsbSearchProvider
import app.lawnchair.theme.color.ColorOption
import app.lawnchair.util.pendingIntent
import app.lawnchair.util.repeatOnAttached
import app.lawnchair.util.viewAttachedScope
Expand All @@ -37,6 +40,9 @@ import com.android.launcher3.qsb.QsbContainerView
import com.android.launcher3.util.Themes
import com.android.launcher3.views.ActivityContext
import com.patrykmichalik.opto.core.firstBlocking
import com.patrykmichalik.opto.core.onEach
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flatMapLatest
Expand All @@ -53,6 +59,9 @@ class LawnQsbLayout(context: Context, attrs: AttributeSet?) : FrameLayout(contex
private lateinit var preferenceManager: PreferenceManager
private lateinit var preferenceManager2: PreferenceManager2
private var searchPendingIntent: PendingIntent? = null
private val coroutineScope = CoroutineScope(Dispatchers.Default)

private var strokeColor: ColorOption? = null

@OptIn(ExperimentalCoroutinesApi::class)
override fun onFinishInflate() {
Expand All @@ -65,6 +74,11 @@ class LawnQsbLayout(context: Context, attrs: AttributeSet?) : FrameLayout(contex
preferenceManager = PreferenceManager.getInstance(context)
preferenceManager2 = PreferenceManager2.getInstance(context)

preferenceManager2.strokeColorStyle.onEach(launchIn = coroutineScope) {
strokeColor = it
setUpBackground()
}

setUpBackground()
clipIconRipples()

Expand Down Expand Up @@ -116,6 +130,7 @@ class LawnQsbLayout(context: Context, attrs: AttributeSet?) : FrameLayout(contex
}

preferenceManager.searchBackgroundHotseatTransparency.subscribeChanges(this::setUpBackground)
preferenceManager.searchStrokeWidth.subscribeChanges(this::setUpBackground)
}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
Expand Down Expand Up @@ -186,12 +201,25 @@ class LawnQsbLayout(context: Context, attrs: AttributeSet?) : FrameLayout(contex
val baseColor = if (themed) Themes.getColorBackgroundFloating(context) else Themes.getAttrColor(context, R.attr.qsbFillColor)
val alphaValue = (transparency * 255) / 100
val color = Color.argb(alphaValue, Color.red(baseColor), Color.green(baseColor), Color.blue(baseColor))
val strokeColor = strokeColor
val strokeWidth = preferenceManager.searchStrokeWidth.get()

val backgroundDrawable = PaintDrawable(color).apply {
setCornerRadius(cornerRadius)
}

val strokeDrawable = PaintDrawable().apply {
paint.style = Paint.Style.STROKE
paint.color = strokeColor?.colorPreferenceEntry?.lightColor?.invoke(context) ?: Themes.getColorAccent(context)
paint.strokeWidth = strokeWidth
setCornerRadius(cornerRadius)
}

val combinedDrawable = LayerDrawable(arrayOf(backgroundDrawable, strokeDrawable))

with(inner) {
clipToOutline = cornerRadius > 0
background = PaintDrawable(color).apply {
setCornerRadius(cornerRadius)
}
background = combinedDrawable
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class ColorPreferenceModelList(context: Context) {
dynamicEntries = dynamicColors,
),
)
registerModel(
ColorPreferenceModel(
prefObject = prefs.strokeColorStyle,
labelRes = R.string.stroke_color,
dynamicEntries = dynamicColors,
),
)
registerModel(
ColorPreferenceModel(
prefObject = prefs.notificationDotColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import app.lawnchair.preferences2.preferenceManager2
import app.lawnchair.qsb.providers.QsbSearchProvider
import app.lawnchair.ui.preferences.LocalIsExpandedScreen
import app.lawnchair.ui.preferences.components.NavigationActionPreference
import app.lawnchair.ui.preferences.components.colorpreference.ColorPreference
import app.lawnchair.ui.preferences.components.controls.ListPreference
import app.lawnchair.ui.preferences.components.controls.ListPreferenceEntry
import app.lawnchair.ui.preferences.components.controls.MainSwitchPreference
Expand Down Expand Up @@ -70,13 +71,6 @@ fun DockPreferences(
adapter = prefs2.themedHotseatQsb.getAdapter(),
label = stringResource(id = R.string.apply_accent_color_label),
)
SliderPreference(
label = stringResource(id = R.string.search_background_transparency),
adapter = prefs.searchBackgroundHotseatTransparency.getAdapter(),
step = 5,
valueRange = 0..100,
showUnit = "%",
)
SliderPreference(
label = stringResource(id = R.string.corner_radius_label),
adapter = prefs.hotseatQsbCornerRadius.getAdapter(),
Expand All @@ -94,6 +88,21 @@ fun DockPreferences(
.name,
),
)
SliderPreference(
label = stringResource(id = R.string.search_background_transparency),
adapter = prefs.searchBackgroundHotseatTransparency.getAdapter(),
step = 5,
valueRange = 0..100,
showUnit = "%",
)
SliderPreference(
label = stringResource(id = R.string.stroke_width),
adapter = prefs.searchStrokeWidth.getAdapter(),
step = 1f,
valueRange = 0f..10f,
showUnit = "vw",
)
ColorPreference(preference = prefs2.strokeColorStyle)
}
}
}
Expand Down

0 comments on commit 22bbef7

Please sign in to comment.