From e4f1e668dbb43fd7f9359764dd26541373df12c4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 13 Jul 2016 16:24:27 +0200 Subject: [PATCH] add file and directory icons --- .../simplemobiletools/filemanager/Utils.java | 20 +++++++++++++++ .../filemanager/adapters/ItemsAdapter.java | 23 +++++++++++++----- .../filemanager/fragments/ItemsFragment.java | 3 ++- app/src/main/res/layout/list_item.xml | 20 ++++++++++++--- app/src/main/res/mipmap-hdpi/directory.png | Bin 0 -> 135 bytes app/src/main/res/mipmap-hdpi/file.png | Bin 0 -> 153 bytes app/src/main/res/mipmap-mdpi/directory.png | Bin 0 -> 122 bytes app/src/main/res/mipmap-mdpi/file.png | Bin 0 -> 133 bytes app/src/main/res/mipmap-xhdpi/directory.png | Bin 0 -> 181 bytes app/src/main/res/mipmap-xhdpi/file.png | Bin 0 -> 206 bytes app/src/main/res/mipmap-xxhdpi/directory.png | Bin 0 -> 245 bytes app/src/main/res/mipmap-xxhdpi/file.png | Bin 0 -> 283 bytes app/src/main/res/mipmap-xxxhdpi/directory.png | Bin 0 -> 325 bytes app/src/main/res/mipmap-xxxhdpi/file.png | Bin 0 -> 372 bytes app/src/main/res/values/colors.xml | 2 ++ app/src/main/res/values/dimens.xml | 2 ++ 16 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 app/src/main/res/mipmap-hdpi/directory.png create mode 100644 app/src/main/res/mipmap-hdpi/file.png create mode 100644 app/src/main/res/mipmap-mdpi/directory.png create mode 100644 app/src/main/res/mipmap-mdpi/file.png create mode 100644 app/src/main/res/mipmap-xhdpi/directory.png create mode 100644 app/src/main/res/mipmap-xhdpi/file.png create mode 100644 app/src/main/res/mipmap-xxhdpi/directory.png create mode 100644 app/src/main/res/mipmap-xxhdpi/file.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/directory.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/file.png diff --git a/app/src/main/java/com/simplemobiletools/filemanager/Utils.java b/app/src/main/java/com/simplemobiletools/filemanager/Utils.java index 9a4451be..8b2408b9 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/Utils.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/Utils.java @@ -3,6 +3,14 @@ package com.simplemobiletools.filemanager; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; import android.support.v4.content.ContextCompat; import android.widget.Toast; @@ -22,4 +30,16 @@ public class Utils { public static boolean hasStoragePermission(Context cxt) { return ContextCompat.checkSelfPermission(cxt, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; } + + public static Bitmap getColoredIcon(Resources res, int newColor, int id) { + 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); + paint.setColorFilter(filter); + final Canvas canvas = new Canvas(bmp); + canvas.drawBitmap(bmp, 0, 0, paint); + return bmp; + } } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java b/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java index 5d9e393a..00bd44fd 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/adapters/ItemsAdapter.java @@ -1,13 +1,17 @@ package com.simplemobiletools.filemanager.adapters; import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; +import android.widget.ImageView; import android.widget.TextView; import com.simplemobiletools.filemanager.R; +import com.simplemobiletools.filemanager.Utils; import com.simplemobiletools.filemanager.models.FileDirItem; import java.util.List; @@ -18,10 +22,16 @@ import butterknife.ButterKnife; public class ItemsAdapter extends BaseAdapter { private final List mItems; private final LayoutInflater mInflater; + private final Bitmap mFileBmp; + private final Bitmap mDirectoryBmp; public ItemsAdapter(Context context, List 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); } @Override @@ -38,6 +48,12 @@ public class ItemsAdapter extends BaseAdapter { final FileDirItem item = mItems.get(position); viewHolder.name.setText(item.getName()); + if (item.getIsDirectory()) { + viewHolder.icon.setImageBitmap(mDirectoryBmp); + } else { + viewHolder.icon.setImageBitmap(mFileBmp); + } + return convertView; } @@ -56,14 +72,9 @@ public class ItemsAdapter extends BaseAdapter { return 0; } - public void updateItems(List newItems) { - mItems.clear(); - mItems.addAll(newItems); - notifyDataSetChanged(); - } - static class ViewHolder { @BindView(R.id.item_name) TextView name; + @BindView(R.id.item_icon) ImageView icon; public ViewHolder(View view) { ButterKnife.bind(this, view); diff --git a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java index b2bf9c66..38af6b3e 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java @@ -73,7 +73,8 @@ public class ItemsFragment extends android.support.v4.app.Fragment implements Ad public void onItemClick(AdapterView parent, View view, int position, long id) { final FileDirItem item = mItems.get(position); if (item.getIsDirectory()) { - mListener.itemClicked(item.getPath()); + if (mListener != null) + mListener.itemClicked(item.getPath()); } else { final String path = item.getPath(); final File file = new File(path); diff --git a/app/src/main/res/layout/list_item.xml b/app/src/main/res/layout/list_item.xml index cd8b3c0b..afc3f13e 100644 --- a/app/src/main/res/layout/list_item.xml +++ b/app/src/main/res/layout/list_item.xml @@ -4,13 +4,25 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingBottom="@dimen/activity_margin" - android:paddingRight="@dimen/activity_margin" - android:paddingTop="@dimen/activity_margin"> + android:paddingRight="@dimen/activity_margin"> + + + android:layout_height="match_parent" + android:layout_alignBottom="@+id/item_icon" + android:layout_alignTop="@+id/item_icon" + android:layout_toRightOf="@+id/item_icon" + android:gravity="center_vertical" + android:paddingLeft="@dimen/medium_margin" + android:text="Directory"/> diff --git a/app/src/main/res/mipmap-hdpi/directory.png b/app/src/main/res/mipmap-hdpi/directory.png new file mode 100644 index 0000000000000000000000000000000000000000..02ea533a8d662e512843bf218e372653e95d843b GIT binary patch literal 135 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8K;pQnpsh{y4_S5I>?DDbdcG|@|k0wldT1B8K8f~SjPh{y4_XAbf<81OJ3(CJ7} zndX``b76v-N7DYNg?AXzx0$@j_%O$-MDb9#M4)m=#h>FoD;{~Q*wnG^Q^%Sa9jkV9 zthk}E_JdQ<#r;ZwuA-qP*1MK2|9P?TocWEMO!)@USli?GV)cP`F?hQAxvXL2`{{(qt) zvm)<`Q=Hj9{dp?B-k)#6`~UxbmC(cg19_d}4r?#Evfm-&!|_RRhEx83m({x|$*?rj VKUyK^_-~+L44$rjF6*2Ung9auEG+;4 literal 0 HcmV?d00001 diff --git a/app/src/main/res/mipmap-mdpi/file.png b/app/src/main/res/mipmap-mdpi/file.png new file mode 100644 index 0000000000000000000000000000000000000000..b51ce3ed95a437af48d672cb4b8494807587c080 GIT binary patch literal 133 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1A5Ry@5R21q&u~5;q+UmdnXs1e(j>>FVdQ&MBb@07N}3VE_OC literal 0 HcmV?d00001 diff --git a/app/src/main/res/mipmap-xhdpi/directory.png b/app/src/main/res/mipmap-xhdpi/directory.png new file mode 100644 index 0000000000000000000000000000000000000000..71a5a137c463dfd97dfad592c86b7eac773664c5 GIT binary patch literal 181 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}b0D8c!F;kch)?uX*!1I0(1~u3k7j z(@|)CtD?lCSzab=p|%h2vhJCDWr_9aDM8CMGG^>pz2)3<9-DOK6&2^5E;t7@iOv_Z za^ku1A-hLl9mAHDjh3bd#2aH97>pYj7@1i1Fnhmp-(Sr7N?SnU?z8GoH}30QFuL9E fEIT*+)p6OLF7v?Cmm9c&?qKkA^>bP0l+XkK)+RzI literal 0 HcmV?d00001 diff --git a/app/src/main/res/mipmap-xhdpi/file.png b/app/src/main/res/mipmap-xhdpi/file.png new file mode 100644 index 0000000000000000000000000000000000000000..798ebd4e25f68b658c82e773eea97bd2ad412f17 GIT binary patch literal 206 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}b0Dsh%#5ArXh)UUTGX4&Z5dST1#X z_fmE(jjwTCSC_smS-D$9cp}$l`2@QYT1!{h^YDMEIJ_$LxwOxRqkmdKI;Vst E0NwCNssI20 literal 0 HcmV?d00001 diff --git a/app/src/main/res/mipmap-xxhdpi/directory.png b/app/src/main/res/mipmap-xxhdpi/directory.png new file mode 100644 index 0000000000000000000000000000000000000000..b93d5a1e4a48fb9cddfa530aacfc84e5ea4ad9c9 GIT binary patch literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY0wn)GsXhaw_ISEDhGg7(d&7~dDL|z4q4_1- z7ebF0dKZ*BYIUwt;W*;>)jV%O+J|}OmjAiz^vX--1bb;NmdKI;Vst0GcUV@&Et; literal 0 HcmV?d00001 diff --git a/app/src/main/res/mipmap-xxhdpi/file.png b/app/src/main/res/mipmap-xxhdpi/file.png new file mode 100644 index 0000000000000000000000000000000000000000..f3e153b45eb7886c314afd8642bc9018c1f2b5bd GIT binary patch literal 283 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY0wn)GsXhaw9(lSrhGg7(d+8wOAqSC`hqkR( z1O(pr7kRR-^fM4B-pJrB!18rLU;5WcwbqN9K8JrW^zk~kQ@@Q%*UUm`d)(nn1I4KI z5$WBNZm6sYkec37%CT|!!~%}SX+}cp1pU2?gz^k0^oX!`dZ;RJuH;csnA-GWNs++J zBMgC_G6EBiFkSSp5$HU^66g_g!CF(k6j7})P zi3R_eVwcPdw#%5()K(Lq&bsyI0x4_Bbf>AG4m-Kby09c-#l^%UGs{zXGMryqJkPLY Y&+P+xzK0zI93I~B z(C26sy3FL&q}$ba<$&VE(+|=Gi?KQ4VXb{{b%I@HcvNQkRwH8&_$~OogvaO4 zw%oRd*KGoKY|H)oF+L(JmZ@K7yH~M)rTJtXSd}W-{epFln3^$y#Qw2YO4`4lFD^P$~Ceo|M5hK8FSd#^MHkMkW@H6#Nv%Xop z`uOoFkL`+MxXFXli2*NgVS zce*$hNuLo@ada)wwkl-hV=5FsC)E4*jDt)D|B?8wr!IWgTTscqYIn4V0dUAW1Y}9z7KOhqi^sPPIw7!dLw*NrLf;=eP`^JY9k?(#X=nCd zcgzlKvHty0=g_lyrE}%$KcD@NJa^2A$V!HX=v7zCg9d&s2ko((e7)78&qol`;+ E02^zJCIA2c literal 0 HcmV?d00001 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ca8ad635..b95ecaad 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,4 +3,6 @@ #fff68630 #ffe27725 @color/colorPrimary + + #33000000 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index a8c097c9..4edf4c29 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,4 +1,6 @@ 16dp 14sp + 8dp + 44dp