public class

HVTView

extends RelativeLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.RelativeLayout
         ↳ com.hvt.horizonSDK.HVTView

Class Overview

HVTView is a android.view.View View that can be attached to HVTCamera to preview video.

HVTView enables gestures that provide the following functionality:

  • Tapping on the view, sets a focus area to the camera. After a while, it turns to continuous autofocus.
  • Long tapping, sets a focus area without setting autofocus afterwards. A new tap, will turn continuous autofocus back on.
  • The user can pinch in/out to zoom in/out.
  • Double tapping on the view, toggles the current setFillMode(FillMode) ) fill mode}

Usage

You use this view in conjunction with an HVTCamera instance, as illustrated in the following code fragment:

HVTView view = // an instance created from code or from XML
hvtCameraInstance.attachPreviewView(view);  

If the activity that owns the view is destroyed but the HVTCamera instance is kept alive, call detachPreviewView(HVTView), in order to avoid leaking the view.

The view needs to know the screen rotation, in order to render the camera preview frames with correct orientation. This information is derived internally by the HVTCamera instance it is attached to. So, make sure that you have set the correct screen rotation by calling setScreenRotation(int)

You can set setEnabled(boolean) to false, to stop previewing video. This reduces CPU/GPU usage and reduces battery drain.

Layout positioning

HVTView contains a SurfaceView, which is a special view in terms of how it is composited in relation to the other views in the view hierarchy. It is best to place it either on the bottom of the view hierarchy and have other views render on top of it, or at the top of the view hierarchy.

In order to avoid overdraw, it's best to perform the following optimization steps:

  • In the activity theme, remove the background by setting:
    <item name="android:windowBackground">@null</item>
  • Set transparent background color to the parent of HVTView:
    android:background="@android:color/transparent

If you have HVTView in just a portion of your layout and not fullscreen, these optimizations may produce weird behaviour in other views.

Customizing

According to the current view type , HVTView may show the actual camera frame or the leveled frame.

You can call setFillMode(FillMode) to change the way the video preview fits inside the view's bounds.

You can customize the focus circle that is drawn when user "taps to focus" by styling the following XML attributes:

<attr name="hvt_focus_circle_primary" format="color"/>
<attr name="hvt_focus_circle_secondary" format="color"/>
<attr name="hvt_focus_rect_init_stroke_width" format="dimension"/>
<attr name="hvt_focus_rect_success_stroke_width" format="dimension"/>  

Summary

Nested Classes
enum HVTView.FillMode Enum indicating how the video preview is displayed within HVTView's bounds. 
enum HVTView.ViewType Enum indicating if HVTView will show the actual camera frame or the leveled frame. 
[Expand]
Inherited Constants
From class android.widget.RelativeLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
HVTView(Context context)
HVTView(Context context, AttributeSet attrs)
Public Methods
boolean doubleTapChangesFillMode()
Returns if double tapping changes the fill mode.
int getCropRegionTintColor()
Returns the color used to tint the crop region.
HVTView.FillMode getFillMode()
Gets the current fill mode.
float[] getOutputFramePlacement()
Returns the current width, height and angle of the crop region.
HVTView.ViewType getViewType()
Gets the view type of the view.
boolean isEnabled()
Returns if the view is enabled or disabled.
boolean isHUDVisible()
Gets if the HUD is visible or not.
boolean isTapToFocusEnabled()
Returns if tap to focus is enabled.
void setCropRegionTintColor(int color)
Sets the tint color for the dark area of the crop region.
void setDoubleTapToChangeFillMode(boolean change)
Allows double tapping to change the fill mode.
void setEnabled(boolean enabled)
Enables or disables the view.
void setFillMode(HVTView.FillMode fillMode)
Specifies how the video preview is displayed within the view's bounds.
void setHUDVisible(boolean visible)
Specifies whether HUD elements, such as the crop region and corners, are shown.
void setTapToFocus(boolean enabled)
Enables tap to focus.
void setViewType(HVTView.ViewType viewType)
Specifies the view type of the view.
[Expand]
Inherited Methods
From class android.widget.RelativeLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Public Constructors

public HVTView (Context context)

public HVTView (Context context, AttributeSet attrs)

Public Methods

public boolean doubleTapChangesFillMode ()

Returns if double tapping changes the fill mode.

Returns
  • true if allowed, false otherwise

public int getCropRegionTintColor ()

Returns the color used to tint the crop region.

Returns
  • the tint color as defined in Color

public HVTView.FillMode getFillMode ()

Gets the current fill mode.

Returns

public float[] getOutputFramePlacement ()

Returns the current width, height and angle of the crop region.

This is useful if you want to place a thumbnail on top of the crop frame and match its size and rotation.

Do not call this method for every frame. If you are interested just in the angle of the crop region per frame, use onAngleUpdated(float, float).

Returns
  • a float array consisting of the following crop frame's attributes: width in pixels, height in pixels, rotation in degrees or null

public HVTView.ViewType getViewType ()

Gets the view type of the view.

Returns

public boolean isEnabled ()

Returns if the view is enabled or disabled.

Returns
  • true if enabled, false if disabled

public boolean isHUDVisible ()

Gets if the HUD is visible or not.

Returns
  • true if visible, false otherwise

public boolean isTapToFocusEnabled ()

Returns if tap to focus is enabled.

Returns
  • true if enabled, false otherwise

public void setCropRegionTintColor (int color)

Sets the tint color for the dark area of the crop region.

The RGB values of this color will be multiplied with the video. The alpha value is not used. For example set it to DKGRAY for a dark look.

Parameters
color the color used to tint the video as defined in Color

public void setDoubleTapToChangeFillMode (boolean change)

Allows double tapping to change the fill mode.

Parameters
change true to allow, false to now allow double tapping

public void setEnabled (boolean enabled)

Enables or disables the view.

Disabling the view, stops the preview rendering.

Parameters
enabled set to true to enable the view, false to disable it

public void setFillMode (HVTView.FillMode fillMode)

Specifies how the video preview is displayed within the view's bounds.

If doubleTapChangesFillMode() is true, the user can change the fill mode by double tapping.

The property in animated.

The default value is ASPECT_FIT.

Parameters
fillMode the requested fill mode
See Also

public void setHUDVisible (boolean visible)

Specifies whether HUD elements, such as the crop region and corners, are shown.

This property applies only when the view type is set to NORMAL.

Parameters
visible true to render the HUD, false to hide the HUD

public void setTapToFocus (boolean enabled)

Enables tap to focus.

If enabled:

  • Tapping on the view, sets a focus area to the camera. After a while, it turns to continuous autofocus.
  • Long tapping, sets a focus area without setting autofocus afterwards. A new tap, will turn continuous autofocus back on.

The default value is true.

Parameters
enabled `true` enables tap to focus, `false` disables it

public void setViewType (HVTView.ViewType viewType)

Specifies the view type of the view.

When set to NORMAL, HUD elements can be displayed depending on the isHUDVisible() value.

The default value, NORMAL, is best suited for more apps.

Parameters
viewType the view type to set to the view