Java Code Examples for android.hardware.Sensor#TYPE_LIGHT

The following examples show how to use android.hardware.Sensor#TYPE_LIGHT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LightSensor.java    From PocketMaps with MIT License 6 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event)
{
  if(event.sensor.getType() == Sensor.TYPE_LIGHT)
  {
    if (NaviEngine.getNaviEngine().isNavigating())
    {
      if (event.values[0] <= 0.0f)
      {
        setLight(Brightness.DARK);
      }
      else if (event.values[0] <= 1000.0f)
      {
        setLight(Brightness.MID);
      }
      else if (event.values[0] > 1000.0f)
      {
        setLight(Brightness.LIGHT);
      }
    }
  }
}
 
Example 2
Source File: SensorBackgroundService.java    From android-sensor-example with Apache License 2.0 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    // get sensor manager on starting the service
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    // have a default sensor configured
    int sensorType = Sensor.TYPE_LIGHT;

    Bundle args = intent.getExtras();

    // get some properties from the intent
    if (args != null) {

        // set sensortype from bundle
        if (args.containsKey(KEY_SENSOR_TYPE))
            sensorType = args.getInt(KEY_SENSOR_TYPE);

        // optional logging
        mLogging = args.getBoolean(KEY_LOGGING);

        // treshold values
        // since we want to take them into account only when configured use min and max
        // values for the type to disable
        mThresholdMin = args.containsKey(KEY_THRESHOLD_MIN_VALUE) ? args.getFloat(KEY_THRESHOLD_MIN_VALUE) : Float.MIN_VALUE;
        mThresholdMax = args.containsKey(KEY_THRESHOLD_MAX_VALUE) ? args.getFloat(KEY_THRESHOLD_MAX_VALUE) : Float.MAX_VALUE;
    }

    // we need the light sensor
    Sensor sensor = mSensorManager.getDefaultSensor(sensorType);

    // TODO we could have the sensor reading delay configurable also though that won't do much
    // in this use case since we work with the alarm manager
    mSensorManager.registerListener(this, sensor,
            SensorManager.SENSOR_DELAY_NORMAL);

    return START_STICKY;
}
 
Example 3
Source File: CameraActivity.java    From camerademo with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_LIGHT) {
        //光线强度
        float lux = event.values[0];
        Log.e(TAG, "光线传感器得到的光线强度-->" + lux);
    }
}
 
Example 4
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 5 votes vote down vote up
public static float getMinimumValueForSensor(Sensor sensor) {
    float minimumValue;
    switch (sensor.getType()) {
        case Sensor.TYPE_HEART_RATE:
        case Sensor.TYPE_LIGHT:
        case Sensor.TYPE_PROXIMITY:
        case Sensor.TYPE_STEP_COUNTER:
        case Sensor.TYPE_PRESSURE:
            minimumValue = 0;
            break;
        default:
            minimumValue = -sensor.getMaximumRange();
    }
    return minimumValue;
}
 
Example 5
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 5 votes vote down vote up
public static boolean isDangerousSensor(Sensor sensor) {
    switch (sensor.getType()) {
        case Sensor.TYPE_LIGHT:
        case Sensor.TYPE_ACCELEROMETER:
        case Sensor.TYPE_ORIENTATION:
        case Sensor.TYPE_GYROSCOPE:
        case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
            return true;
        default:
            //Don't have a human string type? Safer to say that it's possibly dangerous.
            return getHumanStringType(sensor) == null;
    }
}
 
Example 6
Source File: MainActivity.java    From journaldev with MIT License 5 votes vote down vote up
public void lightSensorOnClick(View view) {
    if (checkSensorAvailability(Sensor.TYPE_LIGHT)) {
        currentSensor = Sensor.TYPE_LIGHT;
    } else {
        textView.setText("Light Sensor not available");
    }
}
 
