OtherSettingsPopup.java revision fd2c1fb832526c9fa88858d80e53e4759ae9dec3
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.ListPreference;
20import com.android.camera.PreferenceGroup;
21
22import android.content.Context;
23import android.content.res.Resources.Theme;
24import android.content.res.TypedArray;
25import android.util.AttributeSet;
26import android.util.Log;
27import android.view.View;
28import android.view.ViewGroup;
29import android.widget.LinearLayout;
30
31/* A popup window that contains several camera settings. */
32public class OtherSettingsPopup extends LinearLayout
33        implements InLineSettingPicker.Listener {
34    private static final String TAG = "OtherSettingsPopup";
35    private Listener mListener;
36
37    static public interface Listener {
38        public void onOtherSettingChanged();
39    }
40
41    public void setOtherSettingChangedListener(Listener listener) {
42        mListener = listener;
43    }
44
45    public OtherSettingsPopup(Context context, AttributeSet attrs) {
46        super(context, attrs);
47
48        // Use system holo background.
49        Theme dialogTheme = getResources().newTheme();
50        dialogTheme.applyStyle(android.R.style.Theme_Holo_Dialog, true);
51        TypedArray ta = dialogTheme.obtainStyledAttributes(new int[] {
52                android.R.attr.windowBackground });
53        setBackgroundDrawable(ta.getDrawable(0));
54        ta.recycle();
55    }
56
57    public void initialize(PreferenceGroup group) {
58        // Initialize each camera setting.
59        for (int i = getChildCount() - 1; i >= 0; i--) {
60            InLineSettingPicker picker = (InLineSettingPicker) getChildAt(i);
61            ListPreference pref = group.findPreference(picker.getKey());
62            if (pref != null) {
63                picker.setSettingChangedListener(this);
64                picker.initialize(pref);
65            } else {  // remove the row if the preference is not supported
66                removeViewAt(i);
67            }
68       }
69       requestLayout();
70    }
71
72    public void onSettingChanged() {
73        if (mListener != null) {
74            mListener.onOtherSettingChanged();
75        }
76    }
77}
78