From: Andy Scherzinger Date: Fri, 11 Sep 2015 11:06:14 +0000 (+0200) Subject: Merge branch 'new_filetype_icons' of https://github.com/owncloud/android into materia... X-Git-Tag: beta-20151128~7^2~30 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/6eccdc25b3e4ac9bb9c5686aa3e53f60ce07b59d?ds=inline;hp=-c Merge branch 'new_filetype_icons' of https://github.com/owncloud/android into material_buttons Conflicts: src/com/owncloud/android/utils/DisplayUtils.java --- 6eccdc25b3e4ac9bb9c5686aa3e53f60ce07b59d diff --combined src/com/owncloud/android/ui/adapter/FileListListAdapter.java index c2639a8c,5e94e0f2..51883670 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@@ -55,6 -55,7 +55,7 @@@ import com.owncloud.android.services.Op import com.owncloud.android.ui.activity.ComponentsGetter; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; + import com.owncloud.android.utils.MimetypeIconUtil; /** @@@ -193,7 -194,6 +194,7 @@@ public class FileListListAdapter extend switch (viewType){ case LIST_ITEM: TextView fileSizeV = (TextView) view.findViewById(R.id.file_size); + TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator); TextView lastModV = (TextView) view.findViewById(R.id.last_mod); ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox); @@@ -202,7 -202,6 +203,7 @@@ checkBoxV.setVisibility(View.GONE); + fileSizeSeparatorV.setVisibility(View.VISIBLE); fileSizeV.setVisibility(View.VISIBLE); fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength())); @@@ -214,17 -213,16 +215,17 @@@ } else { if (parentList.isItemChecked(position)) { checkBoxV.setImageResource( - android.R.drawable.checkbox_on_background); + R.drawable.ic_checkbox_marked); } else { checkBoxV.setImageResource( - android.R.drawable.checkbox_off_background); + R.drawable.ic_checkbox_blank_outline); } checkBoxV.setVisibility(View.VISIBLE); } } } else { //Folder + fileSizeSeparatorV.setVisibility(View.INVISIBLE); fileSizeV.setVisibility(View.INVISIBLE); } @@@ -332,24 -330,15 +333,15 @@@ } else { - fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(file.getMimetype(), + fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(file.getMimetype(), file.getFileName())); } } else { // Folder - - if (checkIfFileIsSharedWithMe(file)) { - fileIcon.setImageResource(R.drawable.shared_with_me_folder); - } else if (file.isShareByLink()) { - // If folder is sharedByLink, icon folder must be changed to - // folder-public one - fileIcon.setImageResource(R.drawable.folder_public); - } else { - fileIcon.setImageResource( - DisplayUtils.getFileTypeIconId(file.getMimetype(), file.getFileName()) - ); - } + fileIcon.setImageResource( + MimetypeIconUtil.getFolderTypeIconId( + checkIfFileIsSharedWithMe(file), file.isShareByLink())); } } diff --combined src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java index d8abc664,373d791a..8bae9380 --- a/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java @@@ -39,6 -39,7 +39,7 @@@ import com.owncloud.android.R import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.utils.BitmapUtils; import com.owncloud.android.utils.DisplayUtils; + import com.owncloud.android.utils.MimetypeIconUtil; /** * This Adapter populates a ListView with all files and directories contained @@@ -111,11 -112,9 +112,11 @@@ public class LocalFileListAdapter exten fileIcon.setTag(file.hashCode()); TextView fileSizeV = (TextView) view.findViewById(R.id.file_size); + TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator); TextView lastModV = (TextView) view.findViewById(R.id.last_mod); ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox); if (!file.isDirectory()) { + fileSizeSeparatorV.setVisibility(View.VISIBLE); fileSizeV.setVisibility(View.VISIBLE); fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length())); @@@ -126,9 -125,9 +127,9 @@@ checkBoxV.setVisibility(View.GONE); } else { if (parentList.isItemChecked(position)) { - checkBoxV.setImageResource(android.R.drawable.checkbox_on_background); + checkBoxV.setImageResource(R.drawable.ic_checkbox_marked); } else { - checkBoxV.setImageResource(android.R.drawable.checkbox_off_background); + checkBoxV.setImageResource(R.drawable.ic_checkbox_blank_outline); } checkBoxV.setVisibility(View.VISIBLE); } @@@ -161,11 -160,10 +162,11 @@@ } } } else { - fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(null, file.getName())); + fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(null, file.getName())); } } else { + fileSizeSeparatorV.setVisibility(View.GONE); fileSizeV.setVisibility(View.GONE); lastModV.setVisibility(View.GONE); checkBoxV.setVisibility(View.GONE); diff --combined src/com/owncloud/android/utils/DisplayUtils.java index 236a05f5,8a281e92..46c66737 --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@@ -22,27 -22,14 +22,14 @@@ package com.owncloud.android.utils; - import java.math.BigDecimal; - import java.net.IDN; - import java.text.DateFormat; - import java.util.Arrays; - import java.util.Calendar; - import java.util.Date; - import java.util.HashMap; - import java.util.HashSet; - import java.util.Set; - import java.util.Vector; - import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; - import android.graphics.Color; import android.graphics.Point; import android.graphics.PorterDuff; import android.os.Build; import android.text.format.DateUtils; import android.view.Display; - import android.webkit.MimeTypeMap; import android.widget.ProgressBar; import android.widget.SeekBar; @@@ -50,94 -37,54 +37,61 @@@ import com.owncloud.android.MainApp import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; ++import java.math.BigDecimal; + import java.net.IDN; + import java.text.DateFormat; + import java.util.Calendar; + import java.util.Date; + import java.util.HashMap; + import java.util.Map; + /** * A helper class for some string operations. */ public class DisplayUtils { private static final String OWNCLOUD_APP_NAME = "ownCloud"; - - //private static String TAG = DisplayUtils.class.getSimpleName(); private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; + private static final int[] sizeScales = { 0, 0, 0, 1, 1, 2, 2, 2, 2 }; - private static HashMap mimeType2HUmanReadable; + private static Map mimeType2HumanReadable; + static { - mimeType2HUmanReadable = new HashMap(); + mimeType2HumanReadable = new HashMap(); // images - mimeType2HUmanReadable.put("image/jpeg", "JPEG image"); - mimeType2HUmanReadable.put("image/jpg", "JPEG image"); - mimeType2HUmanReadable.put("image/png", "PNG image"); - mimeType2HUmanReadable.put("image/bmp", "Bitmap image"); - mimeType2HUmanReadable.put("image/gif", "GIF image"); - mimeType2HUmanReadable.put("image/svg+xml", "JPEG image"); - mimeType2HUmanReadable.put("image/tiff", "TIFF image"); + mimeType2HumanReadable.put("image/jpeg", "JPEG image"); + mimeType2HumanReadable.put("image/jpg", "JPEG image"); + mimeType2HumanReadable.put("image/png", "PNG image"); + mimeType2HumanReadable.put("image/bmp", "Bitmap image"); + mimeType2HumanReadable.put("image/gif", "GIF image"); + mimeType2HumanReadable.put("image/svg+xml", "JPEG image"); + mimeType2HumanReadable.put("image/tiff", "TIFF image"); // music - mimeType2HUmanReadable.put("audio/mpeg", "MP3 music file"); - mimeType2HUmanReadable.put("application/ogg", "OGG music file"); - + mimeType2HumanReadable.put("audio/mpeg", "MP3 music file"); + mimeType2HumanReadable.put("application/ogg", "OGG music file"); } - private static final String TYPE_APPLICATION = "application"; - private static final String TYPE_AUDIO = "audio"; - private static final String TYPE_IMAGE = "image"; - private static final String TYPE_TXT = "text"; - private static final String TYPE_VIDEO = "video"; - - private static final String SUBTYPE_PDF = "pdf"; - private static final String SUBTYPE_XML = "xml"; - private static final String[] SUBTYPES_DOCUMENT = { - "msword", - "vnd.openxmlformats-officedocument.wordprocessingml.document", - "vnd.oasis.opendocument.text", - "rtf", - "javascript" - }; - private static Set SUBTYPES_DOCUMENT_SET = new HashSet(Arrays.asList(SUBTYPES_DOCUMENT)); - private static final String[] SUBTYPES_SPREADSHEET = { - "msexcel", - "vnd.ms-excel", - "vnd.openxmlformats-officedocument.spreadsheetml.sheet", - "vnd.oasis.opendocument.spreadsheet" - }; - private static Set SUBTYPES_SPREADSHEET_SET = new HashSet(Arrays.asList(SUBTYPES_SPREADSHEET)); - private static final String[] SUBTYPES_PRESENTATION = { - "mspowerpoint", - "vnd.ms-powerpoint", - "vnd.openxmlformats-officedocument.presentationml.presentation", - "vnd.oasis.opendocument.presentation" - }; - private static Set SUBTYPES_PRESENTATION_SET = new HashSet(Arrays.asList(SUBTYPES_PRESENTATION)); - private static final String[] SUBTYPES_COMPRESSED = {"x-tar", "x-gzip", "zip"}; - private static final Set SUBTYPES_COMPRESSED_SET = new HashSet(Arrays.asList(SUBTYPES_COMPRESSED)); - private static final String SUBTYPE_OCTET_STREAM = "octet-stream"; - private static final String EXTENSION_RAR = "rar"; - private static final String EXTENSION_RTF = "rtf"; - private static final String EXTENSION_3GP = "3gp"; - private static final String EXTENSION_PY = "py"; - private static final String EXTENSION_JS = "js"; - /** * Converts the file size in bytes to human readable output. - * + *
    + *
  • appends a size suffix, e.g. B, KB, MB etc.
  • + *
  • rounds the size based on the suffix to 0,1 or 2 decimals
  • + *
