List of usage examples for android.hardware SensorManager SENSOR_DELAY_UI
int SENSOR_DELAY_UI
To view the source code for android.hardware SensorManager SENSOR_DELAY_UI.
Click Source Link
From source file:com.tritop.androsense2.fragments.GpsFragment.java
public void resumeSensors() { mSensorManager.registerListener(this, defaultAccel, SensorManager.SENSOR_DELAY_UI); mSensorManager.registerListener(this, defaultMag, SensorManager.SENSOR_DELAY_UI); mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); mLocationManager.addGpsStatusListener(this); }
From source file:itcr.gitsnes.MainActivity.java
/** * OnCreate methods do that things:/*from ww w.j av a2 s . 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:org.apache.cordova.core.AccelListener.java
/** * Start listening for acceleration sensor. * /* w ww . ja v a 2s . c om*/ * @return status of listener */ private int start() { // If already starting or running, then just return if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) { return this.status; } this.setStatus(AccelListener.STARTING); // Get accelerometer from sensor manager List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); // If found, then register as listener if ((list != null) && (list.size() > 0)) { this.mSensor = list.get(0); this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_UI); this.setStatus(AccelListener.STARTING); } else { this.setStatus(AccelListener.ERROR_FAILED_TO_START); this.fail(AccelListener.ERROR_FAILED_TO_START, "No sensors found to register accelerometer listening to."); return this.status; } // Set a timeout callback on the main thread. stopTimeout(); mainHandler = new Handler(Looper.getMainLooper()); mainHandler.postDelayed(mainRunnable, 2000); return this.status; }
From source file:org.apache.cordova.devicemotion.LightListener.java
/** * Start listening for acceleration sensor. * * @return status of listener// w w w . jav a 2s . co m */ private int start() { // If already starting or running, then restart timeout and return if ((this.status == LightListener.RUNNING) || (this.status == LightListener.STARTING)) { startTimeout(); return this.status; } this.setStatus(LightListener.STARTING); // Get accelerometer from sensor manager List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_LIGHT); // If found, then register as listener if ((list != null) && (list.size() > 0)) { this.mSensor = list.get(0); if (this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_UI)) { this.setStatus(LightListener.STARTING); } else { this.setStatus(LightListener.ERROR_FAILED_TO_START); this.fail(LightListener.ERROR_FAILED_TO_START, "Device sensor returned an error."); return this.status; } ; } else { this.setStatus(LightListener.ERROR_FAILED_TO_START); this.fail(LightListener.ERROR_FAILED_TO_START, "No sensors found to register ambient light listening to."); return this.status; } startTimeout(); return this.status; }
From source file:org.apache.cordova.devicemotion.AccelListener.java
/** * Start listening for acceleration sensor. * * @return status of listener/*from w w w . j a v a 2 s. c o m*/ */ private int start() { // If already starting or running, then restart timeout and return if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) { startTimeout(); return this.status; } this.setStatus(AccelListener.STARTING); // Get accelerometer from sensor manager List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); // If found, then register as listener if ((list != null) && (list.size() > 0)) { this.mSensor = list.get(0); if (this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_UI)) { this.setStatus(AccelListener.STARTING); // CB-11531: Mark accuracy as 'reliable' - this is complementary to // setting it to 'unreliable' 'stop' method this.accuracy = SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM; } else { this.setStatus(AccelListener.ERROR_FAILED_TO_START); this.fail(AccelListener.ERROR_FAILED_TO_START, "Device sensor returned an error."); return this.status; } ; } else { this.setStatus(AccelListener.ERROR_FAILED_TO_START); this.fail(AccelListener.ERROR_FAILED_TO_START, "No sensors found to register accelerometer listening to."); return this.status; } startTimeout(); return this.status; }
From source file:com.bsafe.sensors.motion.BSMotionSensorsPlugin.java
/** * Start listening for acceleration sensor. * * @return status of listener//from w w w . j av a 2s . co m */ private int start() { // If already starting or running, then restart timeout and return if ((this.status == BSMotionSensorsPlugin.RUNNING) || (this.status == BSMotionSensorsPlugin.STARTING)) { startTimeout(); return this.status; } this.setStatus(BSMotionSensorsPlugin.STARTING); // Get accelerometer from sensor manager List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); // If found, then register as listener if ((list != null) && (list.size() > 0)) { this.mSensor = list.get(0); if (this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_UI)) { this.setStatus(BSMotionSensorsPlugin.STARTING); } else { this.setStatus(BSMotionSensorsPlugin.ERROR_FAILED_TO_START); this.fail(BSMotionSensorsPlugin.ERROR_FAILED_TO_START, "Device sensor returned an error."); return this.status; } ; } else { this.setStatus(BSMotionSensorsPlugin.ERROR_FAILED_TO_START); this.fail(BSMotionSensorsPlugin.ERROR_FAILED_TO_START, "No sensors found to register accelerometer listening to."); return this.status; } startTimeout(); return this.status; }
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 . jav a2s . c om 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:com.example.administrator.myapplication2._5_Group._5_Group.RightFragment.java
@Override public void onResume() { super.onResume(); //? ? ?? ? ? if (mCompassEnabled) { mSensorManager.registerListener(mListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_UI); }//from w ww .jav a 2s. co m }
From source file:com.grumpysailor.cordova.magnetsensor.MagnetSensor.java
/** * Start listening for acceleration sensor. * /*from www .jav a 2 s .co m*/ * @return status of listener */ private int start() { // If already starting or running, then just return if ((this.status == MagnetSensor.RUNNING) || (this.status == MagnetSensor.STARTING)) { return this.status; } this.setStatus(MagnetSensor.STARTING); // Get accelerometer from sensor manager List<Sensor> list = this.mSensorManager.getSensorList(Sensor.TYPE_MAGNETIC_FIELD); // If found, then register as listener if ((list != null) && (list.size() > 0)) { this.mMagnetometer = list.get(0); this.mSensorManager.registerListener(this, this.mMagnetometer, SensorManager.SENSOR_DELAY_UI); this.setStatus(MagnetSensor.STARTING); } else { this.setStatus(MagnetSensor.ERROR_FAILED_TO_START); this.fail(MagnetSensor.ERROR_FAILED_TO_START, "No sensors found to register magnet sensor listening to."); return this.status; } // Set a timeout callback on the main thread. stopTimeout(); mainHandler = new Handler(Looper.getMainLooper()); mainHandler.postDelayed(mainRunnable, 2000); return this.status; }
From source file:kn.uni.gis.foxhunt.GameActivity.java
protected void onResume() { super.onResume(); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); if (GameContext.getGame().getType() == Type.HUNTER) { sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI); }//w ww . j a v a 2 s . co m }