From 301d5d5dc22bbfe1319df5871c0c2eaf6ee8d5ee Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Thu, 4 Jul 2019 14:10:55 -0500 Subject: [PATCH] Add default to controls --- .../com/otaliastudios/cameraview/controls/Audio.java | 5 +++-- .../cameraview/controls/ControlParser.java | 12 ++++++++++++ .../otaliastudios/cameraview/controls/Engine.java | 5 +++-- .../com/otaliastudios/cameraview/controls/Flash.java | 5 +++-- .../com/otaliastudios/cameraview/controls/Grid.java | 5 +++-- .../com/otaliastudios/cameraview/controls/Hdr.java | 5 +++-- .../com/otaliastudios/cameraview/controls/Mode.java | 5 +++-- .../otaliastudios/cameraview/controls/Preview.java | 5 +++-- .../cameraview/controls/VideoCodec.java | 5 +++-- .../cameraview/controls/WhiteBalance.java | 5 +++-- 10 files changed, 39 insertions(+), 18 deletions(-) diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Audio.java b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Audio.java index a1a03f0a..4a679960 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Audio.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Audio.java @@ -3,6 +3,7 @@ package com.otaliastudios.cameraview.controls; import com.otaliastudios.cameraview.CameraView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** @@ -34,7 +35,7 @@ public enum Audio implements Control { return value; } - @Nullable + @NonNull static Audio fromValue(int value) { Audio[] list = Audio.values(); for (Audio action : list) { @@ -42,6 +43,6 @@ public enum Audio implements Control { return action; } } - return null; + return DEFAULT; } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/ControlParser.java b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/ControlParser.java index c81f9549..6d8a1b1d 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/ControlParser.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/ControlParser.java @@ -6,6 +6,7 @@ import android.content.res.TypedArray; import com.otaliastudios.cameraview.R; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; /** * Parses controls from XML attributes. @@ -36,42 +37,53 @@ public class ControlParser { this.engine = array.getInteger(R.styleable.CameraView_cameraEngine, Engine.DEFAULT.value()); } + @NonNull public Preview getPreview() { return Preview.fromValue(preview); } + @NonNull public Facing getFacing() { + //noinspection ConstantConditions return Facing.fromValue(facing); } + @NonNull public Flash getFlash() { return Flash.fromValue(flash); } + @NonNull public Grid getGrid() { return Grid.fromValue(grid); } + @NonNull public Mode getMode() { return Mode.fromValue(mode); } + @NonNull public WhiteBalance getWhiteBalance() { return WhiteBalance.fromValue(whiteBalance); } + @NonNull public Hdr getHdr() { return Hdr.fromValue(hdr); } + @NonNull public Audio getAudio() { return Audio.fromValue(audio); } + @NonNull public VideoCodec getVideoCodec() { return VideoCodec.fromValue(videoCodec); } + @NonNull public Engine getEngine() { return Engine.fromValue(engine); } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Engine.java b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Engine.java index c3336d4b..017b7082 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Engine.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Engine.java @@ -3,6 +3,7 @@ package com.otaliastudios.cameraview.controls; import com.otaliastudios.cameraview.CameraView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** @@ -35,7 +36,7 @@ public enum Engine implements Control { return value; } - @Nullable + @NonNull static Engine fromValue(int value) { Engine[] list = Engine.values(); for (Engine action : list) { @@ -43,6 +44,6 @@ public enum Engine implements Control { return action; } } - return null; + return DEFAULT; } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Flash.java b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Flash.java index cf98c91d..224df813 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Flash.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Flash.java @@ -4,6 +4,7 @@ package com.otaliastudios.cameraview.controls; import com.otaliastudios.cameraview.CameraOptions; import com.otaliastudios.cameraview.CameraView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** @@ -56,7 +57,7 @@ public enum Flash implements Control { return value; } - @Nullable + @NonNull static Flash fromValue(int value) { Flash[] list = Flash.values(); for (Flash action : list) { @@ -64,6 +65,6 @@ public enum Flash implements Control { return action; } } - return null; + return DEFAULT; } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Grid.java b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Grid.java index d452935d..6b26ffd5 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Grid.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Grid.java @@ -3,6 +3,7 @@ package com.otaliastudios.cameraview.controls; import com.otaliastudios.cameraview.CameraView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** @@ -46,7 +47,7 @@ public enum Grid implements Control { return value; } - @Nullable + @NonNull static Grid fromValue(int value) { Grid[] list = Grid.values(); for (Grid action : list) { @@ -54,6 +55,6 @@ public enum Grid implements Control { return action; } } - return null; + return DEFAULT; } } \ No newline at end of file diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Hdr.java b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Hdr.java index 9131d34e..f16516c3 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Hdr.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Hdr.java @@ -3,6 +3,7 @@ package com.otaliastudios.cameraview.controls; import com.otaliastudios.cameraview.CameraView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** @@ -34,7 +35,7 @@ public enum Hdr implements Control { return value; } - @Nullable + @NonNull static Hdr fromValue(int value) { Hdr[] list = Hdr.values(); for (Hdr action : list) { @@ -42,6 +43,6 @@ public enum Hdr implements Control { return action; } } - return null; + return DEFAULT; } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Mode.java b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Mode.java index 1352e626..23d838e2 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Mode.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Mode.java @@ -3,6 +3,7 @@ package com.otaliastudios.cameraview.controls; import com.otaliastudios.cameraview.CameraView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import java.io.File; @@ -46,7 +47,7 @@ public enum Mode implements Control { return value; } - @Nullable + @NonNull static Mode fromValue(int value) { Mode[] list = Mode.values(); for (Mode action : list) { @@ -54,6 +55,6 @@ public enum Mode implements Control { return action; } } - return null; + return DEFAULT; } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Preview.java b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Preview.java index 7e6dd271..9e8b9aee 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Preview.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/Preview.java @@ -3,6 +3,7 @@ package com.otaliastudios.cameraview.controls; import com.otaliastudios.cameraview.CameraView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** @@ -44,7 +45,7 @@ public enum Preview implements Control { return value; } - @Nullable + @NonNull static Preview fromValue(int value) { Preview[] list = Preview.values(); for (Preview action : list) { @@ -52,6 +53,6 @@ public enum Preview implements Control { return action; } } - return null; + return DEFAULT; } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/VideoCodec.java b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/VideoCodec.java index 1b136953..92cdc761 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/VideoCodec.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/VideoCodec.java @@ -3,6 +3,7 @@ package com.otaliastudios.cameraview.controls; import com.otaliastudios.cameraview.CameraView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** @@ -41,7 +42,7 @@ public enum VideoCodec implements Control { return value; } - @Nullable + @NonNull static VideoCodec fromValue(int value) { VideoCodec[] list = VideoCodec.values(); for (VideoCodec action : list) { @@ -49,6 +50,6 @@ public enum VideoCodec implements Control { return action; } } - return null; + return DEFAULT; } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/WhiteBalance.java b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/WhiteBalance.java index 20150e7e..a701aa6b 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/controls/WhiteBalance.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/controls/WhiteBalance.java @@ -4,6 +4,7 @@ package com.otaliastudios.cameraview.controls; import com.otaliastudios.cameraview.CameraOptions; import com.otaliastudios.cameraview.CameraView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** @@ -65,7 +66,7 @@ public enum WhiteBalance implements Control { return value; } - @Nullable + @NonNull static WhiteBalance fromValue(int value) { WhiteBalance[] list = WhiteBalance.values(); for (WhiteBalance action : list) { @@ -73,6 +74,6 @@ public enum WhiteBalance implements Control { return action; } } - return null; + return DEFAULT; } } \ No newline at end of file