move icon coloring into an extension
This commit is contained in:
parent
40b547921d
commit
f14b488dfc
|
@ -3,14 +3,6 @@ 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;
|
||||||
|
|
||||||
|
@ -37,19 +29,6 @@ public class Utils {
|
||||||
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 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(color, PorterDuff.Mode.SRC_IN);
|
|
||||||
paint.setColorFilter(filter);
|
|
||||||
final Canvas canvas = new Canvas(bmp);
|
|
||||||
canvas.drawBitmap(bmp, 0, 0, paint);
|
|
||||||
return bmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isNameValid(String name) {
|
public static boolean isNameValid(String name) {
|
||||||
final Pattern pattern = Pattern.compile("^[-_.A-Za-z0-9 ]+$");
|
final Pattern pattern = Pattern.compile("^[-_.A-Za-z0-9 ]+$");
|
||||||
final Matcher matcher = pattern.matcher(name);
|
final Matcher matcher = pattern.matcher(name);
|
||||||
|
|
|
@ -11,6 +11,7 @@ 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.Utils
|
||||||
|
import com.simplemobiletools.filemanager.extensions.getColoredIcon
|
||||||
import com.simplemobiletools.filemanager.models.FileDirItem
|
import com.simplemobiletools.filemanager.models.FileDirItem
|
||||||
import kotlinx.android.synthetic.main.list_item.view.*
|
import kotlinx.android.synthetic.main.list_item.view.*
|
||||||
|
|
||||||
|
@ -24,8 +25,8 @@ class ItemsAdapter(context: Context, private val mItems: List<FileDirItem>) : Ba
|
||||||
mInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
mInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
|
|
||||||
mRes = context.resources
|
mRes = context.resources
|
||||||
mDirectoryBmp = Utils.getColoredIcon(mRes, R.color.lightGrey, R.mipmap.directory)
|
mDirectoryBmp = mRes.getColoredIcon(R.color.lightGrey, R.mipmap.directory)
|
||||||
mFileBmp = Utils.getColoredIcon(mRes, R.color.lightGrey, R.mipmap.file)
|
mFileBmp = mRes.getColoredIcon(R.color.lightGrey, R.mipmap.file)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.simplemobiletools.filemanager.extensions
|
||||||
|
|
||||||
|
import android.content.res.Resources
|
||||||
|
import android.graphics.*
|
||||||
|
|
||||||
|
fun Resources.getColoredIcon(colorId: Int, resId: Int): Bitmap {
|
||||||
|
val options = BitmapFactory.Options()
|
||||||
|
options.inMutable = true
|
||||||
|
val bitmap = BitmapFactory.decodeResource(this, resId, options)
|
||||||
|
val paint = Paint()
|
||||||
|
val filter = PorterDuffColorFilter(getColor(colorId), PorterDuff.Mode.SRC_IN)
|
||||||
|
paint.colorFilter = filter
|
||||||
|
val canvas = Canvas(bitmap)
|
||||||
|
canvas.drawBitmap(bitmap, 0f, 0f, paint)
|
||||||
|
return bitmap
|
||||||
|
}
|
Loading…
Reference in New Issue