add file and directory icons
|
@ -3,6 +3,14 @@ package com.simplemobiletools.filemanager;
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
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.support.v4.content.ContextCompat;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -22,4 +30,16 @@ public class Utils {
|
||||||
public static boolean hasStoragePermission(Context cxt) {
|
public static boolean hasStoragePermission(Context cxt) {
|
||||||
return ContextCompat.checkSelfPermission(cxt, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
package com.simplemobiletools.filemanager.adapters;
|
package com.simplemobiletools.filemanager.adapters;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.simplemobiletools.filemanager.R;
|
import com.simplemobiletools.filemanager.R;
|
||||||
|
import com.simplemobiletools.filemanager.Utils;
|
||||||
import com.simplemobiletools.filemanager.models.FileDirItem;
|
import com.simplemobiletools.filemanager.models.FileDirItem;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -18,10 +22,16 @@ import butterknife.ButterKnife;
|
||||||
public class ItemsAdapter extends BaseAdapter {
|
public class ItemsAdapter extends BaseAdapter {
|
||||||
private final List<FileDirItem> mItems;
|
private final List<FileDirItem> mItems;
|
||||||
private final LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
|
private final Bitmap mFileBmp;
|
||||||
|
private final Bitmap mDirectoryBmp;
|
||||||
|
|
||||||
public ItemsAdapter(Context context, List<FileDirItem> items) {
|
public ItemsAdapter(Context context, List<FileDirItem> items) {
|
||||||
mItems = items;
|
mItems = items;
|
||||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
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
|
@Override
|
||||||
|
@ -38,6 +48,12 @@ public class ItemsAdapter extends BaseAdapter {
|
||||||
final FileDirItem item = mItems.get(position);
|
final FileDirItem item = mItems.get(position);
|
||||||
viewHolder.name.setText(item.getName());
|
viewHolder.name.setText(item.getName());
|
||||||
|
|
||||||
|
if (item.getIsDirectory()) {
|
||||||
|
viewHolder.icon.setImageBitmap(mDirectoryBmp);
|
||||||
|
} else {
|
||||||
|
viewHolder.icon.setImageBitmap(mFileBmp);
|
||||||
|
}
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,14 +72,9 @@ public class ItemsAdapter extends BaseAdapter {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateItems(List<FileDirItem> newItems) {
|
|
||||||
mItems.clear();
|
|
||||||
mItems.addAll(newItems);
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class ViewHolder {
|
static class ViewHolder {
|
||||||
@BindView(R.id.item_name) TextView name;
|
@BindView(R.id.item_name) TextView name;
|
||||||
|
@BindView(R.id.item_icon) ImageView icon;
|
||||||
|
|
||||||
public ViewHolder(View view) {
|
public ViewHolder(View view) {
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
|
@ -73,6 +73,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment implements Ad
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
final FileDirItem item = mItems.get(position);
|
final FileDirItem item = mItems.get(position);
|
||||||
if (item.getIsDirectory()) {
|
if (item.getIsDirectory()) {
|
||||||
|
if (mListener != null)
|
||||||
mListener.itemClicked(item.getPath());
|
mListener.itemClicked(item.getPath());
|
||||||
} else {
|
} else {
|
||||||
final String path = item.getPath();
|
final String path = item.getPath();
|
||||||
|
|
|
@ -4,13 +4,25 @@
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="@dimen/activity_margin"
|
android:paddingRight="@dimen/activity_margin">
|
||||||
android:paddingRight="@dimen/activity_margin"
|
|
||||||
android:paddingTop="@dimen/activity_margin">
|
<ImageView
|
||||||
|
android:id="@+id/item_icon"
|
||||||
|
android:layout_width="@dimen/icon_size"
|
||||||
|
android:layout_height="@dimen/icon_size"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:src="@mipmap/directory"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/item_name"
|
android:id="@+id/item_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"/>
|
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"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
After Width: | Height: | Size: 135 B |
After Width: | Height: | Size: 153 B |
After Width: | Height: | Size: 122 B |
After Width: | Height: | Size: 133 B |
After Width: | Height: | Size: 181 B |
After Width: | Height: | Size: 206 B |
After Width: | Height: | Size: 245 B |
After Width: | Height: | Size: 283 B |
After Width: | Height: | Size: 325 B |
After Width: | Height: | Size: 372 B |
|
@ -3,4 +3,6 @@
|
||||||
<color name="colorPrimary">#fff68630</color>
|
<color name="colorPrimary">#fff68630</color>
|
||||||
<color name="colorPrimaryDark">#ffe27725</color>
|
<color name="colorPrimaryDark">#ffe27725</color>
|
||||||
<color name="colorAccent">@color/colorPrimary</color>
|
<color name="colorAccent">@color/colorPrimary</color>
|
||||||
|
|
||||||
|
<color name="lightGrey">#33000000</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="activity_margin">16dp</dimen>
|
<dimen name="activity_margin">16dp</dimen>
|
||||||
<dimen name="normal_text_size">14sp</dimen>
|
<dimen name="normal_text_size">14sp</dimen>
|
||||||
|
<dimen name="medium_margin">8dp</dimen>
|
||||||
|
<dimen name="icon_size">44dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|