Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Added application icons to usage view
Browse files Browse the repository at this point in the history
Fixes #693
  • Loading branch information
M66B committed Nov 13, 2013
1 parent 186da49 commit 2895843
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changelog
* Added setting to disable update notification (per application) ([issue](https://github.com/M66B/XPrivacy/issues/635))
* Not filtering on restricted will filter on not restricted ([issue](https://github.com/M66B/XPrivacy/issues/682))
* Option to randomize subscriber ID (IMSI) ([issue](https://github.com/M66B/XPrivacy/issues/690))
* Added application icons to usage view ([issue](https://github.com/M66B/XPrivacy/issues/693))
* Added traditional Chinese translation
* Updated German translation
* Updated Vietnamese translation
Expand Down
8 changes: 8 additions & 0 deletions res/layout/usageentry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false" />

<ImageView
android:id="@+id/imgIcon"
android:layout_width="16dip"
android:layout_height="16dip"
android:layout_gravity="center_vertical"
android:layout_marginRight="2dip"
android:contentDescription="@string/help_application" />

<ImageView
android:id="@+id/imgRestricted"
android:layout_width="16dip"
Expand Down
60 changes: 57 additions & 3 deletions src/biz/bokhorst/xprivacy/ActivityUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

import biz.bokhorst.xprivacy.PrivacyManager.UsageData;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
Expand Down Expand Up @@ -211,28 +216,73 @@ protected void publishResults(CharSequence constraint, FilterResults results) {
}

private class ViewHolder {
private View row;
private int position;
public TextView tvTime;
public ImageView imgIcon;
public ImageView imgRestricted;
public TextView tvApp;
public TextView tvRestriction;

public ViewHolder(View row) {
public ViewHolder(View theRow, int thePosition) {
row = theRow;
position = thePosition;
tvTime = (TextView) row.findViewById(R.id.tvTime);
imgIcon = (ImageView) row.findViewById(R.id.imgIcon);
imgRestricted = (ImageView) row.findViewById(R.id.imgRestricted);
tvApp = (TextView) row.findViewById(R.id.tvApp);
tvRestriction = (TextView) row.findViewById(R.id.tvRestriction);
}
}

private class HolderTask extends AsyncTask<Object, Object, Object> {
private int position;
private ViewHolder holder;
private UsageData usageData;
private Drawable icon = null;

public HolderTask(int thePosition, ViewHolder theHolder, UsageData theUsageData) {
position = thePosition;
holder = theHolder;
usageData = theUsageData;
}

@Override
protected Object doInBackground(Object... params) {
if (holder.position == position && usageData != null)
try {
PackageManager pm = holder.row.getContext().getPackageManager();
String[] packages = pm.getPackagesForUid(usageData.getUid());
if (packages != null && packages.length > 0) {
ApplicationInfo app = pm.getApplicationInfo(packages[0], 0);
icon = pm.getApplicationIcon(app);
}
} catch (Throwable ex) {
Util.bug(null, ex);
}
return null;
}

@Override
protected void onPostExecute(Object result) {
if (holder.position == position && icon != null) {
holder.imgIcon.setImageDrawable(icon);
holder.imgIcon.setVisibility(View.VISIBLE);
}
}
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.usageentry, null);
holder = new ViewHolder(convertView);
holder = new ViewHolder(convertView, position);
convertView.setTag(holder);
} else
} else {
holder = (ViewHolder) convertView.getTag();
holder.position = position;
}

// Get data
PrivacyManager.UsageData usageData = getItem(position);
Expand All @@ -241,11 +291,15 @@ public View getView(int position, View convertView, ViewGroup parent) {
Date date = new Date(usageData.getTimeStamp());
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss", Locale.ROOT);
holder.tvTime.setText(format.format(date));
holder.imgIcon.setVisibility(View.INVISIBLE);
holder.imgRestricted.setVisibility(usageData.getRestricted() ? View.VISIBLE : View.INVISIBLE);
holder.tvApp.setText(Integer.toString(usageData.getUid()));
holder.tvRestriction.setText(String.format("%s/%s", usageData.getRestrictionName(),
usageData.getMethodName()));

// Async update
new HolderTask(position, holder, usageData).executeOnExecutor(mExecutor, (Object) null);

return convertView;
}
}
Expand Down

0 comments on commit 2895843

Please sign in to comment.