6464 */
6565public 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