Merge pull request #1412 from Andries-Smit/fix/notification-color-contract

Fix notification color contrast
This commit is contained in:
Milos Kozak 2022-03-09 16:36:03 +01:00 committed by GitHub
commit c1034e6e18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 62 additions and 15 deletions

View file

@ -164,11 +164,11 @@ class NotificationStore @Inject constructor(
@Suppress("SetTextI18n") @Suppress("SetTextI18n")
holder.binding.text.text = dateUtil.timeString(notification.date) + " " + notification.text holder.binding.text.text = dateUtil.timeString(notification.date) + " " + notification.text
when (notification.level) { when (notification.level) {
Notification.URGENT -> holder.binding.cv.setBackgroundColor(rh.gc(R.color.notificationUrgent)) Notification.URGENT -> holder.binding.cv.setBackgroundColor(rh.gac(R.attr.notificationUrgent))
Notification.NORMAL -> holder.binding.cv.setBackgroundColor(rh.gc(R.color.notificationNormal)) Notification.NORMAL -> holder.binding.cv.setBackgroundColor(rh.gac(R.attr.notificationNormal))
Notification.LOW -> holder.binding.cv.setBackgroundColor(rh.gc(R.color.notificationLow)) Notification.LOW -> holder.binding.cv.setBackgroundColor(rh.gac(R.attr.notificationLow))
Notification.INFO -> holder.binding.cv.setBackgroundColor(rh.gc(R.color.notificationInfo)) Notification.INFO -> holder.binding.cv.setBackgroundColor(rh.gac(R.attr.notificationInfo))
Notification.ANNOUNCEMENT -> holder.binding.cv.setBackgroundColor(rh.gc(R.color.notificationAnnouncement)) Notification.ANNOUNCEMENT -> holder.binding.cv.setBackgroundColor(rh.gac(R.attr.notificationAnnouncement))
} }
} }

View file

@ -7,7 +7,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_margin="1dp" android:layout_margin="1dp"
card_view:cardBackgroundColor="@color/cardColorBackground" card_view:cardBackgroundColor="@color/notificationUrgent"
card_view:cardCornerRadius="6dp"> card_view:cardCornerRadius="6dp">
<LinearLayout <LinearLayout
@ -22,7 +22,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:layout_weight="1" android:layout_weight="1"
android:textColor="?attr/colorOnError"
android:maxLines="4" android:maxLines="4"
android:textStyle="bold"
android:text="Notification text. Notification text. Notification text. Notification text. Notification text. Notification text. " android:text="Notification text. Notification text. Notification text. Notification text. Notification text. Notification text. "
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View file

@ -40,11 +40,6 @@
<color name="colorScheduled">#de7550</color> <color name="colorScheduled">#de7550</color>
<color name="colorActive">#25912e</color> <color name="colorActive">#25912e</color>
<color name="notificationUrgent">#ff0400</color>
<color name="notificationNormal">#ff5e55</color>
<color name="notificationLow">#ff827c</color>
<color name="notificationInfo">#009705</color>
<color name="deviationgrey">#c8666666</color> <color name="deviationgrey">#c8666666</color>
<color name="deviationgreen">#7200FF00</color> <color name="deviationgreen">#7200FF00</color>
<color name="deviationred">#72FF0000</color> <color name="deviationred">#72FF0000</color>

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.utils.resources package info.nightscout.androidaps.utils.resources
import android.content.Context
import android.content.res.AssetFileDescriptor import android.content.res.AssetFileDescriptor
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
@ -11,7 +12,7 @@ interface ResourceHelper {
fun gs(@StringRes id: Int, vararg args: Any?): String fun gs(@StringRes id: Int, vararg args: Any?): String
fun gq(@PluralsRes id: Int, quantity: Int, vararg args: Any?): String fun gq(@PluralsRes id: Int, quantity: Int, vararg args: Any?): String
fun gsNotLocalised(@StringRes id: Int, vararg args: Any?): String fun gsNotLocalised(@StringRes id: Int, vararg args: Any?): String
fun gc(@ColorRes id: Int): Int @ColorInt fun gc(@ColorRes id: Int): Int
fun gd(@DrawableRes id: Int): Drawable? fun gd(@DrawableRes id: Int): Drawable?
fun gb(@BoolRes id :Int) : Boolean fun gb(@BoolRes id :Int) : Boolean
fun gcs(@ColorRes id: Int): String fun gcs(@ColorRes id: Int): String
@ -23,4 +24,13 @@ interface ResourceHelper {
fun dpToPx(dp: Int): Int fun dpToPx(dp: Int): Int
fun dpToPx(dp: Float): Int fun dpToPx(dp: Float): Int
fun shortTextMode(): Boolean fun shortTextMode(): Boolean
}
/**
* Get Attribute Color based on theme style
*/
@ColorInt fun gac(@AttrRes attributeId: Int): Int
/**
* Get Attribute Color based on theme style for specified context
*/
@ColorInt fun gac(context: Context, @AttrRes attributeId: Int): Int
}

