コード例 #1
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   boolean useFrontCamera = getArguments().getBoolean(FRONT_CAMERA, false);
   camera = getCameraInstance(useFrontCamera);
   if (camera == null) {
     return;
   }
   initScreenParams();
   parameters = camera.getParameters();
   zoomRatios = parameters.getZoomRatios();
   zoomIndex = minZoomIndex = 0;
   maxZoomIndex = parameters.getMaxZoom();
   previewSizes = buildPreviewSizesRatioMap(parameters.getSupportedPreviewSizes());
   pictureSizes = buildPictureSizesRatioMap(parameters.getSupportedPictureSizes());
   List<String> sceneModes = parameters.getSupportedSceneModes();
   if (sceneModes != null) {
     for (String mode : sceneModes) {
       if (mode.equals(Camera.Parameters.SCENE_MODE_HDR)) {
         supportedHDR = true;
         break;
       }
     }
   }
   // it returns false positive
   /*getActivity().getApplicationContext().getPackageManager()
   .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);*/
   List<String> flashModes = parameters.getSupportedFlashModes();
   if (flashModes == null || flashModes.size() <= 1) {
     /* Device has no flash */
     supportedFlash = false;
   } else {
     supportedFlash = true;
   }
   if (CameraConst.DEBUG) {
     Timber.d("PictureSizesRatioMap:");
     for (Ratio r : pictureSizes.keySet()) {
       Timber.d(r.toString() + ":");
       for (Quality q : pictureSizes.get(r).keySet()) {
         Camera.Size size = pictureSizes.get(r).get(q);
         if (size != null) {
           Timber.d(q.toString() + ": " + size.width + "x" + size.height);
         }
       }
     }
   }
   expandParams(getArguments());
   initParams();
 }
コード例 #2
0
  private Map<Ratio, Map<Quality, Camera.Size>> buildPictureSizesRatioMap(List<Camera.Size> sizes) {
    Map<Ratio, Map<Quality, Camera.Size>> map = new HashMap<>();

    Map<Ratio, List<Camera.Size>> ratioListMap = new HashMap<>();
    for (Camera.Size size : sizes) {
      Ratio ratio = Ratio.pickRatio(size.width, size.height);
      if (ratio != null) {
        List<Camera.Size> sizeList = ratioListMap.get(ratio);
        if (sizeList == null) {
          sizeList = new ArrayList<>();
          ratioListMap.put(ratio, sizeList);
        }
        sizeList.add(size);
      }
    }
    for (Ratio r : ratioListMap.keySet()) {
      List<Camera.Size> list = ratioListMap.get(r);
      ratioListMap.put(r, sortSizes(list));
      Map<Quality, Camera.Size> sizeMap = new HashMap<>();
      int i = 0;
      for (Quality q : Quality.values()) {
        Camera.Size size = null;
        if (i < list.size()) {
          size = list.get(i++);
        }
        sizeMap.put(q, size);
      }
      map.put(r, sizeMap);
    }

    return map;
  }
コード例 #3
0
 private void expandParams(Bundle params) {
   if (params == null) {
     params = new Bundle();
   }
   int id = 0;
   if (params.containsKey(RATIO)) {
     id = params.getInt(RATIO, 1);
   }
   ratio = Ratio.getRatioById(id);
   id = 0;
   if (params.containsKey(QUALITY)) {
     id = params.getInt(QUALITY, 0);
   }
   quality = Quality.getQualityById(id);
   id = 0;
   if (params.containsKey(FOCUS_MODE)) {
     id = params.getInt(FOCUS_MODE);
   }
   focusMode = FocusMode.getFocusModeById(id);
   id = 0;
   if (params.containsKey(FLASH_MODE)) {
     id = params.getInt(FLASH_MODE);
   }
   flashMode = FlashMode.getFlashModeById(id);
   id = 0;
   if (params.containsKey(HDR_MODE)) {
     id = params.getInt(HDR_MODE);
   }
   hdrMode = HDRMode.getHDRModeById(id);
 }
コード例 #4
0
  private Bundle packSettings() {
    Bundle params = new Bundle();

    params.putInt(QUALITY, quality.getId());
    params.putInt(RATIO, ratio.getId());
    params.putInt(FOCUS_MODE, focusMode.getId());
    params.putInt(HDR_MODE, hdrMode.getId());
    return params;
  }
コード例 #5
0
 @Override
 public void onRatioChanged(int id) {
   ratio = Ratio.getRatioById(id);
   setPreviewSize(parameters, ratio);
   setPictureSize(parameters, quality, ratio);
   camera.setParameters(parameters);
   setPreviewContainerSize(mScreenWidth, mScreenHeight, ratio);
   if (paramsChangedListener != null) {
     paramsChangedListener.onRatioChanged(id);
   }
 }
コード例 #6
0
  private Map<Ratio, Camera.Size> buildPreviewSizesRatioMap(List<Camera.Size> sizes) {
    Map<Ratio, Camera.Size> map = new HashMap<>();

    for (Camera.Size size : sizes) {
      Ratio ratio = Ratio.pickRatio(size.width, size.height);
      if (ratio != null) {
        Camera.Size oldSize = map.get(ratio);
        if (oldSize == null || (oldSize.width < size.width || oldSize.height < size.height)) {
          map.put(ratio, size);
        }
      }
    }

    return map;
  }