/*
 * Copyright (c) 2015 Diona Ltd.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of Diona
 * ("Confidential Information"). You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the license agreement you
 * entered into with Diona.
 */
package org.odk.collect.android.activities;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * An Activity for launching the camera.
 */
public class FormCameraActivity extends AppCompatActivity {

  public static Intent newIntent(final Context context) {
    return new Intent(context, FormCameraActivity.class);
  }

  private String[] getRequiredCameraPermissions(final Context context) {
    final List<String> requiredPermissions = new ArrayList<>();
    final boolean hasStoragePermission = ContextCompat.checkSelfPermission(context,
        Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
    final boolean hasCameraPermission = ContextCompat.checkSelfPermission(context,
        Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
    if (!hasCameraPermission) {
      requiredPermissions.add(Manifest.permission.CAMERA);
    }
    if (!hasStoragePermission) {
      requiredPermissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    if (requiredPermissions.isEmpty()) {
      return null;
    } else {
      return requiredPermissions.toArray(new String[requiredPermissions.size()]);
    }
  }
}