+ * * @param bytes Input file size * @return Like something readable like "12 MB" */ public static String bytesToHumanReadable(long bytes) { double result = bytes; -- int attachedsuff = 0; -- while (result > 1024 && attachedsuff < sizeSuffixes.length) { ++ int attachedSuff = 0; ++ while (result > 1024 && attachedSuff < sizeSuffixes.length) { result /= 1024.; -- attachedsuff++; ++ attachedSuff++; } - result = ((int) (result * 100)) / 100.; - return result + " " + sizeSuffixes[attachedsuff]; + + return new BigDecimal(result).setScale( - sizeScales[attachedsuff], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[attachedsuff]; ++ sizeScales[attachedSuff], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[attachedSuff]; } /** @@@ -148,100 -95,14 +102,14 @@@ * @return A human friendly version of the MIME type */ public static String convertMIMEtoPrettyPrint(String mimetype) { - if (mimeType2HUmanReadable.containsKey(mimetype)) { - return mimeType2HUmanReadable.get(mimetype); + if (mimeType2HumanReadable.containsKey(mimetype)) { + return mimeType2HumanReadable.get(mimetype); } if (mimetype.split("/").length >= 2) return mimetype.split("/")[1].toUpperCase() + " file"; return "Unknown type"; } - - - /** - * Returns the resource identifier of an image to use as icon associated to a known MIME type. - * - * @param mimetype MIME type string; if NULL, the method tries to guess it from the extension in filename - * @param filename Name, with extension. - * @return Identifier of an image resource. - */ - public static int getFileTypeIconId(String mimetype, String filename) { - - if (mimetype == null) { - String fileExtension = getExtension(filename); - mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); - if (mimetype == null) { - mimetype = TYPE_APPLICATION + "/" + SUBTYPE_OCTET_STREAM; - } - } - - if ("DIR".equals(mimetype)) { - return R.drawable.ic_menu_archive; - - } else { - String [] parts = mimetype.split("/"); - String type = parts[0]; - String subtype = (parts.length > 1) ? parts[1] : ""; - - if(TYPE_TXT.equals(type)) { - return R.drawable.file_doc; - - } else if(TYPE_IMAGE.equals(type)) { - return R.drawable.file_image; - - } else if(TYPE_VIDEO.equals(type)) { - return R.drawable.file_movie; - - } else if(TYPE_AUDIO.equals(type)) { - return R.drawable.file_sound; - - } else if(TYPE_APPLICATION.equals(type)) { - - if (SUBTYPE_PDF.equals(subtype)) { - return R.drawable.file_pdf; - - } else if (SUBTYPE_XML.equals(subtype)) { - return R.drawable.file_doc; - - } else if (SUBTYPES_DOCUMENT_SET.contains(subtype)) { - return R.drawable.file_doc; - - } else if (SUBTYPES_SPREADSHEET_SET.contains(subtype)) { - return R.drawable.file_xls; - - } else if (SUBTYPES_PRESENTATION_SET.contains(subtype)) { - return R.drawable.file_ppt; - - } else if (SUBTYPES_COMPRESSED_SET.contains(subtype)) { - return R.drawable.file_zip; - - } else if (SUBTYPE_OCTET_STREAM.equals(subtype) ) { - if (getExtension(filename).equalsIgnoreCase(EXTENSION_RAR)) { - return R.drawable.file_zip; - - } else if (getExtension(filename).equalsIgnoreCase(EXTENSION_RTF)) { - return R.drawable.file_doc; - - } else if (getExtension(filename).equalsIgnoreCase(EXTENSION_3GP)) { - return R.drawable.file_movie; - - } else if ( getExtension(filename).equalsIgnoreCase(EXTENSION_PY) || - getExtension(filename).equalsIgnoreCase(EXTENSION_JS)) { - return R.drawable.file_doc; - } - } - } - } - - // default icon - return R.drawable.file; - } - - private static String getExtension(String filename) { - String extension = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase(); - return extension; - } - /** * Converts Unix time to human readable format * @param milliseconds that have passed since 01/01/1970 @@@ -253,7 -114,6 +121,6 @@@ return df.format(date); } - public static int getSeasonalIconId() { if (Calendar.getInstance().get(Calendar.DAY_OF_YEAR) >= 354 && MainApp.getAppContext().getString(R.string.app_name).equals(OWNCLOUD_APP_NAME)) {