1 /* 2 * Copyright (C) 2010 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 com.android.camera.PreferenceGroup; 20 import com.android.camera.R; 21 import com.android.camera.Util; 22 23 import android.content.Context; 24 import android.util.AttributeSet; 25 import android.view.MotionEvent; 26 import android.view.View; 27 import android.widget.ImageView; 28 29 /** 30 * A view that contains the top-level indicator control. 31 */ 32 public class IndicatorControlBar extends IndicatorControl implements 33 View.OnClickListener { 34 private static final String TAG = "IndicatorControlBar"; 35 36 // Space between indicator icons. 37 public static final int ICON_SPACING = Util.dpToPixel(16); 38 39 private ImageView mZoomIcon; 40 private ImageView mSecondLevelIcon; 41 private ZoomControlBar mZoomControl; 42 43 public IndicatorControlBar(Context context, AttributeSet attrs) { 44 super(context, attrs); 45 } 46 47 @Override 48 protected void onFinishInflate() { 49 mSecondLevelIcon = (ImageView) 50 findViewById(R.id.second_level_indicator_bar_icon); 51 mSecondLevelIcon.setOnClickListener(this); 52 } 53 54 public void initialize(Context context, PreferenceGroup group, 55 boolean zoomSupported) { 56 setPreferenceGroup(group); 57 58 // Add CameraPicker control. 59 initializeCameraPicker(); 60 if (mCameraPicker != null) { 61 mCameraPicker.setBackgroundResource(R.drawable.bg_pressed); 62 } 63 64 // Add the ZoomControl if supported. 65 if (zoomSupported) { 66 mZoomControl = (ZoomControlBar) findViewById(R.id.zoom_control); 67 mZoomControl.setVisibility(View.VISIBLE); 68 } 69 requestLayout(); 70 } 71 72 @Override 73 public boolean dispatchTouchEvent(MotionEvent event) { 74 super.dispatchTouchEvent(event); 75 // We need to consume the event, or it will trigger tap-to-focus. 76 return true; 77 } 78 79 public void onClick(View view) { 80 dismissSettingPopup(); 81 // Only for the click on mSecondLevelIcon. 82 mOnIndicatorEventListener.onIndicatorEvent( 83 OnIndicatorEventListener.EVENT_ENTER_SECOND_LEVEL_INDICATOR_BAR); 84 } 85 86 @Override 87 protected void onLayout( 88 boolean changed, int left, int top, int right, int bottom) { 89 int count = getChildCount(); 90 if (count == 0) return; 91 92 // We have (equal) paddings at left and right, but no padding at top or 93 // bottom. 94 int padding = getPaddingLeft(); 95 int width = right - left; 96 int height = bottom - top; 97 98 // We want the icons to be square (size x size) 99 int size = height; 100 101 mSecondLevelIcon.layout(padding, 0, padding + size, size); 102 103 // Layout the zoom control if required. 104 if (mZoomControl != null) { 105 mZoomControl.layout(padding + size, 0, width - padding - size, size); 106 } 107 108 if (mCameraPicker != null) { 109 mCameraPicker.layout(width - padding - size, 0, width - padding, size); 110 } 111 } 112 113 @Override 114 public void setEnabled(boolean enabled) { 115 super.setEnabled(enabled); 116 if (mCurrentMode == MODE_VIDEO) { 117 mSecondLevelIcon.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); 118 } else { 119 // We also disable the zoom button during snapshot. 120 enableZoom(enabled); 121 } 122 mSecondLevelIcon.setEnabled(enabled); 123 } 124 125 public void enableZoom(boolean enabled) { 126 if (mZoomControl != null) mZoomControl.setEnabled(enabled); 127 } 128 } 129