From 0eef248d7d069b7aa69a0e0d96e589422d4dd581 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 28 Sep 2021 11:33:46 +0100 Subject: [PATCH 1/7] tinting the jump to unread view to the colorPrimary - the vector itself is set to an obvious red to highlight an incorrect usage (we should tint at the consumer to allow for reuse/preparing for design components/compose) --- vector/src/main/res/drawable/ic_jump_to_unread.xml | 2 +- vector/src/main/res/layout/fragment_room_detail.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/vector/src/main/res/drawable/ic_jump_to_unread.xml b/vector/src/main/res/drawable/ic_jump_to_unread.xml index 2c5b8b90c1..3d13aabd50 100644 --- a/vector/src/main/res/drawable/ic_jump_to_unread.xml +++ b/vector/src/main/res/drawable/ic_jump_to_unread.xml @@ -5,6 +5,6 @@ android:viewportHeight="24"> diff --git a/vector/src/main/res/layout/fragment_room_detail.xml b/vector/src/main/res/layout/fragment_room_detail.xml index 66dbbd2840..7af1e27551 100644 --- a/vector/src/main/res/layout/fragment_room_detail.xml +++ b/vector/src/main/res/layout/fragment_room_detail.xml @@ -139,6 +139,7 @@ android:text="@string/room_jump_to_first_unread" android:visibility="invisible" app:chipIcon="@drawable/ic_jump_to_unread" + app:chipIconTint="?colorPrimary" app:closeIcon="@drawable/ic_close_24dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" From 3a79a7595d0fb1414295e29cc14ca7cfb04699b4 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 28 Sep 2021 12:26:41 +0100 Subject: [PATCH 2/7] tinting the in progress recording icon to the colorPrimary - creates extension helpers for tinting and reading theme attributes -extracts the background from the recording vector icon and set as a separate tintable background drawable --- .../im/vector/app/core/extensions/Context.kt | 10 ++++++++++ .../app/core/extensions/ViewExtensions.kt | 18 ++++++++++++++++++ .../composer/VoiceMessageRecorderView.kt | 4 ++++ .../src/main/res/drawable/circle_with_halo.xml | 17 +++++++++++++++++ .../res/drawable/ic_voice_mic_recording.xml | 8 -------- 5 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 vector/src/main/res/drawable/circle_with_halo.xml diff --git a/vector/src/main/java/im/vector/app/core/extensions/Context.kt b/vector/src/main/java/im/vector/app/core/extensions/Context.kt index c1c435edf2..411bea55f0 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/Context.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/Context.kt @@ -17,6 +17,8 @@ package im.vector.app.core.extensions import android.content.Context +import android.util.TypedValue +import androidx.annotation.AttrRes import im.vector.app.core.di.HasVectorInjector import im.vector.app.core.di.VectorComponent @@ -28,3 +30,11 @@ fun Context.vectorComponent(): VectorComponent { throw IllegalStateException("Your application context doesn't implement HasVectorInjector") } } + +fun Context.fetchThemeColor(@AttrRes themeColorResId: Int): Int { + val typedValue = TypedValue() + val a = obtainStyledAttributes(typedValue.data, intArrayOf(themeColorResId)) + val color = a.getColor(0, 0) + a.recycle() + return color +} diff --git a/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt b/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt index b28f33816b..f07b4d7633 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt @@ -18,11 +18,17 @@ package im.vector.app.core.extensions import android.graphics.drawable.Drawable import android.text.InputType +import android.util.TypedValue import android.view.View import android.view.ViewGroup import android.widget.EditText import android.widget.ImageView +import androidx.annotation.AttrRes +import androidx.annotation.DimenRes +import androidx.annotation.DrawableRes import androidx.appcompat.widget.SearchView +import androidx.core.content.ContextCompat +import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.isVisible import im.vector.app.R @@ -58,3 +64,15 @@ fun ImageView.setDrawableOrHide(drawableRes: Drawable?) { setImageDrawable(drawableRes) isVisible = drawableRes != null } + +fun View.setAttributeTintedBackground(@DrawableRes drawableRes: Int, @AttrRes tint: Int) { + val drawable = ContextCompat.getDrawable(context, drawableRes)!! + DrawableCompat.setTint(drawable, context.fetchThemeColor(tint)) + background = drawable +} + +fun View.setAttributeBackground(@AttrRes attributeId: Int) { + val typedValue = TypedValue() + context.theme.resolveAttribute(attributeId, typedValue, true) + setBackgroundResource(typedValue.resourceId) +} diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt index 5f4f53cf1e..ed48f18f8d 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt @@ -27,6 +27,8 @@ import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import im.vector.app.BuildConfig import im.vector.app.R +import im.vector.app.core.extensions.setAttributeBackground +import im.vector.app.core.extensions.setAttributeTintedBackground import im.vector.app.core.hardware.vibrate import im.vector.app.core.utils.CountUpTimer import im.vector.app.core.utils.DimensionConverter @@ -366,6 +368,7 @@ class VoiceMessageRecorderView: ConstraintLayout, VoiceMessagePlaybackTracker.Li private fun showRecordingViews() { views.voiceMessageMicButton.setImageResource(R.drawable.ic_voice_mic_recording) + views.voiceMessageMicButton.setAttributeTintedBackground(R.drawable.circle_with_halo, R.attr.colorPrimary) views.voiceMessageMicButton.updateLayoutParams { setMargins(0, 0, 0, 0) } @@ -443,6 +446,7 @@ class VoiceMessageRecorderView: ConstraintLayout, VoiceMessagePlaybackTracker.Li private fun resetMicButtonUi() { views.voiceMessageMicButton.isVisible = true views.voiceMessageMicButton.setImageResource(R.drawable.ic_voice_mic) + views.voiceMessageMicButton.setAttributeBackground(android.R.attr.selectableItemBackgroundBorderless) views.voiceMessageMicButton.updateLayoutParams { if (rtlXMultiplier == -1) { // RTL diff --git a/vector/src/main/res/drawable/circle_with_halo.xml b/vector/src/main/res/drawable/circle_with_halo.xml new file mode 100644 index 0000000000..8e44bfde7f --- /dev/null +++ b/vector/src/main/res/drawable/circle_with_halo.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/vector/src/main/res/drawable/ic_voice_mic_recording.xml b/vector/src/main/res/drawable/ic_voice_mic_recording.xml index eb6cea39a5..a57852c92f 100644 --- a/vector/src/main/res/drawable/ic_voice_mic_recording.xml +++ b/vector/src/main/res/drawable/ic_voice_mic_recording.xml @@ -3,14 +3,6 @@ android:height="52dp" android:viewportWidth="52" android:viewportHeight="52"> - - Date: Tue, 28 Sep 2021 12:35:46 +0100 Subject: [PATCH 3/7] tinting the voice locked vector to the colorPrimary - extracts a helper extension for tinting image resources --- .../java/im/vector/app/core/extensions/ViewExtensions.kt | 6 ++++++ .../home/room/detail/composer/VoiceMessageRecorderView.kt | 3 ++- vector/src/main/res/drawable/ic_voice_message_locked.xml | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt b/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt index f07b4d7633..713d95b977 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt @@ -71,6 +71,12 @@ fun View.setAttributeTintedBackground(@DrawableRes drawableRes: Int, @AttrRes ti background = drawable } +fun ImageView.setAttributeTintedImageResource(@DrawableRes drawableRes: Int, @AttrRes tint: Int) { + val drawable = ContextCompat.getDrawable(context, drawableRes)!! + DrawableCompat.setTint(drawable, context.fetchThemeColor(tint)) + setImageDrawable(drawable) +} + fun View.setAttributeBackground(@AttrRes attributeId: Int) { val typedValue = TypedValue() context.theme.resolveAttribute(attributeId, typedValue, true) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt index ed48f18f8d..1749c955c9 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt @@ -29,6 +29,7 @@ import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.extensions.setAttributeBackground import im.vector.app.core.extensions.setAttributeTintedBackground +import im.vector.app.core.extensions.setAttributeTintedImageResource import im.vector.app.core.hardware.vibrate import im.vector.app.core.utils.CountUpTimer import im.vector.app.core.utils.DimensionConverter @@ -219,7 +220,7 @@ class VoiceMessageRecorderView: ConstraintLayout, VoiceMessagePlaybackTracker.Li views.voiceMessageLockArrow.translationY = 0F } RecordingState.LOCKING -> { - views.voiceMessageLockImage.setImageResource(R.drawable.ic_voice_message_locked) + views.voiceMessageLockImage.setAttributeTintedImageResource(R.drawable.ic_voice_message_locked, R.attr.colorPrimary) val translationAmount = -distanceY.coerceIn(0F, distanceToLock) views.voiceMessageMicButton.translationY = translationAmount views.voiceMessageLockArrow.translationY = translationAmount diff --git a/vector/src/main/res/drawable/ic_voice_message_locked.xml b/vector/src/main/res/drawable/ic_voice_message_locked.xml index 2b92d9d5e0..a396f684b1 100644 --- a/vector/src/main/res/drawable/ic_voice_message_locked.xml +++ b/vector/src/main/res/drawable/ic_voice_message_locked.xml @@ -1,5 +1,5 @@ - + From 2fee68e0d00274aa4ebaa1e374069f235909520b Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 28 Sep 2021 12:41:45 +0100 Subject: [PATCH 4/7] tinting the radio buttons to the colorPrimary --- .../app/core/epoxy/bottomsheet/BottomSheetRadioActionItem.kt | 3 ++- .../app/core/epoxy/profiles/notifications/RadioButtonItem.kt | 3 ++- .../roomprofile/settings/joinrule/SpaceJoinRuleItem.kt | 3 ++- vector/src/main/res/drawable/ic_radio_on.xml | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/epoxy/bottomsheet/BottomSheetRadioActionItem.kt b/vector/src/main/java/im/vector/app/core/epoxy/bottomsheet/BottomSheetRadioActionItem.kt index 91361aa89d..8899532d04 100644 --- a/vector/src/main/java/im/vector/app/core/epoxy/bottomsheet/BottomSheetRadioActionItem.kt +++ b/vector/src/main/java/im/vector/app/core/epoxy/bottomsheet/BottomSheetRadioActionItem.kt @@ -27,6 +27,7 @@ import im.vector.app.core.epoxy.ClickListener import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.onClick +import im.vector.app.core.extensions.setAttributeTintedImageResource import im.vector.app.core.extensions.setTextOrHide /** @@ -62,7 +63,7 @@ abstract class BottomSheetRadioActionItem : VectorEpoxyModel() { @@ -54,7 +55,7 @@ abstract class RadioButtonItem : VectorEpoxyModel() { } if (selected) { - holder.radioImage.setImageDrawable(ContextCompat.getDrawable(holder.view.context, R.drawable.ic_radio_on)) + holder.radioImage.setAttributeTintedImageResource(R.drawable.ic_radio_on, R.attr.colorPrimary) holder.radioImage.contentDescription = holder.view.context.getString(R.string.a11y_checked) } else { holder.radioImage.setImageDrawable(ContextCompat.getDrawable(holder.view.context, R.drawable.ic_radio_off)) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/SpaceJoinRuleItem.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/SpaceJoinRuleItem.kt index 9110f9b32e..382ef1c545 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/SpaceJoinRuleItem.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/SpaceJoinRuleItem.kt @@ -28,6 +28,7 @@ import im.vector.app.core.epoxy.ClickListener import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.onClick +import im.vector.app.core.extensions.setAttributeTintedImageResource import im.vector.app.core.utils.DebouncedClickListener import im.vector.app.features.home.AvatarRenderer import org.matrix.android.sdk.api.util.MatrixItem @@ -57,7 +58,7 @@ abstract class SpaceJoinRuleItem : VectorEpoxyModel() holder.upgradeRequiredButton.setOnClickListener(DebouncedClickListener(listener)) if (selected) { - holder.radioImage.setImageDrawable(ContextCompat.getDrawable(holder.view.context, R.drawable.ic_radio_on)) + holder.radioImage.setAttributeTintedImageResource(R.drawable.ic_radio_on, R.attr.colorPrimary) holder.radioImage.contentDescription = holder.view.context.getString(R.string.a11y_checked) } else { holder.radioImage.setImageDrawable(ContextCompat.getDrawable(holder.view.context, R.drawable.ic_radio_off)) diff --git a/vector/src/main/res/drawable/ic_radio_on.xml b/vector/src/main/res/drawable/ic_radio_on.xml index 5cda8285e6..4ee05d690c 100644 --- a/vector/src/main/res/drawable/ic_radio_on.xml +++ b/vector/src/main/res/drawable/ic_radio_on.xml @@ -9,6 +9,6 @@ android:fillType="evenOdd"/> + android:fillColor="#FF0000"/> From 0d737a9a5d483df8d4c43b06a8385282f4875625 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 28 Sep 2021 13:11:19 +0100 Subject: [PATCH 5/7] removing unused import --- .../main/java/im/vector/app/core/extensions/ViewExtensions.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt b/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt index 713d95b977..8d952e7cc8 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt @@ -24,7 +24,6 @@ import android.view.ViewGroup import android.widget.EditText import android.widget.ImageView import androidx.annotation.AttrRes -import androidx.annotation.DimenRes import androidx.annotation.DrawableRes import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat From 12ca487e936889a4ec04430173bc435a85e6a621 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 28 Sep 2021 14:57:42 +0100 Subject: [PATCH 6/7] using the existing theme utils logic for reading attributes --- .../java/im/vector/app/core/extensions/Context.kt | 10 ---------- .../im/vector/app/core/extensions/ViewExtensions.kt | 11 +++++------ 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/extensions/Context.kt b/vector/src/main/java/im/vector/app/core/extensions/Context.kt index 411bea55f0..c1c435edf2 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/Context.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/Context.kt @@ -17,8 +17,6 @@ package im.vector.app.core.extensions import android.content.Context -import android.util.TypedValue -import androidx.annotation.AttrRes import im.vector.app.core.di.HasVectorInjector import im.vector.app.core.di.VectorComponent @@ -30,11 +28,3 @@ fun Context.vectorComponent(): VectorComponent { throw IllegalStateException("Your application context doesn't implement HasVectorInjector") } } - -fun Context.fetchThemeColor(@AttrRes themeColorResId: Int): Int { - val typedValue = TypedValue() - val a = obtainStyledAttributes(typedValue.data, intArrayOf(themeColorResId)) - val color = a.getColor(0, 0) - a.recycle() - return color -} diff --git a/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt b/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt index 8d952e7cc8..54fcac42d1 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt @@ -18,7 +18,6 @@ package im.vector.app.core.extensions import android.graphics.drawable.Drawable import android.text.InputType -import android.util.TypedValue import android.view.View import android.view.ViewGroup import android.widget.EditText @@ -30,6 +29,7 @@ import androidx.core.content.ContextCompat import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.isVisible import im.vector.app.R +import im.vector.app.features.themes.ThemeUtils /** * Remove left margin of a SearchView @@ -66,18 +66,17 @@ fun ImageView.setDrawableOrHide(drawableRes: Drawable?) { fun View.setAttributeTintedBackground(@DrawableRes drawableRes: Int, @AttrRes tint: Int) { val drawable = ContextCompat.getDrawable(context, drawableRes)!! - DrawableCompat.setTint(drawable, context.fetchThemeColor(tint)) + DrawableCompat.setTint(drawable, ThemeUtils.getColor(context, tint)) background = drawable } fun ImageView.setAttributeTintedImageResource(@DrawableRes drawableRes: Int, @AttrRes tint: Int) { val drawable = ContextCompat.getDrawable(context, drawableRes)!! - DrawableCompat.setTint(drawable, context.fetchThemeColor(tint)) + DrawableCompat.setTint(drawable, ThemeUtils.getColor(context, tint)) setImageDrawable(drawable) } fun View.setAttributeBackground(@AttrRes attributeId: Int) { - val typedValue = TypedValue() - context.theme.resolveAttribute(attributeId, typedValue, true) - setBackgroundResource(typedValue.resourceId) + val attribute = ThemeUtils.getAttribute(context, attributeId)!! + setBackgroundResource(attribute.resourceId) } From 458c423dab75a1fd24633b70b0f05a596810dcb3 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 28 Sep 2021 15:41:16 +0100 Subject: [PATCH 7/7] removing unused drawable --- vector/src/main/res/drawable/ic_selected_community.xml | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 vector/src/main/res/drawable/ic_selected_community.xml diff --git a/vector/src/main/res/drawable/ic_selected_community.xml b/vector/src/main/res/drawable/ic_selected_community.xml deleted file mode 100644 index e95b54aab3..0000000000 --- a/vector/src/main/res/drawable/ic_selected_community.xml +++ /dev/null @@ -1,9 +0,0 @@ - - -