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:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.InternalSensorService.java
@Override public void onCreate() { // The service is being created Log.e(TAG, "onCreate"); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (pref.getBoolean(getResources().getString(R.string.in_acc), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); }/* ww w. j av a 2 s . c o m*/ if (pref.getBoolean(getResources().getString(R.string.in_lig), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_pres), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_prox), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_mag), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_gyrs), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_grav), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_hum), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_lin_acc), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } if (pref.getBoolean(getResources().getString(R.string.in_tem), false)) { Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } }
From source file:main.MainActivity.java
@Override protected void onCreate(Bundle b) { getWindow().requestFeature(Window.FEATURE_ACTION_BAR); super.onCreate(b); setContentView(R.layout.activity_main); startService(new Intent(this, SensorListener.class)); initialStep = 0;//from ww w . j a v a 2 s .c om firstTime = true; sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); ButterKnife.inject(this); setSupportActionBar(toolbar); adapter = new MyPagerAdapter(getSupportFragmentManager()); pager.setAdapter(adapter); // tabs.setDistributeEvenly(true); tabs.setViewPager(pager); final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()); pager.setPageMargin(pageMargin); pager.setOffscreenPageLimit(3); pager.setCurrentItem(0); tabs.setBackgroundColor(getResources().getColor(R.color.green)); tabs.setIndicatorColor(R.color.tabsScrollColor); tabs.setTextColor(getResources().getColor(R.color.text_shadow_white)); // getSupportActionBar().setIcon(R.drawable.icon2); tabs.setIndicatorColorResource(R.color.tabsScrollColor); }
From source file:com.configurer.easyscreenlock.service.ForegroundSensorService.java
protected void registerListener() { mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); if (isSensorAvailable()) { sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); /**/*from w w w .j a v a2 s.c om*/ * Showing available sensor on Device * */ showAvailableSensors(); listener = new ProximitySensorEventListener(this); boolean isRegistered = mSensorManager.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_FASTEST); Log.i(TAG, "Registering listener : " + isRegistered); } else { Log.w(TAG, "Proximity Sensor not available, sorry :( "); } }
From source file:at.amartinz.hardware.sensors.BaseSensor.java
public BaseSensor(final Context context) { super(context, null); mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); mInflater = LayoutInflater.from(context); final View v = LayoutInflater.from(context).inflate(R.layout.hardware_card_with_container, this, false); super.addView(v); mCardView = (CardView) findViewById(R.id.card_view_root); if (sBackgroundColorGlobal != Integer.MIN_VALUE) { mCardView.setCardBackgroundColor(sBackgroundColorGlobal); }//from w w w .j a v a 2s . com final FrameLayout container = (FrameLayout) findViewById(R.id.layout_container); mInflater.inflate(R.layout.hardware_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:it.durip_app.SensorPlot.java
/** Called when the activity is first created. */ @Override/*from w w w. jav a 2 s. co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sensors); managerSensor = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE); textCharge = (TextView) findViewById(R.id.textvalueConsumption); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); // Set up the action bar. final ActionBar actionBar = getActionBar(); // Specify that the Home/Up button should not be enabled, since there is no hierarchical // parent. actionBar.setHomeButtonEnabled(true); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); managerSensor = (SensorManager) this.getSystemService(SENSOR_SERVICE); List<Sensor> list = managerSensor.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : list) { System.out.println("NAME " + sensor.getName()); } // For each of the sections in the app, add a tab to the action bar. for (int ii = 1; ii <= mAppSectionsPagerAdapter.getCount(); ii++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the // listener for when this tab is selected. actionBar.addTab( actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(ii)).setTabListener(this)); } // Show the Up button in the action bar. // System.out.println("OnCreate \n"); }
From source file:com.abajeli.wearable.gesturecadabra.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.jj_layout);//from ww w .j a v a2 s. c o m setupViews(); mHandler = new Handler(); mJumpCounter = Utils.getCounterFromPreference(this); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //renewTimer(); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY); }
From source file:com.kircherelectronics.fusedgyroscopeexplorer.sensor.MagneticSensor.java
/** * Initialize the state.//from w w w. jav a 2 s .c om * * @param context * the Activities context. */ public MagneticSensor(Context context) { super(); this.context = context; initQuaternionRotations(); observersMagnetic = new ArrayList<MagneticSensorObserver>(); sensorManager = (SensorManager) this.context.getSystemService(Context.SENSOR_SERVICE); }
From source file:com.kircherelectronics.fusedgyroscopeexplorer.sensor.GyroscopeSensor.java
/** * Initialize the state.// w w w.ja v a 2 s.c o m * * @param context * the Activities context. */ public GyroscopeSensor(Context context) { super(); this.context = context; initQuaternionRotations(); observersGyroscope = new ArrayList<GyroscopeSensorObserver>(); sensorManager = (SensorManager) this.context.getSystemService(Context.SENSOR_SERVICE); }
From source file:com.linkedin.android.shaky.Shaky.java
/** * Start listening for shakes. Should be called when the {@link Activity} is resumed. *//*from w ww . j a va 2 s. c om*/ private void start() { if (!delegate.isEnabled()) { return; } shakeDetector.start((SensorManager) activity.getSystemService(Context.SENSOR_SERVICE)); }
From source file:org.wso2.carbon.iot.android.sense.realtimeviewer.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);// w w w . j ava 2 s.c o m sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); listView = (ListView) findViewById(R.id.senseListContainer); registerReceiver(realTimeSensorChangeReceiver, new IntentFilter("sensorDataMap")); //Publish data FloatingActionButton 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(); DataPublisherReceiver dataPublisherReceiver = new DataPublisherReceiver(); dataPublisherReceiver.clearAbortBroadcast(); dataPublisherReceiver.onReceive(getApplicationContext(), null); } }); FloatingActionButton fbtnAddSensors = (FloatingActionButton) findViewById(R.id.addSensors); fbtnAddSensors.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sensorDialog.show(getFragmentManager(), "Sensor List"); } }); sharedPreferences = getSharedPreferences(SupportedSensors.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); }