VideoController.java revision 9d8583fc0e14477466ed0e9f69f40ea2863c393f
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 VideoController extends PieController 29 implements OtherSettingsPopup.Listener { 30 31 private static String TAG = "CAM_videocontrol"; 32 private static float FLOAT_PI_DIVIDED_BY_TWO = (float) Math.PI / 2; 33 34 private VideoModule mModule; 35 private String[] mOtherKeys; 36 private OtherSettingsPopup mPopup; 37 38 public VideoController(CameraActivity activity, VideoModule 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 47 addItem(CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE, FLOAT_PI_DIVIDED_BY_TWO - sweep, sweep); 48 addItem(CameraSettings.KEY_WHITE_BALANCE, FLOAT_PI_DIVIDED_BY_TWO + sweep, sweep); 49 PieItem item = makeItem(R.drawable.ic_switch_video_facing_holo_light); 50 item.setFixedSlice(FLOAT_PI_DIVIDED_BY_TWO, sweep); 51 item.getView().setOnClickListener(new OnClickListener() { 52 53 @Override 54 public void onClick(View v) { 55 // Find the index of next camera. 56 ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID); 57 int index = pref.findIndexOfValue(pref.getValue()); 58 CharSequence[] values = pref.getEntryValues(); 59 index = (index + 1) % values.length; 60 int newCameraId = Integer.parseInt((String) values[index]); 61 mListener.onCameraPickerClicked(newCameraId); 62 } 63 }); 64 mRenderer.addItem(item); 65 mOtherKeys = new String[] { 66 CameraSettings.KEY_VIDEO_EFFECT, 67 CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL, 68 CameraSettings.KEY_VIDEO_QUALITY, 69 CameraSettings.KEY_RECORD_LOCATION}; 70 71 item = makeItem(R.drawable.ic_settings_holo_light); 72 item.setFixedSlice(FLOAT_PI_DIVIDED_BY_TWO * 3, sweep); 73 item.getView().setOnClickListener(new OnClickListener() { 74 @Override 75 public void onClick(View v) { 76 if (mPopup == null) { 77 initializePopup(); 78 } 79 mModule.showPopup(mPopup); 80 } 81 }); 82 mRenderer.addItem(item); 83 } 84 85 protected void setCameraId(int cameraId) { 86 ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID); 87 pref.setValue("" + cameraId); 88 } 89 90 @Override 91 public void reloadPreferences() { 92 super.reloadPreferences(); 93 if (mPopup != null) { 94 mPopup.reloadPreference(); 95 } 96 } 97 98 @Override 99 public void overrideSettings(final String ... keyvalues) { 100 super.overrideSettings(keyvalues); 101 if (mPopup == null) { 102 initializePopup(); 103 } 104 ((OtherSettingsPopup)mPopup).overrideSettings(keyvalues); 105 } 106 107 protected void initializePopup() { 108 LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService( 109 Context.LAYOUT_INFLATER_SERVICE); 110 111 OtherSettingsPopup popup = (OtherSettingsPopup) inflater.inflate( 112 R.layout.other_setting_popup, null, false); 113 popup.setSettingChangedListener(this); 114 popup.initialize(mPreferenceGroup, mOtherKeys); 115 mPopup = popup; 116 } 117 118 @Override 119 public void onRestorePreferencesClicked() { 120 mModule.onRestorePreferencesClicked(); 121 } 122 123} 124