// Path: app/src/main/java/com/google/firebase/ml/md/java/camera/GraphicOverlay.java
// public class GraphicOverlay extends View {
//   private final Object lock = new Object();
// 
//   private int previewWidth;
//   private float widthScaleFactor = 1.0f;
//   private int previewHeight;
//   private float heightScaleFactor = 1.0f;
//   private final List<Graphic> graphics = new ArrayList<>();
// 
//   /**
//    * Base class for a custom graphics object to be rendered within the graphic overlay. Subclass
//    * this and implement the {@link Graphic#draw(Canvas)} method to define the graphics element. Add
//    * instances to the overlay using {@link GraphicOverlay#add(Graphic)}.
//    */
//   public abstract static class Graphic {
//     protected final GraphicOverlay overlay;
//     protected final Context context;
// 
//     protected Graphic(GraphicOverlay overlay) {
//       this.overlay = overlay;
//       this.context = overlay.getContext();
//     }
// 
//     /** Draws the graphic on the supplied canvas. */
//     protected abstract void draw(Canvas canvas);
//   }
// 
//   public GraphicOverlay(Context context, AttributeSet attrs) {
//     super(context, attrs);
//   }
// 
//   /** Removes all graphics from the overlay. */
//   public void clear() {
//     synchronized (lock) {
//       graphics.clear();
//     }
//     postInvalidate();
//   }
// 
//   /** Adds a graphic to the overlay. */
//   public void add(Graphic graphic) {
//     synchronized (lock) {
//       graphics.add(graphic);
//     }
//   }
// 
//   /**
//    * Sets the camera attributes for size and facing direction, which informs how to transform image
//    * coordinates later.
//    */
//   public void setCameraInfo(CameraSource cameraSource) {
//     Size previewSize = cameraSource.getPreviewSize();
//     if (Utils.isPortraitMode(getContext())) {
//       // Swap width and height when in portrait, since camera's natural orientation is landscape.
//       previewWidth = previewSize.getHeight();
//       previewHeight = previewSize.getWidth();
//     } else {
//       previewWidth = previewSize.getWidth();
//       previewHeight = previewSize.getHeight();
//     }
//   }
// 
//   public float translateX(float x) {
//     return x * widthScaleFactor;
//   }
// 
//   public float translateY(float y) {
//     return y * heightScaleFactor;
//   }
// 
//   /**
//    * Adjusts the {@code rect}'s coordinate from the preview's coordinate system to the view
//    * coordinate system.
//    */
//   public RectF translateRect(Rect rect) {
//     return new RectF(
//         translateX(rect.left),
//         translateY(rect.top),
//         translateX(rect.right),
//         translateY(rect.bottom));
//   }
// 
//   /** Draws the overlay with its associated graphic objects. */
//   @Override
//   protected void onDraw(Canvas canvas) {
//     super.onDraw(canvas);
// 
//     if (previewWidth > 0 && previewHeight > 0) {
//       widthScaleFactor = (float) getWidth() / previewWidth;
//       heightScaleFactor = (float) getHeight() / previewHeight;
//     }
// 
//     synchronized (lock) {
//       for (Graphic graphic : graphics) {
//         graphic.draw(canvas);
//       }
//     }
//   }
// }
// 
// Path: app/src/main/java/com/google/firebase/ml/md/java/camera/GraphicOverlay.java
// public abstract static class Graphic {
//   protected final GraphicOverlay overlay;
//   protected final Context context;
// 
//   protected Graphic(GraphicOverlay overlay) {
//     this.overlay = overlay;
//     this.context = overlay.getContext();
//   }
// 
//   /** Draws the graphic on the supplied canvas. */
//   protected abstract void draw(Canvas canvas);
// }


import com.google.firebase.ml.md.R;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.Shader.TileMode;
import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;
import com.google.firebase.ml.md.java.camera.GraphicOverlay;
import com.google.firebase.ml.md.java.camera.GraphicOverlay.Graphic;
/*
 * Copyright 2019 Google LLC
 *
 * 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
 *
 *     https://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.firebase.ml.md.java.objectdetection;


/**
 * Draws the detected object info over the camera preview for multiple objects detection mode.
 */
class ObjectGraphicInMultiMode extends Graphic {

  private final DetectedObject object;
  private final ObjectConfirmationController confirmationController;

  private final Paint boxPaint;
  private final Paint scrimPaint;
  private final Paint eraserPaint;
  @ColorInt
  private final int boxGradientStartColor;
  @ColorInt
  private final int boxGradientEndColor;
  private final int boxCornerRadius;
  private final int minBoxLen;

