Skip to content

Commit 330f47f

Browse files
colorize quota progress bar depending on thresholds met
1 parent 1155857 commit 330f47f

File tree

4 files changed

+85
-34
lines changed

4 files changed

+85
-34
lines changed

res/values/colors.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,10 @@
5252
<!-- special transparent action bar colors for image preview -->
5353
<color name="owncloud_blue_transparent">#201D2D44</color>
5454
<color name="owncloud_blue_dark_transparent">#40162233</color>
55+
56+
<!-- level colors for info notifications/visualisations -->
57+
<color name="infolevel_info">@color/color_accent</color>
58+
<color name="infolevel_warning">#fdd835</color>
59+
<color name="infolevel_critical">#e57373</color>
60+
5561
</resources>

src/com/owncloud/android/ui/activity/DrawerActivity.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
/**
2-
* ownCloud Android client application
2+
* Nextcloud Android client application
33
*
44
* @author Andy Scherzinger
5-
* Copyright (C) 2016 ownCloud Inc.
5+
* Copyright (C) 2016 Andy Scherzinger
6+
* Copyright (C) 2016 Nextcloud.
67
*
7-
* This program is free software: you can redistribute it and/or modify
8-
* it under the terms of the GNU General Public License version 2,
9-
* as published by the Free Software Foundation.
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10+
* License as published by the Free Software Foundation; either
11+
* version 3 of the License, or any later version.
1012
*
1113
* This program is distributed in the hope that it will be useful,
1214
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1315
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
* GNU General Public License for more details.
16+
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
1517
*
16-
* You should have received a copy of the GNU General Public License
17-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
* You should have received a copy of the GNU Affero General Public
19+
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
1820
*/
1921

2022
package com.owncloud.android.ui.activity;
@@ -122,8 +124,20 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
122124
* accounts for the (max) three displayed accounts in the drawer header.
123125
*/
124126
private Account[] mAvatars = new Account[3];
127+
128+
/**
129+
* container layout of the quota view.
130+
*/
125131
private LinearLayout mQuotaView;
132+
133+
/**
134+
* progress bar of the quota view.
135+
*/
126136
private ProgressBar mQuotaProgressBar;
137+
138+
/**
139+
* text view of the quota view.
140+
*/
127141
private TextView mQuotaTextView;
128142

129143
/**
@@ -534,13 +548,13 @@ private void showQuota(boolean showQuota) {
534548
*/
535549
private void setQuotaInformation(long usedSpace, long totalSpace, int relative) {
536550
mQuotaProgressBar.setProgress(relative);
551+
DisplayUtils.colorHorizontalProgressBar(mQuotaProgressBar, DisplayUtils.getRelativeInfoColor(this, relative));
552+
537553
mQuotaTextView.setText(String.format(
538554
getString(R.string.drawer_quota),
539555
DisplayUtils.bytesToHumanReadable(usedSpace),
540556
DisplayUtils.bytesToHumanReadable(totalSpace)));
541557

542-
// TODO Think about coloring of the progressbar at certain thresholds
543-
544558
showQuota(true);
545559
}
546560

src/com/owncloud/android/ui/activity/ToolbarActivity.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
/**
2-
* ownCloud Android client application
2+
* Nextcloud Android client application
33
*
44
* @author Andy Scherzinger
5-
* Copyright (C) 2016 ownCloud Inc.
5+
* Copyright (C) 2016 Andy Scherzinger
6+
* Copyright (C) 2016 Nextcloud.
67
*
7-
* This program is free software: you can redistribute it and/or modify
8-
* it under the terms of the GNU General Public License version 2,
9-
* as published by the Free Software Foundation.
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10+
* License as published by the Free Software Foundation; either
11+
* version 3 of the License, or any later version.
1012
*
1113
* This program is distributed in the hope that it will be useful,
1214
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1315
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
* GNU General Public License for more details.
16+
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
1517
*
16-
* You should have received a copy of the GNU General Public License
17-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
* You should have received a copy of the GNU Affero General Public
19+
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
1820
*/
1921

2022
package com.owncloud.android.ui.activity;

