2222import androidx .annotation .ColorInt ;
2323import androidx .annotation .IdRes ;
2424import androidx .annotation .NonNull ;
25+ import androidx .appcompat .widget .AppCompatAutoCompleteTextView ;
2526import androidx .appcompat .widget .SearchView ;
2627import androidx .appcompat .widget .Toolbar ;
2728import androidx .core .content .ContextCompat ;
3435import com .nextcloud .android .common .ui .theme .ViewThemeUtilsBase ;
3536import com .nextcloud .android .common .ui .theme .utils .MaterialViewThemeUtils ;
3637
38+ import dynamiccolor .MaterialDynamicColors ;
3739import it .niedermann .android .util .ColorUtil ;
3840import it .niedermann .owncloud .notes .R ;
3941import it .niedermann .owncloud .notes .main .navigation .NavigationItem ;
@@ -44,6 +46,8 @@ public class NotesViewThemeUtils extends ViewThemeUtilsBase {
4446
4547 private static final String TAG = NotesViewThemeUtils .class .getSimpleName ();
4648
49+ private final MaterialDynamicColors dynamicColor = new MaterialDynamicColors ();
50+
4751 public NotesViewThemeUtils (@ NonNull MaterialSchemes schemes ) {
4852 super (schemes );
4953 }
@@ -55,7 +59,7 @@ public NotesViewThemeUtils(@NonNull MaterialSchemes schemes) {
5559 public void colorNavigationViewItem (@ NonNull View view ) {
5660 withScheme (view , scheme -> {
5761 view .setBackgroundTintList (buildColorStateList (
58- new Pair <>(android .R .attr .state_selected , scheme . getSecondaryContainer ( )),
62+ new Pair <>(android .R .attr .state_selected , dynamicColor . secondaryContainer (). getArgb ( scheme )),
5963 new Pair <>(-android .R .attr .state_selected , Color .TRANSPARENT )
6064 ));
6165 return view ;
@@ -69,8 +73,8 @@ public void colorNavigationViewItem(@NonNull View view) {
6973 public void colorNavigationViewItemIcon (@ NonNull ImageView view ) {
7074 withScheme (view , scheme -> {
7175 view .setImageTintList (buildColorStateList (
72- new Pair <>(android .R .attr .state_selected , scheme . getOnSecondaryContainer ( )),
73- new Pair <>(-android .R .attr .state_selected , scheme . getOnSurfaceVariant ( ))
76+ new Pair <>(android .R .attr .state_selected , dynamicColor . onSecondaryContainer (). getArgb ( scheme )),
77+ new Pair <>(-android .R .attr .state_selected , dynamicColor . onSurfaceVariant (). getArgb ( scheme ))
7478 ));
7579 return view ;
7680 });
@@ -83,8 +87,8 @@ public void colorNavigationViewItemIcon(@NonNull ImageView view) {
8387 public void colorNavigationViewItemText (@ NonNull TextView view ) {
8488 withScheme (view , scheme -> {
8589 view .setTextColor (buildColorStateList (
86- new Pair <>(android .R .attr .state_selected , scheme . getOnSecondaryContainer ( )),
87- new Pair <>(-android .R .attr .state_selected , scheme . getOnSurfaceVariant ( ))
90+ new Pair <>(android .R .attr .state_selected , dynamicColor . onSecondaryContainer (). getArgb ( scheme )),
91+ new Pair <>(-android .R .attr .state_selected , dynamicColor . onSurfaceVariant (). getArgb ( scheme ))
8892 ));
8993 return view ;
9094 });
@@ -167,7 +171,7 @@ public int getTextHighlightBackgroundColor(@NonNull Context context,
167171 @ Deprecated
168172 public void themeSearchCardView (@ NonNull MaterialCardView searchBarWrapper ) {
169173 withScheme (searchBarWrapper , scheme -> {
170- searchBarWrapper .setBackgroundTintList (ColorStateList .valueOf (scheme . getSurface ( )));
174+ searchBarWrapper .setBackgroundTintList (ColorStateList .valueOf (dynamicColor . surface (). getArgb ( scheme )));
171175 return searchBarWrapper ;
172176 });
173177 }
@@ -179,8 +183,8 @@ public void themeSearchCardView(@NonNull MaterialCardView searchBarWrapper) {
179183 @ Deprecated
180184 public void themeSearchToolbar (@ NonNull MaterialToolbar toolbar ) {
181185 withScheme (toolbar , scheme -> {
182- toolbar .setNavigationIconTint (scheme . getOnSurface ( ));
183- toolbar .setTitleTextColor (scheme . getOnSurface ( ));
186+ toolbar .setNavigationIconTint (dynamicColor . onSurface (). getArgb ( scheme ));
187+ toolbar .setTitleTextColor (dynamicColor . onSurface (). getArgb ( scheme ));
184188 return toolbar ;
185189 });
186190 }
@@ -193,15 +197,15 @@ public void themeSearchToolbar(@NonNull MaterialToolbar toolbar) {
193197 public void themeToolbarSearchView (@ NonNull SearchView searchView ) {
194198 withScheme (searchView , scheme -> {
195199 // hacky as no default way is provided
196- final var editText = (SearchView . SearchAutoComplete ) searchView
200+ final var editText = (AppCompatAutoCompleteTextView ) searchView
197201 .findViewById (androidx .appcompat .R .id .search_src_text );
198202 final var closeButton = (ImageView ) searchView .findViewById (androidx .appcompat .R .id .search_close_btn );
199203 final var searchButton = (ImageView ) searchView .findViewById (androidx .appcompat .R .id .search_button );
200- editText .setHintTextColor (scheme . getOnSurfaceVariant ( ));
201- editText .setHighlightColor (scheme . getInverseOnSurface ( ));
202- editText .setTextColor (scheme . getOnSurface ( ));
203- closeButton .setColorFilter (scheme . getOnSurface ( ));
204- searchButton .setColorFilter (scheme . getOnSurface ( ));
204+ editText .setHintTextColor (dynamicColor . onSurfaceVariant (). getArgb ( scheme ));
205+ editText .setHighlightColor (dynamicColor . inverseOnSurface (). getArgb ( scheme ));
206+ editText .setTextColor (dynamicColor . onSurface (). getArgb ( scheme ));
207+ closeButton .setColorFilter (dynamicColor . onSurface (). getArgb ( scheme ));
208+ searchButton .setColorFilter (dynamicColor . onSurface (). getArgb ( scheme ));
205209 return searchView ;
206210 });
207211 }
0 commit comments