View file

@ -0,0 +1,13 @@
package info.nightscout.androidaps.utils.resources
import android.content.Context
import android.util.TypedValue
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
@ColorInt
fun Context.getThemeColor(@AttrRes attribute: Int) =
TypedValue().let {
theme.resolveAttribute(attribute, it, true)
it.data
}

View file

@ -9,6 +9,7 @@ import android.graphics.BitmapFactory
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.util.DisplayMetrics import android.util.DisplayMetrics
import androidx.annotation.* import androidx.annotation.*
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
@ -83,4 +84,10 @@ class ResourceHelperImplementation @Inject constructor(private val context: Cont
} }
override fun shortTextMode(): Boolean = !gb(R.bool.isTablet) override fun shortTextMode(): Boolean = !gb(R.bool.isTablet)
}
override fun gac(context: Context, attributeId: Int): Int =
context.getThemeColor(attributeId)
override fun gac(attributeId: Int): Int =
ContextThemeWrapper(this.context, R.style.AppTheme).getThemeColor(attributeId)
}

View file

@ -7,4 +7,12 @@
<declare-styleable name="NumberPicker"> <declare-styleable name="NumberPicker">
<attr name="customContentDescription" format="string" /> <attr name="customContentDescription" format="string" />
</declare-styleable> </declare-styleable>
<!---Notification -->
<attr name="notificationUrgent" format="reference|color" />
<attr name="notificationNormal" format="reference|color" />
<attr name="notificationLow" format="reference|color" />
<attr name="notificationInfo" format="reference|color" />
<attr name="notificationAnnouncement" format="reference|color" />
</resources> </resources>

View file

@ -92,8 +92,14 @@
<color name="weekdayOutline">#1ea3e5</color> <color name="weekdayOutline">#1ea3e5</color>
<color name="weekendOutline">#1e88e5</color> <color name="weekendOutline">#1e88e5</color>
<!-- CareportalEvent--> <!-- Notification-->
<color name="notificationAnnouncement">#FF8C00</color> <color name="notificationAnnouncement">#FF8C00</color>
<color name="notificationUrgent">#ff0400</color>
<color name="notificationNormal">#ff5e55</color>
<color name="notificationLow">#ff827c</color>
<!-- Green Colors -->
<color name="notificationInfo">#009705</color>
<!-- Toasts--> <!-- Toasts-->
<color name="toastBorder">#666666</color> <color name="toastBorder">#666666</color>

View file

@ -22,6 +22,12 @@
<item name="android:textColorSecondary">@color/white</item> <item name="android:textColorSecondary">@color/white</item>
<item name="android:textColorPrimary">@color/white</item> <item name="android:textColorPrimary">@color/white</item>
<item name="android:textColor">@color/white</item> <item name="android:textColor">@color/white</item>
<!---Notification -->
<item name="notificationUrgent">@color/notificationUrgent</item>
<item name="notificationNormal">@color/notificationNormal</item>
<item name="notificationLow">@color/notificationLow</item>
<item name="notificationInfo">@color/notificationInfo</item>
<item name="notificationAnnouncement">@color/notificationAnnouncement</item>
</style> </style>
<style name="AppTheme.NoActionBar" parent="Theme.MaterialComponents.NoActionBar"> <style name="AppTheme.NoActionBar" parent="Theme.MaterialComponents.NoActionBar">