Java Code Examples for android.hardware.SensorManager

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project and-bible, under directory /AndBible/src/net/bible/android/control/page/.

Source file: PageTiltScrollControl.java

  22 
vote

/** 
 * Orientation monitor (see Professional Android 2 App Dev Meier pg 469)
 */
private void connectListeners(){
  mDisplay=((WindowManager)BibleApplication.getApplication().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
  SensorManager sm=(SensorManager)BibleApplication.getApplication().getSystemService(Context.SENSOR_SERVICE);
  Sensor oSensor=sm.getDefaultSensor(Sensor.TYPE_ORIENTATION);
  sm.registerListener(myOrientationListener,oSensor,SensorManager.SENSOR_DELAY_UI);
}
 

Example 2

From project android-context, under directory /src/edu/fsu/cs/contextprovider/data/.

Source file: ContextConstants.java

  22 
vote

public static float getMaxSensorRange(Context context,int sensorType,float defaultValue){
  float max=defaultValue;
  SensorManager sm=(SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
  List<Sensor> sensors=sm.getSensorList(sensorType);
  if (sensors != null && sensors.size() > 0)   max=sensors.get(0).getMaximumRange();
  return max;
}
 

Example 3

From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/app/.

Source file: EyePosition.java

  22 
vote

public void pause(){
  if (mSensor != null) {
    SensorManager sManager=(SensorManager)mContext.getSystemService(Context.SENSOR_SERVICE);
    sManager.unregisterListener(mPositionListener);
  }
}
 

Example 4

From project android_packages_apps_phone, under directory /src/com/android/phone/.

Source file: PhoneUtils.java

  22 
vote

static boolean isProximitySensorAvailable(Context ctx){
  if (sProximitySensorAvailable != 0) {
    return sProximitySensorAvailable == 1;
  }
  SensorManager sm=(SensorManager)ctx.getSystemService(Context.SENSOR_SERVICE);
  Sensor sensor=sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
  sProximitySensorAvailable=(sensor != null) ? 1 : -1;
  return isProximitySensorAvailable(ctx);
}
 

Example 5

From project android_packages_apps_QiblaCompass, under directory /src/com/farsitel/qiblacompass/activities/.

Source file: QiblaActivity.java

  22 
vote

private void unregisterListeners(){
  ((LocationManager)getSystemService(Context.LOCATION_SERVICE)).removeUpdates(qiblaManager);
  ((LocationManager)getSystemService(Context.LOCATION_SERVICE)).removeUpdates(qiblaManager);
  SensorManager mSensorManager=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
  Sensor gsensor=mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  Sensor msensor=mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
  mSensorManager.unregisterListener(qiblaManager,gsensor);
  mSensorManager.unregisterListener(qiblaManager,msensor);
  cancelSchedule();
}
 

Example 6

From project gast-lib, under directory /app/src/root/gast/playground/sensor/.

Source file: SensorSelectorFragment.java

  22 
vote

/** 
 * connect with a display fragment to call later when user clicks a sensor name, also setup the ListAdapter to show all the Sensors
 */
public void setSensorDisplay(SensorDisplayFragment sensorDisplay){
  this.sensorDisplay=sensorDisplay;
  SensorManager sensorManager=(SensorManager)getActivity().getSystemService(Activity.SENSOR_SERVICE);
  List<Sensor> sensors=sensorManager.getSensorList(Sensor.TYPE_ALL);
  this.setListAdapter(new SensorListAdapter(getActivity().getApplicationContext(),android.R.layout.simple_list_item_1,sensors));
}
 

Example 7

From project mediaphone, under directory /src/ac/robinson/mediaphone/activity/.

Source file: CameraActivity.java

  22 
vote

@Override protected void onResume(){
  super.onResume();
  SensorManager sensorManager=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
  if (OrientationManager.isSupported(sensorManager)) {
    OrientationManager.startListening(sensorManager,this);
  }
}
 

Example 8

From project platform_packages_apps_contacts, under directory /src/com/android/contacts/.

Source file: ProximitySensorManager.java

  22 
vote

public ProximitySensorManager(Context context,Listener listener){
  SensorManager sensorManager=(SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
  Sensor proximitySensor=sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
  if (proximitySensor == null) {
    mProximitySensorListener=null;
  }
 else {
    mProximitySensorListener=new ProximitySensorEventListener(sensorManager,proximitySensor,listener);
  }
}
 

Example 9

From project platform_packages_apps_CytownPhone, under directory /src/com/android/phone/.

Source file: PhoneUtils.java

  22 
vote

static boolean isProximitySensorAvailable(Context ctx){
  if (sProximitySensorAvailable != 0) {
    return sProximitySensorAvailable == 1;
  }
  SensorManager sm=(SensorManager)ctx.getSystemService(Context.SENSOR_SERVICE);
  Sensor sensor=sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
  sProximitySensorAvailable=(sensor != null) ? 1 : -1;
  return isProximitySensorAvailable(ctx);
}
 

Example 10

From project platform_packages_apps_Gallery2_1, under directory /src/com/android/gallery3d/app/.

Source file: EyePosition.java

  22 
vote

public void pause(){
  if (mSensor != null) {
    SensorManager sManager=(SensorManager)mContext.getSystemService(Context.SENSOR_SERVICE);
    sManager.unregisterListener(mPositionListener);
  }
}
 

Example 11

From project PowerTutor, under directory /src/edu/umich/PowerTutor/phone/.

Source file: DreamConstants.java

  22 
vote

public DreamConstants(Context context){
  SensorManager sensorManager=(SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
  sensorPowerArray=new double[Sensors.MAX_SENSORS];
  for (int i=0; i < Sensors.MAX_SENSORS; i++) {
    Sensor sensor=sensorManager.getDefaultSensor(i);
    if (sensor != null) {
      sensorPowerArray[i]=sensor.getPower() * BATTERY_VOLTAGE;
    }
  }
}
 

Example 12

From project Sketchy-Truck, under directory /andengine/src/org/anddev/andengine/engine/.

Source file: Engine.java

  22 
vote

/** 
 * @return <code>true</code> when the sensor was successfully disabled, <code>false</code> otherwise.
 */
public boolean disableAccelerometerSensor(final Context pContext){
  final SensorManager sensorManager=(SensorManager)pContext.getSystemService(Context.SENSOR_SERVICE);
  if (this.isSensorSupported(sensorManager,Sensor.TYPE_ACCELEROMETER)) {
    this.unregisterSelfAsSensorListener(sensorManager,Sensor.TYPE_ACCELEROMETER);
    return true;
  }
 else {
    return false;
  }
}
 

Example 13

From project android-pedometer, under directory /src/name/bagi/levente/pedometer/.

Source file: StepDetector.java

  19 
vote

public StepDetector(){
  int h=480;
  mYOffset=h * 0.5f;
  mScale[0]=-(h * 0.5f * (1.0f / (SensorManager.STANDARD_GRAVITY * 2)));
  mScale[1]=-(h * 0.5f * (1.0f / (SensorManager.MAGNETIC_FIELD_EARTH_MAX)));
}
 

Example 14

From project android-voip-service, under directory /src/main/java/org/linphone/.

Source file: LinphoneActivity.java

  19 
vote

synchronized void startProxymitySensor(){
  if (mSensorEventListener != null) {
    Log.i("proximity sensor already active");
    return;
  }
  List<Sensor> lSensorList=mSensorManager.getSensorList(Sensor.TYPE_PROXIMITY);
  mSensorEventListener=new SensorEventListener(){
    public void onSensorChanged(    SensorEvent event){
      if (event.timestamp == 0)       return;
      instance().hideScreen(LinphoneManager.isProximitySensorNearby(event));
    }
    public void onAccuracyChanged(    Sensor sensor,    int accuracy){
    }
  }
;
  if (lSensorList.size() > 0) {
    mSensorManager.registerListener(mSensorEventListener,lSensorList.get(0),SensorManager.SENSOR_DELAY_UI);
    Log.i("Proximity sensor detected, registering");
  }
}
 

Example 15

From project Android_1, under directory /CompassExample/src/com/novoda/example/compass/activities/.

Source file: BasicSensorActivity.java

  19 
vote

private void registerAcclSensor(){
  if (sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() > 0) {
    acclSensor=sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(FIRST_SENSOR_ITEM);
    sensorManager.registerListener(this,acclSensor,SensorManager.SENSOR_DELAY_NORMAL);
  }
}
 

Example 16

From project android_packages_apps_cmparts, under directory /src/com/cyanogenmod/cmparts/activities/.

Source file: DisplayActivity.java

  19 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setTitle(R.string.display_settings_title_subhead);
  addPreferencesFromResource(R.xml.display_settings);
  PreferenceScreen prefSet=getPreferenceScreen();
  mBacklightScreen=(PreferenceScreen)prefSet.findPreference(BACKLIGHT_SETTINGS);
  if (((SensorManager)getSystemService(SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_LIGHT) == null) {
    ((PreferenceCategory)prefSet.findPreference(GENERAL_CATEGORY)).removePreference(mBacklightScreen);
  }
  mElectronBeamAnimationOn=(CheckBoxPreference)prefSet.findPreference(ELECTRON_BEAM_ANIMATION_ON);
  mElectronBeamAnimationOff=(CheckBoxPreference)prefSet.findPreference(ELECTRON_BEAM_ANIMATION_OFF);
  if (getResources().getBoolean(com.android.internal.R.bool.config_enableScreenAnimation)) {
    mElectronBeamAnimationOn.setChecked(Settings.System.getInt(getContentResolver(),Settings.System.ELECTRON_BEAM_ANIMATION_ON,getResources().getBoolean(com.android.internal.R.bool.config_enableScreenOnAnimation) ? 1 : 0) == 1);
    mElectronBeamAnimationOff.setChecked(Settings.System.getInt(getContentResolver(),Settings.System.ELECTRON_BEAM_ANIMATION_OFF,getResources().getBoolean(com.android.internal.R.bool.config_enableScreenOffAnimation) ? 1 : 0) == 1);
  }
 else {
    ((PreferenceCategory)prefSet.findPreference(GENERAL_CATEGORY)).removePreference(mElectronBeamAnimationOn);
    ((PreferenceCategory)prefSet.findPreference(GENERAL_CATEGORY)).removePreference(mElectronBeamAnimationOff);
  }
  mRotation0Pref=(CheckBoxPreference)prefSet.findPreference(ROTATION_0_PREF);
  mRotation90Pref=(CheckBoxPreference)prefSet.findPreference(ROTATION_90_PREF);
  mRotation180Pref=(CheckBoxPreference)prefSet.findPreference(ROTATION_180_PREF);
  mRotation270Pref=(CheckBoxPreference)prefSet.findPreference(ROTATION_270_PREF);
  int mode=Settings.System.getInt(getContentResolver(),Settings.System.ACCELEROMETER_ROTATION_MODE,ROTATION_0_MODE | ROTATION_90_MODE | ROTATION_270_MODE);
  mRotation0Pref.setChecked((mode & ROTATION_0_MODE) != 0);
  mRotation90Pref.setChecked((mode & ROTATION_90_MODE) != 0);
  mRotation180Pref.setChecked((mode & ROTATION_180_MODE) != 0);
  mRotation270Pref.setChecked((mode & ROTATION_270_MODE) != 0);
}
 

Example 17

From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/media/.

Source file: RenderView.java

  19 
vote

public RenderView(final Context context){
  super(context);
  setBackgroundDrawable(null);
  setFocusable(true);
  if (getResources().getBoolean(R.bool.use_32bpp_display)) {
    setEGLConfigChooser(8,8,8,8,16,0);
    getHolder().setFormat(PixelFormat.RGBA_8888);
  }
  setRenderer(this);
  mSensorManager=(SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
  if (sCachedTextureLoadThread == null) {
    for (int i=0; i != NUM_TEXTURE_LOAD_THREADS; ++i) {
      TextureLoadThread thread=new TextureLoadThread();
      if (i == 0) {
        sCachedTextureLoadThread=thread;
      }
      if (i == 1) {
        sVideoTextureLoadThread=thread;
      }
      sTextureLoadThreads[i]=thread;
      thread.start();
    }
  }
}
 

Example 18

From project apps-for-android, under directory /Amazed/src/com/example/amazed/.

Source file: AmazedView.java

  19 
vote

/** 
 * Custom view constructor.
 * @param context Application context
 * @param activity Activity controlling the view
 */
public AmazedView(Context context,Activity activity){
  super(context);
  mActivity=activity;
  mPaint=new Paint();
  mPaint.setTextSize(14);
  mPaint.setTypeface(mFont);
  mPaint.setAntiAlias(true);
  mSensorManager=(SensorManager)activity.getSystemService(Context.SENSOR_SERVICE);
  mSensorManager.registerListener(mSensorAccelerometer,SensorManager.SENSOR_ACCELEROMETER,SensorManager.SENSOR_DELAY_GAME);
  mMaze=new Maze(mActivity);
  mMarble=new Marble(this);
  mStrings=getResources().getStringArray(R.array.gameStrings);
  switchGameState(GAME_INIT);
}
 

Example 19

From project cocos2d, under directory /cocos2d-android/src/org/cocos2d/layers/.

Source file: CCLayer.java

  19 
vote

protected CCLayer(){
  sensorManager=(SensorManager)CCDirector.sharedDirector().getActivity().getSystemService(Context.SENSOR_SERVICE);
  if (sensorManager != null)   accelerometer=sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
 else   accelerometer=null;
  CGSize s=CCDirector.sharedDirector().winSize();
  setRelativeAnchorPoint(false);
  setAnchorPoint(CGPoint.make(0.5f,0.5f));
  setContentSize(s);
  setRelativeAnchorPoint(false);
  isTouchEnabled_=false;
  isAccelerometerEnabled_=false;
}
 

Example 20

From project CoinFlip, under directory /src/com/banasiak/coinflip/.

Source file: ShakeListener.java

  19 
vote

public void resume(int forceMultiplier){
  Log.d(TAG,"resume()");
  mForceMultiplier=forceMultiplier;
  mSensorManager=(SensorManager)mContext.getSystemService(Context.SENSOR_SERVICE);
  if (mSensorManager != null) {
    try {
      Sensor accelerometer=mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
      mSensorManager.registerListener(this,accelerometer,SensorManager.SENSOR_DELAY_GAME);
    }
 catch (    Exception e) {
      Log.w(TAG,"Accelerometer not supported",e);
      mSensorManager.unregisterListener(this);
    }
  }
 else {
    Exception e=new UnsupportedOperationException();
    Log.w(TAG,"Sensors not supported",e);
  }
}
 

Example 21

From project cw-advandroid, under directory /Sensor/Shaker/src/com/commonsware/android/shaker/.

Source file: Shaker.java

  19 
vote

public Shaker(Context ctxt,double threshold,long gap,Shaker.Callback cb){
  this.threshold=threshold * threshold;
  this.threshold=this.threshold * SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH;
  this.gap=gap;
  this.cb=cb;
  mgr=(SensorManager)ctxt.getSystemService(Context.SENSOR_SERVICE);
  mgr.registerListener(listener,mgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR_DELAY_UI);
}
 

Example 22

From project cw-omnibus, under directory /Sensor/List/src/com/commonsware/android/sensorlist/.

Source file: SensorListFragment.java

  19 
vote

@Override public void onActivityCreated(Bundle savedInstanceState){
  super.onActivityCreated(savedInstanceState);
  setRetainInstance(true);
  mgr=(SensorManager)getActivity().getSystemService(Context.SENSOR_SERVICE);
  adapter=new SensorListAdapter();
  setListAdapter(adapter);
}
 

Example 23

From project DigitbooksExamples, under directory /DigitbooksExamples/src/fr/digitbooks/android/examples/chapitre11/.

Source file: SensorActivity.java

  19 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.sensor);
  mSensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
  mBallsView=(BallView)findViewById(R.id.ballView);
  mBallsView.start();
}
 

Example 24

From project droidkit, under directory /src/org/droidkit/widget/.

Source file: Scroller.java

  19 
vote

/** 
 * Create a Scroller with the specified interpolator. If the interpolator is null, the default (viscous) interpolator will be used.
 */
public Scroller(Context context,Interpolator interpolator){
  mFinished=true;
  mInterpolator=interpolator;
  float ppi=context.getResources().getDisplayMetrics().density * 160.0f;
  mDeceleration=SensorManager.GRAVITY_EARTH * 39.37f * ppi* ViewConfiguration.getScrollFriction();
}
 

Example 25

From project ElectricSleep, under directory /src/com/androsz/electricsleepbeta/app/.

Source file: SleepMonitoringService.java

  19 
vote

@Override public int onStartCommand(final Intent intent,final int flags,final int startId){
  if (intent != null && mRunning.compareAndSet(false,true)) {
    Log.d(TAG,"Starting sleep monitoring service: " + startId);
    testModeRate=intent.getIntExtra("testModeRate",Integer.MIN_VALUE);
    updateInterval=testModeRate == Integer.MIN_VALUE ? intent.getIntExtra("interval",INTERVAL) : testModeRate;
    sensorDelay=intent.getIntExtra(StartSleepReceiver.EXTRA_SENSOR_DELAY,SensorManager.SENSOR_DELAY_FASTEST);
    alarmTriggerSensitivity=intent.getFloatExtra(StartSleepReceiver.EXTRA_ALARM,SettingsActivity.DEFAULT_ALARM_SENSITIVITY);
    useAlarm=intent.getBooleanExtra(StartSleepReceiver.EXTRA_USE_ALARM,false);
    alarmWindow=intent.getIntExtra(StartSleepReceiver.EXTRA_ALARM_WINDOW,0);
    airplaneMode=intent.getBooleanExtra(StartSleepReceiver.EXTRA_AIRPLANE_MODE,false);
    silentMode=intent.getBooleanExtra(StartSleepReceiver.EXTRA_SILENT_MODE,false);
    forceScreenOn=intent.getBooleanExtra(StartSleepReceiver.EXTRA_FORCE_SCREEN_ON,false);
    startForeground(NOTIFICATION_ID,createServiceNotification());
    obtainWakeLock();
    registerAccelerometerListener();
    new AsyncTask<Void,Void,Void>(){
      @Override protected Void doInBackground(      Void... params){
        toggleSilentMode(true);
        toggleAirplaneMode(true);
        if (!alreadyDeletedResidualFile) {
          deleteFile(SleepMonitoringService.SLEEP_DATA);
          alreadyDeletedResidualFile=true;
        }
        final SharedPreferences.Editor ed=getSharedPreferences(SERVICE_IS_RUNNING,Context.MODE_PRIVATE).edit();
        ed.putBoolean(SERVICE_IS_RUNNING,true);
        ed.commit();
        return null;
      }
    }
.execute();
  }
  return START_STICKY;
}
 

Example 26

From project external-replicaisland, under directory /src/com/replica/replicaisland/.

Source file: AndouKun.java

  19 
vote

@Override protected void onResume(){
  super.onResume();
  SharedPreferences prefs=getSharedPreferences(PreferenceConstants.PREFERENCE_NAME,MODE_PRIVATE);
  final boolean debugLogs=prefs.getBoolean(PreferenceConstants.PREFERENCE_ENABLE_DEBUG,false);
  if (VERSION < 0 || debugLogs) {
    DebugLog.setDebugLogging(true);
  }
 else {
    DebugLog.setDebugLogging(false);
  }
  DebugLog.d("AndouKun","onResume");
  mGLSurfaceView.onResume();
  mGame.onResume(this,false);
  final boolean soundEnabled=prefs.getBoolean(PreferenceConstants.PREFERENCE_SOUND_ENABLED,true);
  final boolean safeMode=prefs.getBoolean(PreferenceConstants.PREFERENCE_SAFE_MODE,false);
  final boolean clickAttack=prefs.getBoolean(PreferenceConstants.PREFERENCE_CLICK_ATTACK,true);
  final boolean tiltControls=prefs.getBoolean(PreferenceConstants.PREFERENCE_TILT_CONTROLS,false);
  final int tiltSensitivity=prefs.getInt(PreferenceConstants.PREFERENCE_TILT_SENSITIVITY,50);
  final int movementSensitivity=prefs.getInt(PreferenceConstants.PREFERENCE_MOVEMENT_SENSITIVITY,100);
  final boolean onScreenControls=prefs.getBoolean(PreferenceConstants.PREFERENCE_SCREEN_CONTROLS,false);
  final int leftKey=prefs.getInt(PreferenceConstants.PREFERENCE_LEFT_KEY,KeyEvent.KEYCODE_DPAD_LEFT);
  final int rightKey=prefs.getInt(PreferenceConstants.PREFERENCE_RIGHT_KEY,KeyEvent.KEYCODE_DPAD_RIGHT);
  final int jumpKey=prefs.getInt(PreferenceConstants.PREFERENCE_JUMP_KEY,KeyEvent.KEYCODE_SPACE);
  final int attackKey=prefs.getInt(PreferenceConstants.PREFERENCE_ATTACK_KEY,KeyEvent.KEYCODE_SHIFT_LEFT);
  mGame.setSoundEnabled(soundEnabled);
  mGame.setControlOptions(clickAttack,tiltControls,tiltSensitivity,movementSensitivity,onScreenControls);
  mGame.setKeyConfig(leftKey,rightKey,jumpKey,attackKey);
  mGame.setSafeMode(safeMode);
  if (mSensorManager != null) {
    Sensor orientation=mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    if (orientation != null) {
      mSensorManager.registerListener(this,orientation,SensorManager.SENSOR_DELAY_GAME,null);
    }
  }
}
 

Example 27

From project fanfoudroid, under directory /src/com/hlidskialf/android/hardware/.

Source file: ShakeListener.java

  19 
vote

public void resume(){
  mSensorMgr=(SensorManager)mContext.getSystemService(Context.SENSOR_SERVICE);
  mSensor=mSensorMgr.getDefaultSensor(SensorManager.SENSOR_ACCELEROMETER);
  if (mSensorMgr == null) {
    throw new UnsupportedOperationException("Sensors not supported");
  }
  boolean supported=mSensorMgr.registerListener(this,mSensor,SensorManager.SENSOR_DELAY_GAME);
  if (!supported) {
    mSensorMgr.unregisterListener(this,mSensor);
    throw new UnsupportedOperationException("Accelerometer not supported");
  }
}
 

Example 28

From project Gaggle, under directory /src/com/geeksville/location/.

Source file: AndroidBarometerClient.java

  19 
vote

@Override public void setAltitude(float meters){
  float p0=pressure / (float)Math.pow((1 - meters / 44330),5.255);
  reference=p0;
  altitude=SensorManager.getAltitude(reference,pressure);
  Log.w(TAG,"Setting baro reference to " + reference + " alt="+ meters);
  isCalibrated=true;
}
 

Example 29

From project HeLauncher, under directory /src/org/adw/launcher/.

Source file: CustomScroller.java

  19 
vote

/** 
 * Create a CustomScroller with the specified interpolator. If the interpolator is null, the default (viscous) interpolator will be used.
 */
public CustomScroller(Context context,Interpolator interpolator){
  mFinished=true;
  mInterpolator=interpolator;
  float ppi=context.getResources().getDisplayMetrics().density * 160.0f;
  mDeceleration=SensorManager.GRAVITY_EARTH * 39.37f * ppi* ViewConfiguration.getScrollFriction();
}
 

Example 30

From project incubator-cordova-android, under directory /framework/src/org/apache/cordova/.

Source file: AccelListener.java

  19 
vote

/** 
 * Start listening for acceleration sensor.
 * @return          status of listener
 */
private int start(){
  if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) {
    return this.status;
  }
  this.setStatus(AccelListener.STARTING);
  List<Sensor> list=this.sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
  if ((list != null) && (list.size() > 0)) {
    this.mSensor=list.get(0);
    this.sensorManager.registerListener(this,this.mSensor,SensorManager.SENSOR_DELAY_UI);
    this.setStatus(AccelListener.STARTING);
  }
 else {
    this.setStatus(AccelListener.ERROR_FAILED_TO_START);
    this.fail(AccelListener.ERROR_FAILED_TO_START,"No sensors found to register accelerometer listening to.");
    return this.status;
  }
  Handler handler=new Handler(Looper.getMainLooper());
  handler.postDelayed(new Runnable(){
    public void run(){
      AccelListener.this.timeout();
    }
  }
,2000);
  return this.status;
}
 

Example 31

From project kevoree-library, under directory /android/org.kevoree.library.android.osmdroid/src/main/java/org/osmdroid/views/overlay/.

Source file: MyLocationOverlay.java

  19 
vote

public MyLocationOverlay(final Context ctx,final MapView mapView,final ResourceProxy pResourceProxy){
  super(pResourceProxy);
  mMapView=mapView;
  mLocationManager=(LocationManager)ctx.getSystemService(Context.LOCATION_SERVICE);
  mSensorManager=(SensorManager)ctx.getSystemService(Context.SENSOR_SERVICE);
  final WindowManager windowManager=(WindowManager)ctx.getSystemService(Context.WINDOW_SERVICE);
  mDisplay=windowManager.getDefaultDisplay();
  mMapController=mapView.getController();
  mCirclePaint.setARGB(0,100,100,255);
  mCirclePaint.setAntiAlias(true);
  PERSON_ICON=mResourceProxy.getBitmap(ResourceProxy.bitmap.person);
  DIRECTION_ARROW=mResourceProxy.getBitmap(ResourceProxy.bitmap.direction_arrow);
  DIRECTION_ARROW_CENTER_X=DIRECTION_ARROW.getWidth() / 2 - 0.5f;
  DIRECTION_ARROW_CENTER_Y=DIRECTION_ARROW.getHeight() / 2 - 0.5f;
  PERSON_HOTSPOT=new PointF(24.0f * mScale + 0.5f,39.0f * mScale + 0.5f);
  createCompassFramePicture();
  createCompassRosePicture();
  COMPASS_FRAME_CENTER_X=mCompassFrame.getWidth() / 2 - 0.5f;
  COMPASS_FRAME_CENTER_Y=mCompassFrame.getHeight() / 2 - 0.5f;
  COMPASS_ROSE_CENTER_X=mCompassRose.getWidth() / 2 - 0.5f;
  COMPASS_ROSE_CENTER_Y=mCompassRose.getHeight() / 2 - 0.5f;
}
 

Example 32

From project LEGO-MINDSTORMS-MINDdroid, under directory /android/src/com/lego/minddroid/.

Source file: GameView.java

  19 
vote

public GameView(Context context,MINDdroid uiActivity){
  super(context);
  mActivity=uiActivity;
  mSensorManager=(SensorManager)mActivity.getSystemService(Context.SENSOR_SERVICE);
  SurfaceHolder holder=getHolder();
  holder.setKeepScreenOn(true);
  holder.addCallback(this);
  this.context=context;
  thread=new GameThread(holder,context,(Vibrator)uiActivity.getSystemService(Context.VIBRATOR_SERVICE),new Handler(){
    @Override public void handleMessage(    Message m){
    }
  }
);
  setFocusable(true);
}
 

Example 33

From project maven-android-plugin-samples, under directory /apidemos-android-10/application/src/main/java/com/example/android/apis/graphics/.

Source file: Compass.java

  19 
vote

@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  mSensorManager=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
  mSensor=mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
  mView=new SampleView(this);
  setContentView(mView);
}
 

Example 34

From project mediautilities, under directory /src/ac/robinson/util/.

Source file: OrientationManager.java

  19 
vote

public static boolean isSupported(SensorManager sensorManager){
  if (mOrientationSupported == null) {
    mOrientationSupported=sensorManager.getSensorList(Sensor.TYPE_ORIENTATION).size() > 0;
  }
  return mOrientationSupported;
}
 

Example 35

From project mixare, under directory /src/org/mixare/.

Source file: MixView.java

  19 
vote

public void onAccuracyChanged(Sensor sensor,int accuracy){
  if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD && accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE && getMixViewData().getCompassErrorDisplayed() == 0) {
    for (int i=0; i < 2; i++) {
      Toast.makeText(getMixViewData().getMixContext(),"Compass data unreliable. Please recalibrate compass.",Toast.LENGTH_LONG).show();
    }
    getMixViewData().setCompassErrorDisplayed(getMixViewData().getCompassErrorDisplayed() + 1);
  }
}
 

