Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 *******************************************************************************
 * @file CameraHelper.java
 * @author Keidan
 * @date 30/10/2015
 * @par Project Light Widget
 *
 * @par Copyright 2015 Keidan, all right reserved
 *
 *      This software is distributed in the hope that it will be useful, but
 *      WITHOUT ANY WARRANTY.
 *
 *      License summary : You can modify and redistribute the sources code and
 *      binaries. You can send me the bug-fix
 *
 *      Term of the license in in the file license.txt.
 *
 *******************************************************************************
 */

import android.hardware.Camera;
import android.hardware.Camera.Parameters;

public class Main {
    private static Camera camera = null;

    public static boolean initializeCameraFlash() {
        checkCamera();
        if (camera != null) {
            final Parameters param = camera.getParameters();
            param.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
            try {
                camera.setParameters(param);
                camera.startPreview();
                return true;
            } catch (final Exception e) {
                releaseCamera();
            }
        }
        return false;
    }

    private static void checkCamera() {
        if (camera == null)
            camera = Camera.open();
    }

    public static void releaseCamera() {
        if (camera != null) {
            camera.stopPreview();
            camera.release();
            camera = null;
        }
    }
}