Fix search bar background

This commit is contained in:
Suphon Thanakornpakapong
2022-05-09 16:34:14 +07:00
parent be53368192
commit 44bb18a4e7
3 changed files with 42 additions and 17 deletions
+2
View File
@@ -23,6 +23,8 @@
<string name="main_process_initializer_class" translatable="false">app.lawnchair.LawnchairProcessInitializer</string>
<string name="task_overlay_factory_class" translatable="false">app.lawnchair.overview.TaskOverlayFactoryImpl</string>
<bool name="config_header_protection_supported">true</bool>
<string-array name="filtered_components">
<!-- Voice search -->
<item>com.google.android.googlequicksearchbox/.VoiceSearchActivity</item>
@@ -228,4 +228,12 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : LinearLayout(
}
override fun getEditText() = input
override fun setBackgroundVisibility(visible: Boolean, maxAlpha: Float) {
input.setBackgroundVisibility(visible, maxAlpha)
}
override fun getBackgroundVisibility(): Boolean {
return input.getBackgroundVisibility()
}
}
@@ -1,5 +1,6 @@
package app.lawnchair.allapps
import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Rect
@@ -11,19 +12,16 @@ import app.lawnchair.theme.drawable.DrawableTokens
import app.lawnchair.util.EditTextExtensions.setCursorColor
import app.lawnchair.util.EditTextExtensions.setTextSelectHandleColor
import com.android.launcher3.ExtendedEditText
import com.android.launcher3.Utilities
import com.android.launcher3.allapps.AllAppsContainerView
class FallbackSearchInputView(context: Context, attrs: AttributeSet?) : ExtendedEditText(context, attrs) {
private var appsView: AllAppsContainerView? = null
private var shown = true
set(value) {
if (field != value) {
field = value
updateBackground()
}
}
private val bg = DrawableTokens.SearchInputFg.resolve(context)
private val bgAlphaAnimator = ValueAnimator.ofFloat(0f, 1f).apply { duration = 300 }
private var bgVisible = true
private var bgAlpha = 1f
init {
background = bg
@@ -32,27 +30,24 @@ class FallbackSearchInputView(context: Context, attrs: AttributeSet?) : Extended
setCursorColor(accentColor)
setTextSelectHandleColor(accentColor)
highlightColor = ColorUtils.setAlphaComponent(accentColor, 82)
bgAlphaAnimator.addUpdateListener { updateBgAlpha() }
}
private fun updateBgAlpha() {
val fraction = bgAlphaAnimator.animatedFraction
bg.alpha = (Utilities.mapRange(fraction, 0f, bgAlpha) * 255).toInt()
}
fun initialize(appsView: AllAppsContainerView) {
this.appsView = appsView
}
private fun updateBackground() {
val showBackground = shown && !isFocused
background = if (showBackground) bg else null
}
override fun hideKeyboard() {
super.hideKeyboard()
this.appsView?.requestFocus()
}
override fun onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?) {
super.onFocusChanged(focused, direction, previouslyFocusedRect)
updateBackground()
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
if (layoutDirection == LAYOUT_DIRECTION_RTL) {
@@ -60,4 +55,24 @@ class FallbackSearchInputView(context: Context, attrs: AttributeSet?) : Extended
gravity = Gravity.RIGHT or Gravity.CENTER
}
}
fun setBackgroundVisibility(visible: Boolean, maxAlpha: Float) {
if (bgVisible != visible) {
bgVisible = visible
bgAlpha = maxAlpha
if (visible) {
bgAlphaAnimator.start()
} else {
bgAlphaAnimator.reverse()
}
} else if (bgAlpha != maxAlpha && !bgAlphaAnimator.isRunning && visible) {
bgAlpha = maxAlpha
bgAlphaAnimator.setCurrentFraction(maxAlpha)
updateBgAlpha()
}
}
fun getBackgroundVisibility(): Boolean {
return bgVisible
}
}