Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.res.Resources;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;

import android.graphics.drawable.BitmapDrawable;

public class Main {
    private static String PACKAGE_NAME = "com.sorcerer.sorcery.iconpack";

    public static BitmapDrawable getCachedIcon(Resources res, String packageName, int resId) {
        return getCachedIcon(res, packageName, resId, null);
    }

    public static BitmapDrawable getCachedIcon(Resources res, String packageName, int resId, Options opts) {
        int displayDpi = res.getDisplayMetrics().densityDpi;
        Bitmap bitmap = BitmapFactory.decodeFile(getCacheFilePath(packageName, resId), opts);
        if (bitmap == null) {
            return null;
        }
        bitmap.setDensity(displayDpi);
        return new BitmapDrawable(res, bitmap);
    }

    public static String getCacheFilePath(String packageName, int resId) {
        return "/data/data/" + PACKAGE_NAME + "/cache/icons/" + packageName + "_" + resId;
    }
}