下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
/* * copyright (C) 2011 The Rexsee Open Source Project * * licensed under the Rexsee license,Version 1.0 (the "license"); * you may not use this file except in compliance with the license. * You may obtain a copy of the license at * * http://www.rexsee.com/CN/legal/license.HTML * * Unless required by applicable law or agreed to in writing,software * distributed under the license is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implIEd. * See the license for the specific language governing permissions and * limitations under the license. */ package rexsee.sensor; import rexsee.core.browser.JavaScriptInterface; import rexsee.core.browser.Rexseebrowser; import androID.content.Context; import androID.harDWare.Sensor; import androID.harDWare.SensorEvent; import androID.harDWare.SensorEventListener; import androID.harDWare.SensorManager; public class RexseeSensorProximity implements JavaScriptInterface { private static final String INTERFACE_name = "Proximity"; @OverrIDe public String getInterfacename() { return mbrowser.application.resources.prefix + INTERFACE_name; } @OverrIDe public JavaScriptInterface getinheritInterface(Rexseebrowser childbrowser) { return this; } @OverrIDe public JavaScriptInterface getNewInterface(Rexseebrowser childbrowser) { return new RexseeSensorProximity(childbrowser); } public static final String EVENT_ONPROXIMITYCHANGED = "onProximityChanged"; private final Context mContext; private final Rexseebrowser mbrowser; private final SensorManager mSensorManager; private final SensorEventListener mSensorListener; private final Sensor mSensor; private int mRate = SensorManager.SENSOR_DELAY_norMAL; private int mCycle = 100; //milliseconds private int mEventCycle = 100; //milliseconds private float mAccuracy = 0; private long lastUpdate = -1; private long lastEvent = -1; private float value = -999f; public RexseeSensorProximity(Rexseebrowser browser) { mContext = browser.getContext(); mbrowser = browser; browser.eventList.add(EVENT_ONPROXIMITYCHANGED); mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mSensorListener = new SensorEventListener() { @OverrIDe public voID onAccuracyChanged(Sensor sensor,int accuracy) { } @OverrIDe public voID onSensorChanged(SensorEvent event) { if (event.sensor.getType() != Sensor.TYPE_PROXIMITY) return; long curTime = System.currentTimeMillis(); if (lastUpdate == -1 || (curTime - lastUpdate) > mCycle) { lastUpdate = curTime; float lastValue = value; value = event.values[SensorManager.DATA_X]; if (lastEvent == -1 || (curTime - lastEvent) > mEventCycle) { if (Math.abs(value - lastValue) > mAccuracy) { lastEvent = curTime; mbrowser.eventList.run(EVENT_ONPROXIMITYCHANGED); } } } } }; } public String getLastKNownValue() { return (value == -999) ? "null" : String.valueOf(value); } public voID setRate(String rate) { mRate = SensorRate.getInt(rate); } public String getRate() { return SensorRate.getString(mRate); } public voID setCycle(int milliseconds) { mCycle = milliseconds; } public int getCycle() { return mCycle; } public voID setEventCycle(int milliseconds) { mEventCycle = milliseconds; } public int getEventCycle() { return mEventCycle; } public voID setAccuracy(float value) { mAccuracy = Math.abs(value); } public float getAccuracy() { return mAccuracy; } public boolean isReady() { return (mSensor == null) ? false : true; } public voID start() { if (isReady()) { mSensorManager.registerListener(mSensorListener,mSensor,mRate); } else { mbrowser.exception(getInterfacename(),"Proximity sensor is not found."); } } public voID stop() { if (isReady()) { mSensorManager.unregisterListener(mSensorListener); } } }
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的Android传感器API之:近距离感应Proximity功能源码全部内容,希望文章能够帮你解决Android传感器API之:近距离感应Proximity功能源码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)