Example 36

From project No-Pain-No-Game, under directory /src/edu/ucla/cs/nopainnogame/pedometer/.

Source file: StepDetector.java

  19 
vote

public StepDetector(){
  int h=480;
  mYOffset=h * 0.5f;
  mScale[0]=-(h * 0.5f * (1.0f / (SensorManager.STANDARD_GRAVITY * 2)));
  mScale[1]=-(h * 0.5f * (1.0f / (SensorManager.MAGNETIC_FIELD_EARTH_MAX)));
}
 

Example 37

From project OneMoreDream, under directory /src/com/dixheure/.

Source file: AlarmAlertFullScreen.java

  19 
vote

@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  mSensorManager=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
  mSensorListener=new ShakeEventListener();
  mSensorListener.setOnShakeListener(new ShakeEventListener.OnShakeListener(){
    public void onShake(){
      snooze();
    }
  }
);
  mTrackIndex=-1;
  mThumbFetcher=new ThumbFetcher(this);
  mAlarm=getIntent().getParcelableExtra(Alarms.ALARM_INTENT_EXTRA);
  final String vol=PreferenceManager.getDefaultSharedPreferences(this).getString(SettingsActivity.KEY_VOLUME_BEHAVIOR,DEFAULT_VOLUME_BEHAVIOR);
  mVolumeBehavior=Integer.parseInt(vol);
  requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
  final Window win=getWindow();
  win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
  if (!getIntent().getBooleanExtra(SCREEN_OFF,false)) {
    win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
  }
  updateLayout();
  launchNextTrack(null);
  registerReceiver(mReceiver,new IntentFilter(Alarms.ALARM_KILLED));
  registerReceiver(mTrackReceiver,new IntentFilter(AlarmKlaxon.TRACK_ACTION));
}
 

