public CloseableLayout(@NonNull Context context) {
    super(context);

    mCloseDrawable = new StateListDrawable();
    mClosePosition = ClosePosition.TOP_RIGHT;

    mCloseDrawable.addState(
        SELECTED_STATE_SET, INTERSTITIAL_CLOSE_BUTTON_PRESSED.createDrawable(context));
    mCloseDrawable.addState(
        EMPTY_STATE_SET, INTERSTITIAL_CLOSE_BUTTON_NORMAL.createDrawable(context));

    mCloseDrawable.setState(EMPTY_STATE_SET);
    mCloseDrawable.setCallback(this);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mCloseRegionSize = Dips.asIntPixels(CLOSE_REGION_SIZE_DP, context);
    mCloseButtonSize = Dips.asIntPixels(CLOSE_BUTTON_SIZE_DP, context);
    mCloseButtonPadding = Dips.asIntPixels(CLOSE_BUTTON_PADDING_DP, context);

    setWillNotDraw(false);
  }
  private void createInterstitialCloseButton() {
    mCloseButton = new ImageButton(getContext());
    StateListDrawable states = new StateListDrawable();
    states.addState(
        new int[] {-android.R.attr.state_pressed},
        INTERSTITIAL_CLOSE_BUTTON_NORMAL.decodeImage(getContext()));
    states.addState(
        new int[] {android.R.attr.state_pressed},
        INTERSTITIAL_CLOSE_BUTTON_PRESSED.decodeImage(getContext()));
    mCloseButton.setImageDrawable(states);
    mCloseButton.setBackgroundDrawable(null);
    mCloseButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            getBaseVideoViewControllerListener().onFinish();
          }
        });

    RelativeLayout.LayoutParams buttonLayout =
        new RelativeLayout.LayoutParams(mButtonSize, mButtonSize);
    buttonLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    buttonLayout.setMargins(mButtonPadding, 0, mButtonPadding, 0);
    getLayout().addView(mCloseButton, buttonLayout);
  }