PhotoController.java revision 2d3af28f91481d7f3887cb0bb9c5d06375baf787
1/*
2 * Copyright (C) 2012 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;
18
19import android.content.Context;
20import android.view.LayoutInflater;
21import android.view.View;
22import android.view.View.OnClickListener;
23
24import com.android.camera.ui.OtherSettingsPopup;
25import com.android.camera.ui.PieItem;
26import com.android.camera.ui.PieRenderer;
27
28public class PhotoController extends PieController
29        implements OtherSettingsPopup.Listener {
30
31    private static String TAG = "CAM_photocontrol";
32    private static float FLOAT_PI_DIVIDED_BY_TWO = (float) Math.PI / 2;
33
34    private PhotoModule mModule;
35    private String[] mOtherKeys;
36    private OtherSettingsPopup mPopup;
37
38    public PhotoController(CameraActivity activity, PhotoModule module, PieRenderer pie) {
39        super(activity, pie);
40        mModule = module;
41    }
42
43    public void initialize(PreferenceGroup group) {
44        super.initialize(group);
45        float sweep = FLOAT_PI_DIVIDED_BY_TWO / 2;
46        addItem(CameraSettings.KEY_FLASH_MODE, FLOAT_PI_DIVIDED_BY_TWO - sweep, sweep);
47        addItem(CameraSettings.KEY_EXPOSURE, FLOAT_PI_DIVIDED_BY_TWO + sweep, sweep);
48        PieItem item = makeItem(R.drawable.ic_switch_photo_facing_holo_light);
49        item.setFixedSlice(FLOAT_PI_DIVIDED_BY_TWO,  sweep);
50        item.getView().setOnClickListener(new OnClickListener() {
51
52            @Override
53            public void onClick(View v) {
54                // Find the index of next camera.
55                ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
56                int index = pref.findIndexOfValue(pref.getValue());
57                CharSequence[] values = pref.getEntryValues();
58                index = (index + 1) % values.length;
59                int newCameraId = Integer.parseInt((String) values[index]);
60                mListener.onCameraPickerClicked(newCameraId);
61            }
62        });
63        mRenderer.addItem(item);
64        mOtherKeys = new String[] {
65                CameraSettings.KEY_WHITE_BALANCE,
66                CameraSettings.KEY_SCENE_MODE,
67                CameraSettings.KEY_RECORD_LOCATION,
68                CameraSettings.KEY_PICTURE_SIZE,
69                CameraSettings.KEY_FOCUS_MODE};
70        item = makeItem(R.drawable.ic_settings_holo_light);
71        item.setFixedSlice(FLOAT_PI_DIVIDED_BY_TWO * 3, sweep);
72        item.getView().setOnClickListener(new OnClickListener() {
73            @Override
74            public void onClick(View v) {
75                if (mPopup == null) {
76                    initializePopup();
77                }
78                mModule.showPopup(mPopup);
79            }
80        });
81        mRenderer.addItem(item);
82    }
83
84    protected void setCameraId(int cameraId) {
85        ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
86        pref.setValue("" + cameraId);
87    }
88
89    @Override
90    public void overrideSettings(final String ... keyvalues) {
91        super.overrideSettings(keyvalues);
92        if (mPopup == null) {
93            initializePopup();
94        }
95        ((OtherSettingsPopup)mPopup).overrideSettings(keyvalues);
96    }
97
98    protected void initializePopup() {
99        LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
100                Context.LAYOUT_INFLATER_SERVICE);
101
102        OtherSettingsPopup popup = (OtherSettingsPopup) inflater.inflate(
103                R.layout.other_setting_popup, null, false);
104        popup.setSettingChangedListener(this);
105        popup.initialize(mPreferenceGroup, mOtherKeys);
106        mPopup = popup;
107    }
108
109    @Override
110    public void onRestorePreferencesClicked() {
111        mModule.onRestorePreferencesClicked();
112    }
113
114}
115