1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-02-25 07:32:46 +00:00

Added application icon to blocked traffic log entries

This commit is contained in:
M66B 2016-01-08 08:12:14 +01:00
parent 653261743f
commit 5f2c6db15e
2 changed files with 29 additions and 0 deletions

View file

@ -2,6 +2,8 @@ package eu.faircode.netguard;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
@ -9,8 +11,11 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CursorAdapter; import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
public class LogAdapter extends CursorAdapter { public class LogAdapter extends CursorAdapter {
@ -52,6 +57,7 @@ public class LogAdapter extends CursorAdapter {
final String whois = (ip.length() > 1 && ip.charAt(0) == '/' ? ip.substring(1) : ip); final String whois = (ip.length() > 1 && ip.charAt(0) == '/' ? ip.substring(1) : ip);
// Get views // Get views
ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
TextView tvTime = (TextView) view.findViewById(R.id.tvTime); TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
TextView tvIP = (TextView) view.findViewById(R.id.tvIP); TextView tvIP = (TextView) view.findViewById(R.id.tvIP);
TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol); TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol);
@ -59,6 +65,22 @@ public class LogAdapter extends CursorAdapter {
TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags); TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags);
TextView tvUid = (TextView) view.findViewById(R.id.tvUid); TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
// Application icon
ApplicationInfo info = null;
PackageManager pm = context.getPackageManager();
String[] pkg = pm.getPackagesForUid(uid);
if (pkg != null && pkg.length > 0)
try {
info = pm.getApplicationInfo(pkg[0], 0);
} catch (PackageManager.NameNotFoundException ignored) {
}
if (info == null || info.icon == 0)
Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon);
else {
Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon);
Picasso.with(context).load(uri).into(ivIcon);
}
// Set values // Set values
tvTime.setText(new SimpleDateFormat("dd").format(time) + " " + tvTime.setText(new SimpleDateFormat("dd").format(time) + " " +
SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM).format(time)); SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM).format(time));

View file

@ -6,10 +6,17 @@
android:orientation="horizontal" android:orientation="horizontal"
tools:context=".ActivityLog"> tools:context=".ActivityLog">
<ImageView
android:id="@+id/ivIcon"
android:layout_width="16dip"
android:layout_height="16dip"
android:layout_gravity="center_vertical" />
<TextView <TextView
android:id="@+id/tvTime" android:id="@+id/tvTime"
android:layout_width="80dp" android:layout_width="80dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:textAppearance="@android:style/TextAppearance.Material.Small" /> android:textAppearance="@android:style/TextAppearance.Material.Small" />
<TextView <TextView