Example 38

From project packages_apps_Phone_1, under directory /src/com/android/phone/.

Source file: AccelerometerListener.java

  19 
vote

public void enable(boolean enable){
  if (DEBUG)   Log.d(TAG,"enable(" + enable + ")");
synchronized (this) {
    if (enable) {
      mOrientation=ORIENTATION_UNKNOWN;
      mPendingOrientation=ORIENTATION_UNKNOWN;
      mSensorManager.registerListener(mSensorListener,mSensor,SensorManager.SENSOR_DELAY_NORMAL);
    }
 else {
      mSensorManager.unregisterListener(mSensorListener);
      mHandler.removeMessages(ORIENTATION_CHANGED);
    }
  }
}
 

Example 39

From project packages_apps_ROMControl, under directory /src/com/aokp/romcontrol/service/.

Source file: FlipService.java

  19 
vote

@Override public int onStartCommand(Intent intent,int flags,int startId){
  if (!mRegistered) {
    IntentFilter filter=new IntentFilter();
    am=(AudioManager)service.getSystemService(Context.AUDIO_SERVICE);
    vib=(Vibrator)service.getSystemService(Context.VIBRATOR_SERVICE);
    if (getUserFlipAudioMode(service) != -1) {
      getSensorManager().registerListener(sl,getSensorManager().getDefaultSensor(Sensor.TYPE_ORIENTATION),SensorManager.SENSOR_DELAY_UI);
    }
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    registerReceiver(screenReceiver,filter);
    mRegistered=true;
    log("register sensor manager");
  }
  return START_STICKY;
}
 

