/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.android.exoplayer2.ui;

import android.view.View;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/** Provides information about an overlay view shown on top of an ad view group. */
public final class AdOverlayInfo {

  /**
   * The purpose of the overlay. One of {@link #PURPOSE_CONTROLS}, {@link #PURPOSE_CLOSE_AD}, {@link
   * #PURPOSE_OTHER} or {@link #PURPOSE_NOT_VISIBLE}.
   */
  @Documented
  @Retention(RetentionPolicy.SOURCE)
  @IntDef({PURPOSE_CONTROLS, PURPOSE_CLOSE_AD, PURPOSE_OTHER, PURPOSE_NOT_VISIBLE})
  public @interface Purpose {}
  /** Purpose for playback controls overlaying the player. */
  public static final int PURPOSE_CONTROLS = 0;
  /** Purpose for ad close buttons overlaying the player. */
  public static final int PURPOSE_CLOSE_AD = 1;
  /** Purpose for other overlays. */
  public static final int PURPOSE_OTHER = 2;
  /** Purpose for overlays that are not visible. */
  public static final int PURPOSE_NOT_VISIBLE = 3;

  /** The overlay view. */
  public final View view;
  /** The purpose of the overlay view. */
  @Purpose public final int purpose;
  /** An optional, detailed reason that the overlay view is needed. */
  @Nullable public final String reasonDetail;

  /**
   * Creates a new overlay info.
   *
   * @param view The view that is overlaying the player.
   * @param purpose The purpose of the view.
   */
  public AdOverlayInfo(View view, @Purpose int purpose) {
    this(view, purpose, /* detailedReason= */ null);
  }

  /**
   * Creates a new overlay info.
   *
   * @param view The view that is overlaying the player.
   * @param purpose The purpose of the view.
   * @param detailedReason An optional, detailed reason that the view is on top of the player.
   */
  public AdOverlayInfo(View view, @Purpose int purpose, @Nullable String detailedReason) {
    this.view = view;
    this.purpose = purpose;
    this.reasonDetail = detailedReason;
  }
}

@@ -656,16 +656,304 @@
 r2.ui;%0A%0A
+import static java.lang.annotation.ElementType.FIELD;%0Aimport static java.lang.annotation.ElementType.LOCAL_VARIABLE;%0Aimport static java.lang.annotation.ElementType.METHOD;%0Aimport static java.lang.annotation.ElementType.PARAMETER;%0Aimport static java.lang.annotation.ElementType.TYPE_USE;%0A%0A
 import a
@@ -1165,16 +1165,52 @@
 nPolicy;
+%0Aimport java.lang.annotation.Target;
 %0A%0A/** Pr
@@ -1541,16 +1541,80 @@
 SOURCE)%0A
+  @Target(%7BFIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE%7D)%0A
   @IntDe
@@ -1827,17 +1827,17 @@
 TROLS = 
-0
+1
 ;%0A  /** 
@@ -1936,17 +1936,17 @@
 SE_AD = 
-1
+2
 ;%0A  /** 
@@ -2018,17 +2018,17 @@
 OTHER = 
-2
+3
 ;%0A  /** 
@@ -2121,18 +2121,1088 @@
 SIBLE = 
-3;
+4;%0A%0A  /** A builder for %7B@link AdOverlayInfo%7D instances. */%0A  public static final class Builder %7B%0A%0A    private final View view;%0A    private final @Purpose int purpose;%0A%0A    @Nullable private String detailedReason;%0A%0A    /**%0A     * Creates a new builder.%0A     *%0A     * @param view The view that is overlaying the player.%0A     * @param purpose The purpose of the view.%0A     */%0A    public Builder(View view, @Purpose int purpose) %7B%0A      this.view = view;%0A      this.purpose = purpose;%0A    %7D%0A%0A    /**%0A     * Sets an optional, detailed reason that the view is on top of the player.%0A     *%0A     * @return This builder, for convenience.%0A     */%0A    public Builder setDetailedReason(@Nullable String detailedReason) %7B%0A      this.detailedReason = detailedReason;%0A      return this;%0A    %7D%0A%0A    /** Returns a new %7B@link AdOverlayInfo%7D instance with the current builder values. */%0A    // Using deprecated constructor while it still exists.%0A    @SuppressWarnings(%22deprecation%22)%0A    public AdOverlayInfo build() %7B%0A      return new AdOverlayInfo(view, purpose, detailedReason);%0A    %7D%0A  %7D
 %0A%0A  /** 
@@ -3292,25 +3292,16 @@
 w. */%0A  
-@Purpose 
 public f
@@ -3301,24 +3301,33 @@
 ublic final 
+@Purpose 
 int purpose;
@@ -3454,154 +3454,66 @@
  /**
-%0A   * C
+ @dep
 re
+c
 ate
-s a new overlay info.%0A   *%0A   * @param view The view that is overlaying the player.%0A   * @param purpose The purpose of the view.%0A   */
+d Use %7B@link Builder%7D instead. */%0A  @Deprecated
 %0A  p
@@ -3634,249 +3634,66 @@
  /**
-%0A   * C
+ @dep
 re
+c
 ate
-s a new overlay info.%0A   *%0A   * @param view The view that is overlaying the player.%0A   * @param purpose The purpose of the view.%0A   * @param detailedReason An optional, detailed reason that the view is on top of the player.%0A   */
+d Use %7B@link Builder%7D instead. */%0A  @Deprecated
 %0A  p

Add AdOverlayInfo.Builder and tweak @Purpose IntDef definition