Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Android Accelerometer Sensor Manager Archetype
 * @author antoine vianey
 * under GPL v3 : http://www.gnu.org/licenses/gpl-3.0.html
 */

import android.hardware.Sensor;
import java.util.List;
import android.content.Context;

import android.hardware.SensorManager;

public class Main {
    private static Context oContext;
    private static SensorManager sensorManager;
    /** indicates whether or not Accelerometer Sensor is supported */
    private static Boolean supported;

    /**
     * Returns true if at least one Accelerometer sensor is available
     */
    public static boolean isSupported() {
        //Log.v(AccelerometerUtils.class.getClass().getCanonicalName(), "isSupported Accelerometer "+supported+" "+oContext);
        if (supported == null) {
            if (oContext != null) {
                sensorManager = (SensorManager) oContext.getSystemService(Context.SENSOR_SERVICE);
                List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
                supported = new Boolean(sensors.size() > 0);
            } else {
                supported = Boolean.FALSE;
            }
        }
        return supported;
    }
}