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