Example usage for android.hardware Sensor TYPE_TEMPERATURE

List of usage examples for android.hardware Sensor TYPE_TEMPERATURE

Introduction

In this page you can find the example usage for android.hardware Sensor TYPE_TEMPERATURE.

Prototype

int TYPE_TEMPERATURE

To view the source code for android.hardware Sensor TYPE_TEMPERATURE.

Click Source Link

Document

A constant describing a temperature sensor type

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
public static String getSensorTypeStr(int type) {
    switch (type) {
    case Sensor.TYPE_ALL://-1
        return "TYPE_ALL";
    //Accelerometer sensor type
    case Sensor.TYPE_ACCELEROMETER://1
        return "TYPE_ACCELEROMETER";
    //Magnetic field sensor type
    case Sensor.TYPE_MAGNETIC_FIELD://2
        return "TYPE_MAGNETIC_FIELD";
    //Orientation sensor type
    case Sensor.TYPE_ORIENTATION://3
        return "TYPE_ORIENTATION";
    //Gyroscope sensor type
    case Sensor.TYPE_GYROSCOPE://4
        return "TYPE_GYROSCOPE";
    //Light sensor type
    case Sensor.TYPE_LIGHT://5
        return "TYPE_LIGHT";
    //Pressure sensor type
    case Sensor.TYPE_PRESSURE://6
        return "TYPE_PRESSURE";
    //Temperature sensor type
    case Sensor.TYPE_TEMPERATURE://7
        return "TYPE_TEMPERATURE";
    //Proximity sensor type
    case Sensor.TYPE_PROXIMITY://8
        return "TYPE_PROXIMITY";
    //Gravity sensor type
    case Sensor.TYPE_GRAVITY://9
        return "TYPE_GRAVITY";
    //Linear acceleration sensor type
    case Sensor.TYPE_LINEAR_ACCELERATION://10
        return "TYPE_LINEAR_ACCELERATION";
    //Rotation vector sensor type
    case Sensor.TYPE_ROTATION_VECTOR://11
        return "TYPE_ROTATION_VECTOR";
    //Relative humidity sensor type
    case Sensor.TYPE_RELATIVE_HUMIDITY://12
        return "TYPE_RELATIVE_HUMIDITY";
    //Ambient temperature sensor type
    case Sensor.TYPE_AMBIENT_TEMPERATURE://13
        return "TYPE_AMBIENT_TEMPERATURE";
    //Uncalibrated magnetic field sensor type
    case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED://14
        return "TYPE_MAGNETIC_FIELD_UNCALIBRATED";
    //Uncalibrated rotation vector sensor type
    case Sensor.TYPE_GAME_ROTATION_VECTOR://15
        return "TYPE_GAME_ROTATION_VECTOR";
    //Uncalibreted gyroscope sensor type
    case Sensor.TYPE_GYROSCOPE_UNCALIBRATED://16
        return "TYPE_GYROSCOPE_UNCALIBRATED";
    //Significant motion trigger sensor
    case Sensor.TYPE_SIGNIFICANT_MOTION://17
        return "TYPE_SIGNIFICANT_MOTION";
    //Step detector sensor
    case Sensor.TYPE_STEP_DETECTOR://18
        return "TYPE_STEP_DETECTOR";
    //Step counter sensor
    case Sensor.TYPE_STEP_COUNTER://19
        return "TYPE_STEP_COUNTER";
    //Geo-magnetic rotation vector
    case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR://20
        return "TYPE_GEOMAGNETIC_ROTATION_VECTOR";
    //Heart rate monitor
    case Sensor.TYPE_HEART_RATE://21
        return "TYPE_HEART_RATE";
    default:/*w  w  w  . j  av  a2 s .c  o m*/
        return UNKNOWN;
    }
}

From source file:com.phonegap.TempListener.java

public void start() {
    List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_TEMPERATURE);
    if (list.size() > 0) {
        this.mSensor = list.get(0);
        this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }//from www.j  a  v a  2 s. c o  m
}

From source file:org.apache.cordova.TempListener.java

