SecondLevelIndicatorControlBar.java revision ff45331706e2fe361b4ff736d90b0ad4af0e7be9
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 camera setting indicators which are spread over a 30 * vertical bar in preview frame. 31 */ 32public class SecondLevelIndicatorControlBar extends IndicatorControl implements 33 View.OnClickListener { 34 private static final String TAG = "SecondLevelIndicatorControlBar"; 35 private ImageView mCloseIcon; 36 int mDegree = 0; 37 int mSelectedIndex = -1; 38 39 public SecondLevelIndicatorControlBar(Context context, AttributeSet attrs) { 40 super(context, attrs); 41 } 42 43 @Override 44 public void initialize(Context context, PreferenceGroup group, 45 String[] keys, String[] otherSettingKeys) { 46 if (mCloseIcon == null) { 47 mCloseIcon = new ImageView(context); 48 mCloseIcon.setImageResource(R.drawable.btn_close_settings); 49 mCloseIcon.setOnClickListener(this); 50 addView(mCloseIcon); 51 } 52 super.initialize(context, group, keys, otherSettingKeys); 53 if (mDegree != 0) setDegree(mDegree); 54 } 55 56 public void onClick(View view) { 57 dismissSettingPopup(); 58 mOnIndicatorEventListener.onIndicatorEvent( 59 OnIndicatorEventListener.EVENT_LEAVE_SECOND_LEVEL_INDICATOR_BAR); 60 } 61 62 @Override 63 public boolean dispatchTouchEvent(MotionEvent event) { 64 if (!onFilterTouchEventForSecurity(event)) return false; 65 66 int action = event.getAction(); 67 if (!isEnabled()) return false; 68 69 double x = (double) event.getX(); 70 double y = (double) event.getY(); 71 int height = getHeight(); 72 if (x > getWidth()) x = getWidth(); 73 if (y >= height) y = height - 1; 74 75 int index = (int) (y * getChildCount()) / height; 76 View b = getChildAt(index); 77 b.dispatchTouchEvent(event); 78 if ((mSelectedIndex != -1) && (index != mSelectedIndex)) { 79 View v = getChildAt(mSelectedIndex); 80 if (v instanceof AbstractIndicatorButton) { 81 AbstractIndicatorButton c = (AbstractIndicatorButton) v; 82 event.setAction(MotionEvent.ACTION_CANCEL); 83 c.dispatchTouchEvent(event); 84 c.dismissPopup(); 85 } 86 87 if (action == MotionEvent.ACTION_MOVE) { 88 event.setAction(MotionEvent.ACTION_DOWN); 89 b.dispatchTouchEvent(event); 90 } 91 } 92 mSelectedIndex = index; 93 return true; 94 } 95 96 @Override 97 public void setDegree(int degree) { 98 mDegree = degree; 99 super.setDegree(degree); 100 } 101 102 @Override 103 protected void onLayout( 104 boolean changed, int left, int top, int right, int bottom) { 105 int count = getChildCount(); 106 if (count == 0) return; 107 int width = right - left; 108 int height = bottom - top; 109 int h = height / count; 110 for (int i = 0; i < count; i++) { 111 getChildAt(i).layout(0, top + i * height / count, width, 112 top + i * height / count + h); 113 } 114 } 115} 116