Example 40

From project platform_packages_apps_phone, under directory /src/com/android/phone/.

Source file: AccelerometerListener.java

  19 
vote

public void enable(boolean enable){
  if (DEBUG)   Log.d(TAG,"enable(" + enable + ")");
synchronized (this) {
    if (enable) {
      mOrientation=ORIENTATION_UNKNOWN;
      mPendingOrientation=ORIENTATION_UNKNOWN;
      mSensorManager.registerListener(mSensorListener,mSensor,SensorManager.SENSOR_DELAY_NORMAL);
    }
 else {
      mSensorManager.unregisterListener(mSensorListener);
      mHandler.removeMessages(ORIENTATION_CHANGED);
    }
  }
}
 

Example 41

From project RebeLauncher, under directory /src/com/dirtypepper/rebelauncher/.

Source file: CustomScroller.java

  19 
vote

/** 
 * Create a CustomScroller with the specified interpolator. If the interpolator is null, the default (viscous) interpolator will be used.
 */
public CustomScroller(Context context,Interpolator interpolator){
  mFinished=true;
  mInterpolator=interpolator;
  float ppi=context.getResources().getDisplayMetrics().density * 160.0f;
  mDeceleration=SensorManager.GRAVITY_EARTH * 39.37f * ppi* ViewConfiguration.getScrollFriction();
}
 

