Merge branch 'file_icons' into workaround_integration

This commit is contained in:
David A. Velasco 2013-01-30 13:49:36 +01:00
commit 37f0586c47
21 changed files with 91 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

View file

@ -1,5 +1,6 @@
/* ownCloud Android client application
* Copyright (C) 2011 Bartek Przybylski
* Copyright (2) 2012-2013 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,18 +19,25 @@
package com.owncloud.android;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import android.util.Log;
/**
* A helper class for some string operations.
*
* @author Bartek Przybylski
*
* @author David A. Velasco
*/
public class DisplayUtils {
private static final String[] suffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
private static String TAG = DisplayUtils.class.getSimpleName();
private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
private static HashMap<String, String> mimeType2HUmanReadable;
static {
@ -48,6 +56,22 @@ public class DisplayUtils {
}
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[] SUBTYPES_DOCUMENT = { "msword", "mspowerpoint", "msexcel",
"vnd.oasis.opendocument.presentation",
"vnd.oasis.opendocument.spreadsheet",
"vnd.oasis.opendocument.text"
};
private static Set<String> SUBTYPES_DOCUMENT_SET = new HashSet<String>(Arrays.asList(SUBTYPES_DOCUMENT));
private static final String[] SUBTYPES_COMPRESSED = {"x-tar", "x-gzip", "zip"};
private static final Set<String> SUBTYPES_COMPRESSED_SET = new HashSet<String>(Arrays.asList(SUBTYPES_COMPRESSED));
/**
* Converts the file size in bytes to human readable output.
*
@ -57,12 +81,12 @@ public class DisplayUtils {
public static String bytesToHumanReadable(long bytes) {
double result = bytes;
int attachedsuff = 0;
while (result > 1024 && attachedsuff < suffixes.length) {
while (result > 1024 && attachedsuff < sizeSuffixes.length) {
result /= 1024.;
attachedsuff++;
}
result = ((int) (result * 100)) / 100.;
return result + " " + suffixes[attachedsuff];
return result + " " + sizeSuffixes[attachedsuff];
}
/**
@ -104,6 +128,58 @@ public class DisplayUtils {
return mimetype.split("/")[1].toUpperCase() + " file";
return "Unknown type";
}
/**
* Returns the resource identifier of an image resource to use as icon associated to a
* known MIME type.
*
* @param mimetype MIME type string.
* @return Resource identifier of an image resource.
*/
public static int getResourceId(String mimetype) {
if (mimetype == null || "DIR".equals(mimetype)) {
return R.drawable.ic_menu_archive;
} else {
String [] parts = mimetype.split("/");
String type = parts[0];
String subtype = 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 (SUBTYPES_DOCUMENT_SET.contains(subtype)) {
return R.drawable.file_doc;
} else if (SUBTYPES_COMPRESSED_SET.contains(subtype)) {
return R.drawable.file_zip;
}
}
// problems: RAR, RTF, 3GP are send as application/octet-stream from the server ; extension in the filename should be explicitly reviewed
}
// default icon
return R.drawable.file;
}
/**
* Converts Unix time to human readable format

View file

@ -115,11 +115,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
fileName.setText(name);
ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
if (file.getMimetype() == null || !file.getMimetype().equals("DIR")) {
fileIcon.setImageResource(R.drawable.file);
} else {
fileIcon.setImageResource(R.drawable.ic_menu_archive);
}
fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));
ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();

View file

@ -507,8 +507,7 @@ public class FileDetailFragment extends SherlockFragment implements
// set file details
setFilename(mFile.getFileName());
setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile
.getMimetype()));
setFiletype(mFile.getMimetype());
setFilesize(mFile.getFileLength());
if(ocVersionSupportsTimeCreated()){
setTimeCreated(mFile.getCreationTimestamp());
@ -560,8 +559,14 @@ public class FileDetailFragment extends SherlockFragment implements
*/
private void setFiletype(String mimetype) {
TextView tv = (TextView) getView().findViewById(R.id.fdType);
if (tv != null)
tv.setText(mimetype);
if (tv != null) {
String printableMimetype = DisplayUtils.convertMIMEtoPrettyPrint(mimetype);;
tv.setText(printableMimetype);
}
ImageView iv = (ImageView) getView().findViewById(R.id.fdIcon);
if (iv != null) {
iv.setImageResource(DisplayUtils.getResourceId(mimetype));
}
}
/**