/*
 * Copyright (c) 2015. Ncomz. All Rights Reserved
 */

package com.ntels.kneet.v3.common.util;

import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;

/**
 * <pre>
 * -----------------------------------------------------------------------------
 * 설명 :  하위 뷰 초기화 클래스
 * 작성자 : 최진오
 * 작성일자 : 2012-12-06
 * 수정일자 : 2012-12-06 최진오 최초생성
 * ------------------------------------------------------------------------------
 * </pre>
 */
public class RecycleUtils {

    public RecycleUtils() {
    }

    ;

    public void recursiveRecycle(View root) {
        if ( root != null ) {
            root.setBackgroundDrawable(null);
            if ( root instanceof ViewGroup ) {
                ViewGroup group = (ViewGroup) root;
                int count = group.getChildCount();
                for ( int i = 0; i < count; i++ ) {
                    recursiveRecycle(group.getChildAt(i));
                }

                if ( !(root instanceof AdapterView) ) {
                    group.removeAllViews();
                }

            }

            if ( root instanceof ImageView ) {
                ((ImageView) root).setImageDrawable(null);
            }

//            if ( root instanceof ImageView ) {
//                ((ImageView) root).setImageURI(null);
//            }

            root = null;

        }
    }
}