Example 7
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 4 votes vote down vote up
@Nullable
public static String getHumanStringType(Sensor sensor) {
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            return "Accelerometer";

        case Sensor.TYPE_AMBIENT_TEMPERATURE:
            return "Ambient Temperature";

        case Sensor.TYPE_GAME_ROTATION_VECTOR:
            return "Game Rotation Vector";

        case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR:
            return "Geomagnetic Rotation Vector";

        case Sensor.TYPE_GRAVITY:
            return "Gravity";

        case Sensor.TYPE_GYROSCOPE:
            return "Gyroscope";

        case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
            return "Gyroscope (Uncalibrated)";

        case Sensor.TYPE_HEART_RATE:
            return "Heart Rate";

        case Sensor.TYPE_LIGHT:
            return "Light";

        case Sensor.TYPE_LINEAR_ACCELERATION:
            return "Linear Acceleration";

        case Sensor.TYPE_MAGNETIC_FIELD:
            return "Magnetic Field";

        case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
            return "Magnetic Field (Uncalibrated)";

        case Sensor.TYPE_PRESSURE:
            return "Pressure";

        case Sensor.TYPE_PROXIMITY:
            return "Proximity";

        case Sensor.TYPE_RELATIVE_HUMIDITY:
            return "Relative Humidity";

        case Sensor.TYPE_ROTATION_VECTOR:
            return "Rotation Vector";

        case Sensor.TYPE_SIGNIFICANT_MOTION:
            return "Significant Motion";

        case Sensor.TYPE_STEP_COUNTER:
            return "Step Counter";

        case Sensor.TYPE_STEP_DETECTOR:
            return "Step Detector";

        case Sensor.TYPE_ORIENTATION:
            return "Orientation";

        case Sensor.TYPE_TEMPERATURE:
            return "Temperature";
    }
    return null;
}
 
Example 8
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 4 votes vote down vote up
public static String[] getLabelsForSensor(Context context, Sensor sensor) {
    String[] labels;
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            labels = context.getResources().getStringArray(R.array.accelerometer_values);
            break;
        case Sensor.TYPE_AMBIENT_TEMPERATURE:
            labels = context.getResources().getStringArray(R.array.ambient_temperature_values);
            break;
        case Sensor.TYPE_GAME_ROTATION_VECTOR:
            labels = context.getResources().getStringArray(R.array.game_rotation_vector_values);
            break;
        case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR:
            labels = context.getResources().getStringArray(R.array.rotation_vector_values);
            break;
        case Sensor.TYPE_GRAVITY:
            labels = context.getResources().getStringArray(R.array.gravity_values);
            break;
        case Sensor.TYPE_GYROSCOPE:
            labels = context.getResources().getStringArray(R.array.gyroscore_values);
            break;
        case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
            labels = context.getResources().getStringArray(R.array.gyroscore_uncalibrated_values);
            break;
        case Sensor.TYPE_HEART_RATE:
            labels = context.getResources().getStringArray(R.array.heart_rate_values);
            break;
        case Sensor.TYPE_LIGHT:
            labels = context.getResources().getStringArray(R.array.light_values);
            break;
        case Sensor.TYPE_LINEAR_ACCELERATION:
            labels = context.getResources().getStringArray(R.array.linear_acceleration_values);
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            labels = context.getResources().getStringArray(R.array.magnetic_values);
            break;
        case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
            labels = context.getResources().getStringArray(R.array.magnetic_field_uncalibrated_values);
            break;
        case Sensor.TYPE_PRESSURE:
            labels = context.getResources().getStringArray(R.array.pressure_values);
            break;
        case Sensor.TYPE_PROXIMITY:
            labels = context.getResources().getStringArray(R.array.proximity_values);
            break;
        case Sensor.TYPE_RELATIVE_HUMIDITY:
            labels = context.getResources().getStringArray(R.array.relative_humidity_values);
            break;
        case Sensor.TYPE_ROTATION_VECTOR:
            labels = context.getResources().getStringArray(R.array.rotation_vector_values);
            break;
        case Sensor.TYPE_STEP_COUNTER:
            labels = context.getResources().getStringArray(R.array.step_counter_values);
            break;
        default:
            labels = new String[]{};
    }
    return labels;
}
 
