Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.view.View;
import android.view.ViewGroup;

import android.widget.ImageView;

public class Main {
    static int screenHeight = -1;
    static int screenWidth = -1;
    static int[] location = new int[2];

    public static void unbindInvisibleImageDrawables(View view) {
        if (null == view) {
            return;
        }

        if (view instanceof ImageView) {
            ImageView imageView = (ImageView) view;

            if (imageView.getDrawable() != null && isInVisisble(imageView)) {
                imageView.getDrawable().setCallback(null);
                imageView.setImageDrawable(null);
            }
        }
        if (view instanceof ViewGroup) {
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                unbindInvisibleImageDrawables(((ViewGroup) view).getChildAt(i));
            }
        }
    }

    public static boolean isInVisisble(View view) {
        if (screenHeight == -1) {
            screenHeight = view.getContext().getResources().getDisplayMetrics().heightPixels;
            screenWidth = view.getContext().getResources().getDisplayMetrics().widthPixels;
        }

        view.getLocationOnScreen(location);
        int left = location[0];
        int top = location[1];
        int height = view.getHeight();

        //in top
        if ((top + height) < -0.5 * screenHeight) {
            return true;
        }

        //in bottom
        if (top > screenHeight + 0.5 * screenHeight) {
            return true;
        }

        return false;
    }
}