package com.yydcdut.sdlv;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;

/**
 * Created by yuyidong on 15/9/25.
 */
class ItemCustomLayout extends FrameLayout {
    private ImageView mBGImage;
    private Drawable mDrawable;
    private Drawable mTransparentDrawable;

    public ItemCustomLayout(Context context) {
        super(context);
        mBGImage = new ImageView(context);
        addView(mBGImage, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        mTransparentDrawable = new ColorDrawable(Color.TRANSPARENT);
    }

    public void addCustomView(View customView) {
        addView(customView, 1, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }

    public View getCustomView() {
        return getChildAt(1);
    }

    public View getRealView() {
        return this;
    }

    public void hideBackground() {
        mBGImage.setVisibility(GONE);
        Compat.setBackgroundDrawable(this, mTransparentDrawable);

    }

    public void showBackground() {
        mBGImage.setVisibility(VISIBLE);
        Compat.setBackgroundDrawable(this, mDrawable);

    }

    public void saveBackground(Drawable drawable) {
        mDrawable = drawable;
        Compat.setBackgroundDrawable(this, mDrawable);
        mBGImage.setImageDrawable(mDrawable);
        showBackground();
    }

    public boolean isBackgroundShowing() {
        return mDrawable == mBGImage.getDrawable();
    }

    public void refreshBackground() {
        hideBackground();
        showBackground();
    }
}

@@ -863,24 +863,80 @@
 stomView) %7B%0A
+        if (customView.getLayoutParams() == null) %7B%0A    
         addV
@@ -1053,24 +1053,189 @@
 H_PARENT));%0A
+        %7D else %7B%0A            addView(customView, 1, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, customView.getLayoutParams().height));%0A        %7D%0A
     %7D%0A%0A    p

fix bug of issues2 MFC2Android No.1