Merge branch 'material_toolbar' of https://github.com/owncloud/android into material_...
authorAndy Scherzinger <info@andy-scherzinger.de>
Fri, 14 Aug 2015 16:55:58 +0000 (18:55 +0200)
committerAndy Scherzinger <info@andy-scherzinger.de>
Fri, 14 Aug 2015 16:55:58 +0000 (18:55 +0200)
1  2 
res/layout/file_preview.xml
src/com/owncloud/android/utils/DisplayUtils.java

@@@ -39,7 -39,7 +39,7 @@@
                android:id="@+id/image_preview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
 -              android:layout_margin="16dp"
 +              android:layout_margin="@dimen/standard_margin"
                android:layout_gravity="center"
                android:contentDescription="@string/preview_image_description"
                android:src="@drawable/logo" />
@@@ -59,6 -59,7 +59,7 @@@
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
+               android:layout_margin="16dp"
            />
  
  </RelativeLayout>
@@@ -22,7 -22,6 +22,7 @@@
  \r
  package com.owncloud.android.utils;\r
  \r
 +import java.math.BigDecimal;\r
  import java.net.IDN;\r
  import java.text.DateFormat;\r
  import java.util.Arrays;\r
@@@ -36,11 -35,15 +36,15 @@@ import java.util.Vector
  import android.annotation.TargetApi;\r
  import android.app.Activity;\r
  import android.content.Context;\r
+ import android.graphics.Color;\r
  import android.graphics.Point;\r
+ import android.graphics.PorterDuff;\r
  import android.os.Build;\r
  import android.text.format.DateUtils;\r
  import android.view.Display;\r
  import android.webkit.MimeTypeMap;\r
+ import android.widget.ProgressBar;\r
+ import android.widget.SeekBar;\r
  \r
  import com.owncloud.android.MainApp;\r
  import com.owncloud.android.R;\r
@@@ -56,7 -59,6 +60,7 @@@ public class DisplayUtils 
      //private static String TAG = DisplayUtils.class.getSimpleName(); \r
      \r
      private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };\r
 +    private static final int[] sizeScales = { 0, 0, 0, 1, 1, 2, 2, 2, 2 };\r
  \r
      private static HashMap<String, String> mimeType2HUmanReadable;\r
      static {\r
      \r
      /**\r
       * Converts the file size in bytes to human readable output.\r
 -     * \r
 +     * <ul>\r
 +     *     <li>appends a size suffix, e.g. B, KB, MB etc.</li>\r
 +     *     <li>rounds the size based on the suffix to 0,1 or 2 decimals</li>\r
 +     * </ul>\r
 +     *\r
       * @param bytes Input file size\r
       * @return Like something readable like "12 MB"\r
       */\r
              result /= 1024.;\r
              attachedsuff++;\r
          }\r
 -        result = ((int) (result * 100)) / 100.;\r
 -        return result + " " + sizeSuffixes[attachedsuff];\r
 +\r
 +        return new BigDecimal(result).setScale(\r
 +                sizeScales[attachedsuff], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[attachedsuff];\r
      }\r
  \r
      /**\r
          return size;\r
      }\r
  \r
+     /**\r
+      * sets the coloring of the given progress bar to color_accent.\r
+      *\r
+      * @param progressBar the progress bar to be colored\r
+      */\r
+     public static void colorPreLollipopHorizontalProgressBar(ProgressBar progressBar) {\r
+         if (progressBar != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {\r
+             int color = progressBar.getResources().getColor(R.color.color_accent);\r
+             progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);\r
+             progressBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);\r
+         }\r
+     }\r
\r
+     /**\r
+      * sets the coloring of the given seek bar to color_accent.\r
+      *\r
+      * @param seekBar the seek bar to be colored\r
+      */\r
+     public static void colorPreLollipopHorizontalSeekBar(SeekBar seekBar) {\r
+         if (seekBar != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {\r
+             colorPreLollipopHorizontalProgressBar(seekBar);\r
\r
+             if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {\r
+                 int color = seekBar.getResources().getColor(R.color.color_accent);\r
+                 seekBar.getThumb().setColorFilter(color, PorterDuff.Mode.SRC_IN);\r
+                 seekBar.getThumb().setColorFilter(color, PorterDuff.Mode.SRC_IN);\r
+             }\r
+         }\r
+     }\r
  }\r