• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.ui;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.util.Log;
22 import android.widget.RelativeLayout;
23 
24 /**
25  * A layout which handles the the width of the control panel, which contains
26  * the shutter button, thumbnail, front/back camera picker, and mode picker.
27  * The purpose of this is to have a consistent width of control panel in camera,
28  * camcorder, and panorama modes. The control panel can also be GONE and the
29  * preview can expand to full-screen in panorama.
30  */
31 public class ControlPanelLayout extends RelativeLayout {
32     private static final String TAG = "ControlPanelLayout";
33 
ControlPanelLayout(Context context, AttributeSet attrs)34     public ControlPanelLayout(Context context, AttributeSet attrs) {
35         super(context, attrs);
36     }
37 
38     @Override
onMeasure(int widthSpec, int heightSpec)39     protected void onMeasure(int widthSpec, int heightSpec) {
40         int widthSpecSize = MeasureSpec.getSize(widthSpec);
41         int heightSpecSize = MeasureSpec.getSize(heightSpec);
42         int widthMode = MeasureSpec.getMode(widthSpec);
43         int measuredWidth = 0;
44 
45         if (widthSpecSize > 0 && heightSpecSize > 0 && widthMode == MeasureSpec.AT_MOST) {
46             // Calculate how big 4:3 preview occupies. Then deduct it from the
47             // width of the parent.
48             measuredWidth = (int) (widthSpecSize - heightSpecSize / 3.0 * 4.0 - 16);
49         } else {
50             Log.e(TAG, "layout_width of ControlPanelLayout should be wrap_content");
51         }
52 
53         // Make sure the width is bigger than the minimum width.
54         int minWidth = getSuggestedMinimumWidth();
55         if (minWidth > measuredWidth) {
56             measuredWidth = minWidth;
57         }
58 
59         // The width cannot be bigger than the constraint.
60         if (widthMode == MeasureSpec.AT_MOST && measuredWidth > widthSpecSize) {
61             measuredWidth = widthSpecSize;
62         }
63 
64         super.onMeasure(MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY),
65                 heightSpec);
66     }
67 }
68