  ObjectGraphicInMultiMode(
      GraphicOverlay overlay,
      DetectedObject object,
      ObjectConfirmationController confirmationController) {
    super(overlay);

    this.object = object;
    this.confirmationController = confirmationController;

    Resources resources = context.getResources();
    boxPaint = new Paint();
    boxPaint.setStyle(Style.STROKE);
    boxPaint.setStrokeWidth(
        resources.getDimensionPixelOffset(
            confirmationController.isConfirmed()
                ? R.dimen.bounding_box_confirmed_stroke_width
// Path: app/src/main/java/com/google/firebase/ml/md/java/camera/GraphicOverlay.java
// public class GraphicOverlay extends View {
//   private final Object lock = new Object();
// 
//   private int previewWidth;
//   private float widthScaleFactor = 1.0f;
//   private int previewHeight;
//   private float heightScaleFactor = 1.0f;
//   private final List<Graphic> graphics = new ArrayList<>();
// 
//   /**
//    * Base class for a custom graphics object to be rendered within the graphic overlay. Subclass
//    * this and implement the {@link Graphic#draw(Canvas)} method to define the graphics element. Add
//    * instances to the overlay using {@link GraphicOverlay#add(Graphic)}.
//    */
//   public abstract static class Graphic {
//     protected final GraphicOverlay overlay;
//     protected final Context context;
// 
//     protected Graphic(GraphicOverlay overlay) {
//       this.overlay = overlay;
//       this.context = overlay.getContext();
//     }
// 
//     /** Draws the graphic on the supplied canvas. */
//     protected abstract void draw(Canvas canvas);
//   }
// 
//   public GraphicOverlay(Context context, AttributeSet attrs) {
//     super(context, attrs);
//   }
// 
//   /** Removes all graphics from the overlay. */
//   public void clear() {
//     synchronized (lock) {
//       graphics.clear();
//     }
//     postInvalidate();
//   }
// 
//   /** Adds a graphic to the overlay. */
//   public void add(Graphic graphic) {
//     synchronized (lock) {
//       graphics.add(graphic);
//     }
//   }
// 
//   /**
//    * Sets the camera attributes for size and facing direction, which informs how to transform image
//    * coordinates later.
//    */
//   public void setCameraInfo(CameraSource cameraSource) {
//     Size previewSize = cameraSource.getPreviewSize();
//     if (Utils.isPortraitMode(getContext())) {
//       // Swap width and height when in portrait, since camera's natural orientation is landscape.
//       previewWidth = previewSize.getHeight();
//       previewHeight = previewSize.getWidth();
//     } else {
//       previewWidth = previewSize.getWidth();
//       previewHeight = previewSize.getHeight();
//     }
//   }
// 
//   public float translateX(float x) {
//     return x * widthScaleFactor;
//   }
// 
//   public float translateY(float y) {
//     return y * heightScaleFactor;
//   }
// 
//   /**
//    * Adjusts the {@code rect}'s coordinate from the preview's coordinate system to the view
//    * coordinate system.
//    */
//   public RectF translateRect(Rect rect) {
//     return new RectF(
//         translateX(rect.left),
//         translateY(rect.top),
//         translateX(rect.right),
//         translateY(rect.bottom));
//   }
// 
//   /** Draws the overlay with its associated graphic objects. */
//   @Override
//   protected void onDraw(Canvas canvas) {
//     super.onDraw(canvas);
// 
//     if (previewWidth > 0 && previewHeight > 0) {
//       widthScaleFactor = (float) getWidth() / previewWidth;
//       heightScaleFactor = (float) getHeight() / previewHeight;
//     }
// 
//     synchronized (lock) {
//       for (Graphic graphic : graphics) {
//         graphic.draw(canvas);
//       }
//     }
//   }
// }
// 
// Path: app/src/main/java/com/google/firebase/ml/md/java/camera/GraphicOverlay.java
// public abstract static class Graphic {
//   protected final GraphicOverlay overlay;
//   protected final Context context;
// 
//   protected Graphic(GraphicOverlay overlay) {
//     this.overlay = overlay;
//     this.context = overlay.getContext();
//   }
// 
//   /** Draws the graphic on the supplied canvas. */
//   protected abstract void draw(Canvas canvas);
// }


// Path: app/src/main/java/com/google/firebase/ml/md/java/objectdetection/ObjectGraphicInMultiMode.java
import com.google.firebase.ml.md.R;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.Shader.TileMode;
import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;
import com.google.firebase.ml.md.java.camera.GraphicOverlay;
import com.google.firebase.ml.md.java.camera.GraphicOverlay.Graphic;

/*
 * Copyright 2019 Google LLC
 *
 * 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
 *
 *     https://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.firebase.ml.md.java.objectdetection;


/**
 * Draws the detected object info over the camera preview for multiple objects detection mode.
 */
class ObjectGraphicInMultiMode extends Graphic {

  private final DetectedObject object;
  private final ObjectConfirmationController confirmationController;

  private final Paint boxPaint;
  private final Paint scrimPaint;
  private final Paint eraserPaint;
  @ColorInt
  private final int boxGradientStartColor;
  @ColorInt
  private final int boxGradientEndColor;
  private final int boxCornerRadius;
  private final int minBoxLen;

  ObjectGraphicInMultiMode(
      GraphicOverlay overlay,
      DetectedObject object,
      ObjectConfirmationController confirmationController) {
    super(overlay);

    this.object = object;
    this.confirmationController = confirmationController;

    Resources resources = context.getResources();
    boxPaint = new Paint();
    boxPaint.setStyle(Style.STROKE);
    boxPaint.setStrokeWidth(
        resources.getDimensionPixelOffset(
            confirmationController.isConfirmed()
                ? R.dimen.bounding_box_confirmed_stroke_width
                : R.dimen.bounding_box_stroke_width));