本文整理汇总了Java中android.hardware.TriggerEvent类的典型用法代码示例。如果您正苦于以下问题:Java TriggerEvent类的具体用法?Java TriggerEvent怎么用?Java TriggerEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TriggerEvent类属于android.hardware包,在下文中一共展示了TriggerEvent类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testObserveTrigger
import android.hardware.TriggerEvent; //导入依赖的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: onTrigger
import android.hardware.TriggerEvent; //导入依赖的package包/类
@Override
public void onTrigger(TriggerEvent event) {
Log.i("BumpMonitor", "Sensor triggered");
//value[0] = 1.0 when the sensor triggers. 1.0 is the only allowed value.
long curTime = System.currentTimeMillis();
// only allow one update every 100ms.
if (event.sensor.getType() == Sensor.TYPE_SIGNIFICANT_MOTION) {
if ((curTime - lastUpdate) > CHECK_INTERVAL) {
lastUpdate = curTime;
/*
* Send Alert
*/
Message message = new Message();
message.what = EventTrigger.BUMP;
try {
if (serviceMessenger != null) {
serviceMessenger.send(message);
}
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//re-register the listener (it finishes after each event)
boolean registered = sensorMgr.requestTriggerSensor(sensorListener, bumpSensor);
Log.i("BumpMonitor", "Significant motion sensor re-registered: "+registered);
}
示例3: bindTriggerSwitch
import android.hardware.TriggerEvent; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void bindTriggerSwitch() {
checkedChanges(triggerSwitch)
.switchMap(new Function<Boolean, Observable<TriggerEvent>>() {
@Override
public Observable<TriggerEvent> apply(Boolean isChecked) {
if (isChecked) {
return rxSensorManager.observeTrigger(Sensor.TYPE_SIGNIFICANT_MOTION)
.toObservable();
} else {
return Observable.empty();
}
}
})
.subscribe(new Observer<TriggerEvent>() {
@Override
public void onSubscribe(Disposable disposable) {
compositeDisposable.add(disposable);
}
@Override
public void onNext(TriggerEvent event) {
toast("Trigger event: " + event.toString());
triggerSwitch.setChecked(false);
}
@Override
public void onError(Throwable e) {
toast("Trigger event error: " + e.getMessage());
}
@Override
public void onComplete() {
toast("This should not have just completed! UNPOSSIBLE!");
}
});
}
示例4: observeTrigger
import android.hardware.TriggerEvent; //导入依赖的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;
}
});
}
});
}
示例5: onTrigger
import android.hardware.TriggerEvent; //导入依赖的package包/类
@Override
public void onTrigger(TriggerEvent event) {
if (event.values[0] == 1) {
mTextView.append(mContext.getString(R.string.sig_motion) + "\n");
mTextView.append(mContext.getString(R.string.sig_motion_auto_disabled) + "\n");
}
// Sensor is auto disabled.
}
示例6: onTrigger
import android.hardware.TriggerEvent; //导入依赖的package包/类
@Override
public void onTrigger(TriggerEvent event) {
Logger.e(TAG, "NAME = " + event.sensor.getName());
Logger.e(TAG, "TIME = " + event.timestamp);
}
示例7: onTrigger
import android.hardware.TriggerEvent; //导入依赖的package包/类
@Override
public void onTrigger(TriggerEvent event) {
triggerCallback.handleOnSensorTriggerEvent(event.sensor, event.sensor.getType(), event.values);
}
示例8: onTrigger
import android.hardware.TriggerEvent; //导入依赖的package包/类
@Override
public void onTrigger(TriggerEvent event) {
mTextView.setText("Significant Motion Triggered!, Click again to request again.");
}
开发者ID:PacktPublishing,项目名称:Android-Sensor-Programming-By-Example,代码行数:5,代码来源:SignificantMotionActivity.java
示例9: testSignificantMotionTrigger
import android.hardware.TriggerEvent; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@OnTrigger
public void testSignificantMotionTrigger(@NonNull TriggerEvent event) {
updateTextViewWithEventData(mSignificantMotionEventOutputTextView, event);
}
示例10: updateTextViewWithEventData
import android.hardware.TriggerEvent; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
void updateTextViewWithEventData(@NonNull TextView textView, @NonNull TriggerEvent event) {
updateTextViewWithEventData(textView, event.timestamp, event.values);
}
示例11: onTrigger
import android.hardware.TriggerEvent; //导入依赖的package包/类
@Override
public void onTrigger( TriggerEvent event )
{
Log.i( "SENSOR", "Significant movement" );
}
示例12: onTrigger
import android.hardware.TriggerEvent; //导入依赖的package包/类
public void onTrigger(TriggerEvent event) {
// being a one shot sensor trigger, it is inherently cancelled
// if you are interested in more such events, call the request trigger again
// SensorManager.requestTriggerSensor(this, Motion);
Log.d ( TAG, "SignificantMotionTriggerListener::onTrigger() ... " + new Date() ) ;
//startActivity (handleSignificantMotionIntent) ;
//startActivity (handleSignificantMotionIntent) ;
//context.startActivity
final Notification.Builder notificationBuilder = new Notification.Builder(getApplicationContext())
.setContentTitle( "Motion ! ")
.setContentText("Motions !")
.setPriority(Notification.PRIORITY_MAX)
.setSmallIcon(R.mipmap.ic_launcher)
.setDefaults(Notification.DEFAULT_VIBRATE);
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1346436, notificationBuilder.build());
SignificantMotionTriggerListener significantMotionTriggerListener = new SignificantMotionTriggerListener();
sensorManager.requestTriggerSensor ( significantMotionTriggerListener, sensorSignificantMotion );
}