mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	display some details at the files and directories
This commit is contained in:
		| @@ -34,12 +34,13 @@ public class Utils { | ||||
|         return ContextCompat.checkSelfPermission(cxt, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; | ||||
|     } | ||||
|  | ||||
|     public static Bitmap getColoredIcon(Resources res, int newColor, int id) { | ||||
|     public static Bitmap getColoredIcon(Resources res, int colorId, int id) { | ||||
|         final int color = res.getColor(colorId); | ||||
|         final BitmapFactory.Options options = new BitmapFactory.Options(); | ||||
|         options.inMutable = true; | ||||
|         final Bitmap bmp = BitmapFactory.decodeResource(res, id, options); | ||||
|         final Paint paint = new Paint(); | ||||
|         final ColorFilter filter = new PorterDuffColorFilter(newColor, PorterDuff.Mode.SRC_IN); | ||||
|         final ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN); | ||||
|         paint.setColorFilter(filter); | ||||
|         final Canvas canvas = new Canvas(bmp); | ||||
|         canvas.drawBitmap(bmp, 0, 0, paint); | ||||
|   | ||||
| @@ -14,6 +14,7 @@ import com.simplemobiletools.filemanager.R; | ||||
| import com.simplemobiletools.filemanager.Utils; | ||||
| import com.simplemobiletools.filemanager.models.FileDirItem; | ||||
|  | ||||
| import java.text.DecimalFormat; | ||||
| import java.util.List; | ||||
|  | ||||
| import butterknife.BindView; | ||||
| @@ -24,14 +25,15 @@ public class ItemsAdapter extends BaseAdapter { | ||||
|     private final LayoutInflater mInflater; | ||||
|     private final Bitmap mFileBmp; | ||||
|     private final Bitmap mDirectoryBmp; | ||||
|     private final Resources mRes; | ||||
|  | ||||
|     public ItemsAdapter(Context context, List<FileDirItem> items) { | ||||
|         mItems = items; | ||||
|         mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | ||||
|  | ||||
|         final Resources res = context.getResources(); | ||||
|         mDirectoryBmp = Utils.getColoredIcon(res, res.getColor(R.color.lightGrey), R.mipmap.directory); | ||||
|         mFileBmp = Utils.getColoredIcon(res, res.getColor(R.color.lightGrey), R.mipmap.file); | ||||
|         mRes = context.getResources(); | ||||
|         mDirectoryBmp = Utils.getColoredIcon(mRes, R.color.lightGrey, R.mipmap.directory); | ||||
|         mFileBmp = Utils.getColoredIcon(mRes, R.color.lightGrey, R.mipmap.file); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -50,13 +52,29 @@ public class ItemsAdapter extends BaseAdapter { | ||||
|  | ||||
|         if (item.getIsDirectory()) { | ||||
|             viewHolder.icon.setImageBitmap(mDirectoryBmp); | ||||
|             viewHolder.details.setText(getChildrenCnt(item)); | ||||
|         } else { | ||||
|             viewHolder.icon.setImageBitmap(mFileBmp); | ||||
|             viewHolder.details.setText(getFormattedSize(item)); | ||||
|         } | ||||
|  | ||||
|         return convertView; | ||||
|     } | ||||
|  | ||||
|     private String getChildrenCnt(FileDirItem item) { | ||||
|         final int children = item.getChildren(); | ||||
|         return mRes.getQuantityString(R.plurals.items, children, children); | ||||
|     } | ||||
|  | ||||
|     private String getFormattedSize(FileDirItem item) { | ||||
|         final long size = item.getSize(); | ||||
|         if (size <= 0) | ||||
|             return "0"; | ||||
|         final String[] units = {"B", "kB", "MB", "GB", "TB"}; | ||||
|         final int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); | ||||
|         return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int getCount() { | ||||
|         return mItems.size(); | ||||
| @@ -75,6 +93,7 @@ public class ItemsAdapter extends BaseAdapter { | ||||
|     static class ViewHolder { | ||||
|         @BindView(R.id.item_name) TextView name; | ||||
|         @BindView(R.id.item_icon) ImageView icon; | ||||
|         @BindView(R.id.item_details) TextView details; | ||||
|  | ||||
|         public ViewHolder(View view) { | ||||
|             ButterKnife.bind(this, view); | ||||
|   | ||||
| @@ -126,11 +126,18 @@ public class ItemsFragment extends android.support.v4.app.Fragment | ||||
|             if (mToBeDeleted.contains(curPath)) | ||||
|                 continue; | ||||
|  | ||||
|             items.add(new FileDirItem(curPath, curName, file.isDirectory())); | ||||
|             int children = getChildren(file); | ||||
|             long size = file.length(); | ||||
|  | ||||
|             items.add(new FileDirItem(curPath, curName, file.isDirectory(), children, size)); | ||||
|         } | ||||
|         return items; | ||||
|     } | ||||
|  | ||||
|     private int getChildren(File file) { | ||||
|         return (file.isDirectory()) ? file.listFiles().length : 0; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | ||||
|         final FileDirItem item = mItems.get(position); | ||||
|   | ||||
| @@ -4,11 +4,15 @@ public class FileDirItem implements Comparable { | ||||
|     private final String mPath; | ||||
|     private final String mName; | ||||
|     private final boolean mIsDirectory; | ||||
|     private final int mChildren; | ||||
|     private final long mSize; | ||||
|  | ||||
|     public FileDirItem(String path, String name, boolean isDirectory) { | ||||
|     public FileDirItem(String path, String name, boolean isDirectory, int children, long size) { | ||||
|         mPath = path; | ||||
|         mName = name; | ||||
|         mIsDirectory = isDirectory; | ||||
|         mChildren = children; | ||||
|         mSize = size; | ||||
|     } | ||||
|  | ||||
|     public String getPath() { | ||||
| @@ -23,6 +27,14 @@ public class FileDirItem implements Comparable { | ||||
|         return mIsDirectory; | ||||
|     } | ||||
|  | ||||
|     public int getChildren() { | ||||
|         return mChildren; | ||||
|     } | ||||
|  | ||||
|     public long getSize() { | ||||
|         return mSize; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int compareTo(Object object) { | ||||
|         final FileDirItem item = (FileDirItem) object; | ||||
| @@ -40,6 +52,8 @@ public class FileDirItem implements Comparable { | ||||
|         return "FileDirItem{" + | ||||
|                 "name=" + getName() + | ||||
|                 ", isDirectory=" + getIsDirectory() + | ||||
|                 ", path=" + getPath() + "}"; | ||||
|                 ", path=" + getPath() + | ||||
|                 ", children=" + getChildren() + | ||||
|                 ", size=" + getSize() +"}"; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -18,12 +18,22 @@ | ||||
|     <TextView | ||||
|         android:id="@+id/item_name" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="match_parent" | ||||
|         android:layout_alignBottom="@+id/item_icon" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_alignTop="@+id/item_icon" | ||||
|         android:layout_toRightOf="@+id/item_icon" | ||||
|         android:gravity="center_vertical" | ||||
|         android:paddingLeft="@dimen/medium_margin" | ||||
|         android:paddingLeft="@dimen/small_margin" | ||||
|         android:paddingTop="@dimen/small_margin" | ||||
|         android:text="Directory"/> | ||||
|  | ||||
|     <TextView | ||||
|         android:id="@+id/item_details" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_below="@+id/item_name" | ||||
|         android:layout_toRightOf="@+id/item_icon" | ||||
|         android:paddingLeft="@dimen/small_margin" | ||||
|         android:text="1 KB" | ||||
|         android:textColor="@color/details_grey" | ||||
|         android:textSize="@dimen/details_text_size"/> | ||||
|  | ||||
| </RelativeLayout> | ||||
|   | ||||
| @@ -7,4 +7,5 @@ | ||||
|     <color name="lightGrey">#33000000</color> | ||||
|     <color name="pressed_item_foreground">#08000000</color> | ||||
|     <color name="activated_item_foreground">#11000000</color> | ||||
|     <color name="details_grey">#33000000</color> | ||||
| </resources> | ||||
|   | ||||
| @@ -1,10 +1,12 @@ | ||||
| <resources> | ||||
|     <dimen name="activity_margin">16dp</dimen> | ||||
|     <dimen name="small_margin">6dp</dimen> | ||||
|     <dimen name="medium_margin">10dp</dimen> | ||||
|     <dimen name="icon_size">48dp</dimen> | ||||
|     <dimen name="social_padding">8dp</dimen> | ||||
|     <dimen name="social_logo">40dp</dimen> | ||||
|     <dimen name="settings_padding">8dp</dimen> | ||||
|  | ||||
|     <dimen name="details_text_size">12sp</dimen> | ||||
|     <dimen name="normal_text_size">14sp</dimen> | ||||
| </resources> | ||||
|   | ||||
| @@ -19,6 +19,11 @@ | ||||
|         <item quantity="other">%1$d items deleted</item> | ||||
|     </plurals> | ||||
|  | ||||
|     <plurals name="items"> | ||||
|         <item quantity="one">1 item</item> | ||||
|         <item quantity="other">%1$d items</item> | ||||
|     </plurals> | ||||
|  | ||||
|     <!-- About --> | ||||
|     <string name="about">About</string> | ||||
|     <string name="website">More simple apps and source code at:\nhttp://simplemobiletools.com</string> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user