1 /* 2 * Copyright (C) 2013 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.content.res.TypedArray; 21 import android.hardware.Camera; 22 import android.hardware.Camera.Parameters; 23 import android.view.View; 24 import android.widget.ImageView; 25 26 import com.android.gallery3d.R; 27 28 /** 29 * The on-screen indicators of the pie menu button. They show the camera 30 * settings in the viewfinder. 31 */ 32 public class OnScreenIndicators { 33 private final int[] mWBArray; 34 private final View mOnScreenIndicators; 35 private final ImageView mExposureIndicator; 36 private final ImageView mFlashIndicator; 37 private final ImageView mSceneIndicator; 38 private final ImageView mLocationIndicator; 39 private final ImageView mTimerIndicator; 40 private final ImageView mWBIndicator; 41 42 public OnScreenIndicators(Context ctx, View onScreenIndicatorsView) { 43 TypedArray iconIds = ctx.getResources().obtainTypedArray( 44 R.array.camera_wb_indicators); 45 final int n = iconIds.length(); 46 mWBArray = new int[n]; 47 for (int i = 0; i < n; i++) { 48 mWBArray[i] = iconIds.getResourceId(i, R.drawable.ic_indicator_wb_off); 49 } 50 mOnScreenIndicators = onScreenIndicatorsView; 51 mExposureIndicator = (ImageView) onScreenIndicatorsView.findViewById( 52 R.id.menu_exposure_indicator); 53 mFlashIndicator = (ImageView) onScreenIndicatorsView.findViewById( 54 R.id.menu_flash_indicator); 55 mSceneIndicator = (ImageView) onScreenIndicatorsView.findViewById( 56 R.id.menu_scenemode_indicator); 57 mLocationIndicator = (ImageView) onScreenIndicatorsView.findViewById( 58 R.id.menu_location_indicator); 59 mTimerIndicator = (ImageView) onScreenIndicatorsView.findViewById( 60 R.id.menu_timer_indicator); 61 mWBIndicator = (ImageView) onScreenIndicatorsView.findViewById( 62 R.id.menu_wb_indicator); 63 } 64 65 /** 66 * Resets all indicators to show the default values. 67 */ 68 public void resetToDefault() { 69 updateExposureOnScreenIndicator(0); 70 updateFlashOnScreenIndicator(Parameters.FLASH_MODE_OFF); 71 updateSceneOnScreenIndicator(Parameters.SCENE_MODE_AUTO); 72 updateWBIndicator(2); 73 updateTimerIndicator(false); 74 updateLocationIndicator(false); 75 } 76 77 /** 78 * Sets the exposure indicator using exposure compensations step rounding. 79 */ 80 public void updateExposureOnScreenIndicator(Camera.Parameters params, int value) { 81 if (mExposureIndicator == null) { 82 return; 83 } 84 float step = params.getExposureCompensationStep(); 85 value = Math.round(value * step); 86 updateExposureOnScreenIndicator(value); 87 } 88 89 /** 90 * Set the exposure indicator to the given value. 91 * 92 * @param value Value between -3 and 3. If outside this range, 0 is used by 93 * default. 94 */ 95 public void updateExposureOnScreenIndicator(int value) { 96 int id = 0; 97 switch(value) { 98 case -3: 99 id = R.drawable.ic_indicator_ev_n3; 100 break; 101 case -2: 102 id = R.drawable.ic_indicator_ev_n2; 103 break; 104 case -1: 105 id = R.drawable.ic_indicator_ev_n1; 106 break; 107 case 0: 108 id = R.drawable.ic_indicator_ev_0; 109 break; 110 case 1: 111 id = R.drawable.ic_indicator_ev_p1; 112 break; 113 case 2: 114 id = R.drawable.ic_indicator_ev_p2; 115 break; 116 case 3: 117 id = R.drawable.ic_indicator_ev_p3; 118 break; 119 } 120 mExposureIndicator.setImageResource(id); 121 } 122 123 public void updateWBIndicator(int wbIndex) { 124 if (mWBIndicator == null) return; 125 mWBIndicator.setImageResource(mWBArray[wbIndex]); 126 } 127 128 public void updateTimerIndicator(boolean on) { 129 if (mTimerIndicator == null) return; 130 mTimerIndicator.setImageResource(on ? R.drawable.ic_indicator_timer_on 131 : R.drawable.ic_indicator_timer_off); 132 } 133 134 public void updateLocationIndicator(boolean on) { 135 if (mLocationIndicator == null) return; 136 mLocationIndicator.setImageResource(on ? R.drawable.ic_indicator_loc_on 137 : R.drawable.ic_indicator_loc_off); 138 } 139 140 /** 141 * Set the flash indicator to the given value. 142 * 143 * @param value One of Parameters.FLASH_MODE_OFF, 144 * Parameters.FLASH_MODE_AUTO, Parameters.FLASH_MODE_ON. 145 */ 146 public void updateFlashOnScreenIndicator(String value) { 147 if (mFlashIndicator == null) { 148 return; 149 } 150 if (value == null || Parameters.FLASH_MODE_OFF.equals(value)) { 151 mFlashIndicator.setImageResource(R.drawable.ic_indicator_flash_off); 152 } else { 153 if (Parameters.FLASH_MODE_AUTO.equals(value)) { 154 mFlashIndicator.setImageResource(R.drawable.ic_indicator_flash_auto); 155 } else if (Parameters.FLASH_MODE_ON.equals(value) 156 || Parameters.FLASH_MODE_TORCH.equals(value)) { 157 mFlashIndicator.setImageResource(R.drawable.ic_indicator_flash_on); 158 } else { 159 mFlashIndicator.setImageResource(R.drawable.ic_indicator_flash_off); 160 } 161 } 162 } 163 164 /** 165 * Set the scene indicator depending on the given scene mode. 166 * 167 * @param value the current Parameters.SCENE_MODE_* value. 168 */ 169 public void updateSceneOnScreenIndicator(String value) { 170 if (mSceneIndicator == null) { 171 return; 172 } 173 if ((value == null) || Parameters.SCENE_MODE_AUTO.equals(value)) { 174 mSceneIndicator.setImageResource(R.drawable.ic_indicator_sce_off); 175 } else if (Parameters.SCENE_MODE_HDR.equals(value)) { 176 mSceneIndicator.setImageResource(R.drawable.ic_indicator_sce_hdr); 177 } else { 178 mSceneIndicator.setImageResource(R.drawable.ic_indicator_sce_on); 179 } 180 } 181 182 /** 183 * Sets the visibility of all indicators. 184 * 185 * @param visibility View.VISIBLE, View.GONE etc. 186 */ 187 public void setVisibility(int visibility) { 188 mOnScreenIndicators.setVisibility(visibility); 189 } 190 } 191