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:net.openfiretechnologies.veloxcontrol.fragments.ActiveDisplaySettings.java
private boolean hasProximitySensor() { SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); return sm.getDefaultSensor(TYPE_PROXIMITY) != null; }
From source file:net.openfiretechnologies.veloxcontrol.fragments.ActiveDisplaySettings.java
private boolean hasLightSensor() { SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); return sm.getDefaultSensor(TYPE_LIGHT) != null; }
From source file:ngoc.com.pedometer.ui.Fragment_Overview.java
@Override public void onResume() { super.onResume(); // getActivity().getActionBar().setDisplayHomeAsUpEnabled(false); Database db = Database.getInstance(getActivity()); if (BuildConfig.DEBUG) db.logState();/* w w w .ja v a 2s . c o m*/ // read todays offset todayOffset = db.getSteps(Util.getToday()); SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_PRIVATE); goal = prefs.getInt("goal", Fragment_Settings.DEFAULT_GOAL); since_boot = db.getCurrentSteps(); // do not use the value from the sharedPreferences int pauseDifference = since_boot - prefs.getInt("pauseCount", since_boot); // register a sensorlistener to live update the UI if a step is taken if (!prefs.contains("pauseCount")) { SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); Sensor sensor = sm.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); if (sensor == null) { new AlertDialog.Builder(getActivity()).setTitle(R.string.no_sensor) .setMessage(R.string.no_sensor_explain) .setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(final DialogInterface dialogInterface) { getActivity().finish(); } }).setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).create().show(); } else { sm.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI, 0); } } since_boot -= pauseDifference; total_start = db.getTotalWithoutToday(); total_days = db.getDays(); db.close(); stepsDistanceChanged(); }
From source file:edu.missouri.bas.service.SensorService.java
@SuppressWarnings("deprecation") @Override/*from www.ja v a 2 s .c o m*/ public void onCreate() { super.onCreate(); Log.d(TAG, "Starting sensor service"); mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100); soundsMap = new HashMap<Integer, Integer>(); soundsMap.put(SOUND1, mSoundPool.load(this, R.raw.bodysensor_alarm, 1)); soundsMap.put(SOUND2, mSoundPool.load(this, R.raw.voice_notification, 1)); serviceContext = this; mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothMacAddress = mBluetoothAdapter.getAddress(); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); //Get location manager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); activityRecognition = new ActivityRecognitionScan(getApplicationContext()); activityRecognition.startActivityRecognitionScan(); mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); serviceWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SensorServiceLock"); serviceWakeLock.acquire(); //Initialize start time stime = System.currentTimeMillis(); //Setup calendar object Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(stime); /* * Setup notification manager */ notification = new Notification(R.drawable.icon2, "Recorded", System.currentTimeMillis()); notification.defaults = 0; notification.flags |= Notification.FLAG_ONGOING_EVENT; notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent notifyIntent = new Intent(Intent.ACTION_MAIN); notifyIntent.setClass(this, MainActivity.class); /* * Display notification that service has started */ notification.tickerText = "Sensor Service Running"; PendingIntent contentIntent = PendingIntent.getActivity(SensorService.this, 0, notifyIntent, Notification.FLAG_ONGOING_EVENT); notification.setLatestEventInfo(SensorService.this, getString(R.string.app_name), "Recording service started at: " + cal.getTime().toString(), contentIntent); notificationManager.notify(SensorService.SERVICE_NOTIFICATION_ID, notification); // locationControl = new LocationControl(this, mLocationManager, 1000 * 60, 200, 5000); IntentFilter activityResultFilter = new IntentFilter(XMLSurveyActivity.INTENT_ACTION_SURVEY_RESULTS); SensorService.this.registerReceiver(alarmReceiver, activityResultFilter); IntentFilter sensorDataFilter = new IntentFilter(SensorService.ACTION_SENSOR_DATA); SensorService.this.registerReceiver(alarmReceiver, sensorDataFilter); Log.d(TAG, "Sensor service created."); try { prepareIO(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } prepareAlarms(); Intent startSensors = new Intent(SensorService.ACTION_START_SENSORS); this.sendBroadcast(startSensors); Intent scheduleCheckConnection = new Intent(SensorService.ACTION_SCHEDULE_CHECK); scheduleCheck = PendingIntent.getBroadcast(serviceContext, 0, scheduleCheckConnection, 0); mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000 * 60 * 5, 1000 * 60 * 5, scheduleCheck); mLocationClient = new LocationClient(this, this, this); }
From source file:it.flaviomascetti.posture.PostureCheckFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); }
From source file:org.wheelmap.android.fragment.POIDetailFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);/* ww w. j a v a 2 s . co m*/ mWSAttributes = SupportManager.wsAttributes; mWheelchairToiletAttributes = SupportManager.wheelchairToiletAttributes; poiId = getArguments().getLong(Extra.POI_ID, Extra.ID_UNKNOWN); if (!UtilsMisc.isTablet(getActivity().getApplication())) { tileUrl = String.format(Locale.US, baseUrl, BuildConfig.MAPBOX_API_KEY); mMapBoxTileSource = new XYTileSource("Mapbox", 3, 21, 256, ".png", new String[] { tileUrl }); EventBus bus = EventBus.getDefault(); mMyLocationProvider.register(); mVerticalDelta = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) VERTICAL_DELTA, getResources().getDisplayMetrics()); MyLocationManager.LocationEvent event = (MyLocationManager.LocationEvent) bus .getStickyEvent(MyLocationManager.LocationEvent.class); Location location = event.location; mMyLocationProvider.updateLocation(location); mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); } }
From source file:net.sourceforge.fidocadj.FidoMain.java
/** * Activate the sensors (gyroscope) which will then be used for actions such * as rotating and mirroring components. */// w w w . j av a 2 s .c om public void activateSensors() { mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); }
From source file:tv.piratemedia.flightcontroller.BluetoothComputerFragment.java
public void setupAtimiter() { SensorManager mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); List<Sensor> sensors = mSensorManager.getSensorList(Sensor.TYPE_PRESSURE); SensorEventListener sensorListener = new SensorEventListener() { @Override/*from w w w. j a v a 2s . c o m*/ public void onSensorChanged(SensorEvent event) { if (currentPreasure > event.values[0] - 0.5 || currentPreasure < event.values[0] + 0.5) { currentPreasure = event.values[0]; currentAltitude = SensorManager.getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, currentPreasure); JSONObject msg = new JSONObject(); try { msg.put("action", "altitude_update"); msg.put("value", currentAltitude); } catch (JSONException e) { e.printStackTrace(); } sendTextMessage(msg.toString()); } } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } }; if (sensors.size() > 0) { sensor = sensors.get(0); mSensorManager.registerListener(sensorListener, sensor, SensorManager.SENSOR_DELAY_NORMAL); } else { } }
From source file:io.authme.sdk.widget.LockPatternView.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public LockPatternView(Context context, AttributeSet attrs) { super(context, attrs); senSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); senAccelerometer = senSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY); if (senAccelerometer == null) { senAccelerometer = senSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); }/*from w ww . j a v a2s . c o m*/ senSensorManager.registerListener(this, senAccelerometer, SensorManager.SENSOR_DELAY_GAME); sensGyro = senSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); if (sensGyro != null) { senSensorManager.registerListener(this, sensGyro, SensorManager.SENSOR_DELAY_GAME); } senMagnetometer = senSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); if (senMagnetometer != null) { senSensorManager.registerListener(this, senMagnetometer, SensorManager.SENSOR_DELAY_GAME); } accelList = new ArrayList<>(); magnetics = new ArrayList<>(); gyrolist = new ArrayList<>(); rawXYList = new ArrayList<>(); velocityList = new ArrayList<>(); orientationArrayList = new ArrayList<>(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Alp_42447968_LockPatternView); final String aspect = a.getString(R.styleable.Alp_42447968_LockPatternView_alp_42447968_aspect); if ("square".equals(aspect)) { mAspect = ASPECT_SQUARE; } else if ("lock_width".equals(aspect)) { mAspect = ASPECT_LOCK_WIDTH; } else if ("lock_height".equals(aspect)) { mAspect = ASPECT_LOCK_HEIGHT; } else { mAspect = ASPECT_SQUARE; } setClickable(true); mPathPaint.setAntiAlias(true); mPathPaint.setDither(true); mRegularColor = getResources().getColor( ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_regular)); mErrorColor = getResources().getColor( ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_error)); mSuccessColor = getResources().getColor( ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_success)); mRegularColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_regularColor, mRegularColor); mErrorColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_errorColor, mErrorColor); mSuccessColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_successColor, mSuccessColor); int pathColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_pathColor, mRegularColor); mPathPaint.setColor(pathColor); mPathPaint.setStyle(Paint.Style.STROKE); mPathPaint.setStrokeJoin(Paint.Join.ROUND); mPathPaint.setStrokeCap(Paint.Cap.ROUND); mPathWidth = getResources().getDimensionPixelSize(R.dimen.alp_42447968_lock_pattern_dot_line_width); mPathPaint.setStrokeWidth(mPathWidth); mDotSize = getResources().getDimensionPixelSize(R.dimen.alp_42447968_lock_pattern_dot_size); mDotSizeActivated = getResources() .getDimensionPixelSize(R.dimen.alp_42447968_lock_pattern_dot_size_activated); mPaint.setAntiAlias(true); mPaint.setDither(true); mCellStates = new CellState[MATRIX_WIDTH][MATRIX_WIDTH]; for (int i = 0; i < MATRIX_WIDTH; i++) { for (int j = 0; j < MATRIX_WIDTH; j++) { mCellStates[i][j] = new CellState(); mCellStates[i][j].size = mDotSize; } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !isInEditMode()) { mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, android.R.interpolator.fast_out_slow_in); mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, android.R.interpolator.linear_out_slow_in); } // if }
From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DataSource.createIcons(getResources()); try {//from w w w .ja v a 2s.com // ?? final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // ? ?? ? this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag"); // ?? locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // ?? . 2 ?? (1/1000s), 3 ?? (m)? ? locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 3, this); //orientation sensor sensorMgr_ori = (SensorManager) getSystemService(Context.SENSOR_SERVICE); orientationSensor = sensorMgr_ori.getDefaultSensor(Sensor.TYPE_ORIENTATION); killOnError(); // ? ? requestWindowFeature(Window.FEATURE_NO_TITLE); // ? ? // ?? FrameLayout frameLayout = new FrameLayout(this); // ? ?, ? frameLayout.setMinimumWidth(3000); frameLayout.setPadding(10, 0, 10, 10); // ? ? ? ?? ? camScreen = new CameraSurface(this); augScreen = new AugmentedView(this); setContentView(camScreen); // ? ?? ? ? // ? ?? ? addContentView(augScreen, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); // ? ? ? ? ?. // ? ? ? ?? ? ? ? addContentView(frameLayout, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM)); topLayoutOnMixView = new TopLayoutOnMixView(this); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); addContentView(topLayoutOnMixView.mainArView, params); // ? ? ? topLayoutOnMixView ? ? handleIntent(getIntent()); // ?? // ? ? ? if (!isInited) { mixContext = new MixContext(this); // ? ? // ? ? mixContext.downloadManager = new DownloadManager(mixContext); //? ? ? navigator = new Navigator(mixContext, topLayoutOnMixView.naverFragment); // ? ? ?? ? ? dWindow = new PaintScreen(); dataView = new DataView(mixContext); isInited = true; // true } if (mixContext.isActualLocation() == false) { Toast.makeText(this, getString(DataView.CONNECTION_GPS_DIALOG_TEXT), Toast.LENGTH_LONG).show(); } } catch (Exception ex) { doError(ex); // ? ? } // ? IntentFilter naviBraodFilter = new IntentFilter(); naviBraodFilter.addAction("NAVI"); registerReceiver(naviRecevicer, naviBraodFilter); }