Skip to content

Commit cc2213e

Browse files
committed
Adding toolbar gradients option to custom themes
1 parent 8a3cc98 commit cc2213e

9 files changed

Lines changed: 69 additions & 16 deletions

File tree

AndroidFilePickerLightLibrary/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ android {
3131
defaultConfig {
3232
minSdkVersion 29
3333
targetSdkVersion 30
34-
versionCode 3
35-
versionName "1.0.2"
34+
versionCode 4
35+
versionName "1.0.3"
3636
}
3737

3838
compileOptions {

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/CustomThemeBuilder.java

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public CustomThemeBuilder(Activity activityCtxRef) {
6161
cancelActionBtnIconResId = NULL_RESOURCE_ID;
6262
themeColorScheme = null;
6363
toolbarIconResId = NULL_RESOURCE_ID;
64+
useToolbarGradients = false;
6465
navBtnIconResIdMap = new HashMap<FileChooserBuilder.DefaultNavFoldersType, Integer>();
6566
fileIconResId = fileHiddenIconResId = folderIconResId = NULL_RESOURCE_ID;
6667
}
@@ -179,6 +180,8 @@ public int getColorToolbarDivider() {
179180
return themeColorsList[COLOR_TOOLBAR_DIVIDER];
180181
}
181182

183+
public int getColorTransparent() { return DisplayUtils.resolveColorFromAttribute(R.color.__colorTransparent); }
184+
182185
public static int[] GenerateThemeColorsList(Activity activityCtxRef, @ColorRes int baseColorResId) {
183186
int resolvedColor = baseColorResId;
184187
try {
@@ -194,7 +197,7 @@ public static int[] GenerateThemeColorsList(Activity activityCtxRef, @ColorRes i
194197
DisplayUtils.darkenColor(resolvedColor, 0.80f), /* COLOR_PRIMARY_VERY_DARK */
195198
DisplayUtils.lightenColor(resolvedColor, 0.72f), /* COLOR_ACCENT */
196199
DisplayUtils.lightenColor(resolvedColor, 0.50f), /* COLOR_ACCENT_MEDIUM */
197-
DisplayUtils.lightenColor(resolvedColor, 0.89f), /* COLOR_ACCENT_LIGHT */
200+
DisplayUtils.lightenColor(resolvedColor, 0.85f), /* COLOR_ACCENT_LIGHT */
198201
DisplayUtils.darkenColor(resolvedColor, 0.88f), /* COLOR_TOOLBAR_BG */
199202
DisplayUtils.lightenColor(resolvedColor, 0.85f), /* COLOR_TOOLBAR_FG */
200203
DisplayUtils.lightenColor(resolvedColor, 0.55f), /* COLOR_TOOLBAR_NAV */
@@ -228,6 +231,13 @@ public CustomThemeBuilder setActivityToolbarIcon(@DrawableRes int customIconResI
228231
return this;
229232
}
230233

234+
private boolean useToolbarGradients;
235+
236+
public CustomThemeBuilder useToolbarGradients(boolean enable) {
237+
useToolbarGradients = enable;
238+
return this;
239+
}
240+
231241
public static int getToolbarIconDimension() {
232242
return 48; // pixels
233243
}
@@ -254,6 +264,7 @@ public interface FileChooserActivityMainLayoutStylizer {
254264

255265
public FileChooserActivityMainLayoutStylizer createActivityMainLayoutStylizer() {
256266

267+
final boolean _useToolbarGradients = useToolbarGradients;
257268
final Drawable _toolbarLogoIconFinal = DisplayUtils.firstNonNull(
258269
DisplayUtils.resolveDrawableFromResId(activityCtx, toolbarIconResId),
259270
DisplayUtils.resolveDrawableFromResId(R.drawable.file_chooser_default_toolbar_icon48)
@@ -290,10 +301,6 @@ public FileChooserActivityMainLayoutStylizer createActivityMainLayoutStylizer()
290301
_navBarPrefixTextFinal == null || _doneActionBtnTextFinal == null || _cancelActionBtnTextFinal == null ||
291302
_toolbarLogoIconFinal == null || _globalBackBtnIconFinal == null ||
292303
_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()));
297304
return null;
298305
}
299306
return new FileChooserActivityMainLayoutStylizer() {
@@ -316,9 +323,17 @@ public boolean styleNavigationDisplayToolbar(Toolbar toolbar) {
316323
return false;
317324
}
318325
toolbar.setSubtitle(String.format(Locale.getDefault(), " ⇤%s⇥", _pickerTitleText));
326+
toolbar.setBackgroundColor(_themeColorScheme.getColorToolbarBG());
319327
toolbar.setTitleTextColor(_themeColorScheme.getColorToolbarFG());
320328
toolbar.setSubtitleTextColor(_themeColorScheme.getColorToolbarFG());
321329
toolbar.setLogo(_toolbarLogoIcon);
330+
if(_useToolbarGradients) {
331+
GradientDrawable bgGrad = DisplayUtils.GradientDrawableBuilder.GetStockGradientFromBaseColor(
332+
ColorUtils.blendARGB(_themeColorScheme.getColorToolbarBG(), _themeColorScheme.getColorPrimary(), 0.32f),
333+
_themeColorScheme.getColorToolbarBG()
334+
);
335+
toolbar.setBackground(bgGrad);
336+
}
322337
return true;
323338
}
324339

@@ -362,11 +377,12 @@ public boolean styleBottomNavigationActionButtons(Button doneActionBtn, Button c
362377
if(doneActionBtn == null || cancelActionBtn == null) {
363378
return false;
364379
}
365-
doneActionBtn.setBackgroundColor(_themeColorScheme.getColorAccentLight());
380+
int btnBGColor = _useToolbarGradients ? _themeColorScheme.getColorTransparent() : _themeColorScheme.getColorAccentLight();
381+
doneActionBtn.setBackgroundColor(btnBGColor);
366382
doneActionBtn.setTextColor(_themeColorScheme.getColorAccentMedium());
367383
doneActionBtn.setText(_doneActionBtnText);
368384
doneActionBtn.setCompoundDrawablesRelativeWithIntrinsicBounds(_doneActionBtnIcon, null, null, null);
369-
cancelActionBtn.setBackgroundColor(_themeColorScheme.getColorAccentLight());
385+
cancelActionBtn.setBackgroundColor(btnBGColor);
370386
cancelActionBtn.setTextColor(_themeColorScheme.getColorAccentMedium());
371387
cancelActionBtn.setText(_cancelActionBtnText);
372388
cancelActionBtn.setCompoundDrawablesRelativeWithIntrinsicBounds(_cancelActionBtnIcon, null, null, null);
@@ -427,10 +443,25 @@ public boolean styleMainActivityLayout(View parentContainerLayout) throws Runtim
427443
navBtnsLinearLayout.setBackgroundColor(_themeColorScheme.getColorToolbarNav());
428444
layoutDivider2.setBackgroundColor(_themeColorScheme.getColorToolbarDivider());
429445
pathsHistoryContainer.setBackgroundColor(_themeColorScheme.getColorAccentLight());
446+
if(_useToolbarGradients) {
447+
GradientDrawable bgGrad = DisplayUtils.GradientDrawableBuilder.GetStockGradientFromBaseColor(
448+
_themeColorScheme.getColorAccentLight(),
449+
_themeColorScheme.getColorPrimary()
450+
);
451+
pathsHistoryContainer.setBackground(bgGrad);
452+
}
430453
layoutDivider3.setBackgroundColor(_themeColorScheme.getColorToolbarDivider());
431454
mainRecyclerViewContainerLayout.setBackgroundColor(_themeColorScheme.getColorPrimary());
432455
layoutDivider4.setBackgroundColor(_themeColorScheme.getColorToolbarDivider());
433456
bottomActionBtnsContainerLayout.setBackgroundColor(_themeColorScheme.getColorAccentLight());
457+
if(_useToolbarGradients) {
458+
GradientDrawable bgGrad = DisplayUtils.GradientDrawableBuilder.GetStockGradientFromBaseColor(
459+
_themeColorScheme.getColorAccentLight(),
460+
DisplayUtils.darkenColor(_themeColorScheme.getColorPrimary(), 0.15f)
461+
);
462+
pathsHistoryContainer.setBackground(bgGrad);
463+
bottomActionBtnsContainerLayout.setBackground(bgGrad);
464+
}
434465
return true;
435466

436467
}
@@ -481,7 +512,7 @@ public interface FileItemLayoutStylizer {
481512

482513
public FileItemLayoutStylizer createFileItemLayoutStylizer() {
483514

484-
if(activityCtx == null || themeColorScheme == null ||
515+
if(themeColorScheme == null ||
485516
fileIconResId == NULL_RESOURCE_ID || fileHiddenIconResId == NULL_RESOURCE_ID ||
486517
folderIconResId == NULL_RESOURCE_ID) {
487518
return null;
@@ -494,7 +525,6 @@ public FileItemLayoutStylizer createFileItemLayoutStylizer() {
494525
}
495526
return new FileItemLayoutStylizer() {
496527

497-
private final Activity _activityCtx = activityCtx;
498528
private final Drawable _fileIcon = fileIconFinal;
499529
private final Drawable _fileHiddenIcon = fileHiddenIconFinal;
500530
private final Drawable _folderIcon = folderIconFinal;

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/DisplayUtils.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,17 @@ public static int[] generateGradientColorsListFromBaseColor(int baseColor, int n
476476
return colorStates;
477477
}
478478

479+
public static int[] generateGradientColorsListFromBaseColor(int baseColor, int blendColor, int numColorStates) {
480+
if(numColorStates < 1) {
481+
return null;
482+
}
483+
int[] colorStates = new int[numColorStates];
484+
for(int cidx = 0; cidx < numColorStates; cidx++) {
485+
colorStates[cidx] = ColorUtils.blendARGB(baseColor, blendColor, (0.80f / numColorStates) * cidx);
486+
}
487+
return colorStates;
488+
}
489+
479490
public static class GradientDrawableBuilder {
480491

481492
private int[] colorsList;
@@ -572,6 +583,17 @@ public static GradientDrawable GetStockGradientFromBaseColor(int baseColor) {
572583
.make();
573584
}
574585

586+
public static GradientDrawable GetStockGradientFromBaseColor(int baseColor, int blendColor) {
587+
return new GradientDrawableBuilder()
588+
.setGradientType(GradientMethodSpec.GRADIENT_METHOD_LINEAR)
589+
.setBorderColor(darkenColor(baseColor, 0.5f))
590+
.setBorderSize(0)
591+
.setBorderStyle(BorderStyleSpec.BORDER_STYLE_SOLID)
592+
.setFillStyle(GradientTypeSpec.GRADIENT_FILL_TYPE_RIGHT_LEFT)
593+
.setColorsArray(generateGradientColorsListFromBaseColor(baseColor, blendColor, 3))
594+
.make();
595+
}
596+
575597
}
576598

577599
}

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/PrefetchFilesUpdater.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ else if(updateDataType.equals(UpdateDataStruct.UpdateDataType.PREPEND_DATA_AT_TO
338338

339339
}
340340

341-
private static final long THREAD_INIT_PAUSE_TIMEOUT = 125L; // Milliseconds
341+
private static final long THREAD_INIT_PAUSE_TIMEOUT = 250L; // Milliseconds
342342
public static final long DEFAULT_THREAD_PAUSE_TIMEOUT = 550L; // Milliseconds
343343

344344
private static long THREAD_PAUSE_TIMEOUT = DEFAULT_THREAD_PAUSE_TIMEOUT;
4.83 KB
Loading

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Key features in the library include the following:
4444
### Screenshots of the library in action
4545

4646
<img src="https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/WorkingUI-Screenshot_20201112-052224.png" width="250" /> <img src="https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/WorkingUI-Screenshot_20201113-134724.png" width="250" /> <img src="https://raw.githubusercontent.com/maxieds/AndroidFilePickerLight/master/Screenshots/SampleApplicationDemo-ProgressBarDisplay.png" width="250" />
47-
<img src="https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/SampleAppThemeGreen-Screenshot_20201117-040512.png" width="250" /> <img src="https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/SampleAppThemeOrange-Screenshot_20201117-040532.png" width="250" />
47+
<img src="https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/SampleAppThemeGreen-Screenshot_20201117-040512.png" width="250" /> <img src="https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/SampleAppThemeOrange-Screenshot_20201117-040532.png" width="250" /> <img src="https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/SampleAppThemeOrangeWithGradientToolbars-Screenshot_20201117-065739.png" width="250" />
4848

4949
## Including the library for use in a client Android application
5050

@@ -74,7 +74,7 @@ dependencies {
7474
// FOR the most recent build:
7575
implementation 'com.github.maxieds:AndroidFilePickerLight:master-SNAPSHOT'
7676
// -- OR: for the latest release:
77-
implementation 'com.github.maxieds:AndroidFilePickerLight:release-v2'
77+
implementation 'com.github.maxieds:AndroidFilePickerLight:release-v3'
7878
}
7979
allprojects {
8080
repositories {
@@ -290,6 +290,7 @@ CustomThemeBuilder customThemeBuilder = new CustomThemeBuilder((Activity) myActi
290290
.setNavigationByPathButtonIcon(R.drawable.my_icon_32x32, FileChooserBuilder.DefaultNavFoldersType.FOLDER_USER_HOME)
291291
.setNavigationByPathButtonIcon(R.drawable.my_icon_32x32, FileChooserBuilder.DefaultNavFoldersType.FOLDER_MEDIA_VIDEO)
292292
.setDefaultFileIcon(R.drawable.my_file_icon_16x16)
293+
.useToolbarGradients(true)
293294
.setDefaultHiddenFileIcon(R.drawable.my_hidden_file_icon_16x16)
294295
.setDefaultFolderIcon(R.drawable.my_folder_icon_16x16);
295296

146 KB
Loading

WorkingItems.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
## TODO: A working tabulation of items that still need to get fixed for the next release of the library (TBD)
22

3-
* The gradient factory new instance / static generate methods are not returning the
4-
correctly formatted Drawable instances. This is lower priority, but still needs to get tracked down.
53
* Ability for users to create / specify icon types for custom file types (see ``FileChooserBuilder.DefaultFileTypes`` enum).
64
* Recent documents default path?
75
* Theme the toast messages and the progress bar.

app/src/main/java/com/maxieds/androidfilepickerlight/AndroidFilePickerLightExampleActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public void actionButtonLaunchMultiPickerActivityNewThemeGreen(View btnView) {
158158
.setCancelActionButtonIcon(R.drawable.greentheme_cancel_button_x_icon24)
159159
.generateThemeColors(R.color.exampleCustomThemeGreen)
160160
.setActivityToolbarIcon(R.drawable.greentheme_file_chooser_default_toolbar_icon48)
161+
.useToolbarGradients(true)
161162
.setNavigationByPathButtonIcon(R.drawable.greentheme_named_folder_sdcard_icon32, FileChooserBuilder.DefaultNavFoldersType.FOLDER_ROOT_STORAGE)
162163
.setNavigationByPathButtonIcon(R.drawable.greentheme_named_folder_images_icon32, FileChooserBuilder.DefaultNavFoldersType.FOLDER_PICTURES)
163164
.setNavigationByPathButtonIcon(R.drawable.greentheme_named_folder_camera_icon32, FileChooserBuilder.DefaultNavFoldersType.FOLDER_CAMERA)
@@ -193,6 +194,7 @@ public void actionButtonLaunchMultiPickerActivityNewThemeOrange(View btnView) {
193194
.setCancelActionButtonIcon(R.drawable.orangetheme_cancel_button_x_icon24)
194195
.generateThemeColors(R.color.exampleCustomThemeOrange)
195196
.setActivityToolbarIcon(R.drawable.orangetheme_file_chooser_default_toolbar_icon48)
197+
.useToolbarGradients(true)
196198
.setNavigationByPathButtonIcon(R.drawable.orangetheme_named_folder_sdcard_icon32, FileChooserBuilder.DefaultNavFoldersType.FOLDER_ROOT_STORAGE)
197199
.setNavigationByPathButtonIcon(R.drawable.orangetheme_named_folder_images_icon32, FileChooserBuilder.DefaultNavFoldersType.FOLDER_PICTURES)
198200
.setNavigationByPathButtonIcon(R.drawable.orangetheme_named_folder_camera_icon32, FileChooserBuilder.DefaultNavFoldersType.FOLDER_CAMERA)

0 commit comments

Comments
 (0)