Java 类android.hardware.SensorManager 实例源码

项目:Android-Code-Demos    文件:CompassSketch.java   
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);
    }
}
项目:haven    文件:AmbientLightMonitor.java   
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);
    }

}
项目:smart-asset-iot-android-demo    文件:MainActivity.java   
@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());
}
项目:AndroidSnooper    文件:ShakeDetector.java   
@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();
  }
}
项目:GravityBox    文件:ModPower.java   
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);
    }
}
项目:homescreenarcade    文件:GameActivity.java   
/** 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);


}
项目:Huochexing12306    文件:PocketProtector.java   
@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;
    }
}
项目:QuranAndroid    文件:QuranPageReadActivity.java   
/**
 * 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);
}
项目:Intelligent_Indoor_Localization_System    文件:J2xxHyperTerm.java   
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
}
项目:Android-SteamVR-controller    文件:AccelerometerCompassProvider.java   
@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);
    }
}
项目:mapbox-plugins-android    文件:CompassManager.java   
@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);
    }
  }
}
项目:buildAPKsSamples    文件:CompassActivity.java   
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)
                    );
        }
    }
项目:enklave    文件:MyCompas.java   
@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);
    }
}
项目:boohee_v5.6    文件:k.java   
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 "";
}
项目:boohee_v5.6    文件:l.java   
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;
}
项目:CSipSimple    文件:CallProximityManager.java   
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;
    }
}
项目:NeoTerm    文件:Accelerometer.java   
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);
    }
}
项目:androidthings    文件:MainActivity.java   
@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);
}
项目:HeadlineNews    文件:VideoDetailActivity.java   
@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);
}
项目:GyroCheck-Android-Library    文件:GyroView.java   
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);

}
项目:microbit    文件:TemperaturePresenter.java   
@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);
        }
    }
}
项目:MapDemo    文件:MyOrientationListener.java   
@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;

    }
}
项目:Android-Wear-Projects    文件:WearStepService.java   
/**
 * 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);
}
项目:GitHub    文件:MyOrientationListener.java   
@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;

    }

}
项目:sensor-graph-opengl-es-android    文件:SensorDemoActivity.java   
@Override
protected void onResume() {
    super.onResume();
    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
    if (rendererSet) {
        glSurfaceView.onResume();
    }
}
项目:Android-Real-Time-Chart    文件:MainActivity.java   
@Override
protected void onResume() {
    super.onResume();
    sensorManager.registerListener(this,
            sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_NORMAL);
}
项目:Zero    文件:Parallax.java   
void start() {

        if (parser != null) {
            for (Sensor sensor : parser.getSensors()) {
                sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);
            }
        }

        Log.d(TAG, "Sensor listener started!");
    }
项目:RNLearn_Project1    文件:ShakeDetector.java   
/**
 * 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);
  }
}
项目:ZxingForAndroid    文件:RotationListener.java   
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();
}
项目:CCDownload    文件:ADMediaPlayActivity.java   
@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);
    }
}
项目:GankIO_weex    文件:ShakeDetector.java   
/**
 * 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);
  }
}
项目:LQRWeChat-master    文件:MyLocationActivity.java   
@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);
}
项目:NUI_Project    文件:SongPlayerFragment.java   
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));
        }
    });
}
项目:CameraFragment    文件:BaseAnncaFragment.java   
@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);
    }
}
项目:Android-SteamVR-controller    文件:ImprovedOrientationSensor2Provider.java   
/**
 * 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));
}
项目:Days    文件:CalendarActivity.java   
/**
 * 计算方向
 *
 * @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]);
}
项目:letv    文件:AlbumController.java   
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);
}
项目:CustomAndroidOneSheeld    文件:GyroscopeShield.java   
@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);
}
项目:CustomAndroidOneSheeld    文件:GravityShield.java   
@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);
}
项目:Android-Code-Demos    文件:SensorSketch.java   
@Override
public void onResume() {
    super.onResume();
    if (null != mManager) {
        mManager.registerListener(mListener, mSensor, SensorManager.SENSOR_DELAY_GAME);
    }
}