IndicatorControlBar.java revision ab2ffa88872149978823c3184d0af162d3cdca13
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 17package com.android.camera.ui; 18 19import com.android.camera.PreferenceGroup; 20import com.android.camera.R; 21 22import android.content.Context; 23import android.util.AttributeSet; 24import android.view.MotionEvent; 25import android.view.View; 26import android.widget.ImageView; 27 28/** 29 * A view that contains the top-level indicator control. 30 */ 31public class IndicatorControlBar extends IndicatorControl implements 32 View.OnClickListener, View.OnTouchListener { 33 private static final String TAG = "IndicatorControlBar"; 34 35 private ImageView mZoomIcon; 36 private ImageView mSecondLevelIcon; 37 38 public IndicatorControlBar(Context context, AttributeSet attrs) { 39 super(context, attrs); 40 } 41 42 public void initialize(Context context, PreferenceGroup group, 43 String flashSetting, boolean zoomSupported) { 44 // From UI spec, we have camera_flash setting on the first level. 45 setPreferenceGroup(group); 46 addControls(new String[] {flashSetting}, null); 47 48 // Add CameraPicker control. 49 initializeCameraPicker(); 50 51 // add Zoom Icon. 52 if (zoomSupported) { 53 mZoomIcon = (ImageView) findViewById(R.id.zoom_control_icon); 54 mZoomIcon.setOnTouchListener(this); 55 mZoomIcon.setVisibility(View.VISIBLE); 56 } 57 58 mSecondLevelIcon = (ImageView) findViewById(R.id.second_level_indicator_bar_icon); 59 mSecondLevelIcon.setOnClickListener(this); 60 requestLayout(); 61 } 62 63 public boolean onTouch(View v, MotionEvent event) { 64 dismissSettingPopup(); 65 if (event.getAction() == MotionEvent.ACTION_DOWN) { 66 mOnIndicatorEventListener.onIndicatorEvent( 67 OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL); 68 return true; 69 } 70 return false; 71 } 72 73 public void onClick(View view) { 74 dismissSettingPopup(); 75 // Only for the click on mSecondLevelIcon. 76 mOnIndicatorEventListener.onIndicatorEvent( 77 OnIndicatorEventListener.EVENT_ENTER_SECOND_LEVEL_INDICATOR_BAR); 78 } 79 80 @Override 81 protected void onLayout( 82 boolean changed, int left, int top, int right, int bottom) { 83 // Layout the static components. 84 super.onLayout(changed, left, top, right, bottom); 85 86 int count = getChildCount(); 87 if (count == 0) return; 88 int width = right - left; 89 int offset = 0; 90 91 for (int i = 0 ; i < count ; i++) { 92 View view = getChildAt(i); 93 if (view instanceof IndicatorButton) { 94 view.layout(0, offset, width, offset + width); 95 offset += width; 96 } 97 } 98 if (mCameraPicker != null) mCameraPicker.layout(0, offset, width, offset + width); 99 } 100} 101