From 9b911f32766e66742a6fd8b0df92e502c258be98 Mon Sep 17 00:00:00 2001
From: Mihai Adrian <48995920+mcarare@users.noreply.github.com>
Date: Thu, 29 Aug 2019 22:55:51 +0300
Subject: [PATCH] Fixes #4894: added workaround for SDK<24 vector drawable with
gradient color (#4944)
Removed drawableStart and added ImageView in layouts
Set ImageView logo programmatically: bitmap for SDK<24, vector for SDK>=24
Added onClickPendingIntent for ImageView in large and medium layouts
---
.../fenix/widget/SearchWidgetProvider.kt | 22 +++++++++++++++++++
.../layout/search_widget_extra_small_v1.xml | 2 +-
.../layout/search_widget_extra_small_v2.xml | 2 +-
.../main/res/layout/search_widget_large.xml | 10 +++++++--
.../main/res/layout/search_widget_medium.xml | 10 +++++++--
.../main/res/layout/search_widget_small.xml | 2 +-
.../res/layout/search_widget_small_no_mic.xml | 2 +-
7 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/app/src/main/java/org/mozilla/fenix/widget/SearchWidgetProvider.kt b/app/src/main/java/org/mozilla/fenix/widget/SearchWidgetProvider.kt
index 1ab6dc838c63..0c2630b0dc1c 100644
--- a/app/src/main/java/org/mozilla/fenix/widget/SearchWidgetProvider.kt
+++ b/app/src/main/java/org/mozilla/fenix/widget/SearchWidgetProvider.kt
@@ -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
diff --git a/app/src/main/res/layout/search_widget_extra_small_v1.xml b/app/src/main/res/layout/search_widget_extra_small_v1.xml
index 2b86fd756a8f..59aeb64cc9da 100644
--- a/app/src/main/res/layout/search_widget_extra_small_v1.xml
+++ b/app/src/main/res/layout/search_widget_extra_small_v1.xml
@@ -11,8 +11,8 @@
android:layout_gravity="center">
\ No newline at end of file
diff --git a/app/src/main/res/layout/search_widget_extra_small_v2.xml b/app/src/main/res/layout/search_widget_extra_small_v2.xml
index ca2a7206e349..eca312a68973 100644
--- a/app/src/main/res/layout/search_widget_extra_small_v2.xml
+++ b/app/src/main/res/layout/search_widget_extra_small_v2.xml
@@ -11,8 +11,8 @@
android:layout_gravity="center">
\ No newline at end of file
diff --git a/app/src/main/res/layout/search_widget_large.xml b/app/src/main/res/layout/search_widget_large.xml
index 3ab9ab0aba10..936b788552c6 100644
--- a/app/src/main/res/layout/search_widget_large.xml
+++ b/app/src/main/res/layout/search_widget_large.xml
@@ -10,16 +10,22 @@
android:background="@drawable/rounded_white_corners"
android:layout_gravity="center">
+
+
diff --git a/app/src/main/res/layout/search_widget_medium.xml b/app/src/main/res/layout/search_widget_medium.xml
index 20644843c9f7..76ce620665c8 100644
--- a/app/src/main/res/layout/search_widget_medium.xml
+++ b/app/src/main/res/layout/search_widget_medium.xml
@@ -10,16 +10,22 @@
android:background="@drawable/rounded_white_corners"
android:layout_gravity="center">
+
+
diff --git a/app/src/main/res/layout/search_widget_small.xml b/app/src/main/res/layout/search_widget_small.xml
index c76087005e79..f0e4e97127d5 100644
--- a/app/src/main/res/layout/search_widget_small.xml
+++ b/app/src/main/res/layout/search_widget_small.xml
@@ -16,9 +16,9 @@
android:layout_marginTop="9dp">
diff --git a/app/src/main/res/layout/search_widget_small_no_mic.xml b/app/src/main/res/layout/search_widget_small_no_mic.xml
index 195916da9442..2435adcda672 100644
--- a/app/src/main/res/layout/search_widget_small_no_mic.xml
+++ b/app/src/main/res/layout/search_widget_small_no_mic.xml
@@ -12,8 +12,8 @@
android:orientation="vertical">
\ No newline at end of file