public void onSensorChanged(SensorEvent event) { if (event.accuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW) return; if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { arrayCopy(event.values, geomagnetic); } if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { arrayCopy(event.values, gravity); } if (SensorManager.getRotationMatrix(R, I, gravity, geomagnetic)) { SensorManager.getOrientation(R, orientation); azimuth += easing * (orientation[0] - azimuth); pitch += easing * (orientation[1] - pitch); roll += easing * (orientation[2] - roll); } }
public AmbientLightMonitor(Context context) { prefs = new PreferenceManager(context); context.bindService(new Intent(context, MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT); sensorMgr = (SensorManager) context.getSystemService(Activity.SENSOR_SERVICE); //noinspection RedundantCast sensor = (Sensor) sensorMgr.getDefaultSensor(Sensor.TYPE_LIGHT); if (sensor == null) { Log.i("AccelerometerFrament", "Warning: no accelerometer"); } else { sensorMgr.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } }
@Override protected void onCreate(Bundle savedInstanceState) { setTheme(R.style.NoActionBar); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); assetIdEdit.addTextChangedListener(watcher); assetIdEdit.setOnEditorActionListener((textView, actionId, keyEvent) -> { boolean handled = false; if (actionId == EditorInfo.IME_ACTION_DONE) { submit(); handled = true; } return handled; }); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(false); sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); locationManager = new RxLocationManager(DemoApplication.get(this).getRxLocation()); }
@Override public void onSensorChanged(SensorEvent event) { float x = event.values[0]; float y = event.values[1]; float z = event.values[2]; float gX = x / SensorManager.GRAVITY_EARTH; float gY = y / SensorManager.GRAVITY_EARTH; float gZ = z / SensorManager.GRAVITY_EARTH; // gForce will be close to 1 when there is no movement. float gForce = (float) Math.sqrt(gX * gX + gY * gY + gZ * gZ); if (gForce > SHAKE_THRESHOLD_GRAVITY) { final long now = System.currentTimeMillis(); // ignore shake events too close to each other (500ms) if (mShakeTimestamp + SHAKE_SLOP_TIME_MS > now) { return; } mShakeTimestamp = now; this.onShakeListener.onShake(); } }
private static void toggleWakeUpWithProximityFeature(boolean enabled) { try { if (enabled) { mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); mProxSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mWakeLock = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); } else { unregisterProxSensorListener(); mProxSensor = null; mSensorManager = null; mWakeLock = null; } if (DEBUG) log("toggleWakeUpWithProximityFeature: " + enabled); } catch (Throwable t) { XposedBridge.log(t); } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mySensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); myAccelerometer = mySensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mySensorManager.registerListener(this, myAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); int level = getIntent().getIntExtra("level", 1); soundEngine = new com.homescreenarcade.mazeman.SoundEngine(this); gameEngine = new com.homescreenarcade.mazeman.GameEngine(this, soundEngine, level); Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); gameView = new com.homescreenarcade.mazeman.GameSurfaceView(this, gameEngine, width, height); setContentView(gameView); }
@Override public boolean start(Object obj) { try{ mSensorManger = (SensorManager)getmServiceContext().getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManger.getDefaultSensor(Sensor.TYPE_PROXIMITY); mSensorListener = new MySensorListener(); request(AntiTheftService.REQUEST_SHOW_MSG, getName() + "防护已开启,将在10秒后正式生效" + SF.TIP); mCDTimer = new CountDownTimer(10000, 1000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { mSensorManger.registerListener(mSensorListener, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } }; setNeedDelay(true); mCDTimer.start(); return true; }catch(Exception e){ request(AntiTheftService.REQUEST_SHOW_MSG, "开启\"" + getName() + "\"防护失败,可能您的设备不支持距离传感器!"); return false; } }
/** * Function to create activity view * * @param savedInstanceState */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_quran_page_read); sm = (SensorManager) getSystemService(SENSOR_SERVICE); proxSensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY); lightSensor = sm.getDefaultSensor(Sensor.TYPE_LIGHT); sm.registerListener(this, proxSensor, SensorManager.SENSOR_DELAY_NORMAL); init(); flag = 1; flag1 = 0; // globalVariable.setEmail(1); }
protected void onResume() { super.onResume(); if(null == ftDev || false == ftDev.isOpen()) { DLog.e(TT, "onResume - reconnect"); createDeviceList(); if(DevCount > 0) { connectFunction(); setConfig(baudRate, dataBit, stopBit, parity, flowControl); } } mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_FASTEST); // Register the accelerometer and determining its speed mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_FASTEST); // Register the magnetometer and determining its speed mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_FASTEST); // Register the Gyroscope and determining its speed }
@Override public void onSensorChanged(SensorEvent event) { // we received a sensor event. it is a good practice to check // that we received the proper event if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { System.arraycopy(event.values, 0, magnitudeValues, 0, magnitudeValues.length); } else if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { System.arraycopy(event.values, 0, accelerometerValues, 0, accelerometerValues.length); } if (magnitudeValues != null && accelerometerValues != null) { // Fuse accelerometer with compass SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, accelerometerValues, magnitudeValues); // Transform rotation matrix to quaternion currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix); } }
@Override public void onSensorChanged(SensorEvent event) { if (internalCompassListener == null) { return; } // check when the last time the compass was updated, return if too soon. long currentTime = SystemClock.elapsedRealtime(); if (currentTime < compassUpdateNextTimestamp) { return; } if (lastAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) { Timber.d("Compass sensor is unreliable, device calibration is needed."); return; } if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) { updateOrientation(event.values); // Update the compassUpdateNextTimestamp compassUpdateNextTimestamp = currentTime + LocationLayerConstants.COMPASS_UPDATE_RATE_MS; } else if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) { internalCompassListener.onCompassChanged((event.values[0] + 360) % 360); for (CompassListener compassListener : compassListeners) { compassListener.onCompassChanged((event.values[0] + 360) % 360); } } }
public void onSensorChanged(SensorEvent event) { int type = event.sensor.getType(); float[] data; if (type == Sensor.TYPE_ACCELEROMETER) { data = mGData; } else if (type == Sensor.TYPE_MAGNETIC_FIELD) { data = mMData; } else { // we should not be here. return; } for (int i=0 ; i<3 ; i++) data[i] = event.values[i]; SensorManager.getRotationMatrix(mR, mI, mGData, mMData); // some test code which will be used/cleaned up before we ship this. // SensorManager.remapCoordinateSystem(mR, // SensorManager.AXIS_X, SensorManager.AXIS_Z, mR); // SensorManager.remapCoordinateSystem(mR, // SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, mR); SensorManager.getOrientation(mR, mOrientation); float incl = SensorManager.getInclination(mI); if (mCount++ > 50) { final float rad2deg = (float)(180.0f/Math.PI); mCount = 0; Log.d("Compass", "yaw: " + (int)(mOrientation[0]*rad2deg) + " pitch: " + (int)(mOrientation[1]*rad2deg) + " roll: " + (int)(mOrientation[2]*rad2deg) + " incl: " + (int)(incl*rad2deg) ); } }
@Override public void onSensorChanged(SensorEvent event) { if(event.sensor == compas){ System.arraycopy(event.values,0,comp,0,event.values.length); c=true; } else if(event.sensor == accelerometer){ System.arraycopy(event.values,0,acc,0,event.values.length); a=true; } if(c && a) { float []r = new float[9],orien=new float[3]; SensorManager.getRotationMatrix(r, null, acc, comp); SensorManager.getOrientation(r, orien); float grad = (float)((Math.toDegrees(orien[0])+360)%360); MyLocation.getInstance().setCompas(grad); } }
public static String A(Context context) { try { SensorManager sensorManager = (SensorManager) context.getSystemService("sensor"); if (sensorManager != null) { List sensorList = sensorManager.getSensorList(-1); if (sensorList != null) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < sensorList.size(); i++) { stringBuilder.append(((Sensor) sensorList.get(i)).getType()); if (i != sensorList.size() - 1) { stringBuilder.append(","); } } return stringBuilder.toString(); } } } catch (Object th) { f.e(th); } return ""; }
public static String M(Context context) { if (e(cE)) { return cE; } try { SensorManager sensorManager = (SensorManager) context.getSystemService("sensor"); if (sensorManager != null) { List sensorList = sensorManager.getSensorList(-1); if (sensorList != null) { StringBuilder stringBuilder = new StringBuilder(sensorList.size() * 10); for (int i = 0; i < sensorList.size(); i++) { stringBuilder.append(((Sensor) sensorList.get(i)).getType()); if (i != sensorList.size() - 1) { stringBuilder.append(","); } } cE = stringBuilder.toString(); } } } catch (Throwable th) { cT.b(th); } return cE; }
public synchronized void startTracking() { // If we should manage it ourselves if (proximitySensor != null && !proximitySensorTracked) { // Fall back to manual mode isFirstRun = true; Log.d(THIS_FILE, "Register sensor"); sensorManager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL); proximitySensorTracked = true; } if(!accelerometerEnabled) { accelerometerManager.enable(true); accelerometerEnabled = true; } }
public synchronized void start() { if( (Globals.UseAccelerometerAsArrowKeys || Globals.AppUsesAccelerometer) && _manager != null && _manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null ) { Log.i("SDL", "libSDL: starting accelerometer"); _manager.registerListener(this, _manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); } if( (Globals.AppUsesGyroscope || Globals.MoveMouseWithGyroscope) && _manager != null && _manager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null ) { Log.i("SDL", "libSDL: starting gyroscope"); _manager.registerListener(gyro, _manager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME); } if( (Globals.AppUsesOrientationSensor) && _manager != null && _manager.getDefaultSensor(Sensor.TYPE_GAME_ROTATION_VECTOR) != null ) { Log.i("SDL", "libSDL: starting orientation sensor"); _manager.registerListener(orientation, _manager.getDefaultSensor( Sensor.TYPE_GAME_ROTATION_VECTOR), SensorManager.SENSOR_DELAY_GAME); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate"); try { if ( sparkFunOLDEBlock == null ) sparkFunOLDEBlock = new OLEDBlock(); if ( lsm9DS0Driver == null ) { lsm9DS0Driver = new LSM9DS0Driver(); lsm9DS0Driver.register(); } } catch (IOException ioex) { Log.e(TAG, "Unable to init Sparkfun : "+ioex.getMessage()); } sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensorManager.registerDynamicSensorCallback(sensorCallback); }
@Override protected void initViews() { super.initViews(); StatusBarUtil.setPaddingSmart(this, findViewById(R.id.id_statusbar)); StatusBarUtil.immersive(this, ResouceUtil.getColor(R.color.gray)); mVideoPlayer = (JCVideoPlayerStandard) findViewById(R.id.id_video_player); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mSensorEventListener = new JCVideoPlayer.JCAutoFullscreenListener(); mVideoPlayer.setAllControlsVisible(GONE, GONE, VISIBLE, GONE, VISIBLE, VISIBLE, GONE); mVideoPlayer.titleTextView.setVisibility(GONE); findViewById(R.id.id_back_iv).setOnClickListener(this); findViewById(R.id.id_comment_count_iv).setOnClickListener(this); findViewById(R.id.id_collect_iv).setOnClickListener(this); findViewById(R.id.id_share_iv).setOnClickListener(this); }
public GyroView(Context context) { super(context); this.context = context; setFitsSystemWindows(true); View v = LayoutInflater.from(getContext()).inflate(R.layout.text, this, false); addView(v); sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); sensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); textX = (TextView) findViewById(R.id.TextX); textY = (TextView) findViewById(R.id.TextY); textZ = (TextView) findViewById(R.id.TextZ); sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); }
@Override public void start() { if(temperatureSensor == null) { //no temperature sensor return; } if(!isRegistered) { isRegistered = true; sensorManager.registerListener(temperatureListener, temperatureSensor, SensorManager.SENSOR_DELAY_NORMAL); if(informationPlugin != null) { CmdArg cmd = new CmdArg(0, "Registered Temperature."); informationPlugin.sendReplyCommand(PluginService.INFORMATION, cmd); } } }
@SuppressWarnings( { "deprecation" }) @Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) { float x = event.values[SensorManager.DATA_X]; if (Math.abs(x - lastX) > 1.0) { if (mOnOrientationListener != null) { mOnOrientationListener.onOrientationChanged(x); } } lastX = x; } }
/** * if the countSensor exists, then try registering */ private void registerCountSensor() { if (countSensor == null) return; Log.d(TAG, "sensorManager.registerListener"); sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI); }
@Override public void onSensorChanged(SensorEvent event) { if(event.sensor.getType()== Sensor.TYPE_ORIENTATION) { float x=event.values[SensorManager.DATA_X]; if(Math.abs(x-lastX)>1.0) { if(mOnOrientationListener!=null) { mOnOrientationListener.onOrientationChanged(x); } } lastX=x; } }
@Override protected void onResume() { super.onResume(); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); if (rendererSet) { glSurfaceView.onResume(); } }
@Override protected void onResume() { super.onResume(); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); }
void start() { if (parser != null) { for (Sensor sensor : parser.getSensors()) { sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); } } Log.d(TAG, "Sensor listener started!"); }
/** * Start listening for shakes. */ public void start(SensorManager manager) { Assertions.assertNotNull(manager); Sensor accelerometer = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (accelerometer != null) { mSensorManager = manager; mLastTimestamp = -1; mCurrentIndex = 0; mMagnitudes = new double[MAX_SAMPLES]; mTimestamps = new long[MAX_SAMPLES]; mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI); } }
public void listen(Context context, RotationCallback callback) { // Stop to make sure we're not registering the listening twice. stop(); // Only use the ApplicationContext. In case of a memory leak (e.g. from a framework bug), // this will result in less being leaked. context = context.getApplicationContext(); this.callback = callback; this.windowManager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); this.orientationEventListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) { @Override public void onOrientationChanged(int orientation) { WindowManager localWindowManager = windowManager; RotationCallback localCallback = RotationListener.this.callback; if(windowManager != null && localCallback != null) { int newRotation = localWindowManager.getDefaultDisplay().getRotation(); if (newRotation != lastRotation) { lastRotation = newRotation; localCallback.onRotationChanged(newRotation); } } } }; this.orientationEventListener.enable(); lastRotation = windowManager.getDefaultDisplay().getRotation(); }
@Override public void onResume() { super.onResume(); isOnPause = false; if (adCount > -1 && frontADInfo != null && rlAd != null) { startAdCountDown(); if (isVideoAd) { try { adPlayer.start(); } catch (Exception e) { } } return; } if (isFreeze) { isFreeze = false; if (isPrepared) { player.start(); } } else { if (isPlaying != null && isPlaying.booleanValue() && isPrepared) { player.start(); } } if (!isLocalPlay) { sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_UI); } }
@Override public void initView() { mBtnToolbarSend.setVisibility(View.VISIBLE); setRlMapHeight(maxHeight); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mOritationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); mLocationManager = TencentLocationManager.getInstance(this); mLocationRequest = TencentLocationRequest.create(); mTencentMap = mMap.getMap(); mTencentSearch = new TencentSearch(this); }
private void setupShakeDetector() { // ShakeDetector initialization mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager .getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mShakeDetector = new ShakeDetector(); mShakeDetector.setOnShakeListener(new ShakeDetector.OnShakeListener() { @Override public void onShake(int count) { mPresenter.shuffleSong(); Logger.get().log(new UserEvent(UserEvent.Source.Gesture, UserEvent.Action.Shuffle)); } }); }
@Override public void onResume() { super.onResume(); cameraController.onResume(); sensorManager.registerListener(sensorEventListener, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); if (cameraFragmentControlsListener != null) { cameraFragmentControlsListener.lockControls(); cameraFragmentControlsListener.allowRecord(false); } }
/** * Initialises a new ImprovedOrientationSensor2Provider * * @param sensorManager The android sensor manager */ public ImprovedOrientationSensor2Provider(SensorManager sensorManager, int sensorRefreshSpeed) { super(sensorManager, sensorRefreshSpeed); //Add the gyroscope and rotation Vector sensorList.add(sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE)); sensorList.add(sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)); }
/** * 计算方向 * * @return */ private void calculateOrientation(float[] accValues, float[] magValues) { float[] R = new float[9]; float[] values = new float[3]; SensorManager.getRotationMatrix(R, null, accValues, magValues); SensorManager.getOrientation(R, values); // 相反方向所以为负 newRotationDegree = (float) Math.toDegrees(values[0]); }
private void initDefaultSensor() { Handler orientationHandler = new ChangeOrientationHandler(this.mActivity); this.mSensorManager = (SensorManager) this.mActivity.getSystemService("sensor"); Sensor sensor = this.mSensorManager.getDefaultSensor(1); this.mOrientationSensorListener = new OrientationSensorListener(orientationHandler, this.mActivity); this.mSensorManager.registerListener(this.mOrientationSensorListener, sensor, 1); }
@Override public ControllerParent<GyroscopeShield> invalidate( com.integreight.onesheeld.shields.ControllerParent.SelectionAction selectionAction, boolean isToastable) { this.selectionAction = selectionAction; mSensorManager = (SensorManager) getApplication().getSystemService( Context.SENSOR_SERVICE); mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); registerSensorListener(isToastable); return super.invalidate(selectionAction, isToastable); }
@Override public ControllerParent<GravityShield> invalidate( com.integreight.onesheeld.shields.ControllerParent.SelectionAction selectionAction, boolean isToastable) { this.selectionAction = selectionAction; mSensorManager = (SensorManager) getApplication().getSystemService( Context.SENSOR_SERVICE); mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY); registerSensorListener(isToastable); return super.invalidate(selectionAction, isToastable); }
@Override public void onResume() { super.onResume(); if (null != mManager) { mManager.registerListener(mListener, mSensor, SensorManager.SENSOR_DELAY_GAME); } }