public void start() {
    @SuppressWarnings("deprecation")
    List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_TEMPERATURE);
    if (list.size() > 0) {
        this.mSensor = list.get(0);
        this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }/* w  w w.j  a  v a  2s.c om*/
}

From source file:ch.jeda.platform.android.SensorManager.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);
    this.sensorMap.clear();
    this.sensorInfoMap.clear();
    this.sensorListenerMap.clear();
    this.imp = (android.hardware.SensorManager) activity.getSystemService(Activity.SENSOR_SERVICE);
    this.checkAdd(SensorType.ACCELERATION, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
    this.checkAdd(SensorType.GRAVITY, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_GRAVITY));
    this.checkAdd(SensorType.LIGHT, 1f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_LIGHT));
    this.checkAdd(SensorType.LINEAR_ACCELERATION, 1f, 0f,
            this.imp.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION));
    // Android returns values in micro Tesla
    this.checkAdd(SensorType.MAGNETIC_FIELD, 1e-6f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD));
    // Android returns value in hekto Pascal
    this.checkAdd(SensorType.PRESSURE, 100f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_PRESSURE));
    // Android returns value in centimeter
    this.checkAdd(SensorType.PROXIMITY, 0.01f, 0f, this.imp.getDefaultSensor(Sensor.TYPE_PROXIMITY));
    // Android returns value in degrees Celcius
    this.checkAdd(SensorType.TEMPERATURE, 1f, -273.15f, this.imp.getDefaultSensor(Sensor.TYPE_TEMPERATURE));
}

From source file:uk.ac.horizon.ubihelper.service.Service.java

