blob: fbce28e1be99fcd49965cfdf4e1c97495ae8f66a [file] [log] [blame]
Michael Kolb8872c232013-01-29 10:33:22 -08001/*
2 * Copyright (C) 2009 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
Angus Kongb50b5cb2013-08-09 14:55:20 -070017package com.android.camera.util;
Michael Kolb8872c232013-01-29 10:33:22 -080018
Michael Kolb8872c232013-01-29 10:33:22 -080019import android.app.Activity;
20import android.app.AlertDialog;
21import android.app.admin.DevicePolicyManager;
22import android.content.ActivityNotFoundException;
Sascha Haeberlingfae11a12013-08-15 14:29:49 -070023import android.content.ComponentName;
Michael Kolb8872c232013-01-29 10:33:22 -080024import android.content.ContentResolver;
25import android.content.Context;
26import android.content.DialogInterface;
27import android.content.Intent;
Doris Liubd1b8f92014-01-03 17:59:51 -080028import android.content.res.TypedArray;
Michael Kolb8872c232013-01-29 10:33:22 -080029import android.graphics.Bitmap;
30import android.graphics.BitmapFactory;
31import android.graphics.Matrix;
32import android.graphics.Point;
33import android.graphics.Rect;
34import android.graphics.RectF;
35import android.hardware.Camera;
36import android.hardware.Camera.CameraInfo;
37import android.hardware.Camera.Parameters;
38import android.hardware.Camera.Size;
39import android.location.Location;
40import android.net.Uri;
Michael Kolb8872c232013-01-29 10:33:22 -080041import android.os.ParcelFileDescriptor;
42import android.telephony.TelephonyManager;
43import android.util.DisplayMetrics;
Michael Kolb8872c232013-01-29 10:33:22 -080044import android.util.Log;
45import android.util.TypedValue;
Doris Liu0ba8eaa2013-10-16 12:51:02 -070046import android.view.Display;
Michael Kolb8872c232013-01-29 10:33:22 -080047import android.view.OrientationEventListener;
48import android.view.Surface;
49import android.view.View;
50import android.view.WindowManager;
51import android.view.animation.AlphaAnimation;
52import android.view.animation.Animation;
Angus Kongb40738a2013-06-03 14:55:34 -070053import android.widget.Toast;
Michael Kolb8872c232013-01-29 10:33:22 -080054
Sascha Haeberlingb7639c62013-09-09 14:42:43 -070055import com.android.camera.CameraActivity;
Angus Kongb50b5cb2013-08-09 14:55:20 -070056import com.android.camera.CameraDisabledException;
Sascha Haeberling37f36112013-08-06 14:31:52 -070057import com.android.camera2.R;
Michael Kolb8872c232013-01-29 10:33:22 -080058
Sascha Haeberling638e6f02013-09-18 14:28:51 -070059import java.io.Closeable;
60import java.io.IOException;
61import java.lang.reflect.Method;
62import java.text.SimpleDateFormat;
63import java.util.Date;
64import java.util.List;
65import java.util.Locale;
66import java.util.StringTokenizer;
67
Michael Kolb8872c232013-01-29 10:33:22 -080068/**
69 * Collection of utility functions used in this package.
70 */
Angus Kongb50b5cb2013-08-09 14:55:20 -070071public class CameraUtil {
Michael Kolb8872c232013-01-29 10:33:22 -080072 private static final String TAG = "Util";
73
ztenghui16a35202013-09-23 11:35:36 -070074 // For calculate the best fps range for still image capture.
75 private final static int MAX_PREVIEW_FPS_TIMES_1000 = 400000;
76 private final static int PREFERRED_PREVIEW_FPS_TIMES_1000 = 30000;
77
Angus Kongb50b5cb2013-08-09 14:55:20 -070078 // For creating crop intents.
79 public static final String KEY_RETURN_DATA = "return-data";
80 public static final String KEY_SHOW_WHEN_LOCKED = "showWhenLocked";
81
Michael Kolb8872c232013-01-29 10:33:22 -080082 // Orientation hysteresis amount used in rounding, in degrees
83 public static final int ORIENTATION_HYSTERESIS = 5;
84
85 public static final String REVIEW_ACTION = "com.android.camera.action.REVIEW";
86 // See android.hardware.Camera.ACTION_NEW_PICTURE.
87 public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE";
88 // See android.hardware.Camera.ACTION_NEW_VIDEO.
89 public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO";
90
Dan Aminzadefca1c5e2013-08-14 17:36:56 -070091 // Broadcast Action: The camera application has become active in picture-taking mode.
92 public static final String ACTION_CAMERA_STARTED = "com.android.camera.action.CAMERA_STARTED";
93 // Broadcast Action: The camera application is no longer in active picture-taking mode.
94 public static final String ACTION_CAMERA_STOPPED = "com.android.camera.action.CAMERA_STOPPED";
95 // When the camera application is active in picture-taking mode, it listens for this intent,
96 // which upon receipt will trigger the shutter to capture a new picture, as if the user had
97 // pressed the shutter button.
98 public static final String ACTION_CAMERA_SHUTTER_CLICK =
99 "com.android.camera.action.SHUTTER_CLICK";
100
Michael Kolb8872c232013-01-29 10:33:22 -0800101 // Fields from android.hardware.Camera.Parameters
102 public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";
103 public static final String RECORDING_HINT = "recording-hint";
104 private static final String AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
105 private static final String AUTO_WHITE_BALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported";
106 private static final String VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported";
107 public static final String SCENE_MODE_HDR = "hdr";
108 public static final String TRUE = "true";
109 public static final String FALSE = "false";
Sascha Haeberlingfae11a12013-08-15 14:29:49 -0700110
111 // Fields for the show-on-maps-functionality
112 private static final String MAPS_PACKAGE_NAME = "com.google.android.apps.maps";
113 private static final String MAPS_CLASS_NAME = "com.google.android.maps.MapsActivity";
114
115 /** Has to be in sync with the receiving MovieActivity. */
116 public static final String KEY_TREAT_UP_AS_BACK = "treat-up-as-back";
Michael Kolb8872c232013-01-29 10:33:22 -0800117
118 public static boolean isSupported(String value, List<String> supported) {
119 return supported == null ? false : supported.indexOf(value) >= 0;
120 }
121
122 public static boolean isAutoExposureLockSupported(Parameters params) {
123 return TRUE.equals(params.get(AUTO_EXPOSURE_LOCK_SUPPORTED));
124 }
125
126 public static boolean isAutoWhiteBalanceLockSupported(Parameters params) {
127 return TRUE.equals(params.get(AUTO_WHITE_BALANCE_LOCK_SUPPORTED));
128 }
129
130 public static boolean isVideoSnapshotSupported(Parameters params) {
131 return TRUE.equals(params.get(VIDEO_SNAPSHOT_SUPPORTED));
132 }
133
134 public static boolean isCameraHdrSupported(Parameters params) {
135 List<String> supported = params.getSupportedSceneModes();
136 return (supported != null) && supported.contains(SCENE_MODE_HDR);
137 }
138
Michael Kolb8872c232013-01-29 10:33:22 -0800139 public static boolean isMeteringAreaSupported(Parameters params) {
Sascha Haeberling638e6f02013-09-18 14:28:51 -0700140 return params.getMaxNumMeteringAreas() > 0;
Michael Kolb8872c232013-01-29 10:33:22 -0800141 }
142
Michael Kolb8872c232013-01-29 10:33:22 -0800143 public static boolean isFocusAreaSupported(Parameters params) {
Sascha Haeberling638e6f02013-09-18 14:28:51 -0700144 return (params.getMaxNumFocusAreas() > 0
145 && isSupported(Parameters.FOCUS_MODE_AUTO,
146 params.getSupportedFocusModes()));
Michael Kolb8872c232013-01-29 10:33:22 -0800147 }
148
149 // Private intent extras. Test only.
150 private static final String EXTRAS_CAMERA_FACING =
151 "android.intent.extras.CAMERA_FACING";
152
153 private static float sPixelDensity = 1;
154 private static ImageFileNamer sImageFileNamer;
155
Angus Kongb50b5cb2013-08-09 14:55:20 -0700156 private CameraUtil() {
Michael Kolb8872c232013-01-29 10:33:22 -0800157 }
158
159 public static void initialize(Context context) {
160 DisplayMetrics metrics = new DisplayMetrics();
161 WindowManager wm = (WindowManager)
162 context.getSystemService(Context.WINDOW_SERVICE);
163 wm.getDefaultDisplay().getMetrics(metrics);
164 sPixelDensity = metrics.density;
165 sImageFileNamer = new ImageFileNamer(
166 context.getString(R.string.image_file_name_format));
167 }
168
169 public static int dpToPixel(int dp) {
170 return Math.round(sPixelDensity * dp);
171 }
172
173 // Rotates the bitmap by the specified degree.
174 // If a new bitmap is created, the original bitmap is recycled.
175 public static Bitmap rotate(Bitmap b, int degrees) {
176 return rotateAndMirror(b, degrees, false);
177 }
178
179 // Rotates and/or mirrors the bitmap. If a new bitmap is created, the
180 // original bitmap is recycled.
181 public static Bitmap rotateAndMirror(Bitmap b, int degrees, boolean mirror) {
182 if ((degrees != 0 || mirror) && b != null) {
183 Matrix m = new Matrix();
184 // Mirror first.
185 // horizontal flip + rotation = -rotation + horizontal flip
186 if (mirror) {
187 m.postScale(-1, 1);
188 degrees = (degrees + 360) % 360;
189 if (degrees == 0 || degrees == 180) {
190 m.postTranslate(b.getWidth(), 0);
191 } else if (degrees == 90 || degrees == 270) {
192 m.postTranslate(b.getHeight(), 0);
193 } else {
194 throw new IllegalArgumentException("Invalid degrees=" + degrees);
195 }
196 }
197 if (degrees != 0) {
198 // clockwise
199 m.postRotate(degrees,
200 (float) b.getWidth() / 2, (float) b.getHeight() / 2);
201 }
202
203 try {
204 Bitmap b2 = Bitmap.createBitmap(
205 b, 0, 0, b.getWidth(), b.getHeight(), m, true);
206 if (b != b2) {
207 b.recycle();
208 b = b2;
209 }
210 } catch (OutOfMemoryError ex) {
211 // We have no memory to rotate. Return the original bitmap.
212 }
213 }
214 return b;
215 }
216
217 /*
218 * Compute the sample size as a function of minSideLength
219 * and maxNumOfPixels.
220 * minSideLength is used to specify that minimal width or height of a
221 * bitmap.
222 * maxNumOfPixels is used to specify the maximal size in pixels that is
223 * tolerable in terms of memory usage.
224 *
225 * The function returns a sample size based on the constraints.
226 * Both size and minSideLength can be passed in as -1
227 * which indicates no care of the corresponding constraint.
228 * The functions prefers returning a sample size that
229 * generates a smaller bitmap, unless minSideLength = -1.
230 *
231 * Also, the function rounds up the sample size to a power of 2 or multiple
232 * of 8 because BitmapFactory only honors sample size this way.
233 * For example, BitmapFactory downsamples an image by 2 even though the
234 * request is 3. So we round up the sample size to avoid OOM.
235 */
236 public static int computeSampleSize(BitmapFactory.Options options,
237 int minSideLength, int maxNumOfPixels) {
238 int initialSize = computeInitialSampleSize(options, minSideLength,
239 maxNumOfPixels);
240
241 int roundedSize;
242 if (initialSize <= 8) {
243 roundedSize = 1;
244 while (roundedSize < initialSize) {
245 roundedSize <<= 1;
246 }
247 } else {
248 roundedSize = (initialSize + 7) / 8 * 8;
249 }
250
251 return roundedSize;
252 }
253
254 private static int computeInitialSampleSize(BitmapFactory.Options options,
255 int minSideLength, int maxNumOfPixels) {
256 double w = options.outWidth;
257 double h = options.outHeight;
258
259 int lowerBound = (maxNumOfPixels < 0) ? 1 :
260 (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels));
261 int upperBound = (minSideLength < 0) ? 128 :
262 (int) Math.min(Math.floor(w / minSideLength),
263 Math.floor(h / minSideLength));
264
265 if (upperBound < lowerBound) {
266 // return the larger one when there is no overlapping zone.
267 return lowerBound;
268 }
269
270 if (maxNumOfPixels < 0 && minSideLength < 0) {
271 return 1;
272 } else if (minSideLength < 0) {
273 return lowerBound;
274 } else {
275 return upperBound;
276 }
277 }
278
279 public static Bitmap makeBitmap(byte[] jpegData, int maxNumOfPixels) {
280 try {
281 BitmapFactory.Options options = new BitmapFactory.Options();
282 options.inJustDecodeBounds = true;
283 BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length,
284 options);
285 if (options.mCancel || options.outWidth == -1
286 || options.outHeight == -1) {
287 return null;
288 }
289 options.inSampleSize = computeSampleSize(
290 options, -1, maxNumOfPixels);
291 options.inJustDecodeBounds = false;
292
293 options.inDither = false;
294 options.inPreferredConfig = Bitmap.Config.ARGB_8888;
295 return BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length,
296 options);
297 } catch (OutOfMemoryError ex) {
298 Log.e(TAG, "Got oom exception ", ex);
299 return null;
300 }
301 }
302
303 public static void closeSilently(Closeable c) {
304 if (c == null) return;
305 try {
306 c.close();
307 } catch (Throwable t) {
308 // do nothing
309 }
310 }
311
312 public static void Assert(boolean cond) {
313 if (!cond) {
314 throw new AssertionError();
315 }
316 }
317
Michael Kolb8872c232013-01-29 10:33:22 -0800318 private static void throwIfCameraDisabled(Activity activity) throws CameraDisabledException {
319 // Check if device policy has disabled the camera.
Sascha Haeberling638e6f02013-09-18 14:28:51 -0700320 DevicePolicyManager dpm = (DevicePolicyManager) activity.getSystemService(
321 Context.DEVICE_POLICY_SERVICE);
322 if (dpm.getCameraDisabled(null)) {
323 throw new CameraDisabledException();
Michael Kolb8872c232013-01-29 10:33:22 -0800324 }
325 }
326
Michael Kolb8872c232013-01-29 10:33:22 -0800327 public static void showErrorAndFinish(final Activity activity, int msgId) {
328 DialogInterface.OnClickListener buttonListener =
329 new DialogInterface.OnClickListener() {
330 @Override
331 public void onClick(DialogInterface dialog, int which) {
332 activity.finish();
333 }
334 };
335 TypedValue out = new TypedValue();
336 activity.getTheme().resolveAttribute(android.R.attr.alertDialogIcon, out, true);
337 new AlertDialog.Builder(activity)
338 .setCancelable(false)
339 .setTitle(R.string.camera_error_title)
340 .setMessage(msgId)
341 .setNeutralButton(R.string.dialog_ok, buttonListener)
342 .setIcon(out.resourceId)
343 .show();
344 }
345
346 public static <T> T checkNotNull(T object) {
347 if (object == null) throw new NullPointerException();
348 return object;
349 }
350
351 public static boolean equals(Object a, Object b) {
352 return (a == b) || (a == null ? false : a.equals(b));
353 }
354
355 public static int nextPowerOf2(int n) {
356 n -= 1;
357 n |= n >>> 16;
358 n |= n >>> 8;
359 n |= n >>> 4;
360 n |= n >>> 2;
361 n |= n >>> 1;
362 return n + 1;
363 }
364
365 public static float distance(float x, float y, float sx, float sy) {
366 float dx = x - sx;
367 float dy = y - sy;
Sascha Haeberling638e6f02013-09-18 14:28:51 -0700368 return (float) Math.sqrt(dx * dx + dy * dy);
Michael Kolb8872c232013-01-29 10:33:22 -0800369 }
370
371 public static int clamp(int x, int min, int max) {
372 if (x > max) return max;
373 if (x < min) return min;
374 return x;
375 }
376
Igor Murashkin160b0362013-10-14 14:57:30 -0700377 public static float clamp(float x, float min, float max) {
378 if (x > max) return max;
379 if (x < min) return min;
380 return x;
381 }
382
Michael Kolb8872c232013-01-29 10:33:22 -0800383 public static int getDisplayRotation(Activity activity) {
384 int rotation = activity.getWindowManager().getDefaultDisplay()
385 .getRotation();
386 switch (rotation) {
387 case Surface.ROTATION_0: return 0;
388 case Surface.ROTATION_90: return 90;
389 case Surface.ROTATION_180: return 180;
390 case Surface.ROTATION_270: return 270;
391 }
392 return 0;
393 }
394
Doris Liu0ba8eaa2013-10-16 12:51:02 -0700395 /**
396 * Calculate the default orientation of the device based on the width and
397 * height of the display when rotation = 0 (i.e. natural width and height)
398 * @param activity the activity context
399 * @return whether the default orientation of the device is portrait
400 */
401 public static boolean isDefaultToPortrait(Activity activity) {
402 Display currentDisplay = activity.getWindowManager().getDefaultDisplay();
403 Point displaySize = new Point();
404 currentDisplay.getSize(displaySize);
405 int orientation = currentDisplay.getRotation();
406 int naturalWidth, naturalHeight;
407 if (orientation == Surface.ROTATION_0 || orientation == Surface.ROTATION_180) {
408 naturalWidth = displaySize.x;
409 naturalHeight = displaySize.y;
410 } else {
411 naturalWidth = displaySize.y;
412 naturalHeight = displaySize.x;
413 }
414 return naturalWidth < naturalHeight;
415 }
416
Michael Kolb8872c232013-01-29 10:33:22 -0800417 public static int getDisplayOrientation(int degrees, int cameraId) {
418 // See android.hardware.Camera.setDisplayOrientation for
419 // documentation.
420 Camera.CameraInfo info = new Camera.CameraInfo();
421 Camera.getCameraInfo(cameraId, info);
422 int result;
423 if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
424 result = (info.orientation + degrees) % 360;
425 result = (360 - result) % 360; // compensate the mirror
426 } else { // back-facing
427 result = (info.orientation - degrees + 360) % 360;
428 }
429 return result;
430 }
431
432 public static int getCameraOrientation(int cameraId) {
433 Camera.CameraInfo info = new Camera.CameraInfo();
434 Camera.getCameraInfo(cameraId, info);
435 return info.orientation;
436 }
437
438 public static int roundOrientation(int orientation, int orientationHistory) {
439 boolean changeOrientation = false;
440 if (orientationHistory == OrientationEventListener.ORIENTATION_UNKNOWN) {
441 changeOrientation = true;
442 } else {
443 int dist = Math.abs(orientation - orientationHistory);
444 dist = Math.min( dist, 360 - dist );
445 changeOrientation = ( dist >= 45 + ORIENTATION_HYSTERESIS );
446 }
447 if (changeOrientation) {
448 return ((orientation + 45) / 90 * 90) % 360;
449 }
450 return orientationHistory;
451 }
452
Michael Kolb8872c232013-01-29 10:33:22 -0800453 private static Point getDefaultDisplaySize(Activity activity, Point size) {
Sascha Haeberling638e6f02013-09-18 14:28:51 -0700454 activity.getWindowManager().getDefaultDisplay().getSize(size);
Michael Kolb8872c232013-01-29 10:33:22 -0800455 return size;
456 }
457
458 public static Size getOptimalPreviewSize(Activity currentActivity,
459 List<Size> sizes, double targetRatio) {
Michael Kolb8872c232013-01-29 10:33:22 -0800460
Ruben Brunk714d4d02013-10-09 16:01:16 -0700461 Point[] points = new Point[sizes.size()];
462
463 int index = 0;
464 for (Size s : sizes) {
465 points[index++] = new Point(s.width, s.height);
466 }
467
468 int optimalPickIndex = getOptimalPreviewSize(currentActivity, points, targetRatio);
469 return (optimalPickIndex == -1) ? null : sizes.get(optimalPickIndex);
470 }
471
472 public static int getOptimalPreviewSize(Activity currentActivity,
473 Point[] sizes, double targetRatio) {
474 // Use a very small tolerance because we want an exact match.
475 final double ASPECT_TOLERANCE = 0.01;
476 if (sizes == null) return -1;
477
478 int optimalSizeIndex = -1;
Michael Kolb8872c232013-01-29 10:33:22 -0800479 double minDiff = Double.MAX_VALUE;
480
481 // Because of bugs of overlay and layout, we sometimes will try to
482 // layout the viewfinder in the portrait orientation and thus get the
483 // wrong size of preview surface. When we change the preview size, the
484 // new overlay will be created before the old one closed, which causes
485 // an exception. For now, just get the screen size.
486 Point point = getDefaultDisplaySize(currentActivity, new Point());
487 int targetHeight = Math.min(point.x, point.y);
488 // Try to find an size match aspect ratio and size
Ruben Brunk714d4d02013-10-09 16:01:16 -0700489 for (int i = 0; i < sizes.length; i++) {
490 Point size = sizes[i];
491 double ratio = (double) size.x / size.y;
Michael Kolb8872c232013-01-29 10:33:22 -0800492 if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
Ruben Brunk714d4d02013-10-09 16:01:16 -0700493 if (Math.abs(size.y - targetHeight) < minDiff) {
494 optimalSizeIndex = i;
495 minDiff = Math.abs(size.y - targetHeight);
Michael Kolb8872c232013-01-29 10:33:22 -0800496 }
497 }
498 // Cannot find the one match the aspect ratio. This should not happen.
499 // Ignore the requirement.
Ruben Brunk714d4d02013-10-09 16:01:16 -0700500 if (optimalSizeIndex == -1) {
Michael Kolb8872c232013-01-29 10:33:22 -0800501 Log.w(TAG, "No preview size match the aspect ratio");
502 minDiff = Double.MAX_VALUE;
Ruben Brunk714d4d02013-10-09 16:01:16 -0700503 for (int i = 0; i < sizes.length; i++) {
504 Point size = sizes[i];
505 if (Math.abs(size.y - targetHeight) < minDiff) {
506 optimalSizeIndex = i;
507 minDiff = Math.abs(size.y - targetHeight);
Michael Kolb8872c232013-01-29 10:33:22 -0800508 }
509 }
510 }
Ruben Brunk714d4d02013-10-09 16:01:16 -0700511 return optimalSizeIndex;
Michael Kolb8872c232013-01-29 10:33:22 -0800512 }
513
514 // Returns the largest picture size which matches the given aspect ratio.
515 public static Size getOptimalVideoSnapshotPictureSize(
516 List<Size> sizes, double targetRatio) {
517 // Use a very small tolerance because we want an exact match.
518 final double ASPECT_TOLERANCE = 0.001;
519 if (sizes == null) return null;
520
521 Size optimalSize = null;
522
523 // Try to find a size matches aspect ratio and has the largest width
524 for (Size size : sizes) {
525 double ratio = (double) size.width / size.height;
526 if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
527 if (optimalSize == null || size.width > optimalSize.width) {
528 optimalSize = size;
529 }
530 }
531
532 // Cannot find one that matches the aspect ratio. This should not happen.
533 // Ignore the requirement.
534 if (optimalSize == null) {
535 Log.w(TAG, "No picture size match the aspect ratio");
536 for (Size size : sizes) {
537 if (optimalSize == null || size.width > optimalSize.width) {
538 optimalSize = size;
539 }
540 }
541 }
542 return optimalSize;
543 }
544
545 public static void dumpParameters(Parameters parameters) {
546 String flattened = parameters.flatten();
547 StringTokenizer tokenizer = new StringTokenizer(flattened, ";");
548 Log.d(TAG, "Dump all camera parameters:");
549 while (tokenizer.hasMoreElements()) {
550 Log.d(TAG, tokenizer.nextToken());
551 }
552 }
553
554 /**
555 * Returns whether the device is voice-capable (meaning, it can do MMS).
556 */
557 public static boolean isMmsCapable(Context context) {
558 TelephonyManager telephonyManager = (TelephonyManager)
559 context.getSystemService(Context.TELEPHONY_SERVICE);
560 if (telephonyManager == null) {
561 return false;
562 }
563
564 try {
565 Class<?> partypes[] = new Class[0];
566 Method sIsVoiceCapable = TelephonyManager.class.getMethod(
567 "isVoiceCapable", partypes);
568
569 Object arglist[] = new Object[0];
570 Object retobj = sIsVoiceCapable.invoke(telephonyManager, arglist);
571 return (Boolean) retobj;
572 } catch (java.lang.reflect.InvocationTargetException ite) {
573 // Failure, must be another device.
574 // Assume that it is voice capable.
575 } catch (IllegalAccessException iae) {
576 // Failure, must be an other device.
577 // Assume that it is voice capable.
578 } catch (NoSuchMethodException nsme) {
579 }
580 return true;
581 }
582
583 // This is for test only. Allow the camera to launch the specific camera.
584 public static int getCameraFacingIntentExtras(Activity currentActivity) {
585 int cameraId = -1;
586
587 int intentCameraId =
Angus Kongb50b5cb2013-08-09 14:55:20 -0700588 currentActivity.getIntent().getIntExtra(CameraUtil.EXTRAS_CAMERA_FACING, -1);
Michael Kolb8872c232013-01-29 10:33:22 -0800589
590 if (isFrontCameraIntent(intentCameraId)) {
591 // Check if the front camera exist
Angus Kong20fad242013-11-11 18:23:46 -0800592 int frontCameraId = ((CameraActivity) currentActivity).getCameraProvider()
593 .getFirstFrontCameraId();
Michael Kolb8872c232013-01-29 10:33:22 -0800594 if (frontCameraId != -1) {
595 cameraId = frontCameraId;
596 }
597 } else if (isBackCameraIntent(intentCameraId)) {
598 // Check if the back camera exist
Angus Kong20fad242013-11-11 18:23:46 -0800599 int backCameraId = ((CameraActivity) currentActivity).getCameraProvider()
600 .getFirstBackCameraId();
Michael Kolb8872c232013-01-29 10:33:22 -0800601 if (backCameraId != -1) {
602 cameraId = backCameraId;
603 }
604 }
605 return cameraId;
606 }
607
608 private static boolean isFrontCameraIntent(int intentCameraId) {
609 return (intentCameraId == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
610 }
611
612 private static boolean isBackCameraIntent(int intentCameraId) {
613 return (intentCameraId == android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK);
614 }
615
616 private static int sLocation[] = new int[2];
617
618 // This method is not thread-safe.
619 public static boolean pointInView(float x, float y, View v) {
620 v.getLocationInWindow(sLocation);
621 return x >= sLocation[0] && x < (sLocation[0] + v.getWidth())
622 && y >= sLocation[1] && y < (sLocation[1] + v.getHeight());
623 }
624
625 public static int[] getRelativeLocation(View reference, View view) {
626 reference.getLocationInWindow(sLocation);
627 int referenceX = sLocation[0];
628 int referenceY = sLocation[1];
629 view.getLocationInWindow(sLocation);
630 sLocation[0] -= referenceX;
631 sLocation[1] -= referenceY;
632 return sLocation;
633 }
634
635 public static boolean isUriValid(Uri uri, ContentResolver resolver) {
636 if (uri == null) return false;
637
638 try {
639 ParcelFileDescriptor pfd = resolver.openFileDescriptor(uri, "r");
640 if (pfd == null) {
641 Log.e(TAG, "Fail to open URI. URI=" + uri);
642 return false;
643 }
644 pfd.close();
645 } catch (IOException ex) {
646 return false;
647 }
648 return true;
649 }
650
Michael Kolb8872c232013-01-29 10:33:22 -0800651 public static void dumpRect(RectF rect, String msg) {
652 Log.v(TAG, msg + "=(" + rect.left + "," + rect.top
653 + "," + rect.right + "," + rect.bottom + ")");
654 }
655
656 public static void rectFToRect(RectF rectF, Rect rect) {
657 rect.left = Math.round(rectF.left);
658 rect.top = Math.round(rectF.top);
659 rect.right = Math.round(rectF.right);
660 rect.bottom = Math.round(rectF.bottom);
661 }
662
Doris Liu36ebcb12013-10-28 14:44:24 -0700663 public static Rect rectFToRect(RectF rectF) {
664 Rect rect = new Rect();
665 rectFToRect(rectF, rect);
666 return rect;
667 }
668
669 public static RectF rectToRectF(Rect r) {
670 return new RectF(r.left, r.top, r.right, r.bottom);
671 }
672
Michael Kolb8872c232013-01-29 10:33:22 -0800673 public static void prepareMatrix(Matrix matrix, boolean mirror, int displayOrientation,
674 int viewWidth, int viewHeight) {
675 // Need mirror for front camera.
676 matrix.setScale(mirror ? -1 : 1, 1);
677 // This is the value for android.hardware.Camera.setDisplayOrientation.
678 matrix.postRotate(displayOrientation);
679 // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
680 // UI coordinates range from (0, 0) to (width, height).
681 matrix.postScale(viewWidth / 2000f, viewHeight / 2000f);
682 matrix.postTranslate(viewWidth / 2f, viewHeight / 2f);
683 }
684
Doris Liu36ebcb12013-10-28 14:44:24 -0700685 public static void prepareMatrix(Matrix matrix, boolean mirror, int displayOrientation,
686 Rect previewRect) {
687 // Need mirror for front camera.
688 matrix.setScale(mirror ? -1 : 1, 1);
689 // This is the value for android.hardware.Camera.setDisplayOrientation.
690 matrix.postRotate(displayOrientation);
691
692 // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
693 // We need to map camera driver coordinates to preview rect coordinates
694 Matrix mapping = new Matrix();
695 mapping.setRectToRect(new RectF(-1000, -1000, 1000, 1000), rectToRectF(previewRect),
696 Matrix.ScaleToFit.FILL);
697 matrix.setConcat(mapping, matrix);
698 }
699
Michael Kolb8872c232013-01-29 10:33:22 -0800700 public static String createJpegName(long dateTaken) {
701 synchronized (sImageFileNamer) {
702 return sImageFileNamer.generateName(dateTaken);
703 }
704 }
705
706 public static void broadcastNewPicture(Context context, Uri uri) {
707 context.sendBroadcast(new Intent(ACTION_NEW_PICTURE, uri));
708 // Keep compatibility
709 context.sendBroadcast(new Intent("com.android.camera.NEW_PICTURE", uri));
710 }
711
712 public static void fadeIn(View view, float startAlpha, float endAlpha, long duration) {
713 if (view.getVisibility() == View.VISIBLE) return;
714
715 view.setVisibility(View.VISIBLE);
716 Animation animation = new AlphaAnimation(startAlpha, endAlpha);
717 animation.setDuration(duration);
718 view.startAnimation(animation);
719 }
720
721 public static void fadeIn(View view) {
722 fadeIn(view, 0F, 1F, 400);
723
724 // We disabled the button in fadeOut(), so enable it here.
725 view.setEnabled(true);
726 }
727
728 public static void fadeOut(View view) {
729 if (view.getVisibility() != View.VISIBLE) return;
730
731 // Since the button is still clickable before fade-out animation
732 // ends, we disable the button first to block click.
733 view.setEnabled(false);
734 Animation animation = new AlphaAnimation(1F, 0F);
735 animation.setDuration(400);
736 view.startAnimation(animation);
737 view.setVisibility(View.GONE);
738 }
739
Angus Kong20fad242013-11-11 18:23:46 -0800740 public static int getJpegRotation(CameraActivity activity, int cameraId, int orientation) {
Michael Kolb8872c232013-01-29 10:33:22 -0800741 // See android.hardware.Camera.Parameters.setRotation for
742 // documentation.
743 int rotation = 0;
744 if (orientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
Angus Kong20fad242013-11-11 18:23:46 -0800745 CameraInfo info = activity.getCameraProvider().getCameraInfo()[cameraId];
Michael Kolb8872c232013-01-29 10:33:22 -0800746 if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
747 rotation = (info.orientation - orientation + 360) % 360;
748 } else { // back-facing camera
749 rotation = (info.orientation + orientation) % 360;
750 }
751 }
752 return rotation;
753 }
754
Sascha Haeberling37f36112013-08-06 14:31:52 -0700755 /**
756 * Down-samples a jpeg byte array.
757 * @param data a byte array of jpeg data
758 * @param downSampleFactor down-sample factor
759 * @return decoded and down-sampled bitmap
760 */
761 public static Bitmap downSample(final byte[] data, int downSampleFactor) {
762 final BitmapFactory.Options opts = new BitmapFactory.Options();
763 // Downsample the image
764 opts.inSampleSize = downSampleFactor;
765 return BitmapFactory.decodeByteArray(data, 0, data.length, opts);
766 }
767
Michael Kolb8872c232013-01-29 10:33:22 -0800768 public static void setGpsParameters(Parameters parameters, Location loc) {
769 // Clear previous GPS location from the parameters.
770 parameters.removeGpsData();
771
772 // We always encode GpsTimeStamp
773 parameters.setGpsTimestamp(System.currentTimeMillis() / 1000);
774
775 // Set GPS location.
776 if (loc != null) {
777 double lat = loc.getLatitude();
778 double lon = loc.getLongitude();
779 boolean hasLatLon = (lat != 0.0d) || (lon != 0.0d);
780
781 if (hasLatLon) {
782 Log.d(TAG, "Set gps location");
783 parameters.setGpsLatitude(lat);
784 parameters.setGpsLongitude(lon);
785 parameters.setGpsProcessingMethod(loc.getProvider().toUpperCase());
786 if (loc.hasAltitude()) {
787 parameters.setGpsAltitude(loc.getAltitude());
788 } else {
789 // for NETWORK_PROVIDER location provider, we may have
790 // no altitude information, but the driver needs it, so
791 // we fake one.
792 parameters.setGpsAltitude(0);
793 }
794 if (loc.getTime() != 0) {
795 // Location.getTime() is UTC in milliseconds.
796 // gps-timestamp is UTC in seconds.
797 long utcTimeSeconds = loc.getTime() / 1000;
798 parameters.setGpsTimestamp(utcTimeSeconds);
799 }
800 } else {
801 loc = null;
802 }
803 }
804 }
805
ztenghui16a35202013-09-23 11:35:36 -0700806 /**
807 * For still image capture, we need to get the right fps range such that the
808 * camera can slow down the framerate to allow for less-noisy/dark
809 * viewfinder output in dark conditions.
810 *
811 * @param params Camera's parameters.
812 * @return null if no appropiate fps range can't be found. Otherwise, return
813 * the right range.
814 */
815 public static int[] getPhotoPreviewFpsRange(Parameters params) {
Ruben Brunk2a74dfd2013-10-29 18:28:32 -0700816 return getPhotoPreviewFpsRange(params.getSupportedPreviewFpsRange());
817 }
818
819 public static int[] getPhotoPreviewFpsRange(List<int[]> frameRates) {
ztenghui16a35202013-09-23 11:35:36 -0700820 if (frameRates.size() == 0) {
821 Log.e(TAG, "No suppoted frame rates returned!");
822 return null;
823 }
824
825 // Find the lowest min rate in supported ranges who can cover 30fps.
826 int lowestMinRate = MAX_PREVIEW_FPS_TIMES_1000;
827 for (int[] rate : frameRates) {
828 int minFps = rate[Parameters.PREVIEW_FPS_MIN_INDEX];
829 int maxFps = rate[Parameters.PREVIEW_FPS_MAX_INDEX];
830 if (maxFps >= PREFERRED_PREVIEW_FPS_TIMES_1000 &&
831 minFps <= PREFERRED_PREVIEW_FPS_TIMES_1000 &&
832 minFps < lowestMinRate) {
833 lowestMinRate = minFps;
834 }
835 }
836
837 // Find all the modes with the lowest min rate found above, the pick the
838 // one with highest max rate.
839 int resultIndex = -1;
840 int highestMaxRate = 0;
841 for (int i = 0; i < frameRates.size(); i++) {
842 int[] rate = frameRates.get(i);
843 int minFps = rate[Parameters.PREVIEW_FPS_MIN_INDEX];
844 int maxFps = rate[Parameters.PREVIEW_FPS_MAX_INDEX];
845 if (minFps == lowestMinRate && highestMaxRate < maxFps) {
846 highestMaxRate = maxFps;
847 resultIndex = i;
848 }
849 }
850
851 if (resultIndex >= 0) {
852 return frameRates.get(resultIndex);
853 }
854 Log.e(TAG, "Can't find an appropiate frame rate range!");
855 return null;
856 }
Angus Kongd82eae22013-06-11 12:00:15 -0700857
858 public static int[] getMaxPreviewFpsRange(Parameters params) {
859 List<int[]> frameRates = params.getSupportedPreviewFpsRange();
860 if (frameRates != null && frameRates.size() > 0) {
861 // The list is sorted. Return the last element.
862 return frameRates.get(frameRates.size() - 1);
863 }
864 return new int[0];
865 }
866
Angus Kong20fad242013-11-11 18:23:46 -0800867 public static void throwIfCameraDisabled(Context context) throws CameraDisabledException {
868 // Check if device policy has disabled the camera.
869 DevicePolicyManager dpm =
870 (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
871 if (dpm.getCameraDisabled(null)) {
872 throw new CameraDisabledException();
873 }
874 }
875
Michael Kolb8872c232013-01-29 10:33:22 -0800876 private static class ImageFileNamer {
Igor Murashkin160b0362013-10-14 14:57:30 -0700877 private final SimpleDateFormat mFormat;
Michael Kolb8872c232013-01-29 10:33:22 -0800878
879 // The date (in milliseconds) used to generate the last name.
880 private long mLastDate;
881
882 // Number of names generated for the same second.
883 private int mSameSecondCount;
884
885 public ImageFileNamer(String format) {
886 mFormat = new SimpleDateFormat(format);
887 }
888
889 public String generateName(long dateTaken) {
890 Date date = new Date(dateTaken);
891 String result = mFormat.format(date);
892
893 // If the last name was generated for the same second,
894 // we append _1, _2, etc to the name.
895 if (dateTaken / 1000 == mLastDate / 1000) {
896 mSameSecondCount++;
897 result += "_" + mSameSecondCount;
898 } else {
899 mLastDate = dateTaken;
900 mSameSecondCount = 0;
901 }
902
903 return result;
904 }
905 }
Angus Kongb40738a2013-06-03 14:55:34 -0700906
Sascha Haeberlingb7639c62013-09-09 14:42:43 -0700907 public static void playVideo(Activity activity, Uri uri, String title) {
Angus Kongb40738a2013-06-03 14:55:34 -0700908 try {
ztenghui98b2a282013-10-11 17:15:40 -0700909 boolean isSecureCamera = ((CameraActivity)activity).isSecureCamera();
Seth Raphaelcbd82672013-11-05 10:12:36 -0800910 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA,
911 UsageStatistics.ACTION_PLAY_VIDEO, null);
ztenghui98b2a282013-10-11 17:15:40 -0700912 if (!isSecureCamera) {
Mangesh Ghiware2d939fe2013-10-14 21:19:22 -0700913 Intent intent = IntentHelper.getVideoPlayerIntent(activity, uri)
ztenghui98b2a282013-10-11 17:15:40 -0700914 .putExtra(Intent.EXTRA_TITLE, title)
915 .putExtra(KEY_TREAT_UP_AS_BACK, true);
916 activity.startActivityForResult(intent, CameraActivity.REQ_CODE_DONT_SWITCH_TO_PREVIEW);
917 } else {
918 // In order not to send out any intent to be intercepted and
919 // show the lock screen immediately, we just let the secure
920 // camera activity finish.
921 activity.finish();
922 }
Angus Kongb40738a2013-06-03 14:55:34 -0700923 } catch (ActivityNotFoundException e) {
Sascha Haeberlingb7639c62013-09-09 14:42:43 -0700924 Toast.makeText(activity, activity.getString(R.string.video_err),
Angus Kongb40738a2013-06-03 14:55:34 -0700925 Toast.LENGTH_SHORT).show();
926 }
927 }
Sascha Haeberlingfae11a12013-08-15 14:29:49 -0700928
929 /**
930 * Starts GMM with the given location shown. If this fails, and GMM could
931 * not be found, we use a geo intent as a fallback.
932 *
Sascha Haeberlingb7639c62013-09-09 14:42:43 -0700933 * @param activity the activity to use for launching the Maps intent.
Sascha Haeberlingfae11a12013-08-15 14:29:49 -0700934 * @param latLong a 2-element array containing {latitude/longitude}.
935 */
Sascha Haeberlingb7639c62013-09-09 14:42:43 -0700936 public static void showOnMap(Activity activity, double[] latLong) {
Sascha Haeberlingfae11a12013-08-15 14:29:49 -0700937 try {
938 // We don't use "geo:latitude,longitude" because it only centers
939 // the MapView to the specified location, but we need a marker
940 // for further operations (routing to/from).
941 // The q=(lat, lng) syntax is suggested by geo-team.
942 String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?f=q&q=(%f,%f)",
943 latLong[0], latLong[1]);
944 ComponentName compName = new ComponentName(MAPS_PACKAGE_NAME,
945 MAPS_CLASS_NAME);
946 Intent mapsIntent = new Intent(Intent.ACTION_VIEW,
947 Uri.parse(uri)).setComponent(compName);
Sascha Haeberlingb7639c62013-09-09 14:42:43 -0700948 activity.startActivityForResult(mapsIntent,
949 CameraActivity.REQ_CODE_DONT_SWITCH_TO_PREVIEW);
Sascha Haeberlingfae11a12013-08-15 14:29:49 -0700950 } catch (ActivityNotFoundException e) {
951 // Use the "geo intent" if no GMM is installed
952 Log.e(TAG, "GMM activity not found!", e);
953 String url = String.format(Locale.ENGLISH, "geo:%f,%f", latLong[0], latLong[1]);
954 Intent mapsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Sascha Haeberlingb7639c62013-09-09 14:42:43 -0700955 activity.startActivity(mapsIntent);
Sascha Haeberlingfae11a12013-08-15 14:29:49 -0700956 }
957 }
Angus Kong7d2388d2013-09-18 23:56:01 -0700958
Angus Kongb21215a2013-09-20 18:41:46 -0700959 /**
960 * Dumps the stack trace.
961 *
962 * @param level How many levels of the stack are dumped. 0 means all.
963 * @return A {@link java.lang.String} of all the output with newline
964 * between each.
965 */
Angus Kong7d2388d2013-09-18 23:56:01 -0700966 public static String dumpStackTrace(int level) {
967 StackTraceElement[] elems = Thread.currentThread().getStackTrace();
968 // Ignore the first 3 elements.
Angus Kongb21215a2013-09-20 18:41:46 -0700969 level = (level == 0 ? elems.length : Math.min(level + 3, elems.length));
Angus Kong7d2388d2013-09-18 23:56:01 -0700970 String ret = new String();
971 for (int i = 3; i < level; i++) {
Angus Kongb21215a2013-09-20 18:41:46 -0700972 ret = ret + "\t" + elems[i].toString() + '\n';
Angus Kong7d2388d2013-09-18 23:56:01 -0700973 }
974 return ret;
975 }
Doris Liubd1b8f92014-01-03 17:59:51 -0800976
977
978 /**
979 * Gets the theme color of a specific mode.
980 *
981 * @param modeIndex index of the mode
982 * @param context current context
983 * @return theme color of the mode if input index is valid, otherwise 0
984 */
985 public static int getCameraThemeColorId(int modeIndex, Context context) {
986
987 // Find the theme color using id from the color array
988 TypedArray colorRes = context.getResources()
989 .obtainTypedArray(R.array.camera_mode_theme_color);
990 if (modeIndex >= colorRes.length() || modeIndex < 0) {
991 // Mode index not found
992 Log.e(TAG, "Invalid mode index: " + modeIndex);
993 return 0;
994 }
995 return colorRes.getResourceId(modeIndex, 0);
996 }
997
998 /**
Spike Spragueb92910e2014-01-13 18:10:54 -0800999 * Gets the theme pressed color of a specific mode.
1000 *
1001 * @param modeIndex index of the mode
1002 * @param context current context
1003 * @return theme pressed color of the mode if input index is valid, otherwise 0
1004 */
1005 public static int getCameraThemePressedColorId(int modeIndex, Context context) {
1006
1007 // Find the theme color using id from the color array
1008 TypedArray colorRes = context.getResources()
1009 .obtainTypedArray(R.array.camera_mode_theme_pressed_color);
1010 if (modeIndex >= colorRes.length() || modeIndex < 0) {
1011 // Mode index not found
1012 Log.e(TAG, "Invalid mode index: " + modeIndex);
1013 return 0;
1014 }
1015 return colorRes.getResourceId(modeIndex, 0);
1016 }
1017
1018 /**
Doris Liubd1b8f92014-01-03 17:59:51 -08001019 * Gets the mode icon resource id of a specific mode.
1020 *
1021 * @param modeIndex index of the mode
1022 * @param context current context
1023 * @return icon resource id if the index is valid, otherwise 0
1024 */
1025 public static int getCameraModeIconResId(int modeIndex, Context context) {
1026 // Find the camera mode icon using id
1027 TypedArray cameraModesIcons = context.getResources()
1028 .obtainTypedArray(R.array.camera_mode_icon);
1029 if (modeIndex >= cameraModesIcons.length() || modeIndex < 0) {
1030 // Mode index not found
1031 Log.e(TAG, "Invalid mode index: " + modeIndex);
1032 return 0;
1033 }
1034 return cameraModesIcons.getResourceId(modeIndex, 0);
1035 }
1036
1037 /**
1038 * Gets the mode text of a specific mode.
1039 *
1040 * @param modeIndex index of the mode
1041 * @param context current context
1042 * @return mode text if the index is valid, otherwise a new empty string
1043 */
1044 public static String getCameraModeText(int modeIndex, Context context) {
1045 // Find the camera mode icon using id
1046 String[] cameraModesText = context.getResources()
1047 .getStringArray(R.array.camera_mode_text);
1048 if (modeIndex < 0 || modeIndex >= cameraModesText.length) {
1049 Log.e(TAG, "Invalid mode index: " + modeIndex);
1050 return new String();
1051 }
1052 return cameraModesText[modeIndex];
1053 }
Erin Dahlgrenfecd7232014-01-16 13:29:42 -08001054
1055 /**
Spike Sprague79718f62014-01-28 18:48:22 -08001056 * Gets the mode content description of a specific mode.
1057 *
1058 * @param modeIndex index of the mode
1059 * @param context current context
1060 * @return mode content description if the index is valid, otherwise a new empty string
1061 */
1062 public static String getCameraModeContentDescription(int modeIndex, Context context) {
1063 String[] cameraModesDesc = context.getResources()
1064 .getStringArray(R.array.camera_mode_content_description);
1065 if (modeIndex < 0 || modeIndex >= cameraModesDesc.length) {
1066 Log.e(TAG, "Invalid mode index: " + modeIndex);
1067 return new String();
1068 }
1069 return cameraModesDesc[modeIndex];
1070 }
1071
1072 /**
Erin Dahlgrenfecd7232014-01-16 13:29:42 -08001073 * Gets the shutter icon res id for a specific mode.
1074 *
1075 * @param modeIndex index of the mode
1076 * @param context current context
1077 * @return mode shutter icon id if the index is valid, otherwise 0.
1078 */
1079 public static int getCameraShutterIconId(int modeIndex, Context context) {
1080 // Find the camera mode icon using id
1081 TypedArray shutterIcons = context.getResources()
1082 .obtainTypedArray(R.array.camera_mode_shutter_icon);
1083 if (modeIndex < 0 || modeIndex >= shutterIcons.length()) {
1084 Log.e(TAG, "Invalid mode index: " + modeIndex);
1085 return 0;
1086 }
1087 return shutterIcons.getResourceId(modeIndex, 0);
1088 }
Michael Kolb8872c232013-01-29 10:33:22 -08001089}