@@ -19,7 +19,10 @@ This program (the AndroidFilePickerLight library) is free software written by
1919
2020import android .app .Activity ;
2121import android .content .res .ColorStateList ;
22+ import android .graphics .PorterDuff ;
2223import android .graphics .drawable .Drawable ;
24+ import android .graphics .drawable .GradientDrawable ;
25+ import android .util .Log ;
2326import android .view .View ;
2427import android .view .Window ;
2528import android .widget .Button ;
@@ -28,11 +31,12 @@ This program (the AndroidFilePickerLight library) is free software written by
2831import android .widget .ImageView ;
2932import android .widget .LinearLayout ;
3033import android .widget .TextView ;
31- import android .widget .Toolbar ;
34+ import androidx . appcompat .widget .Toolbar ;
3235
3336import androidx .annotation .ColorRes ;
3437import androidx .annotation .DrawableRes ;
3538import androidx .annotation .StringRes ;
39+ import androidx .core .graphics .ColorUtils ;
3640
3741import java .util .HashMap ;
3842import java .util .Locale ;
@@ -110,7 +114,7 @@ public CustomThemeBuilder setCancelActionButtonIcon(@DrawableRes int xMarkResId)
110114 }
111115
112116 public static int getActionButtonIconDimension () {
113- return 24 ; // pixels
117+ return 16 ; // pixels
114118 }
115119
116120 public static final int COLOR_PRIMARY = 0 ;
@@ -126,58 +130,53 @@ public static int getActionButtonIconDimension() {
126130
127131 public static class FileChooserColorScheme {
128132
129- private Activity activityCtx ;
130133 private int [] themeColorsList ;
131134
132- public FileChooserColorScheme (Activity activityCtxRef , int [] colorsList ) throws FileChooserException .AndroidFilePickerLightException {
133- if (activityCtxRef == null ) {
134- throw new FileChooserException .InvalidActivityContextException ();
135- }
136- activityCtx = activityCtxRef ;
135+ public FileChooserColorScheme (int [] colorsList ) throws FileChooserException .AndroidFilePickerLightException {
137136 if (colorsList .length != 10 ) {
138137 throw new FileChooserException .InvalidIndexException ();
139138 }
140139 themeColorsList = colorsList ;
141140 }
142141
143142 public int getColorPrimary () {
144- return DisplayUtils . resolveColorFromResId ( activityCtx , themeColorsList [COLOR_PRIMARY ]) ;
143+ return themeColorsList [COLOR_PRIMARY ];
145144 }
146145
147146 public int getColorPrimaryDark () {
148- return DisplayUtils . resolveColorFromResId ( activityCtx , themeColorsList [COLOR_PRIMARY_DARK ]) ;
147+ return themeColorsList [COLOR_PRIMARY_DARK ];
149148 }
150149
151150 public int getColorPrimaryVeryDark () {
152- return DisplayUtils . resolveColorFromResId ( activityCtx , themeColorsList [COLOR_PRIMARY_VERY_DARK ]) ;
151+ return themeColorsList [COLOR_PRIMARY_VERY_DARK ];
153152 }
154153
155154 public int getColorAccent () {
156- return DisplayUtils . resolveColorFromResId ( activityCtx , themeColorsList [COLOR_ACCENT ]) ;
155+ return themeColorsList [COLOR_ACCENT ];
157156 }
158157
159158 public int getColorAccentMedium () {
160- return DisplayUtils . resolveColorFromResId ( activityCtx , themeColorsList [COLOR_ACCENT_MEDIUM ]) ;
159+ return themeColorsList [COLOR_ACCENT_MEDIUM ];
161160 }
162161
163162 public int getColorAccentLight () {
164- return DisplayUtils . resolveColorFromResId ( activityCtx , themeColorsList [COLOR_ACCENT_LIGHT ]) ;
163+ return themeColorsList [COLOR_ACCENT_LIGHT ];
165164 }
166165
167166 public int getColorToolbarBG () {
168- return DisplayUtils . resolveColorFromResId ( activityCtx , themeColorsList [COLOR_TOOLBAR_BG ]) ;
167+ return themeColorsList [COLOR_TOOLBAR_BG ];
169168 }
170169
171170 public int getColorToolbarFG () {
172- return DisplayUtils . resolveColorFromResId ( activityCtx , themeColorsList [COLOR_TOOLBAR_FG ]) ;
171+ return themeColorsList [COLOR_TOOLBAR_FG ];
173172 }
174173
175174 public int getColorToolbarNav () {
176- return DisplayUtils . resolveColorFromResId ( activityCtx , themeColorsList [COLOR_TOOLBAR_NAV ]) ;
175+ return themeColorsList [COLOR_TOOLBAR_NAV ];
177176 }
178177
179178 public int getColorToolbarDivider () {
180- return DisplayUtils . resolveColorFromResId ( activityCtx , themeColorsList [COLOR_TOOLBAR_DIVIDER ]) ;
179+ return themeColorsList [COLOR_TOOLBAR_DIVIDER ];
181180 }
182181
183182 public static int [] GenerateThemeColorsList (Activity activityCtxRef , @ ColorRes int baseColorResId ) {
@@ -190,31 +189,35 @@ public static int[] GenerateThemeColorsList(Activity activityCtxRef, @ColorRes i
190189 } catch (Exception ex2 ) {}
191190 }
192191 return new int [] {
193- resolvedColor ,
194- DisplayUtils .darkenColor (resolvedColor , 0.75f ),
195- DisplayUtils .darkenColor (resolvedColor , 0.86f ),
196- DisplayUtils .lightenColor (resolvedColor , 0.73f ),
197- DisplayUtils .lightenColor (resolvedColor , 0.50f ),
198- DisplayUtils .lightenColor (resolvedColor , 0.85f ),
199- DisplayUtils .darkenColor (resolvedColor , 0.90f ),
200- DisplayUtils .lightenColor (resolvedColor , 0.87f ),
201- DisplayUtils .lightenColor (resolvedColor , 0.54f ),
202- DisplayUtils .lightenColor (resolvedColor , 0.27f )
192+ resolvedColor , /* COLOR_PRIMARY */
193+ DisplayUtils .darkenColor (resolvedColor , 0.65f ), /* COLOR_PRIMARY_DARK */
194+ DisplayUtils .darkenColor (resolvedColor , 0.80f ), /* COLOR_PRIMARY_VERY_DARK */
195+ DisplayUtils .lightenColor (resolvedColor , 0.72f ), /* COLOR_ACCENT */
196+ DisplayUtils .lightenColor (resolvedColor , 0.50f ), /* COLOR_ACCENT_MEDIUM */
197+ DisplayUtils .lightenColor (resolvedColor , 0.89f ), /* COLOR_ACCENT_LIGHT */
198+ DisplayUtils .darkenColor (resolvedColor , 0.88f ), /* COLOR_TOOLBAR_BG */
199+ DisplayUtils .lightenColor (resolvedColor , 0.85f ), /* COLOR_TOOLBAR_FG */
200+ DisplayUtils .lightenColor (resolvedColor , 0.55f ), /* COLOR_TOOLBAR_NAV */
201+ DisplayUtils .darkenColor (resolvedColor , 0.50f ) /* COLOR_TOOLBAR_DIVIDER */
203202 };
203+
204204 }
205205
206206 }
207207
208208 private FileChooserColorScheme themeColorScheme ;
209209
210210 public CustomThemeBuilder setThemeColors (@ ColorRes int [] colorsList ) {
211- themeColorScheme = new FileChooserColorScheme (activityCtx , colorsList );
211+ for (int cidx = 0 ; cidx < colorsList .length ; cidx ++) {
212+ colorsList [cidx ] = DisplayUtils .resolveColorFromResId (activityCtx , colorsList [cidx ]);
213+ }
214+ themeColorScheme = new FileChooserColorScheme (colorsList );
212215 return this ;
213216 }
214217
215218 public CustomThemeBuilder generateThemeColors (@ ColorRes int baseColorResId ) {
216219 int [] themeColorsList = FileChooserColorScheme .GenerateThemeColorsList (activityCtx , baseColorResId );
217- themeColorScheme = new FileChooserColorScheme (activityCtx , themeColorsList );
220+ themeColorScheme = new FileChooserColorScheme (themeColorsList );
218221 return this ;
219222 }
220223
@@ -285,10 +288,12 @@ public FileChooserActivityMainLayoutStylizer createActivityMainLayoutStylizer()
285288 );
286289 if (activityCtx == null || themeColorScheme == null || _pickerTitleTextFinal == null ||
287290 _navBarPrefixTextFinal == null || _doneActionBtnTextFinal == null || _cancelActionBtnTextFinal == null ||
288- _toolbarLogoIconFinal == null || !DisplayUtils .checkIconDimensions (_toolbarLogoIconFinal , getToolbarIconDimension ()) ||
289- _globalBackBtnIconFinal == null || !DisplayUtils .checkIconDimensions (_globalBackBtnIconFinal , getGlobalBackButtonIconDimension ()) ||
290- _doneActionBtnIconFinal == null || !DisplayUtils .checkIconDimensions (_doneActionBtnIconFinal , getActionButtonIconDimension ()) ||
291- _cancelActionBtnIconFinal == null || !DisplayUtils .checkIconDimensions (_cancelActionBtnIconFinal , getActionButtonIconDimension ())) {
291+ _toolbarLogoIconFinal == null || _globalBackBtnIconFinal == null ||
292+ _doneActionBtnIconFinal == null || _cancelActionBtnIconFinal == null ) {
293+ Log .i (LOGTAG , " - " + !DisplayUtils .checkIconDimensions (_toolbarLogoIconFinal , getToolbarIconDimension ()) +
294+ ", " + !DisplayUtils .checkIconDimensions (_globalBackBtnIconFinal , getGlobalBackButtonIconDimension ()) +
295+ ", " + !DisplayUtils .checkIconDimensions (_doneActionBtnIconFinal , getActionButtonIconDimension ()) +
296+ ", " + !DisplayUtils .checkIconDimensions (_cancelActionBtnIconFinal , getActionButtonIconDimension ()));
292297 return null ;
293298 }
294299 return new FileChooserActivityMainLayoutStylizer () {
@@ -360,11 +365,11 @@ public boolean styleBottomNavigationActionButtons(Button doneActionBtn, Button c
360365 doneActionBtn .setBackgroundColor (_themeColorScheme .getColorAccentLight ());
361366 doneActionBtn .setTextColor (_themeColorScheme .getColorAccentMedium ());
362367 doneActionBtn .setText (_doneActionBtnText );
363- doneActionBtn .setCompoundDrawables (_doneActionBtnIcon , null , null , null );
364- doneActionBtn .setBackgroundColor (_themeColorScheme .getColorAccentLight ());
365- doneActionBtn .setTextColor (_themeColorScheme .getColorAccentMedium ());
366- doneActionBtn .setText (_cancelActionBtnText );
367- doneActionBtn . setCompoundDrawables (_cancelActionBtnIcon , null , null , null );
368+ doneActionBtn .setCompoundDrawablesRelativeWithIntrinsicBounds (_doneActionBtnIcon , null , null , null );
369+ cancelActionBtn .setBackgroundColor (_themeColorScheme .getColorAccentLight ());
370+ cancelActionBtn .setTextColor (_themeColorScheme .getColorAccentMedium ());
371+ cancelActionBtn .setText (_cancelActionBtnText );
372+ cancelActionBtn . setCompoundDrawablesRelativeWithIntrinsicBounds (_cancelActionBtnIcon , null , null , null );
368373 return true ;
369374 }
370375
@@ -425,7 +430,7 @@ public boolean styleMainActivityLayout(View parentContainerLayout) throws Runtim
425430 layoutDivider3 .setBackgroundColor (_themeColorScheme .getColorToolbarDivider ());
426431 mainRecyclerViewContainerLayout .setBackgroundColor (_themeColorScheme .getColorPrimary ());
427432 layoutDivider4 .setBackgroundColor (_themeColorScheme .getColorToolbarDivider ());
428- bottomActionBtnsContainerLayout .setBackgroundColor (_themeColorScheme .getColorAccentMedium ());
433+ bottomActionBtnsContainerLayout .setBackgroundColor (_themeColorScheme .getColorAccentLight ());
429434 return true ;
430435
431436 }
@@ -471,30 +476,25 @@ public interface FileItemLayoutStylizer {
471476 boolean setFileTypeIcon (ImageView imgBtn , DisplayTypes .FileType fileItemEntry );
472477 boolean styleSelectionBox (CompoundButton selectBox );
473478 boolean applyStyleToLayout (View parentViewContainer , DisplayTypes .FileType fileItemEntry ) throws RuntimeException ;
479+ boolean applyStyleToLayoutDivider (Drawable fileItemSep );
474480 }
475481
476482 public FileItemLayoutStylizer createFileItemLayoutStylizer () {
477483
478- if (themeColorScheme == null || fileIconResId == NULL_RESOURCE_ID ||
479- fileHiddenIconResId == NULL_RESOURCE_ID || folderIconResId == NULL_RESOURCE_ID ) {
484+ if (activityCtx == null || themeColorScheme == null ||
485+ fileIconResId == NULL_RESOURCE_ID || fileHiddenIconResId == NULL_RESOURCE_ID ||
486+ folderIconResId == NULL_RESOURCE_ID ) {
480487 return null ;
481488 }
482489 final Drawable fileIconFinal = DisplayUtils .resolveDrawableFromResId (activityCtx , fileIconResId );
483490 final Drawable fileHiddenIconFinal = DisplayUtils .resolveDrawableFromResId (activityCtx , fileHiddenIconResId );
484491 final Drawable folderIconFinal = DisplayUtils .resolveDrawableFromResId (activityCtx , folderIconResId );
485- Drawable [] drawablesCheckList = {
486- fileIconFinal ,
487- fileHiddenIconFinal ,
488- folderIconFinal
489- };
490- for (int didx = 0 ; didx < drawablesCheckList .length ; didx ++) {
491- Drawable drawInst = drawablesCheckList [didx ];
492- if (drawInst == null || !DisplayUtils .checkIconDimensions (drawInst , getFileItemEntryIconDimension ())) {
493- return null ;
494- }
492+ if (fileIconFinal == null || fileHiddenIconFinal == null || folderIconFinal == null ) {
493+ return null ;
495494 }
496495 return new FileItemLayoutStylizer () {
497496
497+ private final Activity _activityCtx = activityCtx ;
498498 private final Drawable _fileIcon = fileIconFinal ;
499499 private final Drawable _fileHiddenIcon = fileHiddenIconFinal ;
500500 private final Drawable _folderIcon = folderIconFinal ;
@@ -529,8 +529,8 @@ public boolean styleSelectionBox(CompoundButton selectBox) {
529529 new int [] { android .R .attr .state_checked },
530530 };
531531 int [] cboxTrackColors = new int [] {
532- _themeColorScheme .getColorPrimaryDark (),
533- _themeColorScheme .getColorPrimaryDark (),
532+ ColorUtils . blendARGB ( _themeColorScheme .getColorPrimaryDark (), _themeColorScheme . getColorAccentMedium (), 0.25f ),
533+ ColorUtils . blendARGB ( _themeColorScheme .getColorPrimaryDark (), _themeColorScheme . getColorAccentMedium (), 0.25f ),
534534 };
535535 selectBox .setButtonTintList (new ColorStateList (cboxStatesList , cboxTrackColors ));
536536 return true ;
@@ -566,6 +566,14 @@ public boolean applyStyleToLayout(View parentViewContainer, DisplayTypes.FileTyp
566566 return true ;
567567 }
568568
569+ public boolean applyStyleToLayoutDivider (Drawable fileItemSep ) {
570+ if (fileItemSep == null ) {
571+ return false ;
572+ }
573+ fileItemSep .setColorFilter (_themeColorScheme .getColorAccentMedium (), PorterDuff .Mode .SRC_ATOP );
574+ return true ;
575+ }
576+
569577 };
570578
571579 }
0 commit comments