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

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Dec 25, 2014
1 parent 4fef50e commit 38a5ebd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
26 changes: 2 additions & 24 deletions src/biz/bokhorst/xprivacy/ApplicationInfoEx.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;

@SuppressLint("DefaultLocale")
public class ApplicationInfoEx implements Comparable<ApplicationInfoEx> {
Expand Down Expand Up @@ -172,8 +170,8 @@ public Bitmap getIconBitmap(Context context) {
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(resources, appInfo.icon, options);

final int pixels = Math.round(dipToPixels(context, 48));
options.inSampleSize = calculateInSampleSize(options, pixels, pixels);
final int pixels = Math.round(Util.dipToPixels(context, 48));
options.inSampleSize = Util.calculateInSampleSize(options, pixels, pixels);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(resources, appInfo.icon, options);
} catch (NameNotFoundException ex) {
Expand All @@ -184,26 +182,6 @@ public Bitmap getIconBitmap(Context context) {
return null;
}

private static float dipToPixels(Context context, float dipValue) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics);
}

private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth)
inSampleSize *= 2;
}

return inSampleSize;
}

public boolean hasInternet(Context context) {
if (mInternet == null) {
mInternet = false;
Expand Down
23 changes: 23 additions & 0 deletions src/biz/bokhorst/xprivacy/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
Expand All @@ -46,7 +47,9 @@
import android.os.TransactionTooLargeException;
import android.os.UserHandle;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
Expand Down Expand Up @@ -607,4 +610,24 @@ public static List<View> getViewsByTag(ViewGroup root, String tag) {
}
return views;
}

public static float dipToPixels(Context context, float dipValue) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics);
}

public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth)
inSampleSize *= 2;
}

return inSampleSize;
}
}

0 comments on commit 38a5ebd

Please sign in to comment.