@Override
public void onCreate() {
    // One-time set-up...
    Log.d(TAG, "onCreate()");
    // TODO//from ww w  .  j a v a 2 s  .  co m
    super.onCreate();
    // handler for requests
    mHandler = new Handler();
    // create taskbar notification
    int icon = R.drawable.service_notification_icon;
    CharSequence tickerText = getText(R.string.notification_start_message);
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);

    Context context = this;
    CharSequence contentTitle = getText(R.string.notification_title);
    CharSequence contentText = getText(R.string.notification_description);
    Intent notificationIntent = new Intent(this, MainPreferences.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    startForeground(RUNNING_ID, notification);

    channelManager = new ChannelManager(peerChannelFactory);
    // sensors
    if (!isEmulator()) {
        Log.d(TAG, "Create sensor channels...");

        SensorChannel magnetic = new SensorChannel("magnetic", this, Sensor.TYPE_MAGNETIC_FIELD);
        channelManager.addChannel(magnetic);
        SensorChannel accelerometer = new SensorChannel("accelerometer", this, Sensor.TYPE_ACCELEROMETER);
        channelManager.addChannel(accelerometer);
        SensorChannel gyro = new SensorChannel("gyro", this, Sensor.TYPE_GYROSCOPE);
        channelManager.addChannel(gyro);
        SensorChannel light = new SensorChannel("light", this, Sensor.TYPE_LIGHT);
        channelManager.addChannel(light);
        SensorChannel pressure = new SensorChannel("pressure", this, Sensor.TYPE_PRESSURE);
        channelManager.addChannel(pressure);
        SensorChannel proximity = new SensorChannel("proximity", this, Sensor.TYPE_PROXIMITY);
        channelManager.addChannel(proximity);
        SensorChannel temperature = new SensorChannel("temperature", this, Sensor.TYPE_TEMPERATURE);
        channelManager.addChannel(temperature);

        try {
            Field f = Sensor.class.getField("TYPE_AMBIENT_TEMPERATURE");
            SensorChannel sc = new SensorChannel("ambientTemperature", this, f.getInt(null));
            channelManager.addChannel(sc);
        } catch (Exception e) {
            Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE");
        }
        try {
            Field f = Sensor.class.getField("TYPE_RELATIVE_HUMIDITY");
            SensorChannel sc = new SensorChannel("relativeHumidity", this, f.getInt(null));
            channelManager.addChannel(sc);
        } catch (Exception e) {
            Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE");
        }

        // all sensors by full name
        SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        if (sensorManager != null) {
            List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
            for (Sensor sensor : sensors) {
                SensorChannel sc = new SensorChannel("sensor." + sensor.getName(), this, sensor);
                channelManager.addChannel(sc);
            }
        }
        BluetoothDiscoveryChannel btchannel = new BluetoothDiscoveryChannel(this, mHandler, "bluetooth");
        channelManager.addChannel(btchannel);
        WifiScannerChannel wifichannel = new WifiScannerChannel(this, mHandler, "wifi");
        channelManager.addChannel(wifichannel);
        GpsStatusChannel gpsstatus = new GpsStatusChannel("gpsstatus", this);
        channelManager.addChannel(gpsstatus);
        CellLocationChannel cellchannel = new CellLocationChannel(mHandler, this, "cell.location", false);
        channelManager.addChannel(cellchannel);
        CellLocationChannel cellchannel2 = new CellLocationChannel(mHandler, this, "cell.neighbors", true);
        channelManager.addChannel(cellchannel2);
        CellStrengthChannel cellchannel3 = new CellStrengthChannel(this, "cell.strength");
        channelManager.addChannel(cellchannel3);
    }
    channelManager.addChannel(new TimeChannel(mHandler, "time"));
    List<String> locationProviders = LocationChannel.getAllProviders(this);
    for (String provider : locationProviders) {
        LocationChannel locchannel = new LocationChannel("location." + provider, this, provider);
        channelManager.addChannel(locchannel);
    }

    channelManager.addChannel(new MicChannel(mHandler, "mic"));

    Log.d(TAG, "Create http server...");

    // http server
    httpPort = getPort();

    httpListener = new HttpListener(this, httpPort);
    httpListener.start();

    // peer communication
    peerManager = new PeerManager(this);
    int serverPort = peerManager.getServerPort();

    channelManager.addChannel(new EnabledPeersChannel(this, peerManager, "peers"));

    // wifi discovery
    wifiDiscoveryManager = new WifiDiscoveryManager(this);
    wifiDiscoverable = getWifiDiscoverable();
    wifiDiscoveryManager.setServerPort(serverPort);
    wifiDiscoveryManager.setEnabled(wifiDiscoverable);

    bluetooth = BluetoothAdapter.getDefaultAdapter();
    if (bluetooth != null)
        btmac = bluetooth.getAddress();

    telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    if (telephony != null)
        imei = telephony.getDeviceId();

    logManager = new LogManager(this, channelManager);
    logManager.checkPreferences();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(onRunChangeListener);

    Log.d(TAG, "onCreate() finished");
}

From source file:com.aware.Aware_Preferences.java

/**
 * Temperature module settings UI/*from   w ww. j a v a2 s  . c  om*/
 */
private void temperature() {
    final PreferenceScreen temp_pref = (PreferenceScreen) findPreference("temperature");
    Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_TEMPERATURE);
    if (temp != null) {
        temp_pref.setSummary(
                temp_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA"));
    } else {
        temp_pref.setSummary(temp_pref.getSummary().toString().replace("*", ""));
    }

    final CheckBoxPreference temperature = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_TEMPERATURE);
    temperature.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_TEMPERATURE).equals("true"));
    temperature.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (mSensorMgr.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                temperature.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_TEMPERATURE, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_TEMPERATURE,
                    temperature.isChecked());
            if (temperature.isChecked()) {
                framework.startTemperature();
            } else {
                framework.stopTemperature();
            }
            return true;
        }
    });

    final EditTextPreference frequency_temperature = (EditTextPreference) findPreference(
            Aware_Preferences.FREQUENCY_TEMPERATURE);
    frequency_temperature
            .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TEMPERATURE));
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TEMPERATURE).length() > 0) {
        frequency_temperature
                .setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TEMPERATURE)
                        + " microseconds");
    }
    frequency_temperature.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TEMPERATURE,
                    (String) newValue);
            frequency_temperature.setSummary((String) newValue + " microseconds");
            framework.startTemperature();
            return true;
        }
    });
}