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

package com.ntels.onecable.common.util;

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

/**
 * <pre>
 * 1. ClassName :   RecycleUtils
 * 2. FileName  :   RecycleUtils.java
 * 3. Package   :   com.ntels.onecable.common.util
 * 4. Date      :   2016-12-06
 * 5. Author    :   aaron
 * 6. Comment   :   하위 뷰 초기화 클래스
 * </pre>
 */
public class RecycleUtils {

    public RecycleUtils() {
    }

    /**
     * 하위 뷰 초기화.
     *
     * @param root Root view
     */
    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++) {
                    try {
                        recursiveRecycle(group.getChildAt(i));
                    } catch (Exception ex) {
//                        ex.printStackTrace();
                    }
                }

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

            }

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

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

            root = null;

        }
    }
}
