本文整理汇总了Java中android.hardware.TriggerEventListener类的典型用法代码示例。如果您正苦于以下问题:Java TriggerEventListener类的具体用法?Java TriggerEventListener怎么用?Java TriggerEventListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TriggerEventListener类属于android.hardware包,在下文中一共展示了TriggerEventListener类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testObserveTrigger
import android.hardware.TriggerEventListener; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Test
public void testObserveTrigger() throws Exception {
when(mockSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)).thenReturn(mockSensor);
final ArgumentCaptor<TriggerEventListener> argumentCaptor = ArgumentCaptor.forClass(TriggerEventListener.class);
when(mockSensorManager.requestTriggerSensor(
argumentCaptor.capture(),
eq(mockSensor)
)).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
argumentCaptor.getValue().onTrigger(mock(TriggerEvent.class));
return true;
}
});
rxSensorManager.observeTrigger(Sensor.TYPE_ACCELEROMETER)
.test()
.assertValueCount(1);
}
示例2: observeTrigger
import android.hardware.TriggerEventListener; //导入依赖的package包/类
/**
* Create a {@link Single} that notifies subscribers of a {@link TriggerEvent} on a given {@link Sensor}.
* <p>
* This is modeled as a {@link Single} because once the sensor detects a trigger event condition, the provided
* {@link TriggerEventListener} will be invoked once and then cancelled. To continue receiving trigger events, the
* client must call this method for each event intended to be received.
*
* @param type the {@link Sensor} type to request {@link TriggerEvent}s for
* @return A {@link Single} that notifies subscribers of a {@link TriggerEvent} on a given {@link Sensor}.
* @since 0.8.0
*/
@NonNull
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public Single<TriggerEvent> observeTrigger(final int type) {
return Single.create(new SingleOnSubscribe<TriggerEvent>() {
@Override
public void subscribe(final SingleEmitter<TriggerEvent> emitter) {
final Sensor sensor = sensorManager.getDefaultSensor(type);
if (sensor == null) {
emitter.onError(new SensorNotFoundException(type));
return;
}
final TriggerEventListener triggerEventListener = new TriggerEventListener() {
@Override
public void onTrigger(TriggerEvent triggerEvent) {
emitter.onSuccess(triggerEvent);
}
};
final boolean sensorEnabled = sensorManager.requestTriggerSensor(triggerEventListener, sensor);
if (!sensorEnabled) {
emitter.onError(new SensorListenerException(sensor));
return;
}
emitter.setDisposable(new Disposable() {
boolean disposed = false;
@Override
public void dispose() {
sensorManager.cancelTriggerSensor(triggerEventListener, sensor);
disposed = true;
}
@Override
public boolean isDisposed() {
return disposed;
}
});
}
});
}
示例3: testObserveTriggerOnErrorSensorListenerException
import android.hardware.TriggerEventListener; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Test
public void testObserveTriggerOnErrorSensorListenerException() throws Exception {
when(mockSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)).thenReturn(mockSensor);
when(mockSensorManager.requestTriggerSensor(
any(TriggerEventListener.class),
eq(mockSensor)
)).thenReturn(false);
rxSensorManager.observeTrigger(Sensor.TYPE_ACCELEROMETER)
.test()
.assertError(SensorListenerException.class);
}
示例4: testObserveTriggerDisposable
import android.hardware.TriggerEventListener; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Test
public void testObserveTriggerDisposable() throws Exception {
when(mockSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)).thenReturn(mockSensor);
when(mockSensorManager.requestTriggerSensor(any(TriggerEventListener.class), eq(mockSensor))).thenReturn(true);
Disposable disposable = rxSensorManager.observeTrigger(Sensor.TYPE_ACCELEROMETER).test();
disposable.dispose();
verify(mockSensorManager).cancelTriggerSensor(
any(TriggerEventListener.class), eq(mockSensor)
);
assertEquals(disposable.isDisposed(), true);
}
示例5: requestTriggerSensor
import android.hardware.TriggerEventListener; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public boolean requestTriggerSensor(TriggerEventListener listener, Sensor sensor)
//-------------------------------------------------------------------------------
{
final int type = sensor.getType();
if (! isEmulatingType(type))
return sensorManager.requestTriggerSensor(listener, sensor);
throw new UnsupportedOperationException("Trigger sensor emulation not supported");
}
示例6: cancelTriggerSensor
import android.hardware.TriggerEventListener; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public boolean cancelTriggerSensor(TriggerEventListener listener, Sensor sensor)
//------------------------------------------------------------------------------
{
final int type = sensor.getType();
if (! isEmulatingType(type))
return sensorManager.cancelTriggerSensor(listener, sensor);
throw new UnsupportedOperationException("Trigger sensor emulation not supported");
}
示例7: TriggerEventListenerWrapper
import android.hardware.TriggerEventListener; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public TriggerEventListenerWrapper(@NonNull TriggerEventListener sensorEventListener) {
super(Sensor.TYPE_SIGNIFICANT_MOTION, sensorEventListener);
}