List of usage examples for android.content Context SENSOR_SERVICE
String SENSOR_SERVICE
To view the source code for android.content Context SENSOR_SERVICE.
Click Source Link
From source file:root.gast.playground.sensor.altitude.DetermineAltitudeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.determine_altitude); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); gpsAltitudeView = (TextView) findViewById(R.id.gpsAltitude); gpsRelativeAltitude = (TextView) findViewById(R.id.gpsRelativeAltitude); barometerAltitudeView = (TextView) findViewById(R.id.barometerAltitude); barometerRelativeAltitude = (TextView) findViewById(R.id.barometerRelativeAltitude); mslpBarometerAltitudeView = (TextView) findViewById(R.id.mslpBarometerAltitude); mslpBarometerRelativeAltitude = (TextView) findViewById(R.id.mslpBarometerRelativeAltitude); mslpView = (TextView) findViewById(R.id.mslp); webServiceFetching = false;/* ww w . j a v a 2 s .c o m*/ TextView standardPressure = (TextView) findViewById(R.id.standardPressure); String standardPressureString = String.valueOf(SensorManager.PRESSURE_STANDARD_ATMOSPHERE); standardPressure.setText(standardPressureString); }
From source file:org.cocos2dx.lib.Cocos2dxAccelerometer.java
public Cocos2dxAccelerometer(Context context) { mContext = context;// w w w .java 2 s . c o m //Get an instance of the SensorManager mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); mNaturalOrientation = display.getOrientation(); }
From source file:com.kircherelectronics.gyroscopeexplorer.activity.filter.Orientation.java
public Orientation(Context context) { this.context = context; this.sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); initFilters();/*from ww w.j av a 2 s . c o m*/ }
From source file:com.achep.acdisplay.services.activemode.ActiveModeService.java
/** * Builds the array of supported {@link ActiveModeSensor sensors}. * * @return The array of supported {@link ActiveModeSensor sensors}. * @see ActiveModeSensor/* ww w. j a v a2 s . co m*/ */ @NonNull public static ActiveModeSensor[] buildAvailableSensorsList(@NonNull Context context) { SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); ActiveModeSensor[] sensors = new ActiveModeSensor[] { // all available sensors AccelerometerSensor.getInstance(), GyroscopeSensor.getInstance(), ProximitySensor.getInstance() }; // Count the number of supported sensors, and // mark unsupported. int count = sensors.length; boolean[] supportList = new boolean[sensors.length]; for (int i = 0; i < sensors.length; i++) { supportList[i] = sensors[i].isSupported(sensorManager); if (!supportList[i]) { count--; } } // Create the list of proven sensors. ActiveModeSensor[] sensorsSupported = new ActiveModeSensor[count]; for (int i = 0, j = 0; i < sensors.length; i++) { if (supportList[i]) { sensorsSupported[j++] = sensors[i]; } } return sensorsSupported; }
From source file:com.grumpysailor.cordova.magnetsensor.MagnetSensor.java
/** * Sets the context of the Command. This can then be used to do things like * get file paths associated with the Activity. * * @param cordova The context of the main Activity. * @param webView The associated CordovaWebView. *///from w w w . j ava 2s . c o m @Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.mSensorManager = (SensorManager) cordova.getActivity().getSystemService(Context.SENSOR_SERVICE); this.mSensorData = new ArrayList(); }
From source file:com.polyvi.xface.extension.XAccelerometerExt.java
/** * ?accelerometer sensor/*from w ww . j av a 2s.c o m*/ */ private void start() { if ((mStatus == RUNNING) || (mStatus == STARTING)) { return; } mStatus = STARTING; if (null == mSensorManager) { mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE); } List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); if ((list != null) && (list.size() > 0)) { mSensor = list.get(0); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_UI); } else { mStatus = ERROR_FAILED_TO_START; mCallbackCtx.error("No sensors found to register accelerometer listening to."); } // Wait until running long timeout = 2000; while ((this.mStatus == STARTING) && (timeout > 0)) { timeout = timeout - 100; try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } if (timeout == 0) { mStatus = ERROR_FAILED_TO_START; mCallbackCtx.error("Accelerometer could not be started."); } }
From source file:org.wso2.carbon.iot.android.sense.ActivitySelectSensor.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_activity_select_sensor); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w.j a v a 2 s . c o m*/ sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); listView = (ListView) findViewById(R.id.senseListContainer); registerReceiver(realTimeSensorChangeReceiver, new IntentFilter("sensorDataMap")); //Publish data fbtnPublishData = (FloatingActionButton) findViewById(R.id.publish); fbtnPublishData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Publishing data started", Snackbar.LENGTH_LONG).setAction("Action", null) .show(); check = true; DataUploaderReceiver dataUploaderReceiver = new DataUploaderReceiver(); dataUploaderReceiver.clearAbortBroadcast(); dataUploaderReceiver.onReceive(getApplicationContext(), null); } }); fbtnAddSensors = (FloatingActionButton) findViewById(R.id.addSensors); fbtnAddSensors.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sensorDialog.show(getFragmentManager(), "Sensor List"); } }); sharedPreferences = getSharedPreferences(SenseConstants.SELECTED_SENSORS, 0); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); }
From source file:org.y20k.trackbook.TrackerService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { // listen for finished save operation mTrackRequestReceiver = new BroadcastReceiver() { @Override// w w w. j a v a2s. c o m public void onReceive(Context context, Intent intent) { sendTrackUpdate(); } }; IntentFilter trackRequestReceiverIntentFilter = new IntentFilter(ACTION_TRACK_REQUEST); LocalBroadcastManager.getInstance(this).registerReceiver(mTrackRequestReceiver, trackRequestReceiverIntentFilter); // acquire reference to Location Manager mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // acquire reference to Sensor Manager mSensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE); // get state of location system setting mLocationSystemSetting = LocationHelper.checkLocationSystemSetting(getApplicationContext()); // create content observer for changes in System Settings mSettingsContentObserver = new SettingsContentObserver(new Handler()); // check if user did turn off location in device settings if (!mLocationSystemSetting) { LogHelper.v(LOG_TAG, "Location Setting is turned off."); Toast.makeText(getApplicationContext(), R.string.toast_message_location_offline, Toast.LENGTH_LONG) .show(); stopTracking(); return START_STICKY; } // checking for empty intent if (intent == null) { LogHelper.v(LOG_TAG, "Null-Intent received. Stopping self."); stopSelf(); } // ACTION START else if (intent.getAction().equals(ACTION_START) && mLocationSystemSetting) { startTracking(intent); } // ACTION STOP else if (intent.getAction().equals(ACTION_STOP) || !mLocationSystemSetting) { stopTracking(); // save changed state of Floating Action Button SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(this.getApplicationContext()); SharedPreferences.Editor editor = settings.edit(); editor.putInt(PREFS_FAB_STATE, FAB_STATE_SAVE); editor.apply(); } // START_STICKY is used for services that are explicitly started and stopped as needed return START_STICKY; }
From source file:com.mruddy.devdataviewer.SensorFragment.java
/** * @see android.support.v4.app.Fragment#onResume() *///from ww w .j av a 2 s . c o m @Override public void onResume() { super.onResume(); this.accelerometerTextView = (TextView) this.getActivity().findViewById(R.id.textViewAccelerometer); this.gpsTextView = (TextView) this.getActivity().findViewById(R.id.textViewGPS); this.sensorManager = (SensorManager) this.getActivity().getSystemService(Context.SENSOR_SERVICE); final Sensor accelerometerSensor = this.sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (null != accelerometerSensor) { this.accelerometerTextView.setText("waiting for data..."); this.sensorManager.registerListener(this, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL); } else { this.accelerometerTextView.setText("accelerometer not found"); } this.locationManager = (LocationManager) this.getActivity().getSystemService(Context.LOCATION_SERVICE); this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); }
From source file:se.toxbee.sleepfighter.challenge.shake.ShakeChallenge.java
@Override public void start(Activity activity, ChallengeResolvedParams params, Bundle state) { super.start(activity, params); this.activity().setContentView(R.layout.challenge_shake); // Get view references this.progressBar = (ProgressBar) this.activity().findViewById(R.id.progressBar); this.progressText = (TextView) this.activity().findViewById(R.id.progressText); // Check if required sensor is available boolean hasAccelerometer = activity.getPackageManager() .hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER); if (!hasAccelerometer) { // Complete right away, for now. Checking if device has required // hardware could perhaps be done before the challenge is started. Log.e(TAG, "Device lacks required sensor for ShakeChallenge"); this.complete(); return;/*from ww w . ja v a 2 s. c o m*/ } // Register to get acceleration events this.sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE); this.accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); // Get last progress from bundle, if it exists if (state != null) { this.progress = state.getFloat(KEY_PROGRESS_FLOAT); } updateProgress(); }