MOVERIO Pro Developer's Guide (Rev.1.4)
120
7.4.
Sample code
Sample code of using sensor type TYPE_HEADSET_TAP, and show Toast when tap is detected.
package jp.epson.moverio.bt2pro.sample.TapSample;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity implements SensorEventListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SensorManager sm = (SensorManager)getSystemService(SENSOR_SERVICE);
Sensor sensor = sm.getDefaultSensor(Sensor.TYPE_HEADSET_TAP);
sm.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType() == Sensor.TYPE_HEADSET_TAP){
// if tap event occurs, show Toast
Toast.makeText(this, "tap event!", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onPause() {
super.onPause();
SensorManager sm = (SensorManager)getSystemService(SENSOR_SERVICE);
if (sm != null) {
sm.unregisterListener(this);
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}
Summary of Contents for Moverio Pro BT-2000
Page 7: ...MOVERIO Pro Developer s Guide Rev 1 4 1 1 Introduction ...
Page 12: ...MOVERIO Pro Developer s Guide Rev 1 4 6 2 Developing Apps ...
Page 30: ...MOVERIO Pro Developer s Guide Rev 1 4 24 3 Display control ...
Page 39: ...MOVERIO Pro Developer s Guide Rev 1 4 33 4 UI control ...
Page 47: ...MOVERIO Pro Developer s Guide Rev 1 4 41 5 Voice commands ...
Page 70: ...MOVERIO Pro Developer s Guide Rev 1 4 64 6 Camera control ...
Page 119: ...MOVERIO Pro Developer s Guide Rev 1 4 113 7 Sensor control ...
Page 127: ...MOVERIO Pro Developer s Guide Rev 1 4 121 8 Bluetooth BLE ...
Page 184: ...MOVERIO Pro Developer s Guide Rev 1 4 178 9 Power control ...
Page 187: ...MOVERIO Pro Developer s Guide Rev 1 4 181 10 Self diagnostic function ...
Page 191: ...MOVERIO Pro Developer s Guide Rev 1 4 185 11 GPS Assist ...
Page 202: ...MOVERIO Pro Developer s Guide Rev 1 4 196 Memo ...