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