@ -20,7 +20,11 @@ import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.utils.Settings
import android.os.Build
import androidx.appcompat.widget.AppCompatDrawableManager
import androidx.core.graphics.drawable.toBitmap
@Suppress ( " TooManyFunctions " )
class SearchWidgetProvider : AppWidgetProvider ( ) {
override fun onEnabled ( context : Context ) {
@ -126,6 +130,7 @@ class SearchWidgetProvider : AppWidgetProvider() {
text : String ?
) : RemoteViews {
return RemoteViews ( context . packageName , layout ) . apply {
setIcon ( context )
when ( layout ) {
R . layout . search _widget _extra _small _v1 ,
R . layout . search _widget _extra _small _v2 ,
@ -140,6 +145,7 @@ class SearchWidgetProvider : AppWidgetProvider() {
R . layout . search _widget _large -> {
setOnClickPendingIntent ( R . id . button _search _widget _new _tab , textSearchIntent )
setOnClickPendingIntent ( R . id . button _search _widget _voice , voiceSearchIntent )
setOnClickPendingIntent ( R . id . button _search _widget _new _tab _icon , textSearchIntent )
setTextViewText ( R . id . button _search _widget _new _tab , text )
// Unlike "small" widget, "medium" and "large" sizes do not have separate layouts
// that exclude the microphone icon, which is why we must hide it accordingly here.
@ -151,6 +157,22 @@ class SearchWidgetProvider : AppWidgetProvider() {
}
}
private fun RemoteViews . setIcon ( context : Context ) {
// gradient color available for android:fillColor only on SDK 24+
if ( Build . VERSION . SDK _INT >= Build . VERSION_CODES . N ) {
setImageViewResource (
R . id . button _search _widget _new _tab _icon ,
R . drawable . ic _logo _widget )
} else {
setImageViewBitmap (
R . id . button _search _widget _new _tab _icon ,
AppCompatDrawableManager . get ( ) . getDrawable (
context ,
R . drawable . ic _logo _widget
) ?. toBitmap ( ) )
}
}
// Cell sizes obtained from the actual dimensions listed in search widget specs
companion object {
private const val DP _EXTRA _SMALL = 64