Example 42

From project ReplicaIsland, under directory /src/com/replica/replicaisland/.

Source file: AndouKun.java

  19 
vote

@Override protected void onResume(){
  super.onResume();
  SharedPreferences prefs=getSharedPreferences(PreferenceConstants.PREFERENCE_NAME,MODE_PRIVATE);
  final boolean debugLogs=prefs.getBoolean(PreferenceConstants.PREFERENCE_ENABLE_DEBUG,false);
  if (VERSION < 0 || debugLogs) {
    DebugLog.setDebugLogging(true);
  }
 else {
    DebugLog.setDebugLogging(false);
  }
  DebugLog.d("AndouKun","onResume");
  mGLSurfaceView.onResume();
  mGame.onResume(this,false);
  final boolean soundEnabled=prefs.getBoolean(PreferenceConstants.PREFERENCE_SOUND_ENABLED,true);
  final boolean safeMode=prefs.getBoolean(PreferenceConstants.PREFERENCE_SAFE_MODE,false);
  final boolean clickAttack=prefs.getBoolean(PreferenceConstants.PREFERENCE_CLICK_ATTACK,true);
  final boolean tiltControls=prefs.getBoolean(PreferenceConstants.PREFERENCE_TILT_CONTROLS,false);
  final int tiltSensitivity=prefs.getInt(PreferenceConstants.PREFERENCE_TILT_SENSITIVITY,50);
  final int movementSensitivity=prefs.getInt(PreferenceConstants.PREFERENCE_MOVEMENT_SENSITIVITY,100);
  final boolean onScreenControls=prefs.getBoolean(PreferenceConstants.PREFERENCE_SCREEN_CONTROLS,false);
  final int leftKey=prefs.getInt(PreferenceConstants.PREFERENCE_LEFT_KEY,KeyEvent.KEYCODE_DPAD_LEFT);
  final int rightKey=prefs.getInt(PreferenceConstants.PREFERENCE_RIGHT_KEY,KeyEvent.KEYCODE_DPAD_RIGHT);
  final int jumpKey=prefs.getInt(PreferenceConstants.PREFERENCE_JUMP_KEY,KeyEvent.KEYCODE_SPACE);
  final int attackKey=prefs.getInt(PreferenceConstants.PREFERENCE_ATTACK_KEY,KeyEvent.KEYCODE_SHIFT_LEFT);
  mGame.setSoundEnabled(soundEnabled);
  mGame.setControlOptions(clickAttack,tiltControls,tiltSensitivity,movementSensitivity,onScreenControls);
  mGame.setKeyConfig(leftKey,rightKey,jumpKey,attackKey);
  mGame.setSafeMode(safeMode);
  if (mSensorManager != null) {
    Sensor orientation=mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    if (orientation != null) {
      mSensorManager.registerListener(this,orientation,SensorManager.SENSOR_DELAY_GAME,null);
    }
  }
}
 

