Skip to content

Commit

Permalink
Take account of display density for icons
Browse files Browse the repository at this point in the history
To avoid the icons displayed in the app list being really small on high
resolution screen the size is multiplied by the display density (which
is 1 for medium-density screens).
  • Loading branch information
jensstein committed Jan 15, 2015
1 parent 33fca32 commit 17cff9a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/dk/jens/backup/adapters/AppInfoAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -21,7 +21,7 @@ public class AppInfoAdapter extends ArrayAdapter<AppInfo>
{
Context context;
ArrayList<AppInfo> items;
int layout;
int iconSize, layout;
String currentFilter;

private ArrayList<AppInfo> originalValues;
Expand All @@ -35,6 +35,16 @@ public AppInfoAdapter(Context context, int layout, ArrayList<AppInfo> items)
this.layout = layout;

originalValues = new ArrayList<AppInfo>(items);
try
{
DisplayMetrics metrics = new DisplayMetrics();
((android.app.Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
iconSize = 32 * (int) metrics.density;
}
catch(ClassCastException e)
{
iconSize = 32;
}
}
public void add(AppInfo appInfo)
{
Expand Down Expand Up @@ -84,8 +94,7 @@ public View getView(int pos, View convertView, ViewGroup parent)
viewHolder.icon.setVisibility(View.VISIBLE); // to cancel View.GONE if it was set
viewHolder.icon.setImageBitmap(appInfo.icon);
LayoutParams lp = (LayoutParams) viewHolder.icon.getLayoutParams();
lp.height = 32;
lp.width = 32;
lp.height = lp.width = iconSize;
viewHolder.icon.setLayoutParams(lp);
}
else
Expand Down Expand Up @@ -403,4 +412,4 @@ public void setLocalTimestampFormat(boolean newPref)
{
localTimestampFormat = newPref;
}
}
}

0 comments on commit 17cff9a

Please sign in to comment.