Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.io.InputStream;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;

public class Main {
    public static boolean setAssetImage(ImageView imageView, String filename) {
        return setAssetImage(imageView, null, filename);
    }

    public static boolean setAssetImage(ImageView imageView, String path, String filename) {
        if (filename == null || "".equals(filename) || "NULL".equalsIgnoreCase(filename)) {
            return false;
        }
        String _path = (path == null) ? "" : path;

        InputStream is = null;
        try {
            is = imageView.getContext().getAssets().open(_path + filename);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        Bitmap bitmap = BitmapFactory.decodeStream(is);
        imageView.setImageBitmap(bitmap);

        return true;
    }
}