use of android.hardware.SensorManager in project keepass2android by PhilippC.
the class AmbientLightManager method start.
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);
}
}
}
use of android.hardware.SensorManager in project android_packages_apps_Gallery2 by LineageOS.
the class EyePosition method pause.
public void pause() {
if (mSensor != null) {
SensorManager sManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
sManager.unregisterListener(mPositionListener);
}
}
use of android.hardware.SensorManager in project habpanelviewer by vbier.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EventBus.getDefault().register(this);
try {
ConnectionUtil.initialize(this);
} catch (Exception e) {
Toast.makeText(MainActivity.this, R.string.sslFailed, Toast.LENGTH_LONG).show();
}
setContentView(R.layout.activity_main);
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
// inflate navigation header to make sure the textview holding the connection text is created
NavigationView navigationView = findViewById(R.id.nav_view);
LinearLayout navHeader = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.nav_header_main, null);
navigationView.addHeaderView(navHeader);
navigationView.setNavigationItemSelectedListener(this);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
if (mServerConnection == null) {
mServerConnection = new ServerConnection(this);
mServerConnection.addConnectionListener(this);
}
if (mConnections == null) {
mConnections = new ConnectionStatistics(this);
}
if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && mFlashService == null) {
try {
mFlashService = new FlashHandler(this, (CameraManager) getSystemService(Context.CAMERA_SERVICE));
} catch (CameraAccessException | IllegalAccessException e) {
Log.d(TAG, "Could not create flash controller");
}
}
if (mCam == null) {
mCam = new Camera(this, findViewById(R.id.previewView), prefs);
}
if (mMotionVisualizer == null) {
int scaledSize = getResources().getDimensionPixelSize(R.dimen.motionFontSize);
final SurfaceView motionView = findViewById(R.id.motionView);
mMotionVisualizer = new MotionVisualizer(motionView, navigationView, prefs, mCam.getSensorOrientation(), scaledSize);
mMotionDetector = new MotionDetector(this, mCam, mMotionVisualizer, mServerConnection);
}
}
if (mDiscovery == null) {
mDiscovery = new ServerDiscovery((NsdManager) getSystemService(Context.NSD_SERVICE));
}
if (prefs.getBoolean("pref_first_start", true)) {
SharedPreferences.Editor editor1 = prefs.edit();
editor1.putBoolean("pref_first_start", false);
editor1.putString("pref_app_version", BuildConfig.VERSION_NAME);
editor1.apply();
final String startText = ResourcesUtil.fetchFirstStart(this);
UiUtil.showScrollDialog(this, "HABPanelViewer", getString(R.string.welcome), startText);
if (prefs.getString("pref_server_url", "").isEmpty()) {
mDiscovery.discover(new ServerDiscovery.DiscoveryListener() {
@Override
public void found(String serverUrl) {
SharedPreferences.Editor editor1 = prefs.edit();
editor1.putString("pref_server_url", serverUrl);
editor1.apply();
}
@Override
public void notFound() {
}
}, true, true);
}
} else {
// make sure old server url preference is used in case it is still set
if (prefs.getString("pref_server_url", "").isEmpty()) {
final String oldUrl = prefs.getString("pref_url", "");
if (!oldUrl.isEmpty()) {
SharedPreferences.Editor editor1 = prefs.edit();
editor1.putString("pref_server_url", oldUrl);
editor1.remove("pref_url");
editor1.apply();
}
}
String lastVersion = prefs.getString("pref_app_version", "0.9.2");
if (!BuildConfig.VERSION_NAME.equals(lastVersion)) {
SharedPreferences.Editor editor1 = prefs.edit();
editor1.putString("pref_app_version", BuildConfig.VERSION_NAME);
editor1.apply();
final String relText = ResourcesUtil.fetchReleaseNotes(this, lastVersion);
UiUtil.showScrollDialog(this, getString(R.string.updated), getString(R.string.updatedText), relText);
}
}
if (mBatteryMonitor == null) {
mBatteryMonitor = new BatteryMonitor(this, mServerConnection);
}
if (mVolumeMonitor == null) {
mVolumeMonitor = new VolumeMonitor(this, (AudioManager) getSystemService(Context.AUDIO_SERVICE), mServerConnection);
}
if (mConnectedReporter == null) {
mConnectedReporter = new ConnectedIndicator(this, mServerConnection);
}
SensorManager m = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
if (mProximityMonitor == null && getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_PROXIMITY)) {
try {
mProximityMonitor = new ProximityMonitor(this, m, mServerConnection);
} catch (SensorMissingException e) {
Log.d(TAG, "Could not create proximity monitor");
}
}
if (mBrightnessMonitor == null && getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_LIGHT)) {
try {
mBrightnessMonitor = new BrightnessMonitor(this, m, mServerConnection);
} catch (SensorMissingException e) {
Log.d(TAG, "Could not create brightness monitor");
}
}
if (mPressureMonitor == null && getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_BAROMETER)) {
try {
mPressureMonitor = new PressureMonitor(this, m, mServerConnection);
} catch (SensorMissingException e) {
Log.d(TAG, "Could not create pressure monitor");
}
}
if (mTemperatureMonitor == null && getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_AMBIENT_TEMPERATURE)) {
try {
mTemperatureMonitor = new TemperatureMonitor(this, m, mServerConnection);
} catch (SensorMissingException e) {
Log.d(TAG, "Could not create temperature monitor");
}
}
if (mCommandQueue == null) {
ScreenHandler mScreenHandler = new ScreenHandler((PowerManager) getSystemService(POWER_SERVICE), this);
mCommandQueue = new CommandQueue(this, mServerConnection);
mCommandQueue.addHandler(new InternalCommandHandler(this, mMotionDetector, mServerConnection));
mCommandQueue.addHandler(new AdminHandler(this));
mCommandQueue.addHandler(new BluetoothHandler(this, (BluetoothManager) getSystemService(BLUETOOTH_SERVICE)));
mCommandQueue.addHandler(mScreenHandler);
mCommandQueue.addHandler(new VolumeHandler(this, (AudioManager) getSystemService(Context.AUDIO_SERVICE)));
if (mFlashService != null) {
mCommandQueue.addHandler(mFlashService);
}
}
mRestartCount = getIntent().getIntExtra("restartCount", 0);
showInitialToastMessage(mRestartCount);
mTextView = navHeader.findViewById(R.id.textView);
mWebView = findViewById(R.id.activity_main_webview);
mWebView.initialize(new IConnectionListener() {
@Override
public void connected(String url) {
}
@Override
public void disconnected() {
if (prefs.getBoolean("pref_track_browser_connection", false)) {
mServerConnection.reconnect();
}
}
});
mCommandQueue.addHandler(new WebViewHandler(mWebView));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
startActivityForResult(projectionManager.createScreenCaptureIntent(), ScreenCapturer.REQUEST_MEDIA_PROJECTION);
}
}
use of android.hardware.SensorManager in project platform_packages_apps_Settings by BlissRoms.
the class DoubleTwistPreferenceController method isGestureAvailable.
public static boolean isGestureAvailable(Context context) {
final Resources resources = context.getResources();
final String name = resources.getString(R.string.gesture_double_twist_sensor_name);
final String vendor = resources.getString(R.string.gesture_double_twist_sensor_vendor);
if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(vendor)) {
final SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
for (Sensor s : sensorManager.getSensorList(Sensor.TYPE_ALL)) {
if (name.equals(s.getName()) && vendor.equals(s.getVendor())) {
return true;
}
}
}
return false;
}
use of android.hardware.SensorManager in project MusicLake by caiyonglong.
the class ShakeManager method cancel.
public void cancel() {
SensorManager sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
// 取消传感器监听
sensorManager.unregisterListener(mySensor);
}
Aggregations