Class PreviewScalingStrategy
- java.lang.Object
-
- com.journeyapps.barcodescanner.camera.PreviewScalingStrategy
-
- Direct Known Subclasses:
CenterCropStrategy,FitCenterStrategy,FitXYStrategy,LegacyPreviewScalingStrategy
public abstract class PreviewScalingStrategy extends Object
-
-
Constructor Summary
Constructors Constructor Description PreviewScalingStrategy()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description List<Size>getBestPreviewOrder(List<Size> sizes, Size desired)Sort previews based on their suitability.SizegetBestPreviewSize(List<Size> sizes, Size desired)Choose the best preview size, based on our viewfinder size.protected floatgetScore(Size size, Size desired)Get a score for our size.abstract RectscalePreview(Size previewSize, Size viewfinderSize)Scale and position the preview relative to the viewfinder.
-
-
-
Method Detail
-
getBestPreviewSize
public Size getBestPreviewSize(List<Size> sizes, Size desired)
Choose the best preview size, based on our viewfinder size. The default implementation lets subclasses calculate a score for each size, the picks the one with the best score. The sizes list may be reordered by this call.- Parameters:
sizes- supported preview sizes, containing at least one size. Sizes are in natural camera orientation.desired- The desired viewfinder size, in the same orientation- Returns:
- the best preview size, never null
-
getBestPreviewOrder
public List<Size> getBestPreviewOrder(List<Size> sizes, Size desired)
Sort previews based on their suitability. In most cases,getBestPreviewSize(List, Size)should be used instead. The sizes list may be reordered by this call.- Parameters:
sizes- supported preview sizes, containing at least one size. Sizes are in natural camera orientation.desired- The desired viewfinder size, in the same orientation- Returns:
- an ordered list, best preview first
-
getScore
protected float getScore(Size size, Size desired)
Get a score for our size. 1.0 is perfect (exact match). 0.0 means we can't use it at all. Subclasses should override this.- Parameters:
size- the camera preview size (that can be scaled)desired- the viewfinder size- Returns:
- the score
-
scalePreview
public abstract Rect scalePreview(Size previewSize, Size viewfinderSize)
Scale and position the preview relative to the viewfinder.- Parameters:
previewSize- the size of the preview (camera), in current display orientationviewfinderSize- the size of the viewfinder (display), in current display orientation- Returns:
- a rect placing the preview, relative to the viewfinder
-
-