AI2 Component  (Version nb184)
LightSensor.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2019 MIT, All rights reserved
3 // Released under the Apache License, Version 2.0
4 // http://www.apache.org/licenses/LICENSE-2.0
5 
6 
7 package com.google.appinventor.components.runtime;
8 
15 
16 import android.content.Context;
17 import android.hardware.Sensor;
18 import android.hardware.SensorEvent;
19 import android.hardware.SensorEventListener;
20 import android.hardware.SensorManager;
21 
30 @DesignerComponent(version = YaVersion.LIGHTSENSOR_COMPONENT_VERSION,
31  description = "A sensor component that can measure the light level.",
32  category = ComponentCategory.SENSORS,
33  nonVisible = true,
34  iconName = "images/lightsensor.png")
35 @SimpleObject
36 public class LightSensor extends BufferedSingleValueSensor {
37  private static final int BUFFER_SIZE = 10;
38 
44  public LightSensor(ComponentContainer container) {
45  super(container.$form(), Sensor.TYPE_LIGHT, BUFFER_SIZE);
46  }
47 
48  @Override
49  protected void onValueChanged(float value) {
51  }
52 
58  @SimpleEvent(description = "Called when a change is detected in the light level.")
59  public void LightChanged(float lux) {
60  EventDispatcher.dispatchEvent(this, "LightChanged", lux);
61  }
62 
69  @SimpleProperty(description = "The most recent light level, in lux, if the sensor is available " +
70  "and enabled.")
71  public float Lux() {
72  return getValue();
73  }
74 
81  @SimpleProperty(description = "The average of the 10 most recent light levels measured, in lux.")
82  public float AverageLux() {
83  return getAverageValue();
84  }
85 }
com.google.appinventor.components.runtime.EventDispatcher
Definition: EventDispatcher.java:22
com.google.appinventor.components.runtime.LightSensor.LightChanged
void LightChanged(float lux)
Definition: LightSensor.java:59
com.google.appinventor.components.common.YaVersion
Definition: YaVersion.java:14
com.google.appinventor.components.runtime.BufferedSingleValueSensor.getAverageValue
float getAverageValue()
Definition: BufferedSingleValueSensor.java:38
com.google.appinventor.components
com.google.appinventor.components.runtime.LightSensor.onValueChanged
void onValueChanged(float value)
Definition: LightSensor.java:49
com.google.appinventor.components.annotations.DesignerComponent
Definition: DesignerComponent.java:22
com.google.appinventor.components.annotations.SimpleEvent
Definition: SimpleEvent.java:20
com.google.appinventor.components.runtime.LightSensor.AverageLux
float AverageLux()
Definition: LightSensor.java:82
com.google.appinventor.components.runtime.LightSensor
Definition: LightSensor.java:36
com.google.appinventor.components.runtime.SingleValueSensor.getValue
float getValue()
Definition: SingleValueSensor.java:191
com.google.appinventor.components.runtime.LightSensor.LightSensor
LightSensor(ComponentContainer container)
Definition: LightSensor.java:44
com.google.appinventor.components.runtime.EventDispatcher.dispatchEvent
static boolean dispatchEvent(Component component, String eventName, Object...args)
Definition: EventDispatcher.java:188
com.google.appinventor.components.annotations.SimpleProperty
Definition: SimpleProperty.java:23
com.google.appinventor.components.runtime.ComponentContainer
Definition: ComponentContainer.java:16
com.google.appinventor.components.runtime.LightSensor.Lux
float Lux()
Definition: LightSensor.java:71
com.google.appinventor.components.common
Definition: ComponentCategory.java:7
com.google.appinventor.components.common.ComponentCategory
Definition: ComponentCategory.java:48
com.google.appinventor.components.annotations.SimpleObject
Definition: SimpleObject.java:23
com.google
com
com.google.appinventor.components.runtime.SingleValueSensor.value
float value
Definition: SingleValueSensor.java:33
com.google.appinventor.components.runtime.ComponentContainer.$form
Form $form()
com.google.appinventor.components.runtime.BufferedSingleValueSensor
Definition: BufferedSingleValueSensor.java:20
com.google.appinventor.components.annotations
com.google.appinventor