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