package com.reactlibrary;

import android.content.Context;
import android.util.AttributeSet;

import com.appnexus.opensdk.BannerAdView;

public class RTCAppNexusBannerView extends BannerAdView {
    public RTCAppNexusBannerView(Context context) {
        super(context);
    }

    public RTCAppNexusBannerView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RTCAppNexusBannerView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public RTCAppNexusBannerView(Context context, int refresh_interval) {
        super(context, refresh_interval);
    }

    @Override
    public void requestLayout() {
        super.requestLayout();

        // The spinner relies on a measure + layout pass happening after it calls requestLayout().
        // Without this, the widget never actually changes the selection and doesn't call the
        // appropriate listeners. Since we override onLayout in our ViewGroups, a layout pass never
        // happens after a call to requestLayout, so we simulate one here.
        post(measureAndLayout);
    }

    private final Runnable measureAndLayout = new Runnable() {
        @Override
        public void run() {
            measure(
                    MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
            layout(getLeft(), getTop(), getRight(), getBottom());
        }
    };

}
