Home | History | Annotate | Download | only in camera
      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 
     17 package com.android.camera;
     18 
     19 import java.util.Locale;
     20 
     21 import android.content.res.Resources;
     22 import android.hardware.Camera.Parameters;
     23 
     24 import com.android.camera.ui.AbstractSettingPopup;
     25 import com.android.camera.ui.CountdownTimerPopup;
     26 import com.android.camera.ui.ListPrefSettingPopup;
     27 import com.android.camera.ui.PieItem;
     28 import com.android.camera.ui.PieItem.OnClickListener;
     29 import com.android.camera.ui.PieRenderer;
     30 import com.android.camera2.R;
     31 
     32 public class PhotoMenu extends PieController
     33         implements CountdownTimerPopup.Listener,
     34         ListPrefSettingPopup.Listener {
     35     private static String TAG = "PhotoMenu";
     36 
     37     private final String mSettingOff;
     38 
     39     private PhotoUI mUI;
     40     private AbstractSettingPopup mPopup;
     41     private CameraActivity mActivity;
     42 
     43     public PhotoMenu(CameraActivity activity, PhotoUI ui, PieRenderer pie) {
     44         super(activity, pie);
     45         mUI = ui;
     46         mSettingOff = activity.getString(R.string.setting_off_value);
     47         mActivity = activity;
     48     }
     49 
     50     public void initialize(PreferenceGroup group) {
     51         super.initialize(group);
     52         mPopup = null;
     53         PieItem item = null;
     54         final Resources res = mActivity.getResources();
     55         Locale locale = res.getConfiguration().locale;
     56         // The order is from left to right in the menu.
     57 
     58         // HDR+ (GCam).
     59         if (group.findPreference(CameraSettings.KEY_CAMERA_HDR_PLUS) != null) {
     60             item = makeSwitchItem(CameraSettings.KEY_CAMERA_HDR_PLUS, true);
     61             mRenderer.addItem(item);
     62         }
     63 
     64         // HDR.
     65         if (group.findPreference(CameraSettings.KEY_CAMERA_HDR) != null) {
     66             item = makeSwitchItem(CameraSettings.KEY_CAMERA_HDR, true);
     67             mRenderer.addItem(item);
     68         }
     69         // Exposure compensation.
     70         if (group.findPreference(CameraSettings.KEY_EXPOSURE) != null) {
     71             item = makeItem(CameraSettings.KEY_EXPOSURE);
     72             item.setLabel(res.getString(R.string.pref_exposure_label));
     73             mRenderer.addItem(item);
     74         }
     75         // More settings.
     76         PieItem more = makeItem(R.drawable.ic_settings_holo_light);
     77         more.setLabel(res.getString(R.string.camera_menu_more_label));
     78         mRenderer.addItem(more);
     79 
     80         // Flash.
     81         if (group.findPreference(CameraSettings.KEY_FLASH_MODE) != null) {
     82             item = makeItem(CameraSettings.KEY_FLASH_MODE);
     83             item.setLabel(res.getString(R.string.pref_camera_flashmode_label));
     84             mRenderer.addItem(item);
     85         }
     86         // Camera switcher.
     87         if (group.findPreference(CameraSettings.KEY_CAMERA_ID) != null) {
     88             item = makeSwitchItem(CameraSettings.KEY_CAMERA_ID, false);
     89             final PieItem fitem = item;
     90             item.setOnClickListener(new OnClickListener() {
     91                 @Override
     92                 public void onClick(PieItem item) {
     93                     // Find the index of next camera.
     94                     ListPreference pref = mPreferenceGroup
     95                             .findPreference(CameraSettings.KEY_CAMERA_ID);
     96                     if (pref != null) {
     97                         int index = pref.findIndexOfValue(pref.getValue());
     98                         CharSequence[] values = pref.getEntryValues();
     99                         index = (index + 1) % values.length;
    100                         pref.setValueIndex(index);
    101                         mListener.onCameraPickerClicked(index);
    102                     }
    103                     updateItem(fitem, CameraSettings.KEY_CAMERA_ID);
    104                 }
    105             });
    106             mRenderer.addItem(item);
    107         }
    108         // Location.
    109         if (group.findPreference(CameraSettings.KEY_RECORD_LOCATION) != null) {
    110             item = makeSwitchItem(CameraSettings.KEY_RECORD_LOCATION, true);
    111             more.addItem(item);
    112             if (mActivity.isSecureCamera()) {
    113                 // Prevent location preference from getting changed in secure camera mode
    114                 item.setEnabled(false);
    115             }
    116         }
    117         // Countdown timer.
    118         final ListPreference ctpref = group.findPreference(CameraSettings.KEY_TIMER);
    119         final ListPreference beeppref = group.findPreference(CameraSettings.KEY_TIMER_SOUND_EFFECTS);
    120         item = makeItem(R.drawable.ic_timer);
    121         item.setLabel(res.getString(R.string.pref_camera_timer_title).toUpperCase(locale));
    122         item.setOnClickListener(new OnClickListener() {
    123             @Override
    124             public void onClick(PieItem item) {
    125                 CountdownTimerPopup timerPopup = (CountdownTimerPopup) mActivity.getLayoutInflater().inflate(
    126                         R.layout.countdown_setting_popup, null, false);
    127                 timerPopup.initialize(ctpref, beeppref);
    128                 timerPopup.setSettingChangedListener(PhotoMenu.this);
    129                 mUI.dismissPopup();
    130                 mPopup = timerPopup;
    131                 mUI.showPopup(mPopup);
    132             }
    133         });
    134         more.addItem(item);
    135         // Image size.
    136         item = makeItem(R.drawable.ic_imagesize);
    137         final ListPreference sizePref = group.findPreference(CameraSettings.KEY_PICTURE_SIZE);
    138         item.setLabel(res.getString(R.string.pref_camera_picturesize_title).toUpperCase(locale));
    139         item.setOnClickListener(new OnClickListener() {
    140             @Override
    141             public void onClick(PieItem item) {
    142                 ListPrefSettingPopup popup = (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate(
    143                         R.layout.list_pref_setting_popup, null, false);
    144                 popup.initialize(sizePref);
    145                 popup.setSettingChangedListener(PhotoMenu.this);
    146                 mUI.dismissPopup();
    147                 mPopup = popup;
    148                 mUI.showPopup(mPopup);
    149             }
    150         });
    151         more.addItem(item);
    152         // White balance.
    153         if (group.findPreference(CameraSettings.KEY_WHITE_BALANCE) != null) {
    154             item = makeItem(CameraSettings.KEY_WHITE_BALANCE);
    155             item.setLabel(res.getString(R.string.pref_camera_whitebalance_label));
    156             more.addItem(item);
    157         }
    158         // Scene mode.
    159         if (group.findPreference(CameraSettings.KEY_SCENE_MODE) != null) {
    160             IconListPreference pref = (IconListPreference) group.findPreference(
    161                     CameraSettings.KEY_SCENE_MODE);
    162             pref.setUseSingleIcon(true);
    163             item = makeItem(CameraSettings.KEY_SCENE_MODE);
    164             more.addItem(item);
    165         }
    166     }
    167 
    168     @Override
    169     // Hit when an item in a popup gets selected
    170     public void onListPrefChanged(ListPreference pref) {
    171         if (mPopup != null) {
    172             mUI.dismissPopup();
    173         }
    174         onSettingChanged(pref);
    175     }
    176 
    177     public void popupDismissed() {
    178         if (mPopup != null) {
    179             mPopup = null;
    180         }
    181     }
    182 
    183     // Return true if the preference has the specified key but not the value.
    184     private static boolean notSame(ListPreference pref, String key, String value) {
    185         return (key.equals(pref.getKey()) && !value.equals(pref.getValue()));
    186     }
    187 
    188     private void setPreference(String key, String value) {
    189         ListPreference pref = mPreferenceGroup.findPreference(key);
    190         if (pref != null && !value.equals(pref.getValue())) {
    191             pref.setValue(value);
    192             reloadPreferences();
    193         }
    194     }
    195 
    196     @Override
    197     public void onSettingChanged(ListPreference pref) {
    198         // Reset the scene mode if HDR is set to on. Reset HDR if scene mode is
    199         // set to non-auto.
    200         if (notSame(pref, CameraSettings.KEY_CAMERA_HDR, mSettingOff)) {
    201             setPreference(CameraSettings.KEY_SCENE_MODE, Parameters.SCENE_MODE_AUTO);
    202         } else if (notSame(pref, CameraSettings.KEY_SCENE_MODE, Parameters.SCENE_MODE_AUTO)) {
    203             setPreference(CameraSettings.KEY_CAMERA_HDR, mSettingOff);
    204         }
    205         super.onSettingChanged(pref);
    206     }
    207 }
    208