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.view.MotionEvent; 22 import android.view.View; 23 import android.view.animation.Animation; 24 import android.view.animation.Animation.AnimationListener; 25 import android.view.animation.AnimationUtils; 26 27 import com.android.camera.CameraPreference.OnPreferenceChangedListener; 28 import com.android.camera.PreferenceGroup; 29 import com.android.camera.R; 30 31 /** 32 * The IndicatorControlBarContainer is an IndicatorControlContainer containing 33 * IndicatorControlBar, SecondLevelIndicatorControlBar and ZoomControlBar for 34 * Phone UI. 35 */ 36 public class IndicatorControlBarContainer extends IndicatorControlContainer { 37 @SuppressWarnings("unused") 38 private static final String TAG = "IndicatorControlBarContainer"; 39 40 private Animation mFadeIn, mFadeOut; 41 private Animation mSecondLevelFadeIn, mSecondLevelFadeOut; 42 private IndicatorControlBar mIndicatorControlBar; 43 private SecondLevelIndicatorControlBar mSecondLevelIndicatorControlBar; 44 45 public IndicatorControlBarContainer(Context context, AttributeSet attrs) { 46 super(context, attrs); 47 mFadeIn = AnimationUtils.loadAnimation( 48 context, R.anim.first_level_fade_in); 49 mFadeOut = AnimationUtils.loadAnimation( 50 context, R.anim.first_level_fade_out); 51 mFadeOut.setAnimationListener(mAnimationListener); 52 mSecondLevelFadeIn = AnimationUtils.loadAnimation( 53 context, R.anim.second_level_fade_in); 54 mSecondLevelFadeOut = AnimationUtils.loadAnimation( 55 context, R.anim.second_level_fade_out); 56 mSecondLevelFadeOut.setAnimationListener(mAnimationListener); 57 } 58 59 @Override 60 protected void onFinishInflate() { 61 mIndicatorControlBar = (IndicatorControlBar) 62 findViewById(R.id.indicator_bar); 63 mIndicatorControlBar.setOnIndicatorEventListener(this); 64 mSecondLevelIndicatorControlBar = (SecondLevelIndicatorControlBar) 65 findViewById(R.id.second_level_indicator_bar); 66 mSecondLevelIndicatorControlBar.setOnIndicatorEventListener(this); 67 } 68 69 @Override 70 public void initialize(Context context, PreferenceGroup group, 71 boolean isZoomSupported, String[] secondLevelKeys, 72 String[] secondLevelOtherSettingKeys) { 73 74 mIndicatorControlBar.initialize(context, group, isZoomSupported); 75 76 mSecondLevelIndicatorControlBar.initialize(context, group, 77 secondLevelKeys, secondLevelOtherSettingKeys); 78 } 79 80 @Override 81 public void setOrientation(int orientation, boolean animation) { 82 mIndicatorControlBar.setOrientation(orientation, animation); 83 mSecondLevelIndicatorControlBar.setOrientation(orientation, animation); 84 } 85 86 @Override 87 public boolean dispatchTouchEvent(MotionEvent event) { 88 if (mIndicatorControlBar.getVisibility() == View.VISIBLE) { 89 return mIndicatorControlBar.dispatchTouchEvent(event); 90 } else if (mSecondLevelIndicatorControlBar.getVisibility() == View.VISIBLE) { 91 return mSecondLevelIndicatorControlBar.dispatchTouchEvent(event); 92 } 93 return true; 94 } 95 96 private AnimationListener mAnimationListener = new AnimationListener() { 97 @Override 98 public void onAnimationEnd(Animation animation) { 99 if (animation == mSecondLevelFadeOut) { 100 mSecondLevelIndicatorControlBar.setVisibility(View.GONE); 101 } else if (animation == mFadeOut) { 102 mIndicatorControlBar.setVisibility(View.GONE); 103 } 104 } 105 106 @Override 107 public void onAnimationRepeat(Animation animation) { 108 } 109 110 @Override 111 public void onAnimationStart(Animation animation) { 112 } 113 }; 114 115 private void leaveSecondLevelIndicator() { 116 mIndicatorControlBar.startAnimation(mFadeIn); 117 mIndicatorControlBar.setVisibility(View.VISIBLE); 118 mSecondLevelIndicatorControlBar.startAnimation(mSecondLevelFadeOut); 119 } 120 121 @Override 122 public void onIndicatorEvent(int event) { 123 switch (event) { 124 case OnIndicatorEventListener.EVENT_ENTER_SECOND_LEVEL_INDICATOR_BAR: 125 mIndicatorControlBar.startAnimation(mFadeOut); 126 mSecondLevelIndicatorControlBar.startAnimation(mSecondLevelFadeIn); 127 mSecondLevelIndicatorControlBar.setVisibility(View.VISIBLE); 128 break; 129 130 case OnIndicatorEventListener.EVENT_LEAVE_SECOND_LEVEL_INDICATOR_BAR: 131 leaveSecondLevelIndicator(); 132 break; 133 } 134 } 135 136 @Override 137 public void reloadPreferences() { 138 mIndicatorControlBar.reloadPreferences(); 139 mSecondLevelIndicatorControlBar.reloadPreferences(); 140 } 141 142 @Override 143 public void setListener(OnPreferenceChangedListener listener) { 144 mIndicatorControlBar.setListener(listener); 145 mSecondLevelIndicatorControlBar.setListener(listener); 146 } 147 148 @Override 149 public View getActiveSettingPopup() { 150 if (mIndicatorControlBar.getVisibility() == View.VISIBLE) { 151 return mIndicatorControlBar.getActiveSettingPopup(); 152 } else if (mSecondLevelIndicatorControlBar.getVisibility() == View.VISIBLE) { 153 return mSecondLevelIndicatorControlBar.getActiveSettingPopup(); 154 } 155 return null; 156 } 157 158 @Override 159 public boolean dismissSettingPopup() { 160 if (mIndicatorControlBar.getVisibility() == View.VISIBLE) { 161 return mIndicatorControlBar.dismissSettingPopup(); 162 } else if (mSecondLevelIndicatorControlBar.getVisibility() == View.VISIBLE) { 163 return mSecondLevelIndicatorControlBar.dismissSettingPopup(); 164 } 165 return false; 166 } 167 168 @Override 169 public void overrideSettings(final String ... keyvalues) { 170 mSecondLevelIndicatorControlBar.overrideSettings(keyvalues); 171 } 172 173 @Override 174 public void setEnabled(boolean enabled) { 175 mIndicatorControlBar.setEnabled(enabled); 176 mSecondLevelIndicatorControlBar.setEnabled(enabled); 177 } 178 179 @Override 180 public void enableZoom(boolean enabled) { 181 mIndicatorControlBar.enableZoom(enabled); 182 } 183 184 @Override 185 public void dismissSecondLevelIndicator() { 186 if (mSecondLevelIndicatorControlBar.getVisibility() == View.VISIBLE) { 187 leaveSecondLevelIndicator(); 188 } 189 } 190 191 @Override 192 public void enableFilter(boolean enabled) { 193 mIndicatorControlBar.setupFilter(enabled); 194 mSecondLevelIndicatorControlBar.setupFilter(enabled); 195 } 196 } 197