1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-01-01 21:04:08 +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.text.SimpleDateFormat;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
public class AdapterLog extends CursorAdapter {
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);
else
icon = Icon.createWithResource(info.packageName, info.icon);
icon.loadDrawableAsync(context, new Icon.OnDrawableLoadedListener() {
@Override
public void onDrawableLoaded(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
Bitmap original = ((BitmapDrawable) drawable).getBitmap();
Bitmap scaled = Bitmap.createScaledBitmap(original, iconSize, iconSize, false);
ivIcon.setImageDrawable(new BitmapDrawable(context.getResources(), scaled));
} else
ivIcon.setImageDrawable(drawable);
}
}, new Handler(context.getMainLooper()));
try {
icon.loadDrawableAsync(context, new Icon.OnDrawableLoadedListener() {
@Override
public void onDrawableLoaded(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
Bitmap original = ((BitmapDrawable) drawable).getBitmap();
Bitmap scaled = Bitmap.createScaledBitmap(original, iconSize, iconSize, false);
ivIcon.setImageDrawable(new BitmapDrawable(context.getResources(), scaled));
} else
ivIcon.setImageDrawable(drawable);
}
}, new Handler(context.getMainLooper()));
} catch (RejectedExecutionException ex) {
Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
} else {
if (info.icon == 0)
Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon);
else {

View file

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