src/com/owncloud/android/utils/DisplayUtils.java

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@
6464
*/
6565
public class DisplayUtils {
6666
private static final String TAG = DisplayUtils.class.getSimpleName();
67-
68-
private static final String OWNCLOUD_APP_NAME = "ownCloud";
69-
67+
7068
private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
7169
private static final int[] sizeScales = { 0, 0, 1, 1, 1, 2, 2, 2, 2 };
70+
public static final int RELATIVE_THRESHOLD_WARNING = 90;
71+
public static final int RELATIVE_THRESHOLD_CRITICAL = 95;
7272

7373
private static Map<String, String> mimeType2HumanReadable;
7474

7575
static {
76-
mimeType2HumanReadable = new HashMap<String, String>();
76+
mimeType2HumanReadable = new HashMap<>();
7777
// images
7878
mimeType2HumanReadable.put("image/jpeg", "JPEG image");
7979
mimeType2HumanReadable.put("image/jpg", "JPEG image");
@@ -155,9 +155,9 @@ public static String convertIdn(String url, boolean toASCII) {
155155
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
156156
// Find host name after '//' or '@'
157157
int hostStart = 0;
158-
if (urlNoDots.indexOf("//") != -1) {
158+
if (urlNoDots.contains("//")) {
159159
hostStart = url.indexOf("//") + "//".length();
160-
} else if (url.indexOf("@") != -1) {
160+
} else if (url.contains("@")) {
161161
hostStart = url.indexOf("@") + "@".length();
162162
}
163163

@@ -207,6 +207,24 @@ public static CharSequence getRelativeTimestamp(Context context, long modificati
207207
DateUtils.WEEK_IN_MILLIS, 0);
208208
}
209209

210+
/**
211+
* determines the info level color based on certain thresholds
212+
* {@link #RELATIVE_THRESHOLD_WARNING} and {@link #RELATIVE_THRESHOLD_CRITICAL}.
213+
*
214+
* @param context the app's context
215+
* @param relative relative value for which the info level color should be looked up
216+
* @return info level color
217+
*/
218+
public static int getRelativeInfoColor(Context context, int relative) {
219+
if (relative < RELATIVE_THRESHOLD_WARNING) {
220+
return context.getResources().getColor(R.color.infolevel_info);
221+
} else if (relative >= RELATIVE_THRESHOLD_WARNING && relative < RELATIVE_THRESHOLD_CRITICAL) {
222+
return context.getResources().getColor(R.color.infolevel_warning);
223+
} else {
224+
return context.getResources().getColor(R.color.infolevel_critical);
225+
}
226+
}
227+
210228
@SuppressWarnings("deprecation")
211229
public static CharSequence getRelativeDateTimeString (
212230
Context c, long time, long minResolution, long transitionResolution, int flags
@@ -238,8 +256,9 @@ else if ((System.currentTimeMillis() - time) < 60 * 1000) {
238256
}
239257

240258
/**
241-
* Update the passed path removing the last "/" if it is not the root folder
242-
* @param path
259+
* Update the passed path removing the last "/" if it is not the root folder.
260+
*
261+
* @param path the path to be trimmed
243262
*/
244263
public static String getPathWithoutLastSlash(String path) {
245264

@@ -250,12 +269,11 @@ public static String getPathWithoutLastSlash(String path) {
250269
return path;
251270
}
252271

253-
254272
/**
255-
* Gets the screen size in pixels in a backwards compatible way
273+
* Gets the screen size in pixels in a backwards compatible way.
256274
*
257-
* @param caller Activity calling; needed to get access to the {@link android.view.WindowManager}
258-
* @return Size in pixels of the screen, or default {@link Point} if caller is null
275+
* @param caller Activity calling; needed to get access to the {@link android.view.WindowManager}
276+
* @return Size in pixels of the screen, or default {@link Point} if caller is null
259277
*/
260278
public static Point getScreenSize(Activity caller) {
261279
Point size = new Point();
@@ -277,7 +295,18 @@ public static Point getScreenSize(Activity caller) {
277295
*/
278296
public static void colorPreLollipopHorizontalProgressBar(ProgressBar progressBar) {
279297
if (progressBar != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
280-
int color = progressBar.getResources().getColor(R.color.color_accent);
298+
colorHorizontalProgressBar(progressBar, progressBar.getResources().getColor(R.color.color_accent));
299+
}
300+
}
301+
302+
/**
303+
* sets the coloring of the given progress bar to color_accent.
304+
*
305+
* @param progressBar the progress bar to be colored
306+
* @param color the color to be used
307+
*/
308+
public static void colorHorizontalProgressBar(ProgressBar progressBar, @ColorInt int color) {
309+
if (progressBar != null) {
281310
progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
282311
progressBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
283312
}
@@ -315,7 +344,7 @@ public static void colorSnackbar(Context context, Snackbar snackbar) {
315344
* Sets the color of the status bar to {@code color} on devices with OS version lollipop or higher.
316345
*
317346
* @param fragmentActivity fragment activity
318-
* @param color the color
347+
* @param color the color
319348
*/
320349
public static void colorStatusBar(FragmentActivity fragmentActivity, @ColorInt int color) {
321350
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
@@ -326,11 +355,11 @@ public static void colorStatusBar(FragmentActivity fragmentActivity, @ColorInt i
326355
/**
327356
* Sets the color of the progressbar to {@code color} within the given toolbar.
328357
*
329-
* @param activity the toolbar activity instance
358+
* @param activity the toolbar activity instance
330359
* @param progressBarColor the color to be used for the toolbar's progress bar
331360
*/
332361
public static void colorToolbarProgressBar(FragmentActivity activity, int progressBarColor) {
333-
if(activity instanceof ToolbarActivity) {
362+
if (activity instanceof ToolbarActivity) {
334363
((ToolbarActivity) activity).setProgressBarBackgroundColor(progressBarColor);
335364
}
336365
}

0 commit comments

Comments
 (0)