Example 43

From project roboguice, under directory /roboguice/src/main/java/roboguice/config/.

Source file: RoboModule.java

  19 
vote

/** 
 * Configure this module to define Android related bindings.<br /> <br /> If you want to provide your own bindings, you should <strong>NOT</strong> override this method, but rather create a  {@link Module} implementationand add it to the configuring modules by overriding {@link roboguice.application.RoboApplication#addApplicationModules(List)}.<br />
 */
@SuppressWarnings("unchecked") @Override protected void configure(){
  bindScope(ContextScoped.class,contextScope);
  bind(ContextScope.class).toInstance(contextScope);
  bind(Context.class).toProvider(throwingContextProvider).in(ContextScoped.class);
  bind(Activity.class).toProvider(ActivityProvider.class);
  bind(AssetManager.class).toProvider(AssetManagerProvider.class);
  bind(SharedPreferences.class).toProvider(SharedPreferencesProvider.class);
  bind(Resources.class).toProvider(ResourcesProvider.class);
  bind(ContentResolver.class).toProvider(ContentResolverProvider.class);
  bind(EventManager.class).toInstance(eventManager);
  for (Class<?> c=application.getClass(); c != null && Application.class.isAssignableFrom(c); c=c.getSuperclass())   bind((Class<Object>)c).toInstance(application);
  bind(LocationManager.class).toProvider(new SystemServiceProvider<LocationManager>(Context.LOCATION_SERVICE));
  bind(WindowManager.class).toProvider(new SystemServiceProvider<WindowManager>(Context.WINDOW_SERVICE));
  bind(LayoutInflater.class).toProvider(new SystemServiceProvider<LayoutInflater>(Context.LAYOUT_INFLATER_SERVICE));
  bind(ActivityManager.class).toProvider(new SystemServiceProvider<ActivityManager>(Context.ACTIVITY_SERVICE));
  bind(PowerManager.class).toProvider(new SystemServiceProvider<PowerManager>(Context.POWER_SERVICE));
  bind(AlarmManager.class).toProvider(new SystemServiceProvider<AlarmManager>(Context.ALARM_SERVICE));
  bind(NotificationManager.class).toProvider(new SystemServiceProvider<NotificationManager>(Context.NOTIFICATION_SERVICE));
  bind(KeyguardManager.class).toProvider(new SystemServiceProvider<KeyguardManager>(Context.KEYGUARD_SERVICE));
  bind(SearchManager.class).toProvider(new SystemServiceProvider<SearchManager>(Context.SEARCH_SERVICE));
  bind(Vibrator.class).toProvider(new SystemServiceProvider<Vibrator>(Context.VIBRATOR_SERVICE));
  bind(ConnectivityManager.class).toProvider(new SystemServiceProvider<ConnectivityManager>(Context.CONNECTIVITY_SERVICE));
  bind(WifiManager.class).toProvider(new SystemServiceProvider<WifiManager>(Context.WIFI_SERVICE));
  bind(InputMethodManager.class).toProvider(new SystemServiceProvider<InputMethodManager>(Context.INPUT_METHOD_SERVICE));
  bind(SensorManager.class).toProvider(new SystemServiceProvider<SensorManager>(Context.SENSOR_SERVICE));
  bind(TelephonyManager.class).toProvider(new SystemServiceProvider<TelephonyManager>(Context.TELEPHONY_SERVICE));
  bindListener(Matchers.any(),resourceListener);
  bindListener(Matchers.any(),extrasListener);
  bindListener(Matchers.any(),viewListener);
  if (preferenceListener != null)   bindListener(Matchers.any(),preferenceListener);
  if (eventManager.isEnabled())   bindListener(Matchers.any(),new ObservesTypeListener(contextProvider,eventManager));
  requestInjection(eventManager);
  requestStaticInjection(Ln.class);
  requestStaticInjection(RoboThread.class);
  requestStaticInjection(RoboAsyncTask.class);
}
 

