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.util.Log;
22 import android.view.accessibility.AccessibilityEvent;
23 import android.widget.TextView;
24 
25 import com.android.camera.ListPreference;
26 import com.android.camera.R;
27 
28 /* Setting menu item that will bring up a menu when you click on it. */
29 public class InLineSettingMenu extends InLineSettingItem {
30     private static final String TAG = "InLineSettingMenu";
31     // The view that shows the current selected setting. Ex: 5MP
32     private TextView mEntry;
33 
InLineSettingMenu(Context context, AttributeSet attrs)34     public InLineSettingMenu(Context context, AttributeSet attrs) {
35         super(context, attrs);
36     }
37 
38     @Override
onFinishInflate()39     protected void onFinishInflate() {
40         super.onFinishInflate();
41         mEntry = (TextView) findViewById(R.id.current_setting);
42     }
43 
44     @Override
initialize(ListPreference preference)45     public void initialize(ListPreference preference) {
46         super.initialize(preference);
47         //TODO: add contentDescription
48     }
49 
50     @Override
updateView()51     protected void updateView() {
52         if (mOverrideValue == null) {
53             mEntry.setText(mPreference.getEntry());
54         } else {
55             int index = mPreference.findIndexOfValue(mOverrideValue);
56             if (index != -1) {
57                 mEntry.setText(mPreference.getEntries()[index]);
58             } else {
59                 // Avoid the crash if camera driver has bugs.
60                 Log.e(TAG, "Fail to find override value=" + mOverrideValue);
61                 mPreference.print();
62             }
63         }
64     }
65 
66     @Override
dispatchPopulateAccessibilityEvent(AccessibilityEvent event)67     public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
68         event.getText().add(mPreference.getTitle() + mPreference.getEntry());
69         return true;
70     }
71 
72     @Override
setEnabled(boolean enable)73     public void setEnabled(boolean enable) {
74         super.setEnabled(enable);
75         if (mTitle != null) mTitle.setEnabled(enable);
76         if (mEntry != null) mEntry.setEnabled(enable);
77     }
78 }
79