Example 9
Source File: MainActivity.java    From SensorAnnotations with Apache License 2.0 4 votes vote down vote up
@OnAccuracyChanged(Sensor.TYPE_LIGHT)
public void testLightAccuracyChanged(@NonNull Sensor sensor, int accuracy) {
    logAccuracyChangedForSensor(sensor, accuracy);
}
 
Example 10
Source File: SensorDetailFragment.java    From AndroidDemoProjects with Apache License 2.0 4 votes vote down vote up
private void populateTypeField( int type ) {
	if( type == 0 || mTypeRow == null || mType == null )
		return;

	String typeName;

	switch( type ) {
		case Sensor.TYPE_ACCELEROMETER: {
			typeName = "Accelerometer";
			break;
		}
		case Sensor.TYPE_AMBIENT_TEMPERATURE: {
			typeName = "Ambient Temperature";
			break;
		}
		case Sensor.TYPE_GAME_ROTATION_VECTOR: {
			typeName = "Game Rotation Vector";
			break;
		}
		case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR: {
			typeName = "Geomagnetic Rotation Vector";
			break;
		}
		case Sensor.TYPE_GRAVITY: {
			typeName = "Gravity";
			break;
		}
		case Sensor.TYPE_GYROSCOPE: {
			typeName = "Gyroscope";
			break;
		}
		case Sensor.TYPE_GYROSCOPE_UNCALIBRATED: {
			typeName = "Uncalibrated Gyroscope";
			break;
		}
		case Sensor.TYPE_LIGHT: {
			typeName = "Light";
			break;
		}
		case Sensor.TYPE_LINEAR_ACCELERATION: {
			typeName = "Linear Acceleration";
			break;
		}
		case Sensor.TYPE_MAGNETIC_FIELD: {
			typeName = "Magnetic Field";
			break;
		}
		case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED: {
			typeName = "Uncalibrated Magnetic Field";
			break;
		}
		case Sensor.TYPE_PRESSURE: {
			typeName = "Pressure";
			break;
		}
		case Sensor.TYPE_PROXIMITY: {
			typeName = "Proximity";
			break;
		}
		case Sensor.TYPE_RELATIVE_HUMIDITY: {
			typeName = "Relative Humidity";
			break;
		}
		case Sensor.TYPE_ROTATION_VECTOR: {
			typeName = "Rotation Vector";
			break;
		}
		case Sensor.TYPE_SIGNIFICANT_MOTION: {
			typeName = "Significant Motion";
			break;
		}
		case Sensor.TYPE_STEP_COUNTER: {
			typeName = "Step Counter";
			break;
		}
		case Sensor.TYPE_STEP_DETECTOR: {
			typeName = "Step Detector";
			break;
		}
		default: {
			typeName = "Other";
		}
	}
	mType.setText( typeName );
	mTypeRow.setVisibility( View.VISIBLE );
}
 
Example 11
Source File: MainActivity.java    From SensorAnnotations with Apache License 2.0 4 votes vote down vote up
@OnSensorChanged(Sensor.TYPE_LIGHT)
public void testLightSensorChanged(@NonNull SensorEvent event) {
    updateTextViewWithEventData(mLightEventOutputTextView, event);
}
 