Example 44

From project SASAbus, under directory /src/it/sasabz/android/sasabus/.

Source file: PointingLocationActivity.java

  19 
vote

/** 
 * Called with the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.pointer);
  Bundle extras=getIntent().getExtras();
  int palinanr=-1;
  if (extras != null) {
    palinanr=extras.getInt("palina");
  }
  if (palinanr == -1) {
    System.exit(-1);
  }
  palina=PalinaList.getById(palinanr);
  mlocManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
  mlocListener=new MyLocationListener();
  mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,60000,0,mlocListener);
  sensorService=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
  Sensor sensor=sensorService.getDefaultSensor(Sensor.TYPE_ORIENTATION);
  if (sensor != null) {
    mySensorEventListener=new MySensorEventListener();
    sensorService.registerListener(mySensorEventListener,sensor,SensorManager.SENSOR_DELAY_NORMAL);
    Log.v("Compass MainActivity","Registerered for ORIENTATION Sensor");
  }
 else {
    Log.v("Compass MainActivity","Registerered for ORIENTATION Sensor");
    Toast.makeText(this,R.string.sensor_off,Toast.LENGTH_LONG);
  }
}
 

Example 45

From project shoppinglist, under directory /ShoppingList/src/org/openintents/shopping/ui/.

Source file: ShoppingActivity.java

  19 
vote

private void registerSensor(){
  if (!mUseSensor) {
    return;
  }
  if (mItemsView.mMode == MODE_IN_SHOP) {
    if (mSensorManager == null) {
      mSensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
    }
    mSensorManager.registerListener(mMySensorListener,SensorManager.SENSOR_ACCELEROMETER,SensorManager.SENSOR_DELAY_UI);
  }
}
 

Example 46

From project TeamMeet, under directory /android/src/de/teammeet/service/.

Source file: TeamMeetService.java

  19 
vote

private void activateCompass(){
  Log.e(CLASS,"activateCompass()");
  mSensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
  List<Sensor> sensorList=mSensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
  for (Iterator<Sensor> sensors=sensorList.iterator(); sensors.hasNext(); ) {
    Sensor sensor=(Sensor)sensors.next();
    Log.e(CLASS,"Sensor: " + sensor.getName());
  }
  Sensor m_rotationVectorSensor=mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
  if (m_rotationVectorSensor != null) {
    mSensorManager.registerListener(mLocationListener,m_rotationVectorSensor,SensorManager.SENSOR_DELAY_NORMAL);
  }
 else {
    mTostSingleton.addLongToast("No ORIENTATION Sensor");
  }
}
 

Example 47

From project vanilla, under directory /src/org/kreed/vanilla/.

Source file: PlaybackService.java

  19 
vote

/** 
 * Setup the accelerometer.
 */
