1 /* 2 * Copyright (C) 2014 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 17 package com.android.camera.widget; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.View; 22 import android.widget.LinearLayout; 23 24 import com.android.camera2.R; 25 26 public class AspectRatioSelector extends LinearLayout { 27 public static enum AspectRatio { 28 ASPECT_RATIO_4x3, 29 ASPECT_RATIO_16x9 30 }; 31 32 private AspectRatio mAspectRatio = AspectRatio.ASPECT_RATIO_4x3; 33 private View mAspectRatio4x3Button; 34 private View mAspectRatio16x9Button; 35 AspectRatioSelector(Context context, AttributeSet attrs)36 public AspectRatioSelector(Context context, AttributeSet attrs) { 37 super(context, attrs); 38 } 39 40 @Override onFinishInflate()41 public void onFinishInflate() { 42 mAspectRatio4x3Button = findViewById(R.id.aspect_ratio_4x3_button); 43 mAspectRatio4x3Button.setOnClickListener(new OnClickListener() { 44 @Override 45 public void onClick(View v) { 46 setAspectRatio(AspectRatio.ASPECT_RATIO_4x3); 47 } 48 }); 49 mAspectRatio16x9Button = findViewById(R.id.aspect_ratio_16x9_button); 50 mAspectRatio16x9Button.setOnClickListener(new OnClickListener() { 51 @Override 52 public void onClick(View v) { 53 setAspectRatio(AspectRatio.ASPECT_RATIO_16x9); 54 } 55 }); 56 } 57 setAspectRatio(AspectRatio aspectRatio)58 public void setAspectRatio(AspectRatio aspectRatio) { 59 if (aspectRatio == AspectRatio.ASPECT_RATIO_4x3) { 60 // Select 4x3 view. 61 mAspectRatio4x3Button.setSelected(true); 62 // Unselect 16x9 view. 63 mAspectRatio16x9Button.setSelected(false); 64 } else if (aspectRatio == AspectRatio.ASPECT_RATIO_16x9) { 65 // Select 16x9 view. 66 mAspectRatio16x9Button.setSelected(true); 67 // Unselect 4x3 view. 68 mAspectRatio4x3Button.setSelected(false); 69 } else { 70 // Log error. 71 return; 72 } 73 mAspectRatio = aspectRatio; 74 } 75 getAspectRatio()76 public AspectRatio getAspectRatio() { 77 return mAspectRatio; 78 } 79 } 80