2019-01-29 19:03:39 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2019-01-29 19:03:39 +01:00
|
|
|
|
|
|
|
package org.mozilla.fenix.home
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.graphics.drawable.TransitionDrawable
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.widget.FrameLayout
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
|
|
|
|
class SearchView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {
|
2019-03-13 12:33:18 +01:00
|
|
|
private val lightDrawable =
|
2019-04-02 02:53:37 +02:00
|
|
|
resources.getDrawable(R.drawable.home_search_background_normal, context.theme)
|
2019-03-13 12:33:18 +01:00
|
|
|
private val darkDrawable =
|
|
|
|
resources.getDrawable(R.drawable.home_search_background_dark, context.theme)
|
|
|
|
private val darkNoBorderDrawable =
|
|
|
|
resources.getDrawable(R.drawable.home_search_background_dark_no_border, context.theme)
|
2019-01-29 19:03:39 +01:00
|
|
|
|
|
|
|
private val lightToDark = TransitionDrawable(arrayOf(lightDrawable, darkDrawable))
|
|
|
|
private val darkToNoBorder = TransitionDrawable(arrayOf(darkDrawable, darkNoBorderDrawable))
|
|
|
|
|
|
|
|
fun transitionToLight() {
|
2019-04-13 00:20:49 +02:00
|
|
|
background = lightToDark
|
|
|
|
lightToDark.reverseTransition(transitionDurationMs)
|
2019-01-29 19:03:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun transitionToDark() {
|
2019-04-13 00:20:49 +02:00
|
|
|
background = lightToDark
|
|
|
|
lightToDark.startTransition(transitionDurationMs)
|
2019-01-29 19:03:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun transitionToDarkFromNoBorder() {
|
2019-04-13 00:20:49 +02:00
|
|
|
background = darkToNoBorder
|
|
|
|
darkToNoBorder.reverseTransition(transitionDurationMs)
|
2019-01-29 19:03:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun transitionToDarkNoBorder() {
|
2019-04-13 00:20:49 +02:00
|
|
|
background = darkToNoBorder
|
|
|
|
darkToNoBorder.startTransition(transitionDurationMs)
|
2019-01-29 19:03:39 +01:00
|
|
|
}
|
2019-01-30 17:36:14 +01:00
|
|
|
|
|
|
|
companion object {
|
2019-04-05 18:38:14 +02:00
|
|
|
const val transitionDurationMs = 200
|
2019-01-30 17:36:14 +01:00
|
|
|
}
|
|
|
|
}
|