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 android.content.Context;
     20 import android.view.LayoutInflater;
     21 
     22 import com.android.camera.ui.AbstractSettingPopup;
     23 import com.android.camera.ui.ListPrefSettingPopup;
     24 import com.android.camera.ui.MoreSettingPopup;
     25 import com.android.camera.ui.PieItem;
     26 import com.android.camera.ui.PieItem.OnClickListener;
     27 import com.android.camera.ui.PieRenderer;
     28 import com.android.camera.ui.TimeIntervalPopup;
     29 
     30 public class VideoController extends PieController
     31         implements MoreSettingPopup.Listener,
     32         ListPrefSettingPopup.Listener,
     33         TimeIntervalPopup.Listener {
     34 
     35 
     36     private static String TAG = "CAM_videocontrol";
     37     private static float FLOAT_PI_DIVIDED_BY_TWO = (float) Math.PI / 2;
     38 
     39     private VideoModule mModule;
     40     private String[] mOtherKeys;
     41     private AbstractSettingPopup mPopup;
     42 
     43     private static final int POPUP_NONE = 0;
     44     private static final int POPUP_FIRST_LEVEL = 1;
     45     private static final int POPUP_SECOND_LEVEL = 2;
     46     private int mPopupStatus;
     47 
     48     public VideoController(CameraActivity activity, VideoModule module, PieRenderer pie) {
     49         super(activity, pie);
     50         mModule = module;
     51     }
     52 
     53     public void initialize(PreferenceGroup group) {
     54         super.initialize(group);
     55         mPopup = null;
     56         mPopupStatus = POPUP_NONE;
     57         float sweep = FLOAT_PI_DIVIDED_BY_TWO / 2;
     58 
     59         addItem(CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE, FLOAT_PI_DIVIDED_BY_TWO - sweep, sweep);
     60         addItem(CameraSettings.KEY_WHITE_BALANCE, 3 * FLOAT_PI_DIVIDED_BY_TWO + sweep, sweep);
     61         PieItem item = makeItem(R.drawable.ic_switch_video_facing_holo_light);
     62         item.setFixedSlice(FLOAT_PI_DIVIDED_BY_TWO + sweep,  sweep);
     63         item.setOnClickListener(new OnClickListener() {
     64 
     65             @Override
     66             public void onClick(PieItem item) {
     67                 // Find the index of next camera.
     68                 ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
     69                 if (pref != null) {
     70                     int index = pref.findIndexOfValue(pref.getValue());
     71                     CharSequence[] values = pref.getEntryValues();
     72                     index = (index + 1) % values.length;
     73                     int newCameraId = Integer.parseInt((String) values[index]);
     74                     mListener.onCameraPickerClicked(newCameraId);
     75                 }
     76             }
     77         });
     78         mRenderer.addItem(item);
     79         mOtherKeys = new String[] {
     80                 CameraSettings.KEY_VIDEO_EFFECT,
     81                 CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL,
     82                 CameraSettings.KEY_VIDEO_QUALITY,
     83                 CameraSettings.KEY_RECORD_LOCATION};
     84 
     85         item = makeItem(R.drawable.ic_settings_holo_light);
     86         item.setFixedSlice(FLOAT_PI_DIVIDED_BY_TWO * 3, sweep);
     87         item.setOnClickListener(new OnClickListener() {
     88             @Override
     89             public void onClick(PieItem item) {
     90                 if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
     91                     initializePopup();
     92                     mPopupStatus = POPUP_FIRST_LEVEL;
     93                 }
     94                 mModule.showPopup(mPopup);
     95             }
     96         });
     97         mRenderer.addItem(item);
     98     }
     99 
    100     protected void setCameraId(int cameraId) {
    101         ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
    102         pref.setValue("" + cameraId);
    103     }
    104 
    105     @Override
    106     public void reloadPreferences() {
    107         super.reloadPreferences();
    108         if (mPopup != null) {
    109             mPopup.reloadPreference();
    110         }
    111     }
    112 
    113     @Override
    114     public void overrideSettings(final String ... keyvalues) {
    115         super.overrideSettings(keyvalues);
    116         if (mPopup == null || mPopupStatus != POPUP_FIRST_LEVEL) {
    117             mPopupStatus = POPUP_FIRST_LEVEL;
    118             initializePopup();
    119         }
    120         ((MoreSettingPopup) mPopup).overrideSettings(keyvalues);
    121     }
    122 
    123     @Override
    124     // Hit when an item in the second-level popup gets selected
    125     public void onListPrefChanged(ListPreference pref) {
    126         if (mPopup != null) {
    127             if (mPopupStatus == POPUP_SECOND_LEVEL) {
    128                 mModule.dismissPopup(true);
    129             }
    130         }
    131         super.onSettingChanged(pref);
    132     }
    133 
    134     protected void initializePopup() {
    135         LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
    136                 Context.LAYOUT_INFLATER_SERVICE);
    137 
    138         MoreSettingPopup popup = (MoreSettingPopup) inflater.inflate(
    139                 R.layout.more_setting_popup, null, false);
    140         popup.setSettingChangedListener(this);
    141         popup.initialize(mPreferenceGroup, mOtherKeys);
    142         mPopup = popup;
    143     }
    144 
    145     public void popupDismissed(boolean topPopupOnly) {
    146         // if the 2nd level popup gets dismissed
    147         if (mPopupStatus == POPUP_SECOND_LEVEL) {
    148             initializePopup();
    149             mPopupStatus = POPUP_FIRST_LEVEL;
    150             if (topPopupOnly) mModule.showPopup(mPopup);
    151         }
    152     }
    153 
    154     @Override
    155     // Hit when an item in the first-level popup gets selected, then bring up
    156     // the second-level popup
    157     public void onPreferenceClicked(ListPreference pref) {
    158         if (mPopupStatus != POPUP_FIRST_LEVEL) return;
    159 
    160         LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
    161                 Context.LAYOUT_INFLATER_SERVICE);
    162 
    163         if (CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL.equals(pref.getKey())) {
    164             TimeIntervalPopup timeInterval = (TimeIntervalPopup) inflater.inflate(
    165                     R.layout.time_interval_popup, null, false);
    166             timeInterval.initialize((IconListPreference) pref);
    167             timeInterval.setSettingChangedListener(this);
    168             mModule.dismissPopup(true);
    169             mPopup = timeInterval;
    170         } else {
    171             ListPrefSettingPopup basic = (ListPrefSettingPopup) inflater.inflate(
    172                     R.layout.list_pref_setting_popup, null, false);
    173             basic.initialize(pref);
    174             basic.setSettingChangedListener(this);
    175             mModule.dismissPopup(true);
    176             mPopup = basic;
    177         }
    178         mModule.showPopup(mPopup);
    179         mPopupStatus = POPUP_SECOND_LEVEL;
    180     }
    181 
    182 }
    183