private void setupSensor(){
  if (mShakeAction == Action.Nothing || (mState & FLAG_PLAYING) == 0) {
    if (mSensorManager != null)     mSensorManager.unregisterListener(this);
  }
 else {
    if (mSensorManager == null)     mSensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
    mSensorManager.registerListener(this,mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR_DELAY_UI);
  }
}
 

Example 48

From project W3i-ReplicaIsland, under directory /src/com/w3i/replica/replicaisland/activities/.

Source file: AndouKun.java

  19 
vote

@Override protected void onResume(){
  super.onResume();
  SharedPreferences prefs=getSharedPreferences(PreferenceConstants.PREFERENCE_NAME,MODE_PRIVATE);
  final boolean debugLogs=prefs.getBoolean(PreferenceConstants.PREFERENCE_ENABLE_DEBUG,false);
  if (VERSION < 0 || debugLogs) {
    DebugLog.setDebugLogging(true);
  }
 else {
    DebugLog.setDebugLogging(false);
  }
  DebugLog.d("AndouKun","onResume");
  mGLSurfaceView.onResume();
  mGame.onResume(this,false);
  final boolean soundEnabled=prefs.getBoolean(PreferenceConstants.PREFERENCE_SOUND_ENABLED,true);
  final boolean safeMode=prefs.getBoolean(PreferenceConstants.PREFERENCE_SAFE_MODE,false);
  final boolean clickAttack=prefs.getBoolean(PreferenceConstants.PREFERENCE_CLICK_ATTACK,true);
  final boolean tiltControls=prefs.getBoolean(PreferenceConstants.PREFERENCE_TILT_CONTROLS,false);
  final int tiltSensitivity=prefs.getInt(PreferenceConstants.PREFERENCE_TILT_SENSITIVITY,50);
  final int movementSensitivity=prefs.getInt(PreferenceConstants.PREFERENCE_MOVEMENT_SENSITIVITY,100);
  final boolean onScreenControls=prefs.getBoolean(PreferenceConstants.PREFERENCE_SCREEN_CONTROLS,false);
  final int leftKey=prefs.getInt(PreferenceConstants.PREFERENCE_LEFT_KEY,KeyEvent.KEYCODE_DPAD_LEFT);
  final int rightKey=prefs.getInt(PreferenceConstants.PREFERENCE_RIGHT_KEY,KeyEvent.KEYCODE_DPAD_RIGHT);
  final int jumpKey=prefs.getInt(PreferenceConstants.PREFERENCE_JUMP_KEY,KeyEvent.KEYCODE_SPACE);
  final int attackKey=prefs.getInt(PreferenceConstants.PREFERENCE_ATTACK_KEY,KeyEvent.KEYCODE_SHIFT_LEFT);
  mGame.setSoundEnabled(soundEnabled);
  mGame.setControlOptions(clickAttack,tiltControls,tiltSensitivity,movementSensitivity,onScreenControls);
  mGame.setKeyConfig(leftKey,rightKey,jumpKey,attackKey);
  mGame.setSafeMode(safeMode);
  if (mSensorManager != null) {
    Sensor orientation=mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    if (orientation != null) {
      mSensorManager.registerListener(this,orientation,SensorManager.SENSOR_DELAY_GAME,null);
    }
  }
}
 

Example 49

From project Wake-Me-At, under directory /src/uk/co/spookypeanut/wake_me_at/.

Source file: Compass.java

  19 
vote

public Compass(Context context,AttributeSet attributeSet){
  super(context,attributeSet);
  LOG_NAME=(String)context.getText(R.string.app_name_nospaces);
  BROADCAST_UPDATE=(String)context.getText(R.string.serviceBroadcastName);
  Log.d(LOG_NAME,"Compass constructor");
  mContext=context;
  SurfaceHolder holder=getHolder();
  holder.addCallback(this);
  mSensorManager=(SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
  preparePaths();
  mCurrLoc=new Location("");
  mDestLoc=new Location("");
}
 

Example 50

From project wheelmap-android, under directory /wheelmap/wheelmap/src/main/java/org/wheelmap/android/fragment/.

Source file: POIsListFragment.java

  19 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  Log.d(TAG,"onCreate " + hashCode());
  setHasOptionsMenu(true);
  mSensorManager=(SensorManager)getActivity().getSystemService(Context.SENSOR_SERVICE);
  mSensor=mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
  mOrientationAvailable=mSensor != null;
}
 

Example 51

From project yammp, under directory /src/org/yammp/util/.

Source file: ShakeListener.java

  19 
vote

@Override public void onSensorChanged(SensorEvent event){
  mCurrentTimeStamp=event.timestamp / 1000 / 1000;
  float eventX=event.values[SensorManager.DATA_X], eventY=event.values[SensorManager.DATA_Y], eventZ=event.values[SensorManager.DATA_Z];
  if (mFirstSensorUpdate) {
    mLastX=eventX;
    mLastY=eventY;
    mLastZ=eventZ;
    mLastUpdateTime=mCurrentTimeStamp;
    mFirstDeltaUpdate=true;
    mFirstSensorUpdate=false;
    return;
  }
  float deltaX=eventX - mLastX, deltaY=eventY - mLastY, deltaZ=eventZ - mLastZ;
  mLastX=eventX;
  mLastY=eventY;
  mLastZ=eventZ;
  float deltaTimeForSpeed=mCurrentTimeStamp - mLastUpdateTime;
  mLastUpdateTime=mCurrentTimeStamp;
  if (mFirstDeltaUpdate) {
    mCurrentSpeed=FloatMath.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) / deltaTimeForSpeed;
    mFirstDeltaUpdate=false;
    return;
  }
  mLastSpeed=mCurrentSpeed;
  mCurrentSpeed=FloatMath.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) / deltaTimeForSpeed;
  float delta=Math.abs(mLastSpeed - mCurrentSpeed) / deltaTimeForSpeed * 1000 * 1000;
  if (delta > mShakeThreshold) {
    if (mCurrentTimeStamp > mLastShakeTimeStamp + mShakeInterval) {
      mLastShakeTimeStamp=mCurrentTimeStamp;
      notifyListeners();
    }
  }
}