Example 12
Source File: MainActivity.java    From satstat with GNU General Public License v3.0 4 votes vote down vote up
/**
   * Called when a sensor's reading changes. Updates sensor display and rotates sky plot according
   * to bearing.
   */
  public void onSensorChanged(SensorEvent event) {
//to enforce sensor rate
boolean isRateElapsed = false;

switch (event.sensor.getType()) {
	case Sensor.TYPE_ACCELEROMETER:
		isRateElapsed = (event.timestamp / 1000) - mAccLast >= iSensorRate;
		// if Z acceleration is greater than X/Y combined, lock rotation, else unlock
		if (Math.pow(event.values[2], 2) > Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2)) {
			// workaround (SCREEN_ORIENTATION_LOCK is unsupported on API < 18)
			if (isWideScreen)
				setRequestedOrientation(OR_FROM_ROT_WIDE[this.getWindowManager().getDefaultDisplay().getRotation()]);
			else
				setRequestedOrientation(OR_FROM_ROT_TALL[this.getWindowManager().getDefaultDisplay().getRotation()]);
		} else {
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
		}
		break;
	case Sensor.TYPE_ORIENTATION:
		isRateElapsed = (event.timestamp / 1000) - mOrLast >= iSensorRate;
		break;
	case Sensor.TYPE_GYROSCOPE:
		isRateElapsed = (event.timestamp / 1000) - mGyroLast >= iSensorRate;
		break;
	case Sensor.TYPE_MAGNETIC_FIELD:
		isRateElapsed = (event.timestamp / 1000) - mMagLast >= iSensorRate;
		break;
	case Sensor.TYPE_LIGHT:
		isRateElapsed = (event.timestamp / 1000) - mLightLast >= iSensorRate;
		break;
	case Sensor.TYPE_PROXIMITY:
		isRateElapsed = (event.timestamp / 1000) - mProximityLast >= iSensorRate;
		break;
	case Sensor.TYPE_PRESSURE:
		isRateElapsed = (event.timestamp / 1000) - mPressureLast >= iSensorRate;
		break;
	case Sensor.TYPE_RELATIVE_HUMIDITY:
		isRateElapsed = (event.timestamp / 1000) - mHumidityLast >= iSensorRate;
		break;
	case Sensor.TYPE_AMBIENT_TEMPERATURE:
		isRateElapsed = (event.timestamp / 1000) - mTempLast >= iSensorRate;
		break;
}

if (!isRateElapsed)
	return;

switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
	mAccLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_ORIENTATION:
	mOrLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_GYROSCOPE:
	mGyroLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_MAGNETIC_FIELD:
	mMagLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_LIGHT:
	mLightLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_PROXIMITY:
	mProximityLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_PRESSURE:
	mPressureLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_RELATIVE_HUMIDITY:
	mHumidityLast = event.timestamp / 1000;
	break;
case Sensor.TYPE_AMBIENT_TEMPERATURE:
	mTempLast = event.timestamp / 1000;
	break;
}


if (sensorSectionFragment != null) {
	sensorSectionFragment.onSensorChanged(event);
  	}
if (gpsSectionFragment != null) {
	gpsSectionFragment.onSensorChanged(event);
}
  }
 
Example 13
Source File: MainService.java    From always-on-amoled with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onSensorChanged(final SensorEvent event) {
    switch (event.sensor.getType()) {
        case Sensor.TYPE_PROXIMITY:
            Utils.logDebug("proximity", String.valueOf(event.values[0]));
            if (event.values[0] < 1) {
                // Sensor distance smaller than 1cm
                stayAwakeWakeLock.release();
                Globals.isShown = false;
                Globals.sensorIsScreenOff = false;
                if (isScreenOn) {
                    showBlackScreen(true);
                    turnScreenOff();
                }
            } else {
                showBlackScreen(false);
                if (!Globals.sensorIsScreenOff) {
                    new Handler().postDelayed(() -> onSensorChanged(event), 200);
                    return;
                }
                if (!isScreenOn)
                    ScreenReceiver.turnScreenOn(this, false);
                Globals.isShown = true;
                new Handler().postDelayed(() -> {
                    if (!refreshing)
                        refresh();
                    if (!raiseToWake)
                        stayAwakeWakeLock.acquire();
                }, 500);
            }
            break;
        case Sensor.TYPE_LIGHT:
            boolean nightMode = event.values[0] < 2;
            if ((nightMode && !nigtModeOn) || (!nightMode && nigtModeOn)) {
                Utils.logDebug("Lights changed", String.valueOf(event.values[0]));
                setLights(ON, nightMode, false);
                nigtModeOn = nightMode;
            }
            break;
    }
}
 
