summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAayush Gupta <theimpulson@e.email>2022-05-06 12:33:53 +0000
committerAayush Gupta <theimpulson@e.email>2022-05-06 12:33:53 +0000
commit124864fb715c437c6ca16f7bbf051c96748211b4 (patch)
treecd5b3a9ebde6f9d52ce17b8f8684b0e4ae9a116d /app/src/main
parentaa2d67340959570e7347cb92c2c2664eba1737a8 (diff)
parent68f64614c7922dfb79e6ce2ae5d9c8a9b1d90383 (diff)
Merge branch '238-auto_adapt_text_color' into 'main'
Add support for auto adapt text color in light mode for widget See merge request e/privacy-central/privacycentralapp!54
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt18
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt77
-rw-r--r--app/src/main/res/drawable/ic_chevron_right_24dp_light.xml28
-rw-r--r--app/src/main/res/drawable/ic_settings_light.xml27
-rw-r--r--app/src/main/res/drawable/ic_shield_off_light.xml35
-rw-r--r--app/src/main/res/drawable/ic_shield_on_light.xml34
-rw-r--r--app/src/main/res/layout/widget.xml4
-rw-r--r--app/src/main/res/values/colors.xml3
8 files changed, 221 insertions, 5 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt b/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt
index 6fd9470..048b58c 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt
@@ -20,6 +20,7 @@ package foundation.e.privacycentralapp
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
+import android.os.Bundle
import foundation.e.privacycentralapp.domain.usecases.GetQuickPrivacyStateUseCase
import foundation.e.privacycentralapp.domain.usecases.TrackersStatisticsUseCase
import foundation.e.privacycentralapp.widget.State
@@ -71,6 +72,9 @@ class Widget : AppWidgetProvider() {
private var state: StateFlow<State> = MutableStateFlow(State())
+ private const val DARK_TEXT_KEY = "foundation.e.blisslauncher.WIDGET_OPTION_DARK_TEXT"
+ var isDarkText = false
+
private fun initState(
getPrivacyStateUseCase: GetQuickPrivacyStateUseCase,
trackersStatisticsUseCase: TrackersStatisticsUseCase,
@@ -135,4 +139,18 @@ class Widget : AppWidgetProvider() {
}
}
}
+
+ @FlowPreview
+ override fun onAppWidgetOptionsChanged(
+ context: Context,
+ appWidgetManager: AppWidgetManager,
+ appWidgetId: Int,
+ newOptions: Bundle?
+ ) {
+ super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions)
+ if (newOptions != null) {
+ isDarkText = newOptions.getBoolean(DARK_TEXT_KEY)
+ }
+ render(context, state.value, appWidgetManager)
+ }
}
diff --git a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt
index ca93617..f95083e 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt
@@ -27,6 +27,7 @@ import android.view.View
import android.widget.RemoteViews
import foundation.e.privacycentralapp.R
import foundation.e.privacycentralapp.Widget
+import foundation.e.privacycentralapp.Widget.Companion.isDarkText
import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState
import foundation.e.privacycentralapp.extensions.dpToPxF
import foundation.e.privacycentralapp.main.MainActivity
@@ -49,6 +50,7 @@ fun render(
appWidgetManager: AppWidgetManager,
) {
val views = RemoteViews(context.packageName, R.layout.widget)
+ applyDarkText(context, state, views)
views.apply {
val openPIntent = PendingIntent.getActivity(
context,
@@ -59,11 +61,6 @@ fun render(
setOnClickPendingIntent(R.id.settings_btn, openPIntent)
setOnClickPendingIntent(R.id.widget_container, openPIntent)
- setImageViewResource(
- R.id.state_icon,
- if (state.quickPrivacyState.isEnabled()) R.drawable.ic_shield_on_white
- else R.drawable.ic_shield_off_white
- )
setTextViewText(
R.id.state_label,
context.getString(
@@ -268,3 +265,73 @@ private const val REQUEST_CODE_DASHBOARD = 1
private const val REQUEST_CODE_TOGGLE = 2
private const val REQUEST_CODE_TRACKERS = 3
private const val REQUEST_CODE_HIGHLIGHT = 100
+
+@FlowPreview
+fun applyDarkText(context: Context, state: State, views: RemoteViews) {
+ views.apply {
+ listOf(
+ R.id.state_label,
+ R.id.graph_legend_blocked,
+ R.id.graph_legend_allowed,
+
+ )
+ .forEach {
+ setTextColor(
+ it,
+ context.getColor(if (isDarkText) R.color.on_surface_disabled_light else R.color.on_primary_medium_emphasis)
+ )
+ }
+ setTextColor(
+ R.id.widget_title,
+ context.getColor(if (isDarkText) R.color.on_surface_medium_emphasis_light else R.color.on_surface_high_emphasis)
+ )
+ listOf(
+ R.id.state_trackers,
+ R.id.state_geolocation,
+ R.id.state_ip_address,
+ R.id.graph_legend,
+ R.id.graph_view_trackers_btn
+ )
+ .forEach {
+ setTextColor(
+ it,
+ context.getColor(if (isDarkText) R.color.on_surface_medium_emphasis_light else R.color.on_primary_high_emphasis)
+ )
+ }
+
+ listOf(
+ R.id.trackers_label,
+ R.id.geolocation_label,
+ R.id.ip_address_label,
+ R.id.graph_empty
+
+ )
+ .forEach {
+ setTextColor(
+ it,
+ context.getColor(if (isDarkText) R.color.on_surface_disabled_light else R.color.on_primary_disabled)
+ )
+ }
+ setTextViewCompoundDrawables(
+ R.id.graph_view_trackers_btn,
+ 0,
+ 0,
+ if (isDarkText) R.drawable.ic_chevron_right_24dp_light else R.drawable.ic_chevron_right_24dp,
+ 0
+ )
+ setImageViewResource(
+ R.id.settings_btn,
+ if (isDarkText) R.drawable.ic_settings_light else R.drawable.ic_settings
+ )
+ setImageViewResource(
+ R.id.state_icon,
+ if (isDarkText) {
+ if (state.quickPrivacyState.isEnabled()) R.drawable.ic_shield_on_light
+ else R.drawable.ic_shield_off_light
+ } else {
+ if (state.quickPrivacyState.isEnabled()) R.drawable.ic_shield_on_white
+ else R.drawable.ic_shield_off_white
+ }
+ )
+ }
+}
diff --git a/app/src/main/res/drawable/ic_chevron_right_24dp_light.xml b/app/src/main/res/drawable/ic_chevron_right_24dp_light.xml
new file mode 100644
index 0000000..acbf2f2
--- /dev/null
+++ b/app/src/main/res/drawable/ic_chevron_right_24dp_light.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2022 E FOUNDATION
+ ~
+ ~ This program is free software: you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation, either version 3 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ along with this program. If not, see <https://www.gnu.org/licenses/>.
+ -->
+
+<vector
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:autoMirrored="true"
+ android:height="24dp"
+ android:width="24dp"
+ android:viewportHeight="24.0"
+ android:viewportWidth="24.0">
+ <path android:fillColor="@color/on_surface_medium_emphasis_light"
+ android:pathData="M9.71,18.71l-1.42,-1.42l5.3,-5.29l-5.3,-5.29l1.42,-1.42l6.7,6.71z"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_settings_light.xml b/app/src/main/res/drawable/ic_settings_light.xml
new file mode 100644
index 0000000..4eca968
--- /dev/null
+++ b/app/src/main/res/drawable/ic_settings_light.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2022 E FOUNDATION
+ ~
+ ~ This program is free software: you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation, either version 3 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ along with this program. If not, see <https://www.gnu.org/licenses/>.
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:pathData="M19.14,12.94C19.18,12.64 19.2,12.33 19.2,12C19.2,11.68 19.18,11.36 19.13,11.06L21.16,9.48C21.34,9.34 21.39,9.07 21.28,8.87L19.36,5.55C19.24,5.33 18.99,5.26 18.77,5.33L16.38,6.29C15.88,5.91 15.35,5.59 14.76,5.35L14.4,2.81C14.36,2.57 14.16,2.4 13.92,2.4H10.08C9.84,2.4 9.65,2.57 9.61,2.81L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33C5.02,5.25 4.77,5.33 4.65,5.55L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48L4.89,11.06C4.84,11.36 4.8,11.69 4.8,12C4.8,12.31 4.82,12.64 4.87,12.94L2.84,14.52C2.66,14.66 2.61,14.93 2.72,15.13L4.64,18.45C4.76,18.67 5.01,18.74 5.23,18.67L7.62,17.71C8.12,18.09 8.65,18.41 9.24,18.65L9.6,21.19C9.65,21.43 9.84,21.6 10.08,21.6H13.92C14.16,21.6 14.36,21.43 14.39,21.19L14.75,18.65C15.34,18.41 15.88,18.09 16.37,17.71L18.76,18.67C18.98,18.75 19.23,18.67 19.35,18.45L21.27,15.13C21.39,14.91 21.34,14.66 21.15,14.52L19.14,12.94ZM12,15.6C10.02,15.6 8.4,13.98 8.4,12C8.4,10.02 10.02,8.4 12,8.4C13.98,8.4 15.6,10.02 15.6,12C15.6,13.98 13.98,15.6 12,15.6Z"
+ android:fillColor="@color/on_surface_disabled_light" />
+</vector>
diff --git a/app/src/main/res/drawable/ic_shield_off_light.xml b/app/src/main/res/drawable/ic_shield_off_light.xml
new file mode 100644
index 0000000..c562835
--- /dev/null
+++ b/app/src/main/res/drawable/ic_shield_off_light.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2022 E FOUNDATION
+ ~
+ ~ This program is free software: you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation, either version 3 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ along with this program. If not, see <https://www.gnu.org/licenses/>.
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="25dp"
+ android:height="24dp"
+ android:viewportWidth="25"
+ android:viewportHeight="24">
+ <group>
+ <clip-path
+ android:pathData="M12.5,1L3.5,5V11C3.5,16.55 7.34,21.74 12.5,23C17.66,21.74 21.5,16.55 21.5,11V5L12.5,1Z"/>
+ <path
+ android:pathData="M12.5,1L13.3123,-0.8276L12.5,-1.1886L11.6877,-0.8276L12.5,1ZM3.5,5L2.6877,3.1724L1.5,3.7002V5H3.5ZM12.5,23L12.0256,24.9429L12.5,25.0588L12.9744,24.9429L12.5,23ZM21.5,5H23.5V3.7002L22.3123,3.1724L21.5,5ZM11.6877,-0.8276L2.6877,3.1724L4.3123,6.8276L13.3123,2.8276L11.6877,-0.8276ZM1.5,5V11H5.5V5H1.5ZM1.5,11C1.5,17.3888 5.8919,23.4452 12.0256,24.9429L12.9744,21.0571C8.7881,20.0348 5.5,15.7112 5.5,11H1.5ZM12.9744,24.9429C19.1081,23.4452 23.5,17.3888 23.5,11H19.5C19.5,15.7112 16.2119,20.0348 12.0256,21.0571L12.9744,24.9429ZM23.5,11V5H19.5V11H23.5ZM22.3123,3.1724L13.3123,-0.8276L11.6877,2.8276L20.6877,6.8276L22.3123,3.1724Z"
+ android:fillColor="@color/on_surface_disabled_light"/>
+ </group>
+ <path
+ android:pathData="M15.6213,10.1213L16.3284,9.4142L14.9142,8L14.2071,8.7071L12.4142,10.5L10.6213,8.7071L9.9142,8L8.5,9.4142L9.2071,10.1213L11,11.9142L9.2071,13.7071L8.5,14.4142L9.9142,15.8284L10.6213,15.1213L12.4142,13.3284L14.2071,15.1213L14.9142,15.8284L16.3284,14.4142L15.6213,13.7071L13.8284,11.9142L15.6213,10.1213Z"
+ android:fillColor="@color/on_surface_disabled_light"
+ android:fillType="evenOdd"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_shield_on_light.xml b/app/src/main/res/drawable/ic_shield_on_light.xml
new file mode 100644
index 0000000..ef34c06
--- /dev/null
+++ b/app/src/main/res/drawable/ic_shield_on_light.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2022 E FOUNDATION
+ ~
+ ~ This program is free software: you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation, either version 3 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ along with this program. If not, see <https://www.gnu.org/licenses/>.
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="25dp"
+ android:height="25dp"
+ android:viewportWidth="25"
+ android:viewportHeight="25">
+ <group>
+ <clip-path
+ android:pathData="M12.5,1.5L3.5,5.5V11.5C3.5,17.05 7.34,22.24 12.5,23.5C17.66,22.24 21.5,17.05 21.5,11.5V5.5L12.5,1.5Z"/>
+ <path
+ android:pathData="M12.5,1.5L13.3123,-0.3276L12.5,-0.6886L11.6877,-0.3276L12.5,1.5ZM3.5,5.5L2.6877,3.6724L1.5,4.2003V5.5H3.5ZM12.5,23.5L12.0256,25.4429L12.5,25.5588L12.9744,25.4429L12.5,23.5ZM21.5,5.5H23.5V4.2003L22.3123,3.6724L21.5,5.5ZM11.6877,-0.3276L2.6877,3.6724L4.3123,7.3276L13.3123,3.3276L11.6877,-0.3276ZM1.5,5.5V11.5H5.5V5.5H1.5ZM1.5,11.5C1.5,17.8888 5.8919,23.9452 12.0256,25.4429L12.9744,21.5571C8.7881,20.5348 5.5,16.2112 5.5,11.5H1.5ZM12.9744,25.4429C19.1081,23.9452 23.5,17.8888 23.5,11.5H19.5C19.5,16.2112 16.2119,20.5348 12.0256,21.5571L12.9744,25.4429ZM23.5,11.5V5.5H19.5V11.5H23.5ZM22.3123,3.6724L13.3123,-0.3276L11.6877,3.3276L20.6877,7.3276L22.3123,3.6724Z"
+ android:fillColor="@color/on_surface_disabled_light"/>
+ </group>
+ <path
+ android:pathData="M11.1951,14.5L10.5141,15.2323L11.1948,15.8654L11.8758,15.2326L11.1951,14.5ZM10.181,12.1912L9.4488,11.5102L8.0867,12.9747L8.819,13.6557L10.181,12.1912ZM16.1807,11.2326L16.9133,10.5519L15.5519,9.0867L14.8193,9.7674L16.1807,11.2326ZM11.8762,13.7677L10.181,12.1912L8.819,13.6557L10.5141,15.2323L11.8762,13.7677ZM14.8193,9.7674L10.5144,13.7674L11.8758,15.2326L16.1807,11.2326L14.8193,9.7674Z"
+ android:fillColor="@color/on_surface_disabled_light"/>
+</vector>
diff --git a/app/src/main/res/layout/widget.xml b/app/src/main/res/layout/widget.xml
index 999a888..d2d8490 100644
--- a/app/src/main/res/layout/widget.xml
+++ b/app/src/main/res/layout/widget.xml
@@ -29,6 +29,7 @@
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
+ android:id="@+id/widget_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
@@ -93,6 +94,7 @@
android:orientation="vertical"
>
<TextView
+ android:id="@+id/trackers_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dashboard_state_trackers_label"
@@ -118,6 +120,7 @@
android:orientation="vertical"
>
<TextView
+ android:id="@+id/geolocation_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dashboard_state_geolocation_label"
@@ -143,6 +146,7 @@
android:orientation="vertical"
>
<TextView
+ android:id="@+id/ip_address_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dashboard_state_ipaddress_label"
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index dc4e44b..8a18288 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -28,4 +28,7 @@
<color name="widget_background">#4D666666</color>
<color name="launcher_icon_background">#2CCF69</color>
+
+ <color name="on_surface_medium_emphasis_light">#99000000</color>
+ <color name="on_surface_disabled_light">#61000000</color>
</resources> \ No newline at end of file