old mode 100755new mode 100644.. | .. |
---|
33 | 33 | import com.android.camera.widget.ModeOptions; |
---|
34 | 34 | import com.android.camera2.R; |
---|
35 | 35 | |
---|
| 36 | +import android.util.Log; |
---|
| 37 | +import android.hardware.camera2.CameraManager; |
---|
| 38 | +import android.hardware.camera2.CameraAccessException; |
---|
| 39 | +import android.hardware.camera2.CameraCharacteristics; |
---|
| 40 | +import com.android.camera.one.OneCamera.Facing; |
---|
| 41 | + |
---|
36 | 42 | /** |
---|
37 | 43 | * A class for generating pre-initialized |
---|
38 | 44 | * {@link #android.widget.ImageButton}s. |
---|
.. | .. |
---|
51 | 57 | public static final int BUTTON_GRID_LINES = 10; |
---|
52 | 58 | public static final int BUTTON_EXPOSURE_COMPENSATION = 11; |
---|
53 | 59 | public static final int BUTTON_COUNTDOWN = 12; |
---|
| 60 | + |
---|
| 61 | + public static final int ZERO_CAMERA = 0; |
---|
| 62 | + public static final int ONE_CAMERA = 1; |
---|
| 63 | + public static final int TWO_CAMERAS = 2; |
---|
54 | 64 | |
---|
55 | 65 | /** For two state MultiToggleImageButtons, the off index. */ |
---|
56 | 66 | public static final int OFF = 0; |
---|
.. | .. |
---|
101 | 111 | |
---|
102 | 112 | private final AppController mAppController; |
---|
103 | 113 | |
---|
104 | | - private static final String ANDROID_UVC_PROPERTY = "ro.camera.uvcfacing"; |
---|
| 114 | + private CameraManager mCameraManager; |
---|
| 115 | + private static String TAG = "ButtonManager"; |
---|
105 | 116 | |
---|
106 | 117 | /** |
---|
107 | 118 | * Get a new global ButtonManager. |
---|
.. | .. |
---|
114 | 125 | |
---|
115 | 126 | mSettingsManager = app.getSettingsManager(); |
---|
116 | 127 | mSettingsManager.addListener(this); |
---|
| 128 | + mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); |
---|
117 | 129 | } |
---|
118 | 130 | |
---|
119 | 131 | /** |
---|
.. | .. |
---|
361 | 373 | initializeHdrPlusFlashButton(button, cb, preCb, R.array.camera_flashmode_icons); |
---|
362 | 374 | break; |
---|
363 | 375 | case BUTTON_CAMERA: |
---|
364 | | - String uvcProperty = SystemProperties.get(ANDROID_UVC_PROPERTY, ""); |
---|
365 | | - if(uvcProperty.equals("null") || uvcProperty.equals("")){ |
---|
366 | | - initializeCameraButton(button, cb, |
---|
367 | | - preCb, R.array.camera_id_icons); |
---|
| 376 | + String[] cameraIds = new String[]{}; |
---|
| 377 | + int front_num = 0; |
---|
| 378 | + int back_num = 0; |
---|
| 379 | + int external_num = 0; |
---|
| 380 | + try { |
---|
| 381 | + cameraIds = mCameraManager.getCameraIdList(); |
---|
| 382 | + for (String cameraId : cameraIds) { |
---|
| 383 | + CameraCharacteristics characteristics = mCameraManager |
---|
| 384 | + .getCameraCharacteristics(cameraId); |
---|
| 385 | + if (characteristics.get(CameraCharacteristics.LENS_FACING) == |
---|
| 386 | + CameraCharacteristics.LENS_FACING_FRONT) { |
---|
| 387 | + front_num = front_num + 1; |
---|
| 388 | + } else if (characteristics.get(CameraCharacteristics.LENS_FACING) == |
---|
| 389 | + CameraCharacteristics.LENS_FACING_BACK) { |
---|
| 390 | + back_num = back_num + 1; |
---|
| 391 | + } else if (characteristics.get(CameraCharacteristics.LENS_FACING) == |
---|
| 392 | + CameraCharacteristics.LENS_FACING_EXTERNAL) { |
---|
| 393 | + external_num = external_num + 1; |
---|
| 394 | + } |
---|
| 395 | + } |
---|
368 | 396 | } |
---|
369 | | - else if (uvcProperty.equals("back")) { |
---|
370 | | - initializeCameraButton(button, cb, |
---|
371 | | - preCb, R.array.camera_id_icons_with_front_external); |
---|
| 397 | + catch (CameraAccessException ex) { |
---|
| 398 | + Log.e(TAG, "Unable to read camera list.", ex); |
---|
372 | 399 | } |
---|
373 | | - else if (uvcProperty.equals("front")) { |
---|
374 | | - initializeCameraButton(button, cb, |
---|
375 | | - preCb, R.array.camera_id_icons_with_back_external); |
---|
| 400 | + if (front_num == ONE_CAMERA && back_num == ZERO_CAMERA) { |
---|
| 401 | + if (external_num == ONE_CAMERA) { |
---|
| 402 | + initializeCameraButton(button, cb, |
---|
| 403 | + preCb, R.array.camera_id_icon_front_with_external); |
---|
| 404 | + } else if (external_num == TWO_CAMERAS) { |
---|
| 405 | + initializeCameraButton(button, cb, |
---|
| 406 | + preCb, R.array.camera_id_icon_front_with_double_external); |
---|
| 407 | + } |
---|
| 408 | + } else if (front_num == ZERO_CAMERA && back_num == ONE_CAMERA) { |
---|
| 409 | + if (external_num == ONE_CAMERA) { |
---|
| 410 | + initializeCameraButton(button, cb, |
---|
| 411 | + preCb, R.array.camera_id_icon_back_with_external); |
---|
| 412 | + } else if (external_num == TWO_CAMERAS) { |
---|
| 413 | + initializeCameraButton(button, cb, |
---|
| 414 | + preCb, R.array.camera_id_icon_back_with_double_external); |
---|
| 415 | + } |
---|
| 416 | + } else if (front_num == ONE_CAMERA && back_num == ONE_CAMERA) { |
---|
| 417 | + if (external_num == ZERO_CAMERA) { |
---|
| 418 | + initializeCameraButton(button, cb, |
---|
| 419 | + preCb, R.array.camera_id_icons); |
---|
| 420 | + } else if (external_num == ONE_CAMERA) { |
---|
| 421 | + initializeCameraButton(button, cb, |
---|
| 422 | + preCb, R.array.camera_id_icons_with_external); |
---|
| 423 | + } else if (external_num == TWO_CAMERAS) { |
---|
| 424 | + initializeCameraButton(button, cb, |
---|
| 425 | + preCb, R.array.camera_id_icons_with_double_external); |
---|
| 426 | + } |
---|
| 427 | + } else { |
---|
| 428 | + switch (cameraIds.length) { |
---|
| 429 | + case TWO_CAMERAS: |
---|
| 430 | + initializeCameraButton(button, cb, |
---|
| 431 | + preCb, R.array.camera_id_icons_external_double); |
---|
| 432 | + break; |
---|
| 433 | + } |
---|
376 | 434 | } |
---|
377 | | - else if (uvcProperty.equals("external")) { |
---|
378 | | - initializeCameraButton(button, cb, |
---|
379 | | - preCb, R.array.camera_id_icons_with_external); |
---|
380 | | - } |
---|
381 | | - else if (uvcProperty.equals("external-only")) { |
---|
382 | | - initializeCameraButton(button, cb, |
---|
383 | | - preCb, R.array.camera_id_icons_with_only_external); |
---|
384 | | - } |
---|
| 435 | + |
---|
385 | 436 | break; |
---|
386 | 437 | case BUTTON_HDR_PLUS: |
---|
387 | 438 | initializeHdrPlusButton(button, cb, preCb, R.array.pref_camera_hdr_plus_icons); |
---|