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 setFocusMode(Camera mCamera, Context item, int type) {
        Camera.Parameters params = mCamera.getParameters();
        List<String> FocusModes = params.getSupportedFocusModes();

        switch (type) {
        case 0:
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
            else
                Toast.makeText(item, "Auto Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 1:
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO))
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
            else
                Toast.makeText(item, "Continuous Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 2:
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_EDOF))
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_EDOF);
            else
                Toast.makeText(item, "EDOF Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 3:
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_FIXED))
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED);
            else
                Toast.makeText(item, "Fixed Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 4:
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_INFINITY))
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
            else
                Toast.makeText(item, "Infinity Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        case 5:
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_MACRO))
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
            else
                Toast.makeText(item, "Macro Mode not supported", Toast.LENGTH_SHORT).show();
            break;
        }

        mCamera.setParameters(params);
    }
}