Java Code Examples for android.hardware.SensorManager#getDefaultSensor()
The following examples show how to use
android.hardware.SensorManager#getDefaultSensor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModLedControl.java From GravityBox with Apache License 2.0 | 6 votes |
private static void toggleActiveScreenFeature(boolean enable) { try { if (enable && mContext != null) { mPm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mKm = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); mSm = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); mProxSensor = mSm.getDefaultSensor(Sensor.TYPE_PROXIMITY); } else { mProxSensor = null; mSm = null; mPm = null; mKm = null; } if (DEBUG) log("Active screen feature: " + enable); } catch (Throwable t) { XposedBridge.log(t); } }
Example 2
Source File: MeiFireflyActivity.java From kAndroid with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mei_firefly); mMobikeView = findViewById(R.id.mo_bike); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); addViews(); mMobikeView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mMobikeView.onRandomChanged(); } }); }
Example 3
Source File: SecurityScene.java From EhViewer with Apache License 2.0 | 6 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Context context = getContext2(); AssertUtils.assertNotNull(context); mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); if (null != mSensorManager) { mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (null != mAccelerometer) { mShakeDetector = new ShakeDetector(); mShakeDetector.setOnShakeListener(this); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mFingerprintManager = context.getSystemService(FingerprintManager.class); } if (null == savedInstanceState) { mRetryTimes = MAX_RETRY_TIMES; } else { mRetryTimes = savedInstanceState.getInt(KEY_RETRY_TIMES); } }
Example 4
Source File: TranslationReadActivity.java From QuranAndroid with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_translation_read); db = new DatabaseHandler(this); sm = (SensorManager) getSystemService(SENSOR_SERVICE); proxSensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY); lightSensor = sm.getDefaultSensor(Sensor.TYPE_LIGHT); sm.registerListener(this,proxSensor,SensorManager.SENSOR_DELAY_NORMAL); //toolbar object Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); //init translation read activity init(); }
Example 5
Source File: ShakeListener.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
public void start() { sensorManager = (SensorManager) context .getSystemService(Context.SENSOR_SERVICE); // 获得传感器管理器 if (sensorManager != null) { // 获得重力传感器 sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); } // 注册 if (sensor != null) { sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); } }
Example 6
Source File: BarometerNetworkActivity.java From PressureNet with GNU General Public License v3.0 | 5 votes |
/** * Check if we have a hygrometer. */ private boolean checkHygrometer() { SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); Sensor humid = sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); if(humid==null) { hasHygrometer = false; } else { hasHygrometer = true; } return hasHygrometer; }
Example 7
Source File: SensorsTester.java From PermissionAgent with Apache License 2.0 | 5 votes |
@Override public boolean test() throws Throwable { SensorManager sensorManager = (SensorManager)mContext.getSystemService(Context.SENSOR_SERVICE); try { Sensor heartRateSensor = sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE); sensorManager.registerListener(SENSOR_EVENT_LISTENER, heartRateSensor, 3); sensorManager.unregisterListener(SENSOR_EVENT_LISTENER, heartRateSensor); } catch (Throwable e) { PackageManager packageManager = mContext.getPackageManager(); return !packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_HEART_RATE); } return true; }
Example 8
Source File: CompassActivity.java From MuslimMateAndroid with GNU General Public License v3.0 | 5 votes |
/** * Function to init compass activity */ private void init() { countryName = (TextView) findViewById(R.id.textView11); if (MainActivity.locationInfo != null) countryName.setText(getResources().getConfiguration() .locale.getDisplayLanguage().equals("العربية") ? ConfigPreferences.getLocationConfig(this).name_english : ConfigPreferences.getLocationConfig(this).name); //init compass activity views Quibladegree = (TextView) findViewById(R.id.textView12); Quibladegree.setText(getString(R.string.qibla_direction) + " " + ConfigPreferences.getQuibla(this)); indicator = (ImageView) findViewById(R.id.imageView2); compass = (RelativeLayout) findViewById(R.id.compassContainer); compassMapContainer = (RelativeLayout) findViewById(R.id.compassMapContainer); compassMain = (RelativeLayout) findViewById(R.id.compassMain); smallCircleLevel = (ImageView) findViewById(R.id.smallCircle); innerPosition = (RelativeLayout) findViewById(R.id.innerplace); pointerIndicatorInner = (ImageView) findViewById(R.id.poinerInner); redCircle = (ImageView) findViewById(R.id.red_circle); errorImage = (ImageView) findViewById(R.id.error); //init sensor services mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); compassLevel = (ImageView) findViewById(R.id.compassLevel); //animate compass pointer RotateAnimation ra = new RotateAnimation(currentDegree, MainActivity.quiblaDegree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); ra.setDuration(400); ra.setFillAfter(true); indicator.startAnimation(ra); pointerIndicatorInner.startAnimation(ra); }
Example 9
Source File: AmbientLightManager.java From AndroidWebServ with Apache License 2.0 | 5 votes |
void start(CameraManager cameraManager) { this.cameraManager = cameraManager; SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); if (FrontLightMode.readPref(sharedPrefs) == FrontLightMode.AUTO) { SensorManager sensorManager = (SensorManager) context .getSystemService(Context.SENSOR_SERVICE); lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); if (lightSensor != null) { sensorManager .registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL); } } }
Example 10
Source File: CompassView.java From android with Apache License 2.0 | 5 votes |
private void initSensors() { mDefaultDisplay = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE); mGravitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMagneticSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mRotationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); }
Example 11
Source File: SynthCircle.java From Circle-Synth with GNU General Public License v2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Setting up Google analytics. GA parameters in the analytics.xml file EasyTracker.getInstance().setContext(getApplicationContext()); // Instantiate the Tracker tracker = EasyTracker.getTracker(); /** * IMPORTANT : if using decimal format, remember to set the decimal * separator explicitly, else your app will crash when used in locales * which use ',' as the decimal separator. */ symbols.setDecimalSeparator('.'); df = new DecimalFormat("#.##", symbols); df1 = new DecimalFormat("#.#", symbols); // Accessing default Shared Preferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Call and setup the accelerometer which we will be using later mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mAccelerometer = mSensorManager .getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(this, mAccelerometer, 100000); // make sure the screen doesn't turn off getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); initPdService(); /* * IMPORTANT:make sure you have the READ_PHONE_STATE permission * specified to use the method below. This method will ensure that * pdservice is paused during a phone call. */ initSystemServices(); }
Example 12
Source File: CompassTile.java From GravityBox with Apache License 2.0 | 5 votes |
public CompassTile(Object host, String key, XSharedPreferences prefs, QsTileEventDistributor eventDistributor) throws Throwable { super(host, key, prefs, eventDistributor); mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); mAccelerationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mGeomagneticFieldSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); }
Example 13
Source File: JoystickView.java From RobotCA with GNU General Public License v3.0 | 5 votes |
private void init(Context context) { initVirtualJoystick(context); // topicName = "~cmd_vel"; try { sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); } catch (UnsupportedOperationException e) { // No accelerometer, too bad Log.w(TAG, "No tilt control"); } }
Example 14
Source File: QiblaPresenter.java From Muslim-Athkar-Islamic-Reminders with MIT License | 5 votes |
@Override public boolean checkSensorAvailability(SensorManager mSensorManager){ if (mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null){ return true; } else { return false; } }
Example 15
Source File: MotionStrategy.java From MD360Player4Android with Apache License 2.0 | 5 votes |
@Override public boolean isSupport(Context context) { if (mIsSupport == null){ SensorManager mSensorManager = (SensorManager) context .getSystemService(Context.SENSOR_SERVICE); Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); mIsSupport = (sensor != null); } return mIsSupport; }
Example 16
Source File: MainActivity.java From Android-9-Development-Cookbook with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTextView = (TextView)findViewById(R.id.textView); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); }
Example 17
Source File: SensorHelper.java From NotificationPeekPort with Apache License 2.0 | 5 votes |
/** * Check if the given sensor is presented in the device and/or the user choose to use it. * * @param context Context instance. * @param sensor Sensor type, can be {@link SensorHelper#SENSOR_GYRO} * or {@link SensorHelper#SENSOR_PROXIMITY_LIGHT} * @param combinePreference Boolean value for whether we need to check the preference or not. * @return */ public static boolean checkSensorStatus(Context context, int sensor, boolean combinePreference) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); switch (sensor) { case SENSOR_PROXIMITY_LIGHT: Sensor proxSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) != null ? sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) : sensorManager .getDefaultSensor(Sensor.TYPE_LIGHT); return proxSensor != null && (preferences.getBoolean(PreferenceKeys.PREF_PROX_LIGHT_SENSOR, true) || !combinePreference); case SENSOR_GYRO: Sensor gyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); return gyroSensor != null && (preferences.getBoolean(PreferenceKeys.PREF_GYRO_SENSOR, true) || !combinePreference); default: return false; } }
Example 18
Source File: AutoHighBrightnessModeService.java From kernel_adiutor with Apache License 2.0 | 4 votes |
public void activateLightSensorRead() { sMgr = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE); light = sMgr.getDefaultSensor(Sensor.TYPE_LIGHT); sMgr.registerListener(_SensorEventListener, light, SensorManager.SENSOR_DELAY_NORMAL); }
Example 19
Source File: EventPreferencesOrientation.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
@Override void checkPreferences(PreferenceManager prefMng, Context context) { SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); boolean hasAccelerometer = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null); boolean hasMagneticField = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null); boolean hasProximity = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) != null); boolean hasLight = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT) != null); boolean enabledAll = (hasAccelerometer) && (hasMagneticField); Preference preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_DISPLAY); if (preference != null) { if (!hasAccelerometer) preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+ ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware)); preference.setEnabled(hasAccelerometer); } preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_SIDES); if (preference != null) { if (!enabledAll) preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+ ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware)); preference.setEnabled(enabledAll); } boolean enabled = hasProximity; preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_DISTANCE); if (preference != null) { if (!enabled) preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+ ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware)); preference.setEnabled(enabled); } SwitchPreferenceCompat switchPreference = prefMng.findPreference(PREF_EVENT_ORIENTATION_CHECK_LIGHT); if (switchPreference != null) { boolean checkLight = switchPreference.isChecked(); if (checkLight) { enabled = hasLight; preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_LIGHT_MIN); if (preference != null) { if (!enabled) preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed) + ": " + context.getString(R.string.preference_not_allowed_reason_no_hardware)); preference.setEnabled(enabled); } preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_LIGHT_MAX); if (preference != null) { if (!enabled) preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed) + ": " + context.getString(R.string.preference_not_allowed_reason_no_hardware)); preference.setEnabled(enabled); } } } enabled = PPPExtenderBroadcastReceiver.isEnabled(context.getApplicationContext(), PPApplication.VERSION_CODE_EXTENDER_3_0); ApplicationsMultiSelectDialogPreferenceX applicationsPreference = prefMng.findPreference(PREF_EVENT_ORIENTATION_IGNORED_APPLICATIONS); if (applicationsPreference != null) { applicationsPreference.setEnabled(enabled); applicationsPreference.setSummaryAMSDP(); } SharedPreferences preferences = prefMng.getSharedPreferences(); setSummary(prefMng, PREF_EVENT_ORIENTATION_APP_SETTINGS, preferences, context); setCategorySummary(prefMng, preferences, context); }
Example 20
Source File: AndroidSensorTest.java From ssj with GNU General Public License v3.0 | 4 votes |
@Test public void testSensors() throws Exception { // Test for every sensor type for (SensorType type : SensorType.values()) { SensorManager mSensorManager = (SensorManager) getInstrumentation().getContext().getSystemService(Context.SENSOR_SERVICE); if (mSensorManager.getDefaultSensor(type.getType()) != null) { // Setup Pipeline frame = Pipeline.getInstance(); frame.options.bufferSize.set(10.0f); // Sensor AndroidSensor sensor = new AndroidSensor(); AndroidSensorChannel channel = new AndroidSensorChannel(); channel.options.sensorType.set(type); frame.addSensor(sensor, channel); // Logger Logger log = new Logger(); frame.addConsumer(log, channel, 1, 0); // Start framework frame.start(); // Wait duration try { Thread.sleep(TestHelper.DUR_TEST_SHORT); } catch (Exception e) { e.printStackTrace(); } // Stop framework frame.stop(); frame.release(); } else { Log.i(type.getName() + " not present on device"); } } }