Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.Bitmap.CompressFormat;

import android.graphics.drawable.BitmapDrawable;

import java.io.ByteArrayOutputStream;
import java.io.File;

import java.io.FileOutputStream;

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

    public static boolean cacheDrawable(String packageName, int resId, BitmapDrawable drawable) {
        try {
            File f = new File("/data/data/" + PACKAGE_NAME + "/cache/icons/", packageName + "_" + resId);
            if (f.exists()) {
                f.delete();
            }
            f.createNewFile();
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            drawable.getBitmap().compress(CompressFormat.PNG, 0, bos);
            new FileOutputStream(f).write(bos.toByteArray());
            f.setReadable(true, false);
            f.setWritable(true, false);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}