List of usage examples for android.hardware Sensor TYPE_ACCELEROMETER
int TYPE_ACCELEROMETER
To view the source code for android.hardware Sensor TYPE_ACCELEROMETER.
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); }//from w ww . j a v a 2 s . c om 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:org.sociotech.fishification.ui.fragments.FeedFishFragment.java
@Override public void onResume() { super.onResume(); // Register for Sensor changes if (m_sensorManager != null) { m_sensorManager.registerListener(this, m_sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); }//from w w w .j a v a 2s. c o m }
From source file:com.tritop.androsense2.fragments.GpsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); mSensorManager = ((AndrosensApp) getActivity().getApplication()).getSensorManager(); defaultAccel = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); defaultMag = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mGpsListAdapter = new SimpleAdapter(getActivity(), itemListGps, R.layout.gpsfragment_sat_item, boundRows, boundViews);// ww w .java 2s. c o m mGlonassListAdapter = new SimpleAdapter(getActivity(), itemListGlonass, R.layout.gpsfragment_sat_item, boundRows, boundViews); setupViewBinders(mGpsListAdapter, R.drawable.shape_satitem_background_nofix, R.drawable.shape_satitem_background_fix); setupViewBinders(mGlonassListAdapter, R.drawable.shape_satitem_background_glonass_nofix, R.drawable.shape_satitem_background_glonass_fix); display = getActivity().getWindowManager().getDefaultDisplay(); return inflater.inflate(R.layout.gpsfragment_layout, container, false); }
From source file:com.kircherelectronics.androidlinearacceleration.sensor.AccelerationSensor.java
/** * Register for Sensor.TYPE_ACCELEROMETER measurements. * /*from ww w. j ava2s. c om*/ * @param observer * The observer to be registered. */ public void registerAccelerationObserver(AccelerationSensorObserver observer) { // If there are currently no observers, but one has just requested to be // registered, register to listen for sensor events from the device. if (observersAcceleration.size() == 0) { sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST); } // Only register the observer if it is not already registered. int i = observersAcceleration.indexOf(observer); if (i == -1) { observersAcceleration.add(observer); } }
From source file:com.fallahpoor.infocenter.fragments.SensorsFragment.java
@TargetApi(Build.VERSION_CODES.KITKAT) public ArrayList<String> getSubItemsArrayList() { HashMap<Integer, String> sensorsHashMap = new HashMap<>(); ArrayList<String> subItems = new ArrayList<>(); Iterator<Integer> iterator; String supported = getString(R.string.supported); String unsupported = getString(R.string.unsupported); ArrayList<Integer> sensorTypes = new ArrayList<>(Arrays.asList(new Integer[] { Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_AMBIENT_TEMPERATURE, Sensor.TYPE_GRAVITY, Sensor.TYPE_GYROSCOPE, Sensor.TYPE_LIGHT, Sensor.TYPE_LINEAR_ACCELERATION, Sensor.TYPE_MAGNETIC_FIELD, Sensor.TYPE_PRESSURE, Sensor.TYPE_PROXIMITY, Sensor.TYPE_RELATIVE_HUMIDITY, Sensor.TYPE_ROTATION_VECTOR })); if (mIsApiAtLeast18) { sensorTypes.add(Sensor.TYPE_GAME_ROTATION_VECTOR); sensorTypes.add(Sensor.TYPE_SIGNIFICANT_MOTION); }/*w w w.ja va 2 s . com*/ if (mIsApiAtLeast19) { sensorTypes.add(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR); sensorTypes.add(Sensor.TYPE_STEP_COUNTER); sensorTypes.add(Sensor.TYPE_STEP_DETECTOR); } SensorManager sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); // Get the list of all available sensors of the device List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); iterator = sensorTypes.iterator(); // Assume all sensor types are unsupported while (iterator.hasNext()) { sensorsHashMap.put(iterator.next(), unsupported); } /* * For each sensor type that is in sensors change its status from * "unsupported" to "supported". */ for (Sensor sensor : sensors) { sensorsHashMap.put(sensor.getType(), supported); } iterator = sensorTypes.iterator(); while (iterator.hasNext()) { subItems.add(sensorsHashMap.get(iterator.next())); } return subItems; }
From source file:com.mruddy.devdataviewer.SensorFragment.java
/** * @see android.hardware.SensorEventListener#onSensorChanged(android.hardware.SensorEvent) *///from w ww .j a va 2 s . c om @Override public void onSensorChanged(final SensorEvent event) { if (Sensor.TYPE_ACCELEROMETER == event.sensor.getType()) { this.accelerometerTextView.setText(event.values[0] + "\n" + event.values[1] + "\n" + event.values[2]); } }
From source file:com.example.zoeoeh.ETuner.OpenGLClass.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment // Replaces setContentView - set the content to the XML activity containing the custom surface view View myView = inflater.inflate(R.layout.activity_open_glclass, container, false); // myGLview is my custom GL surface which sets the client version and initialises the renderer myGLview = (MyGLSurface) myView.findViewById(R.id.surfaceView); // switch handler for change events. controls looping of sound playing loopSwitch = (Switch) myView.findViewById(R.id.loopSwitch); loopSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override//from w w w . j a v a 2 s. c o m public void onCheckedChanged(CompoundButton btn, boolean isChecked) { // bool used for setting looping state of media player loopingChecked = isChecked; updatePlay(); } }); playSwitch = (Switch) myView.findViewById(R.id.playSwitch); playSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton btn, boolean isChecked) { playChecked = isChecked; if (isChecked) { playSound(TabSwitcher.getmContext(), currentSoundIndex); } else { // if unchecked and player isn't null stop it. if (myPlayer != null) { stopPlay(); // stop vibrating of string TestRenderer.setChosenString(-1); } } } }); // initialise sensor listener mySensorMan = (SensorManager) TabSwitcher.getmContext().getSystemService(Context.SENSOR_SERVICE); myAccel = mySensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mySensorMan.registerListener(this, myAccel, SensorManager.SENSOR_DELAY_NORMAL); // return this view return myView; }
From source file:org.loon.framework.android.game.LGameAndroid2DActivity.java
private void initSensors() { try {/* w w w .j a va 2 s .c o m*/ if (sensorManager == null) { sensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE); } if (sensorAccelerometer == null) { sensorAccelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); } if (sensorMagnetic == null) { sensorMagnetic = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); } boolean accelSupported = sensorManager.registerListener(this, sensorAccelerometer, SensorManager.SENSOR_DELAY_GAME); // ??Accelerometer?? if (!accelSupported) { sensorManager.unregisterListener(this, sensorAccelerometer); } this.sensorManager.registerListener(this, sensorMagnetic, SensorManager.SENSOR_DELAY_GAME); } catch (Exception ex) { } }
From source file:itcr.gitsnes.MainActivity.java
/** * OnCreate methods do that things://from ww w . j a v a 2 s.c om * - Inflate Login formulary frame (hide action bar) * - Init Accelerometer intent (onShake) * - Create login method (auth with FB) * - Handle exceptions of previously methods */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* -- Shows action bar and inflate main Listview from JSON (see BackendHandler) --- */ getActionBar().hide(); setContentView(R.layout.activity_main); FragmentManager fm = getFragmentManager(); FragmentTransaction transaction = fm.beginTransaction(); /* Add transaction and login FB intent to mainActivity*/ Login login = new Login(); transaction.add(R.id.placeholder, login).commit(); /* Init shake sensor and create event to get random game from DB (Backend on app-engine)*/ mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mShakeDetector = new ShakeDetector(); mShakeDetector.setOnShakeListener(new ShakeDetector.OnShakeListener() { @Override public void onShake(int count) { /* Inflate random-game detail */ Toast.makeText(getApplicationContext(), "Buscando juego aleatorio!!", Toast.LENGTH_SHORT).show(); MasterGames new_fragment = new MasterGames(json_arr); new_fragment.setRandomgame("random"); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.placeholder, new_fragment); transaction.addToBackStack(null); transaction.commit(); } }); mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI); /*Initialize FB API helper methods and listen callback from fb_loginbutton*/ uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); authButton = (LoginButton) findViewById(R.id.authButton); authButton.setOnErrorListener(new LoginButton.OnErrorListener() { @Override public void onError(FacebookException error) { Log.i(TAG, "Error " + error.getMessage()); } }); /*Obtaining data from successfully FB API callback using GraphUser*/ authButton.setReadPermissions(Arrays.asList("email")); authButton.setSessionStatusCallback(new Session.StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { Log.i(TAG, "Accesssss Token"); if (session.isOpened()) { Log.i(TAG, "Access Token" + session.getAccessToken()); Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { Log.i(TAG, "User ID " + user.getId()); Log.i(TAG, "Email " + user.asMap().get("email")); /* Inflate main-Listview from JSON (see BackendHandler) and saving current user*/ back_stage(); getActionBar().show(); KS.setCurrent_user(user.asMap().get("email").toString()); Toast.makeText(getApplicationContext(), "Welcome!! " + KS.getCurrent_user(), Toast.LENGTH_SHORT).show(); new BackendHandler().sendUser(KS.getCurrent_user(), user.asMap().get("email").toString()); //lblEmail.setText(user.asMap().get("email").toString()); } } }); } else Log.i(TAG, "Nopes Token"); } }); }
From source file:com.example.android.networkconnect.BureauFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Before initializing the textView, check if any arguments were provided via setArguments. mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); // List of Sensors Available List<Sensor> msensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMagneticField = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); //mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY); //mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); //mLinearAcceleration = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION); //mRotationVector = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); //mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); // float m_result[]=mSensorManager.getOrientation(m_rotationMatrix,m_orientation); //Log.i(TAG,"azimuth: "+m_result[0]); //Log.i(TAG,"pith: "+m_result[1]); //Log.i(TAG,"roll_angle: "+m_result[2]); //mMagneticField = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); //mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); //mPressure = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); //mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); for (int k = 0; k < msensorList.size(); k++) { Log.i(TAG, "Sensor: " + msensorList.get(k).getName()); }//w ww .jav a 2 s .c o m //Log.i (TAG, "Sensor CreateView String: "+mOrientation.getStringType()); //Log.i (TAG, "azimuth_angle: "+event.values[0]); //Log.i (TAG, "pitch_angle: "+event.values[1]); //Log.i (TAG, "roll_angle: "+event.values[2]) processArguments(); fa = super.getActivity(); View layout = inflater.inflate(R.layout.bureaulayout, container, false); // final ImageButton mImageButton= (ImageButton) layout.findViewById(R.id.lauchscan); // mImageButton.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Toast toast3 = Toast.makeText(getActivity(), "click", Toast.LENGTH_LONG); // toast3.show(); //SimpleTextFragment bureauFragment = (SimpleTextFragment) getFragmentManager().findFragmentById(R.id.bureau_fragment); // this.showFragment(); // } // }); if (mText != null) { mTextView.setText(mText); Log.i("SimpleTextFragment", mText); } //return inflater.inflate(R.layout.bureaulayout,container,false); //return mDrawableView; return layout; }