Example 14
Source File: EnvironmentalSucker.java    From CameraV with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * 
Sensor	Sensor event data	Units of measure	Data description
TYPE_AMBIENT_TEMPERATURE	event.values[0]	°C	Ambient air temperature.
TYPE_LIGHT	event.values[0]	lx	Illuminance.
TYPE_PRESSURE	event.values[0]	hPa or mbar	Ambient air pressure.
TYPE_RELATIVE_HUMIDITY	event.values[0]	%	Ambient relative humidity.
TYPE_TEMPERATURE	event.values[0]	°C	Device temperature.1

	 */
	@SuppressWarnings("deprecation")
	@Override
	public void onSensorChanged(SensorEvent event) {
		synchronized(this) {
			if(getIsRunning()) {
				ILogPack sVals = new ILogPack();
				
				try {				
					switch(event.sensor.getType()) {
					case Sensor.TYPE_AMBIENT_TEMPERATURE:
						sVals.put(Environment.Keys.AMBIENT_TEMP_CELSIUS, event.values[0]);
						currentAmbientTemp = sVals;
						break;
					case Sensor.TYPE_TEMPERATURE:
						sVals.put(Environment.Keys.DEVICE_TEMP_CELSIUS, event.values[0]);
						currentDeviceTemp = sVals;
						break;
					case Sensor.TYPE_RELATIVE_HUMIDITY:
						sVals.put(Environment.Keys.HUMIDITY_PERC,event.values[0]);
						currentHumidity = sVals;
						break;
					case Sensor.TYPE_PRESSURE:
						sVals.put(Environment.Keys.PRESSURE_MBAR, event.values[0]);
						
						//TODO we need to get real local sea level pressure here from a dynamic source
						//as the default value doesn't cut it
						float altitudeFromPressure = SensorManager.getAltitude(mPressureSeaLevel, event.values[0]);						
						sVals.put(Environment.Keys.PRESSURE_ALTITUDE, altitudeFromPressure);
						
						currentPressure = sVals;
						break;
					case Sensor.TYPE_LIGHT:
						sVals.put(Environment.Keys.LIGHT_METER_VALUE, event.values[0]);
						currentLight = sVals;
						break;
						
					}
					
				} catch(JSONException e) {}
			}
		}
	}
 
Example 15
Source File: SKAbstractNativeSensorModule.java    From SensingKit-Android with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressLint("InlinedApi")  // There is a check in STEP_DETECTOR and STEP_COUNTER
private static int getSensorType(SKSensorModuleType sensorType) throws SKException{

    switch (sensorType) {

        case ACCELEROMETER:
            return Sensor.TYPE_ACCELEROMETER;

        case GRAVITY:
            return Sensor.TYPE_GRAVITY;

        case LINEAR_ACCELERATION:
            return Sensor.TYPE_LINEAR_ACCELERATION;

        case GYROSCOPE:
            return Sensor.TYPE_GYROSCOPE;

        case ROTATION:
            return Sensor.TYPE_ROTATION_VECTOR;

        case MAGNETOMETER:
            return Sensor.TYPE_MAGNETIC_FIELD;

        case AMBIENT_TEMPERATURE:
            return Sensor.TYPE_AMBIENT_TEMPERATURE;

        case STEP_DETECTOR:

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                return Sensor.TYPE_STEP_DETECTOR;
            }
            else
            {
                throw new SKException(TAG, "STEP_DETECTOR requires Android KitKat or greater.", SKExceptionErrorCode.UNKNOWN_ERROR);
            }

        case STEP_COUNTER:

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                return Sensor.TYPE_STEP_COUNTER;
            }
            else
            {
                throw new SKException(TAG, "STEP_COUNTER requires Android KitKat or greater.", SKExceptionErrorCode.UNKNOWN_ERROR);
            }

        case LIGHT:
            return Sensor.TYPE_LIGHT;

        case LOCATION:
        case ACTIVITY:
        case BATTERY:
            throw new SKException(TAG, "Not a native SensorModule.", SKExceptionErrorCode.UNKNOWN_ERROR);

        default:
            throw new SKException(TAG, "Unknown SensorModule", SKExceptionErrorCode.UNKNOWN_ERROR);

    }
}
 
Example 16
Source File: BrightnessMonitor.java    From habpanelviewer with GNU General Public License v3.0 4 votes vote down vote up
public BrightnessMonitor(Context ctx, SensorManager sensorManager, ServerConnection serverConnection) {
    super(ctx, sensorManager, serverConnection, ctx.getString(R.string.pref_brightness), "brightness", Sensor.TYPE_LIGHT);
}
 
