1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-01-04 06:23:04 +00:00

Prevent crash

This commit is contained in:
M66B 2017-08-24 17:23:42 +02:00
parent 84cdf13a78
commit 2671c34976
2 changed files with 32 additions and 23 deletions

View file

@ -51,6 +51,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.List; import java.util.List;
import java.util.concurrent.RejectedExecutionException;
public class AdapterLog extends CursorAdapter { public class AdapterLog extends CursorAdapter {
private static String TAG = "NetGuard.Log"; private static String TAG = "NetGuard.Log";
@ -227,19 +228,22 @@ public class AdapterLog extends CursorAdapter {
icon = Icon.createWithResource(context, android.R.drawable.sym_def_app_icon); icon = Icon.createWithResource(context, android.R.drawable.sym_def_app_icon);
else else
icon = Icon.createWithResource(info.packageName, info.icon); icon = Icon.createWithResource(info.packageName, info.icon);
icon.loadDrawableAsync(context, new Icon.OnDrawableLoadedListener() { try {
@Override icon.loadDrawableAsync(context, new Icon.OnDrawableLoadedListener() {
public void onDrawableLoaded(Drawable drawable) { @Override
if (drawable instanceof BitmapDrawable) { public void onDrawableLoaded(Drawable drawable) {
Bitmap original = ((BitmapDrawable) drawable).getBitmap(); if (drawable instanceof BitmapDrawable) {
Bitmap scaled = Bitmap.createScaledBitmap(original, iconSize, iconSize, false); Bitmap original = ((BitmapDrawable) drawable).getBitmap();
ivIcon.setImageDrawable(new BitmapDrawable(context.getResources(), scaled)); Bitmap scaled = Bitmap.createScaledBitmap(original, iconSize, iconSize, false);
} else ivIcon.setImageDrawable(new BitmapDrawable(context.getResources(), scaled));
ivIcon.setImageDrawable(drawable); } else
} ivIcon.setImageDrawable(drawable);
}, new Handler(context.getMainLooper())); }
}, new Handler(context.getMainLooper()));
} catch (RejectedExecutionException ex) {
Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
} else { } else {
if (info.icon == 0) if (info.icon == 0)
Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon); Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon);
else { else {

View file

@ -76,6 +76,7 @@ import com.squareup.picasso.Picasso;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.RejectedExecutionException;
public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> implements Filterable { public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> implements Filterable {
private static final String TAG = "NetGuard.Adapter"; private static final String TAG = "NetGuard.Adapter";
@ -342,17 +343,21 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
icon = Icon.createWithResource(context, android.R.drawable.sym_def_app_icon); icon = Icon.createWithResource(context, android.R.drawable.sym_def_app_icon);
else else
icon = Icon.createWithResource(rule.info.packageName, rule.info.applicationInfo.icon); icon = Icon.createWithResource(rule.info.packageName, rule.info.applicationInfo.icon);
icon.loadDrawableAsync(context, new Icon.OnDrawableLoadedListener() { try {
@Override icon.loadDrawableAsync(context, new Icon.OnDrawableLoadedListener() {
public void onDrawableLoaded(Drawable drawable) { @Override
if (drawable instanceof BitmapDrawable) { public void onDrawableLoaded(Drawable drawable) {
Bitmap original = ((BitmapDrawable) drawable).getBitmap(); if (drawable instanceof BitmapDrawable) {
Bitmap scaled = Bitmap.createScaledBitmap(original, iconSize, iconSize, false); Bitmap original = ((BitmapDrawable) drawable).getBitmap();
holder.ivIcon.setImageDrawable(new BitmapDrawable(context.getResources(), scaled)); Bitmap scaled = Bitmap.createScaledBitmap(original, iconSize, iconSize, false);
} else holder.ivIcon.setImageDrawable(new BitmapDrawable(context.getResources(), scaled));
holder.ivIcon.setImageDrawable(drawable); } else
} holder.ivIcon.setImageDrawable(drawable);
}, new Handler(context.getMainLooper())); }
}, new Handler(context.getMainLooper()));
} catch (RejectedExecutionException ex) {
Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
} else { } else {
if (rule.info.applicationInfo.icon == 0) if (rule.info.applicationInfo.icon == 0)
Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(holder.ivIcon); Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(holder.ivIcon);