当前位置: 首页>>代码示例>>Java>>正文


Java TriggerEventListener类代码示例

本文整理汇总了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);
}
 
开发者ID:bryandunlap,项目名称:RxSensorManager,代码行数:20,代码来源:RxSensorManagerTest.java

示例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;
                }
            });
        }
    });
}
 
开发者ID:bryandunlap,项目名称:RxSensorManager,代码行数:51,代码来源:RxSensorManager.java

示例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);
}
 
开发者ID:bryandunlap,项目名称:RxSensorManager,代码行数:13,代码来源:RxSensorManagerTest.java

示例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);
}
 
开发者ID:bryandunlap,项目名称:RxSensorManager,代码行数:13,代码来源:RxSensorManagerTest.java

示例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");
}
 
开发者ID:donaldmunro,项目名称:AARemu,代码行数:10,代码来源:ARSensorManager.java

示例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");
}
 
开发者ID:donaldmunro,项目名称:AARemu,代码行数:10,代码来源:ARSensorManager.java

示例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);
}
 
开发者ID:dvoiss,项目名称:SensorAnnotations,代码行数:5,代码来源:TriggerEventListenerWrapper.java


注:本文中的android.hardware.TriggerEventListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。