Example 17
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 4 votes vote down vote up
public static String getDescription(Sensor sensor) {
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            return "Measures the acceleration force in m/s² that is applied to a device on all three physical axes (x, y, and z), including the force of gravity.";

        case Sensor.TYPE_AMBIENT_TEMPERATURE:
            return "Measures the ambient room temperature in degrees Celsius (°C).";

        case Sensor.TYPE_GRAVITY:
            return "Measures the force of gravity in m/s² that is applied to a device on all three physical axes (x, y, z).";

        case Sensor.TYPE_GYROSCOPE:
            return "Measures a device's rate of rotation in rad/s around each of the three physical axes (x, y, and z).";

        case Sensor.TYPE_HEART_RATE:
            return "Measures heart rate.";

        case Sensor.TYPE_LIGHT:
            return "Measures the ambient light level (illumination) in lx.";

        case Sensor.TYPE_LINEAR_ACCELERATION:
            return "Measures the acceleration force in m/s² that is applied to a device on all three physical axes (x, y, and z), excluding the force of gravity.";

        case Sensor.TYPE_MAGNETIC_FIELD:
            return "Measures the ambient geomagnetic field for all three physical axes (x, y, z) in μT.";

        case Sensor.TYPE_PRESSURE:
            return "Measures the ambient air pressure in hPa or mbar.";

        case Sensor.TYPE_PROXIMITY:
            return "Measures the proximity of an object in cm relative to the view screen of a device. This sensor is typically used to determine whether a handset is being held up to a person's ear.";

        case Sensor.TYPE_RELATIVE_HUMIDITY:
            return "Measures the relative ambient humidity in percent (%).";

        case Sensor.TYPE_ROTATION_VECTOR:
            return "Measures the orientation of a device by providing the three elements of the device's rotation vector.";

        case Sensor.TYPE_ORIENTATION:
            return "Measures degrees of rotation that a device makes around all three physical axes (x, y, z). ";

        case Sensor.TYPE_TEMPERATURE:
            return "Measures the temperature of the device in degrees Celsius (°C). ";

        default:
            return "Information about this sensor is unavailable.";
    }
}
 
Example 18
Source File: LightUpdatesProvider.java    From PrivacyStreams with Apache License 2.0 4 votes vote down vote up
LightUpdatesProvider(int sensorDelay) {
    super(Sensor.TYPE_LIGHT, sensorDelay);
}
 
Example 19
Source File: EnvironmentalSucker.java    From CameraV with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "deprecation" })
public EnvironmentalSucker(Context context) {
	super(context);
	setSucker(this);
	
	sm = (SensorManager)context.getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
	availableSensors = sm.getSensorList(Sensor.TYPE_ALL);
	
	for(Sensor s : availableSensors) {
		switch(s.getType()) {
		case Sensor.TYPE_AMBIENT_TEMPERATURE:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		case Sensor.TYPE_RELATIVE_HUMIDITY:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		case Sensor.TYPE_PRESSURE:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		case Sensor.TYPE_LIGHT:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;				
		case Sensor.TYPE_TEMPERATURE:
			sm.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL);
			break;
		}
			
	}
	
	setTask(new TimerTask() {
		
		@Override
		public void run() {
				if(currentAmbientTemp != null)
					sendToBuffer(currentAmbientTemp);
				if(currentDeviceTemp != null)
					sendToBuffer(currentDeviceTemp);
				if(currentHumidity != null)
					sendToBuffer(currentHumidity);
				if(currentPressure != null)
					sendToBuffer(currentPressure);
				if(currentLight != null)
					sendToBuffer(currentLight);
		}
	});
	
	getTimer().schedule(getTask(), 0, Environment.LOG_RATE);
}
 
Example 20
Source File: LightSensor.java    From appinventor-extensions with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new LightSensor component.
 *
 * @param container  ignored (because this is a non-visible component)
 */
public LightSensor(ComponentContainer container) {
  super(container.$form(), Sensor.TYPE_LIGHT, BUFFER_SIZE);
}