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 IndicatorControlBar(Context context, AttributeSet attrs)43 public IndicatorControlBar(Context context, AttributeSet attrs) { 44 super(context, attrs); 45 } 46 47 @Override onFinishInflate()48 protected void onFinishInflate() { 49 mSecondLevelIcon = (ImageView) 50 findViewById(R.id.second_level_indicator_bar_icon); 51 mSecondLevelIcon.setOnClickListener(this); 52 } 53 initialize(Context context, PreferenceGroup group, boolean zoomSupported)54 public void initialize(Context context, PreferenceGroup group, 55 boolean zoomSupported) { 56 setPreferenceGroup(group); 57 58 // Add CameraPicker control. 59 initializeCameraPicker(); 60 61 // Add the ZoomControl if supported. 62 if (zoomSupported) { 63 mZoomControl = (ZoomControlBar) findViewById(R.id.zoom_control); 64 mZoomControl.setVisibility(View.VISIBLE); 65 } 66 requestLayout(); 67 } 68 69 @Override dispatchTouchEvent(MotionEvent event)70 public boolean dispatchTouchEvent(MotionEvent event) { 71 super.dispatchTouchEvent(event); 72 // We need to consume the event, or it will trigger tap-to-focus. 73 return true; 74 } 75 onClick(View view)76 public void onClick(View view) { 77 dismissSettingPopup(); 78 // Only for the click on mSecondLevelIcon. 79 mOnIndicatorEventListener.onIndicatorEvent( 80 OnIndicatorEventListener.EVENT_ENTER_SECOND_LEVEL_INDICATOR_BAR); 81 } 82 83 @Override onLayout( boolean changed, int left, int top, int right, int bottom)84 protected void onLayout( 85 boolean changed, int left, int top, int right, int bottom) { 86 int padding = getPaddingTop(); 87 88 int count = getChildCount(); 89 if (count == 0) return; 90 int width = right - left; 91 92 // First indicator will be CameraPicker if exists. 93 if (mCameraPicker != null) { 94 mCameraPicker.layout(0, padding, width, padding + width); 95 } 96 97 // Layout the zoom control if required. 98 int offset = padding + width; // the padding and the icon height 99 if (mZoomControl != null) { 100 mZoomControl.layout(0, offset, width, bottom - top - offset); 101 } 102 103 mSecondLevelIcon.layout(0, bottom - top - offset, width, bottom - top); 104 } 105 106 @Override setEnabled(boolean enabled)107 public void setEnabled(boolean enabled) { 108 super.setEnabled(enabled); 109 if (mCurrentMode == MODE_VIDEO) { 110 mSecondLevelIcon.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); 111 } else { 112 // We also disable the zoom button during snapshot. 113 enableZoom(enabled); 114 } 115 mSecondLevelIcon.setEnabled(enabled); 116 } 117 enableZoom(boolean enabled)118 public void enableZoom(boolean enabled) { 119 if (mZoomControl != null) mZoomControl.setEnabled(enabled); 120 } 121 } 122