List of usage examples for android.hardware SensorManager getDefaultSensor
public Sensor getDefaultSensor(int type)
From source file:Main.java
public static boolean isSupportAccelerometerSensor(Context context) { SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); return sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null; }
From source file:Main.java
public static boolean isSensorAvailable(Context ctx, int type_sensor) { boolean isSensorAvailable = false; SensorManager sensorManger = null; sensorManger = (SensorManager) ctx.getSystemService(ctx.SENSOR_SERVICE); if (sensorManger.getDefaultSensor(type_sensor) != null) { isSensorAvailable = true;//from w w w . j a va 2 s. co m } return isSensorAvailable; }
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 . jav a 2 s . c o m }
From source file:de.sopamo.triangula.android.GameActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); App.setActivityContext(this); Bundle b = getIntent().getExtras();/*w w w . j a va 2 s .c om*/ if (b != null) { level = (Level) b.get("level"); } else { level = new Level1(); } mGameGlSurfaceView = new GameGLSurfaceView(this); setContentView(R.layout.main); LinearLayout ll = (LinearLayout) findViewById(R.id.layout_main); ll.addView(mGameGlSurfaceView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); status = (TextView) findViewById(R.id.tv_status); // Disable hiding for debug if (true) { status.setVisibility(View.GONE); } SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE); sm.registerListener(this, sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); mGameGlSurfaceView.init(); }
From source file:net.openfiretechnologies.veloxcontrol.fragments.ActiveDisplaySettings.java
private boolean hasProximitySensor() { SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); return sm.getDefaultSensor(TYPE_PROXIMITY) != null; }
From source file:net.openfiretechnologies.veloxcontrol.fragments.ActiveDisplaySettings.java
private boolean hasLightSensor() { SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); return sm.getDefaultSensor(TYPE_LIGHT) != null; }
From source file:com.artioml.practice.MainActivity.java
@Override protected void onPause() { super.onPause(); SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensorManager.unregisterListener(sensorEventListener, sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION)); }
From source file:com.artioml.practice.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w ww . j av a2 s . co m ImageButton settingsButton = (ImageButton) findViewById(R.id.settingsButton); settingsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MainSettingsDialog mainSettingsDialog = new MainSettingsDialog(MainActivity.this); mainSettingsDialog.show(); } }); fillSettingsPanel(); AudioAttributes.Builder attrBuilder = new AudioAttributes.Builder(); attrBuilder.setUsage(AudioAttributes.USAGE_GAME); SoundPool.Builder builder = new SoundPool.Builder(); builder.setMaxStreams(1); builder.setAudioAttributes(attrBuilder.build()); soundPool = builder.build(); soundMap = new SparseIntArray(1); soundMap.put(0, soundPool.load(getBaseContext(), R.raw.fire, 1)); punchButton = (Button) findViewById(R.id.punchButton); punchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { punchButton.setEnabled(false); (new Handler()).postDelayed(new Runnable() { @Override public void run() { soundPool.play(soundMap.get(0), 1, 1, 1, 0, 1f); reaction = 0.00f; maxAcceleration = 0; count = 0; data = new ArrayList<>(); SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensorManager.registerListener(sensorEventListener, sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION), 1000); } }, 2000); } }); Button historyButton = (Button) findViewById(R.id.historyButton); historyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent historyIntent = new Intent(MainActivity.this, HistoryActivity.class); startActivity(historyIntent); } }); }
From source file:org.jitsi.android.gui.fragment.ProximitySensorFragment.java
/** * {@inheritDoc}/*from ww w. jav a 2 s. c o m*/ */ @Override public void onResume() { super.onResume(); // Skips if the sensor has been already attached if (proximitySensor != null) return; SensorManager manager = JitsiApplication.getSensorManager(); List<Sensor> sensors = manager.getSensorList(Sensor.TYPE_ALL); logger.trace("Device has " + sensors.size() + " sensors"); for (Sensor s : sensors) { logger.trace("Sensor " + s.getName() + " type: " + s.getType()); } this.proximitySensor = manager.getDefaultSensor(Sensor.TYPE_PROXIMITY); if (proximitySensor == null) { return; } logger.info("Using proximity sensor: " + proximitySensor.getName()); sensorDisabled = false; manager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_UI); }
From source file:ngoc.com.pedometer.ui.Fragment_Overview.java
@Override public void onResume() { super.onResume(); // getActivity().getActionBar().setDisplayHomeAsUpEnabled(false); Database db = Database.getInstance(getActivity()); if (BuildConfig.DEBUG) db.logState();/*from w ww . j ava 2 s.com*/ // read todays offset todayOffset = db.getSteps(Util.getToday()); SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_PRIVATE); goal = prefs.getInt("goal", Fragment_Settings.DEFAULT_GOAL); since_boot = db.getCurrentSteps(); // do not use the value from the sharedPreferences int pauseDifference = since_boot - prefs.getInt("pauseCount", since_boot); // register a sensorlistener to live update the UI if a step is taken if (!prefs.contains("pauseCount")) { SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); Sensor sensor = sm.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); if (sensor == null) { new AlertDialog.Builder(getActivity()).setTitle(R.string.no_sensor) .setMessage(R.string.no_sensor_explain) .setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(final DialogInterface dialogInterface) { getActivity().finish(); } }).setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).create().show(); } else { sm.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI, 0); } } since_boot -= pauseDifference; total_start = db.getTotalWithoutToday(); total_days = db.getDays(); db.close(); stepsDistanceChanged(); }