Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2008 ZXing authors
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import android.content.Context;

import android.hardware.Camera;

import android.widget.Toast;

import java.util.List;

public class Main {
    public static void setFlashMode(Camera mCamera, Context item, int type) {
        Camera.Parameters params = mCamera.getParameters();
        List<String> FlashModes = params.getSupportedFlashModes();

        switch (type) {
        case 0:
            if (FlashModes.contains(Camera.Parameters.FLASH_MODE_AUTO))
                params.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
            else
                Toast.makeText(item, "Auto Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 1:
            if (FlashModes.contains(Camera.Parameters.FLASH_MODE_OFF))
                params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
            else
                Toast.makeText(item, "Off Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 2:
            if (FlashModes.contains(Camera.Parameters.FLASH_MODE_ON))
                params.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
            else
                Toast.makeText(item, "On Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 3:
            if (FlashModes.contains(Camera.Parameters.FLASH_MODE_RED_EYE))
                params.setFlashMode(Camera.Parameters.FLASH_MODE_RED_EYE);
            else
                Toast.makeText(item, "Red Eye Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 4:
            if (FlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH))
                params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
            else
                Toast.makeText(item, "Torch Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        }

        mCamera.setParameters(params);
    }
}