Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import android.widget.ImageView;

import java.io.InputStream;

public class Main {
    private static void loadAssetImage(ImageView view, String filename, int defaultIconId) {

        InputStream input = null;
        try {
            input = view.getContext().getAssets().open(filename);
            Bitmap icon = BitmapFactory.decodeStream(input);
            view.setImageBitmap(icon);
            input.close();
        } catch (Exception error) {
            view.setImageResource(defaultIconId);
        } finally {
            silentClose(input);
        }
    }

    private static boolean loadAssetImage(ImageView view, String filename) {

        InputStream input = null;
        try {
            input = view.getContext().getAssets().open(filename);
            Bitmap icon = BitmapFactory.decodeStream(input);
            view.setImageBitmap(icon);
            input.close();
            return true;
        } catch (Exception error) {
        } finally {
            silentClose(input);
        }
        return false;
    }

    private static void silentClose(InputStream input) {
        try {
            if (input != null) {
                input.close();
            }
        } catch (Exception error) {
            //should never happen
        } finally {
        }
    }
}