TriggerEventListener.java revision 6e544fd4ca82a3f415c4cf6ca70eedea5112015e
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.hardware;
18
19/**
20 * This class is the listener used to handle Trigger Sensors.
21 * Trigger Sensors are sensors that trigger an event and are automatically
22 * disabled. {@link Sensor#TYPE_SIGNIFICANT_MOTION} is one such example.
23 * <p>
24 * SensorManager lets you access the device's {@link android.hardware.Sensor
25 * sensors}. Get an instance of this class by calling
26 * {@link android.content.Context#getSystemService(java.lang.String)
27 * Context.getSystemService()} with the argument
28 * {@link android.content.Context#SENSOR_SERVICE}.
29 * Usage details are explained in the example below.
30 * </p>
31 *
32 * <pre class="prettyprint">
33 * class TriggerListener extends TriggerEventListener {
34 *     public void onTrigger(TriggerEvent event) {
35 *          // Do Work.
36 *
37 *     // As it is a one shot sensor, it will be canceled automatically.
38 *     // SensorManager.requestTriggerSensor(this, mSigMotion); needs to
39 *     // be called again, if needed.
40 *     }
41 * }
42 * public class SensorActivity extends Activity {
43 *     private final SensorManager mSensorManager;
44 *     private final Sensor mSigMotion;
45 *     private final TriggerEventListener mListener = new TriggerEventListener();
46 *
47 *     public SensorActivity() {
48 *         mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
49 *         mSigMotion = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
50 *     }
51 *
52 *     protected void onResume() {
53 *         super.onResume();
54 *         mSensorManager.requestTriggerSensor(mListener, mSigMotion);
55 *     }
56 *
57 *     protected void onPause() {
58 *         super.onPause();
59 *         // Call disable to ensure that the trigger request has been canceled.
60 *         mSensorManager.cancelTriggerSensor(mListener, mSigMotion);
61 *     }
62 *
63 * }
64 * </pre>
65 *
66 * @see TriggerEvent
67 * @see Sensor
68 */
69public abstract class TriggerEventListener {
70    /**
71     * The method that will be called when the sensor
72     * is triggered. Override this method in your implementation
73     * of this class.
74     *
75     * @param event The details of the event.
76     */
77    public abstract void onTrigger(TriggerEvent event);
78}
79