Back to project page rcdroid.
The source code is released under:
Copyright (c) 2013, Jamie Furness (jamie@jamierf.co.uk) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following...
If you think the Android project rcdroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.jamierf.rcdroid.logic.sensors; /*from w ww . j av a 2s . co m*/ import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import com.jamierf.rcdroid.http.WebController; import com.jamierf.rcdroid.http.Packet; import com.jamierf.rcdroid.input.api.Coordinate; import com.jamierf.rcdroid.input.sensor.RotationSensor; import com.jamierf.rcdroid.input.sensor.listener.SensorListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; public class RotationSensorHandler implements SensorListener<RotationSensor> { private static final Logger LOG = LoggerFactory.getLogger(RotationSensorHandler.class); private final WebController web; public RotationSensorHandler(WebController web) { this.web = web; } @Override public void onSensorChanged(RotationSensor sensor) { final Optional<Coordinate> value = sensor.getValue(); if (!value.isPresent()) return; final Coordinate rotation = value.get(); final long timestamp = sensor.getTimestamp(); try { web.send(new Packet(Packet.Type.ROTATION_UPDATED, ImmutableMap.<String, Object>of( "x", rotation.getX(), "y", rotation.getY(), "z", rotation.getZ() ), timestamp)); } catch (IOException e) { LOG.warn("Failed to send rotation sensor update", e); } } }