Search in sources :

Example 76 with SensorManager

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);
        }
    }
}
Also used : SensorManager(android.hardware.SensorManager) SharedPreferences(android.content.SharedPreferences)

Example 77 with SensorManager

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);
    }
}
Also used : SensorManager(android.hardware.SensorManager)

Example 78 with SensorManager

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);
    }
}
Also used : NavigationView(android.support.design.widget.NavigationView) FlashHandler(de.vier_bier.habpanelviewer.command.FlashHandler) ConnectedIndicator(de.vier_bier.habpanelviewer.reporting.ConnectedIndicator) MotionVisualizer(de.vier_bier.habpanelviewer.reporting.motion.MotionVisualizer) CommandQueue(de.vier_bier.habpanelviewer.command.CommandQueue) BluetoothManager(android.bluetooth.BluetoothManager) ServerDiscovery(de.vier_bier.habpanelviewer.openhab.ServerDiscovery) BatteryMonitor(de.vier_bier.habpanelviewer.reporting.BatteryMonitor) CameraAccessException(android.hardware.camera2.CameraAccessException) AudioManager(android.media.AudioManager) AdminHandler(de.vier_bier.habpanelviewer.command.AdminHandler) IMotionDetector(de.vier_bier.habpanelviewer.reporting.motion.IMotionDetector) MotionDetector(de.vier_bier.habpanelviewer.reporting.motion.MotionDetector) ScreenHandler(de.vier_bier.habpanelviewer.command.ScreenHandler) Camera(de.vier_bier.habpanelviewer.reporting.motion.Camera) NsdManager(android.net.nsd.NsdManager) SurfaceView(android.view.SurfaceView) VolumeHandler(de.vier_bier.habpanelviewer.command.VolumeHandler) WebViewHandler(de.vier_bier.habpanelviewer.command.WebViewHandler) SharedPreferences(android.content.SharedPreferences) BluetoothHandler(de.vier_bier.habpanelviewer.command.BluetoothHandler) BrightnessMonitor(de.vier_bier.habpanelviewer.reporting.BrightnessMonitor) ServerConnection(de.vier_bier.habpanelviewer.openhab.ServerConnection) CameraManager(android.hardware.camera2.CameraManager) ProximityMonitor(de.vier_bier.habpanelviewer.reporting.ProximityMonitor) SensorMissingException(de.vier_bier.habpanelviewer.reporting.SensorMissingException) CameraException(de.vier_bier.habpanelviewer.reporting.motion.CameraException) CameraAccessException(android.hardware.camera2.CameraAccessException) Point(android.graphics.Point) PressureMonitor(de.vier_bier.habpanelviewer.reporting.PressureMonitor) MediaProjectionManager(android.media.projection.MediaProjectionManager) SensorManager(android.hardware.SensorManager) IConnectionListener(de.vier_bier.habpanelviewer.openhab.IConnectionListener) TemperatureMonitor(de.vier_bier.habpanelviewer.reporting.TemperatureMonitor) SensorMissingException(de.vier_bier.habpanelviewer.reporting.SensorMissingException) VolumeMonitor(de.vier_bier.habpanelviewer.reporting.VolumeMonitor) InternalCommandHandler(de.vier_bier.habpanelviewer.command.InternalCommandHandler) LinearLayout(android.widget.LinearLayout)

Example 79 with SensorManager

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;
}
Also used : SensorManager(android.hardware.SensorManager) Resources(android.content.res.Resources) Sensor(android.hardware.Sensor)

Example 80 with SensorManager

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);
}
Also used : SensorManager(android.hardware.SensorManager)

Aggregations

SensorManager (android.hardware.SensorManager)89 Sensor (android.hardware.Sensor)29 SharedPreferences (android.content.SharedPreferences)12 Resources (android.content.res.Resources)8 PowerManager (android.os.PowerManager)6 ContentResolver (android.content.ContentResolver)5 IntentFilter (android.content.IntentFilter)5 SystemSensorManager (android.hardware.SystemSensorManager)5 IPowerManager (android.os.IPowerManager)5 RemoteException (android.os.RemoteException)5 WindowManager (android.view.WindowManager)5 DisplayManagerInternal (android.hardware.display.DisplayManagerInternal)4 BatteryManagerInternal (android.os.BatteryManagerInternal)4 DreamManagerInternal (android.service.dreams.DreamManagerInternal)4 IVrManager (android.service.vr.IVrManager)4 Display (android.view.Display)4 WindowManagerPolicy (android.view.WindowManagerPolicy)4 LightsManager (com.android.server.lights.LightsManager)4 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3