OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.device.sensors; |
| 6 |
| 7 import android.hardware.Sensor; |
| 8 import android.hardware.SensorEvent; |
| 9 import android.hardware.SensorManager; |
| 10 import android.os.Handler; |
| 11 |
| 12 import org.chromium.mojo.system.SharedBufferHandle; |
| 13 import org.chromium.mojom.device.sensors.SensorType; |
| 14 |
| 15 import java.nio.ByteBuffer; |
| 16 |
| 17 /** |
| 18 * ProximitySensor implementation. |
| 19 */ |
| 20 public class ProximitySensorImpl extends SensorBase { |
| 21 ProximitySensorImpl(SensorManager manager, Handler handler, SharedBufferHand
le handle, |
| 22 long offset, long size, SensorStateObserver observer) |
| 23 throws SensorException { |
| 24 super(Sensor.TYPE_PROXIMITY, manager, handler, handle, offset, size, obs
erver); |
| 25 } |
| 26 |
| 27 @Override |
| 28 public int getType() { |
| 29 return SensorType.PROXIMITY; |
| 30 } |
| 31 |
| 32 @Override |
| 33 protected void fillSensorReadingData(SensorEvent event, ByteBuffer buffer) |
| 34 throws SensorException { |
| 35 if(event.values.length < 1) throw new SensorException(); |
| 36 // Distance |
| 37 buffer.putDouble(event.values[0]); |
| 38 } |
| 39 } |
OLD | NEW |