mirror of
https://github.com/M66B/NetGuard.git
synced 2025-01-30 19:31:26 +00:00
Use Glide to load app icons
Loading vector images has been fixed now
This commit is contained in:
parent
b130571b89
commit
f0066af16a
6 changed files with 33 additions and 114 deletions
|
@ -314,14 +314,15 @@ Attribution
|
|||
|
||||
NetGuard uses:
|
||||
|
||||
* [Android Support Library](https://developer.android.com/tools/support-library/index.html)
|
||||
* [Glide](https://bumptech.github.io/glide/)
|
||||
* [Android Support Library](https://developer.android.com/tools/support-library/)
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
[GNU General Public License version 3](http://www.gnu.org/licenses/gpl.txt)
|
||||
|
||||
Copyright (c) 2015-2017 Marcel Bokhorst ([M66B](https://contact.faircode.eu/))
|
||||
Copyright (c) 2015-2018 Marcel Bokhorst ([M66B](https://contact.faircode.eu/))
|
||||
|
||||
All rights reserved
|
||||
|
||||
|
|
|
@ -59,6 +59,9 @@ dependencies {
|
|||
// https://firebase.google.com/docs/android/setup
|
||||
implementation 'com.google.firebase:firebase-core:11.6.0'
|
||||
implementation 'com.google.firebase:firebase-ads:11.6.0'
|
||||
|
||||
implementation 'com.github.bumptech.glide:glide:4.4.0'
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.4.0'
|
||||
}
|
||||
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
|
|
10
app/proguard-rules.pro
vendored
10
app/proguard-rules.pro
vendored
|
@ -47,8 +47,14 @@
|
|||
-keep class android.support.v7.widget.** { *; }
|
||||
-dontwarn android.support.v4.**
|
||||
|
||||
#Picasso
|
||||
-dontwarn com.squareup.okhttp.**
|
||||
#Glide
|
||||
-keep public class * implements com.bumptech.glide.module.GlideModule
|
||||
-keep public class * extends com.bumptech.glide.module.AppGlideModule
|
||||
-keep enum com.bumptech.glide.** {*;}
|
||||
#-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
|
||||
# **[] $VALUES;
|
||||
# public *;
|
||||
#}
|
||||
|
||||
#AdMob
|
||||
-dontwarn com.google.android.gms.internal.**
|
||||
|
|
|
@ -24,12 +24,10 @@ import android.content.SharedPreferences;
|
|||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
|
@ -47,8 +45,6 @@ import java.net.InetAddress;
|
|||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class AdapterLog extends CursorAdapter {
|
||||
private static String TAG = "NetGuard.Log";
|
||||
|
@ -77,9 +73,6 @@ public class AdapterLog extends CursorAdapter {
|
|||
private InetAddress vpn4 = null;
|
||||
private InetAddress vpn6 = null;
|
||||
|
||||
private ExecutorService executor = Executors.newFixedThreadPool(
|
||||
Runtime.getRuntime().availableProcessors());
|
||||
|
||||
public AdapterLog(Context context, Cursor cursor, boolean resolve, boolean organization) {
|
||||
super(context, cursor, 0);
|
||||
this.resolve = resolve;
|
||||
|
@ -225,40 +218,11 @@ public class AdapterLog extends CursorAdapter {
|
|||
if (info.icon <= 0)
|
||||
ivIcon.setImageResource(android.R.drawable.sym_def_app_icon);
|
||||
else {
|
||||
ivIcon.setHasTransientState(true);
|
||||
final ApplicationInfo finalInfo = info;
|
||||
executor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Drawable drawable = context.getPackageManager().getApplicationIcon(finalInfo.packageName);
|
||||
final Drawable scaledDrawable;
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
Bitmap original = ((BitmapDrawable) drawable).getBitmap();
|
||||
Bitmap scaled = Bitmap.createScaledBitmap(original, iconSize, iconSize, false);
|
||||
scaledDrawable = new BitmapDrawable(context.getResources(), scaled);
|
||||
} else
|
||||
scaledDrawable = drawable;
|
||||
|
||||
new Handler(context.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ivIcon.setImageDrawable(scaledDrawable);
|
||||
ivIcon.setHasTransientState(false);
|
||||
}
|
||||
});
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
new Handler(context.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ivIcon.setImageDrawable(null);
|
||||
ivIcon.setHasTransientState(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon);
|
||||
GlideApp.with(context)
|
||||
.load(uri)
|
||||
.override(iconSize, iconSize)
|
||||
.into(ivIcon);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,15 +27,12 @@ import android.content.SharedPreferences;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
@ -69,13 +66,10 @@ import android.widget.ListView;
|
|||
import android.widget.PopupMenu;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> implements Filterable {
|
||||
private static final String TAG = "NetGuard.Adapter";
|
||||
|
@ -95,9 +89,6 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
|
|||
private List<Rule> listAll = new ArrayList<>();
|
||||
private List<Rule> listFiltered = new ArrayList<>();
|
||||
|
||||
private ExecutorService executor = Executors.newFixedThreadPool(
|
||||
Runtime.getRuntime().availableProcessors());
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public View view;
|
||||
|
||||
|
@ -154,8 +145,6 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
|
|||
public ImageButton btnClearAccess;
|
||||
public CheckBox cbNotify;
|
||||
|
||||
public IconLoader iconLoader = null;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
view = itemView;
|
||||
|
@ -342,8 +331,11 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
|
|||
if (rule.icon <= 0)
|
||||
holder.ivIcon.setImageResource(android.R.drawable.sym_def_app_icon);
|
||||
else {
|
||||
holder.iconLoader = new IconLoader(holder, rule);
|
||||
executor.submit(holder.iconLoader);
|
||||
Uri uri = Uri.parse("android.resource://" + rule.packageName + "/" + rule.icon);
|
||||
GlideApp.with(context)
|
||||
.load(uri)
|
||||
.override(iconSize, iconSize)
|
||||
.into(holder.ivIcon);
|
||||
}
|
||||
|
||||
// Show application label
|
||||
|
@ -833,9 +825,6 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
|
|||
public void onViewRecycled(ViewHolder holder) {
|
||||
super.onViewRecycled(holder);
|
||||
|
||||
if (holder.iconLoader != null)
|
||||
holder.iconLoader.cancel();
|
||||
|
||||
CursorAdapter adapter = (CursorAdapter) holder.lvAccess.getAdapter();
|
||||
if (adapter != null) {
|
||||
Log.i(TAG, "Closing access cursor");
|
||||
|
@ -996,56 +985,4 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
|
|||
public int getItemCount() {
|
||||
return listFiltered.size();
|
||||
}
|
||||
|
||||
private class IconLoader implements Runnable {
|
||||
private ViewHolder holder;
|
||||
private Rule rule;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public IconLoader(ViewHolder holder, Rule rule) {
|
||||
this.holder = holder;
|
||||
this.rule = rule;
|
||||
holder.ivIcon.setHasTransientState(true);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
if (!cancelled)
|
||||
Log.i(TAG, "Cancelling icon loader");
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (cancelled)
|
||||
throw new InterruptedException();
|
||||
|
||||
Drawable drawable = context.getPackageManager().getApplicationIcon(rule.packageName);
|
||||
final Drawable scaledDrawable;
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
Bitmap original = ((BitmapDrawable) drawable).getBitmap();
|
||||
Bitmap scaled = Bitmap.createScaledBitmap(original, iconSize, iconSize, false);
|
||||
scaledDrawable = new BitmapDrawable(context.getResources(), scaled);
|
||||
} else
|
||||
scaledDrawable = drawable;
|
||||
|
||||
new Handler(context.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
holder.ivIcon.setImageDrawable(scaledDrawable);
|
||||
holder.ivIcon.setHasTransientState(false);
|
||||
}
|
||||
});
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
new Handler(context.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
holder.ivIcon.setImageDrawable(null);
|
||||
holder.ivIcon.setHasTransientState(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
8
app/src/main/java/eu/faircode/netguard/GlideHelper.java
Normal file
8
app/src/main/java/eu/faircode/netguard/GlideHelper.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package eu.faircode.netguard;
|
||||
|
||||
import com.bumptech.glide.annotation.GlideModule;
|
||||
import com.bumptech.glide.module.AppGlideModule;
|
||||
|
||||
@GlideModule
|
||||
public final class GlideHelper extends AppGlideModule {
|
||||
}
|
Loading…
Reference in a new issue