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:alaindc.crowdroid.SensorsIntentService.java
@Override protected void onHandleIntent(Intent intent) { if (intent != null) { final String action = intent.getAction(); if (action.equals(Constants.INTENT_START_SENSORS)) { // Init throughput taken SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean(Constants.THROUGHPUT_TAKEN, false); editor.commit();//from ww w .j a va 2 s . c o m // Configure sensors and eventlistener mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE); List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensorList) { if (Constants.isInMonitoredSensors(sensor.getType())) mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } // TODO STUB: Comment this in release for (int type : Constants.STUBBED_MONITORED_SENSORS) { stub_onSensorChanged(type); } } if (action.equals(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE)) { // Configure amplitude and start TEST amplitudeTask = new GetAmplitudeTask(this); amplitudeTask.getData(); } if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_AMBIENT_TEMPERATURE)) { stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1)); } if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_PRESSURE)) { stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1)); } if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_RELATIVE_HUMIDITY)) { stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1)); } if (action.equals(Constants.INTENT_RECEIVED_AMPLITUDE)) { double amplitude = intent.getDoubleExtra(Constants.EXTRA_AMPLITUDE, -1); if (amplitude > 0) { SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString(Constants.PREF_SENSOR_ + Constants.TYPE_AMPLITUDE, Double.toString(amplitude)); editor.commit(); // Update view Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS); senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA, "Sensor " + Constants.getNameOfSensor(Constants.TYPE_AMPLITUDE) + " value: " + Double.toString(amplitude)); LocalBroadcastManager.getInstance(this).sendBroadcast(senseintent); } int index = Constants.getIndexAlarmForSensor(Constants.TYPE_AMPLITUDE); // Set the alarms for next sensing of amplitude alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); Intent intentAlarm = new Intent(getApplicationContext(), SensorsIntentService.class); intentAlarm.setAction(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE); alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0); // TIMEOUT for another monitoring of audio int seconds = 30; // TODO: De-hardcode this alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000, alarmIntent); } } }
From source file:com.android.plugins.GyroscopeListener.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 www. j ava 2s .c om @Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.sensorManager = (SensorManager) cordova.getActivity().getSystemService(Context.SENSOR_SERVICE); }
From source file:jp.co.recruit_lifestyle.android.widget.BeerSwipeRefreshLayout.java
public BeerSwipeRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setWillNotDraw(false);/*from ww w . java 2 s .co m*/ ViewCompat.setChildrenDrawingOrderEnabled(this, true); addView(mBeerView = new BeerView(context)); mBeerView.setVisibility(GONE); mBeerView.setAlpha(0.f); mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE); mRotationVectorSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); }
From source file:org.zywx.wbpalmstar.plugin.uexaudio.EUExAudio.java
public static void onActivityReStart(Context context) { BDebug.i(tag, "onActivityReStart"); if (sensorEventListener != null) { SensorManager mSensorManager = (SensorManager) context.getApplicationContext() .getSystemService(Context.SENSOR_SERVICE); Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mSensorManager.registerListener(sensorEventListener, mSensor, SensorManager.SENSOR_DELAY_NORMAL); }/*from w w w. ja v a2s . c o m*/ }
From source file:ch.bfh.sensordataprocessor.sensor.SensorDisplayFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.sensor_view, null); sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); name = (TextView) layout.findViewById(R.id.name); type = (TextView) layout.findViewById(R.id.type); maxRange = (TextView) layout.findViewById(R.id.maxRange); minDelay = (TextView) layout.findViewById(R.id.minDelay); power = (TextView) layout.findViewById(R.id.power); resolution = (TextView) layout.findViewById(R.id.resolution); vendor = (TextView) layout.findViewById(R.id.vendor); version = (TextView) layout.findViewById(R.id.version); accuracy = (TextView) layout.findViewById(R.id.accuracy); timestampLabel = (TextView) layout.findViewById(R.id.timestampLabel); timestamp = (TextView) layout.findViewById(R.id.timestamp); timestampUnits = (TextView) layout.findViewById(R.id.timestampUnits); dataLabel = (TextView) layout.findViewById(R.id.dataLabel); dataUnits = (TextView) layout.findViewById(R.id.dataUnits); xAxis = (TextView) layout.findViewById(R.id.xAxis); xAxisLabel = (TextView) layout.findViewById(R.id.xAxisLabel); yAxis = (TextView) layout.findViewById(R.id.yAxis); yAxisLabel = (TextView) layout.findViewById(R.id.yAxisLabel); zAxis = (TextView) layout.findViewById(R.id.zAxis); zAxisLabel = (TextView) layout.findViewById(R.id.zAxisLabel); singleValue = (TextView) layout.findViewById(R.id.singleValue); cosLabel = (TextView) layout.findViewById(R.id.cosLabel); cos = (TextView) layout.findViewById(R.id.cos); layout.findViewById(R.id.delayFastest).setOnClickListener(new OnClickListener() { @Override//w w w . j a v a 2 s. c o m public void onClick(View v) { sensorManager.unregisterListener(SensorDisplayFragment.this); sensorManager.registerListener(SensorDisplayFragment.this, sensor, SensorManager.SENSOR_DELAY_FASTEST); } }); layout.findViewById(R.id.delayGame).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { sensorManager.unregisterListener(SensorDisplayFragment.this); sensorManager.registerListener(SensorDisplayFragment.this, sensor, SensorManager.SENSOR_DELAY_GAME); } }); layout.findViewById(R.id.delayNormal).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { sensorManager.unregisterListener(SensorDisplayFragment.this); sensorManager.registerListener(SensorDisplayFragment.this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } }); layout.findViewById(R.id.delayUi).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { sensorManager.unregisterListener(SensorDisplayFragment.this); sensorManager.registerListener(SensorDisplayFragment.this, sensor, SensorManager.SENSOR_DELAY_UI); } }); return layout; }
From source file:it.flaviomascetti.posture.AccuracyTestFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sp = getActivity().getSharedPreferences("saved_preferences", Context.MODE_PRIVATE); sensorManager = (SensorManager) getActivity().getApplicationContext() .getSystemService(Context.SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); }
From source file:org.namelessrom.devicecontrol.modules.device.sensors.BaseSensor.java
public BaseSensor(final Context context) { super(context, null); mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); mInflater = LayoutInflater.from(context); View v = LayoutInflater.from(context).inflate(R.layout.card_with_container, this, false); CardView cardView = (CardView) v.findViewById(R.id.card_view_root); cardView.setCardBackgroundColor(AppResources.get().getCardBackgroundColor()); super.addView(v); final FrameLayout container = (FrameLayout) findViewById(R.id.layout_container); mInflater.inflate(R.layout.item_sensor, container, true); mIcon = (ImageView) findViewById(R.id.sensor_icon); mIcon.setImageDrawable(getSensorImage()); mTitle = (TextView) findViewById(R.id.sensor_label); mName = (TextView) findViewById(R.id.sensor_name); mVendor = (TextView) findViewById(R.id.sensor_vendor); mPowerUsage = (TextView) findViewById(R.id.sensor_power_usage); mDataContainer = (LinearLayout) findViewById(R.id.sensor_data_container); }
From source file:com.sorin.cloudcog.phone.batterymeter.BatteryInfoActivity.java
@Override public void onCreate(Bundle savedInstanceState) { startMillis = System.currentTimeMillis(); context = getApplicationContext();// ww w.j av a2 s.c o m res = getResources(); str = new Str(res); loadSettingsFiles(); super.onCreate(savedInstanceState); // Recreates Fragments, so only call // after doing necessary setup setContentView(R.layout.battery_info); pagerAdapter = new BatteryInfoPagerAdapter(getSupportFragmentManager()); viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(pagerAdapter); viewPager.setCurrentItem(1); PagerTabStrip tabStrip = (PagerTabStrip) findViewById(R.id.pager_tab_strip); tabStrip.setTabIndicatorColor(0x33b5e5); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mShakeDetector = new ShakeDetectorActivity(); mShakeDetector.setOnShakeListener(new OnShakeListener() { @Override public void onShake(int count) { BatteryInfoActivity.this.finish(); } }); // ShakeDetector method end }
From source file:org.skt.runtime.html5apis.Accelerometer.java
/** * Sets the context of the Command. This can then be used to do things like * get file paths associated with the Activity. * // ww w . jav a 2s.c om * @param ctx The context of the main Activity. */ public void setContext(RuntimeInterface ctx) { super.setContext(ctx); this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE); }
From source file:org.wso2.carbon.iot.android.sense.event.streams.speed.SpeedDataReader.java
public SpeedDataReader(Context context) { ctx = context;/*from w w w . j a va 2s. c o m*/ SharedPreferences sharedPreferences = ctx.getSharedPreferences(SupportedSensors.SELECTED_SENSORS, Context.MODE_MULTI_PROCESS); Set<String> selectedSet = sharedPreferences.getStringSet(SupportedSensors.SELECTED_SENSORS_BY_USER, null); mSensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE); selectedSensorList(selectedSet); for (Sensor sensor : sensorList) { mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } LocalBroadcastManager.getInstance(ctx).registerReceiver(mMessageReceiver, new IntentFilter("speedUpdate")); }