From 406e75fec78d750d813d25d1fb0509eee4395e9d Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Tue, 18 Jun 2024 12:07:27 +0200 Subject: [PATCH 1/3] feat(android): optionBar color properties --- .../titanium/ui/widget/TiUIOptionBar.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java index 729549b64ad..433979ee209 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java @@ -7,6 +7,7 @@ package ti.modules.titanium.ui.widget; import android.content.Context; +import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.view.View; import android.view.ViewGroup; @@ -207,6 +208,63 @@ private void addButton(String title, String accessibilityLabel, Drawable imageDr MaterialButton button = new MaterialButton(context, null, attributeId); button.setEnabled(isEnabled); button.setText(title); + if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_SELECTED_BACKGROUND_COLOR)) { + ColorStateList oldColors = button.getBackgroundTintList(); + int col = TiConvert.toColor((String) proxy.getProperty(TiC.PROPERTY_SELECTED_BACKGROUND_COLOR), context); + ColorStateList trackStates = new ColorStateList( + new int[][] { + new int[] { -android.R.attr.state_checked }, + new int[] { android.R.attr.state_checked }, + new int[] {} + + }, + new int[] { + oldColors.getColorForState(new int[] { -android.R.attr.state_checked }, R.attr.colorOnSurface), + col, + oldColors.getColorForState(new int[] { }, R.attr.colorOnSurface), + } + ); + button.setBackgroundTintList(trackStates); + } + if (proxy.hasPropertyAndNotNull("selectedBorderColor")) { + ColorStateList oldColors = button.getStrokeColor(); + int col = TiConvert.toColor((String) proxy.getProperty("selectedBorderColor"), context); + ColorStateList trackStates = new ColorStateList( + new int[][] { + new int[] { -android.R.attr.state_checked }, + new int[] { android.R.attr.state_checked }, + new int[] {} + }, + new int[] { + oldColors.getColorForState(new int[] { -android.R.attr.state_checked }, R.attr.colorOnSurface), + col, + oldColors.getColorForState(new int[] { }, R.attr.colorOnSurface), + } + ); + button.setStrokeColor(trackStates); + } + if (proxy.hasPropertyAndNotNull("selectedTextColor") || proxy.hasPropertyAndNotNull(TiC.PROPERTY_COLOR)) { + int textCol = button.getCurrentHintTextColor(); + int selCol = button.getCurrentTextColor(); + + if (proxy.hasPropertyAndNotNull("selectedTextColor")) { + selCol = TiConvert.toColor((String) proxy.getProperty("selectedTextColor"), context); + } + if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_COLOR)) { + textCol = TiConvert.toColor((String) proxy.getProperty(TiC.PROPERTY_COLOR), context); + } + ColorStateList trackStates = new ColorStateList( + new int[][] { + new int[] { -android.R.attr.state_checked }, + new int[] { android.R.attr.state_checked }, + }, + new int[] { + textCol, + selCol, + } + ); + button.setTextColor(trackStates); + } if ((accessibilityLabel != null) && !accessibilityLabel.isEmpty()) { button.setContentDescription(accessibilityLabel); } From 6a3b063d7be81e571f23a5684ca1934f8291ff77 Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Tue, 18 Jun 2024 12:23:40 +0200 Subject: [PATCH 2/3] remove unused states --- .../ti/modules/titanium/ui/widget/TiUIOptionBar.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java index 433979ee209..cc18e9b3e95 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIOptionBar.java @@ -215,13 +215,10 @@ private void addButton(String title, String accessibilityLabel, Drawable imageDr new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked }, - new int[] {} - }, new int[] { oldColors.getColorForState(new int[] { -android.R.attr.state_checked }, R.attr.colorOnSurface), - col, - oldColors.getColorForState(new int[] { }, R.attr.colorOnSurface), + col } ); button.setBackgroundTintList(trackStates); @@ -233,12 +230,10 @@ private void addButton(String title, String accessibilityLabel, Drawable imageDr new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked }, - new int[] {} }, new int[] { oldColors.getColorForState(new int[] { -android.R.attr.state_checked }, R.attr.colorOnSurface), - col, - oldColors.getColorForState(new int[] { }, R.attr.colorOnSurface), + col } ); button.setStrokeColor(trackStates); From 1245552514b11d9986165b7f721855886e228a0d Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Tue, 18 Jun 2024 13:36:57 +0200 Subject: [PATCH 3/3] docs --- apidoc/Titanium/UI/OptionBar.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/apidoc/Titanium/UI/OptionBar.yml b/apidoc/Titanium/UI/OptionBar.yml index 9c6fc680bf1..f96bbe19130 100644 --- a/apidoc/Titanium/UI/OptionBar.yml +++ b/apidoc/Titanium/UI/OptionBar.yml @@ -60,6 +60,30 @@ properties: default: horizontal availability: creation + - name: selectedBackgroundColor + summary: Background color of the selected button + type: [String, Titanium.UI.Color] + platforms: [android] + since: { android: "12.4.0"} + + - name: selectedTextColor + summary: Text color of the selected button + type: [String, Titanium.UI.Color] + platforms: [android] + since: { android: "12.4.0"} + + - name: selectedBorderColor + summary: Border color of the selected button + type: [String, Titanium.UI.Color] + platforms: [android] + since: { android: "12.4.0"} + + - name: color + summary: Text color of the unselected button + type: [String, Titanium.UI.Color] + platforms: [android] + since: { android: "12.4.0"} + examples: - title: Text-Only Buttons example: |