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:com.polyvi.xface.extension.XCompassExt.java
/** * ?compass sensor/*from ww w.j a v a2 s . c om*/ */ private int start() { if ((mStatus == RUNNING) || (mStatus == STARTING)) { return mStatus; } //FIXME:SENSOR_SERVICE?hang? // ? if (null == mSensorManager) { mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE); } List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_ORIENTATION); if (list != null && list.size() > 0) { mSensor = list.get(0); mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); mLastAccessTime = System.currentTimeMillis(); mStatus = STARTING; } else { mStatus = ERROR_FAILED_TO_START; } return mStatus; }
From source file:de.tubs.ibr.dtn.dtalkie.TalkieActivity.java
@Override protected void onPause() { SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sm.unregisterListener(mSensorListener); super.onPause(); }
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// w w w.jav a 2s . 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:com.nextgis.mobile.forms.CameraFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRetainInstance(true);/*from w w w . jav a2s . c o m*/ View view = inflater.inflate(R.layout.camfragment, container, false); Button button = (Button) view.findViewById(R.id.insert_take_photo); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onCapturePhoto(); } }); ListView photoList = (ListView) view.findViewById(R.id.poi_photos_list); adapter = new SimpleAdapter(view.getContext(), listItems, R.layout.row, new String[] { IMG_NAME, IMG_ROT, }, new int[] { R.id.image_name, R.id.image_rotation }); photoList.setAdapter(adapter); final LocationManager locationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); if (currentLocation == null) { currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (currentLocation == null) { currentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } } long now = System.currentTimeMillis(); declination = CompassFragment.getDeclination(currentLocation, now); sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); return view; }
From source file:de.da_sense.moses.client.abstraction.HardwareAbstraction.java
/** * Get all available sensors from the operating system. * /*from w w w.j a v a 2 s . c o m*/ * @return All available sensors on this device */ public static List<Sensor> getSensors() { if (MosesService.getInstance() != null) { List<Sensor> sensors = new ArrayList<Sensor>(); SensorManager s = (SensorManager) MosesService.getInstance().getSystemService(Context.SENSOR_SERVICE); for (Sensor sen : s.getSensorList(Sensor.TYPE_ALL)) sensors.add(sen); return sensors; } else { return null; } }
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. ja v a2s . 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; }
From source file:com.example.yihongxu.weightliftingcounter.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.rs_layout);//from w ww .j a va 2 s . c om setupViews(); mHandler = new Handler(); mCounter = 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:itcr.gitsnes.MainActivity.java
/** * OnCreate methods do that things:/*from ww w . ja va 2s . c o m*/ * - 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:de.tubs.ibr.dtn.dtalkie.TalkieActivity.java
@Override public void onResume() { super.onResume(); SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE); List<Sensor> sensors = sm.getSensorList(Sensor.TYPE_PROXIMITY); if (sensors.size() > 0) { Sensor sensor = sensors.get(0);/*from w w w . ja v a 2 s . com*/ sm.registerListener(mSensorListener, sensor, SensorManager.SENSOR_DELAY_NORMAL); } // set output to speaker setAudioOutput(); }
From source file:com.kircherelectronics.fusedgyroscopeexplorer.sensor.GravitySensor.java
/** * Initialize the state./* w w w. jav a 2s . c om*/ * * @param context * the Activities context. */ public GravitySensor(Context context) { super(); this.context = context; initQuaternionRotations(); observersAcceleration = new ArrayList<GravitySensorObserver>(); sensorManager = (SensorManager) this.context.getSystemService(Context.SENSOR_SERVICE); }