1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.google.jetpackcamera.settings.model 17 18 import android.util.Rational 19 import com.google.jetpackcamera.settings.AspectRatio as AspectRatioProto 20 21 enum class AspectRatio(val ratio: Rational) { 22 THREE_FOUR(Rational(3, 4)), 23 NINE_SIXTEEN(Rational(9, 16)), 24 ONE_ONE(Rational(1, 1)); 25 <lambda>null26 val landscapeRatio: Rational by lazy { 27 Rational(ratio.denominator, ratio.numerator) 28 } 29 30 companion object { 31 32 /** returns the AspectRatio enum equivalent of a provided AspectRatioProto */ fromProtonull33 fun fromProto(aspectRatioProto: AspectRatioProto): AspectRatio { 34 return when (aspectRatioProto) { 35 AspectRatioProto.ASPECT_RATIO_NINE_SIXTEEN -> NINE_SIXTEEN 36 AspectRatioProto.ASPECT_RATIO_ONE_ONE -> ONE_ONE 37 38 // defaults to 3:4 aspect ratio 39 AspectRatioProto.ASPECT_RATIO_THREE_FOUR, 40 AspectRatioProto.ASPECT_RATIO_UNDEFINED, 41 AspectRatioProto.UNRECOGNIZED 42 -> THREE_FOUR 43 } 44 } 45 } 46 } 47