Example usage for android.content Context SENSOR_SERVICE

List of usage examples for android.content Context SENSOR_SERVICE

Introduction

In this page you can find the example usage for android.content Context SENSOR_SERVICE.

Prototype

String SENSOR_SERVICE

To view the source code for android.content Context SENSOR_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.hardware.SensorManager for accessing sensors.

Usage

From source file:cn.edu.gdmec.t00385.lightsensor.LightSensorListener.java

/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 *
 * @param cordova The context of the main Activity.
 * @param webView The CordovaWebView Cordova is running in.
 *///from   ww w  .  j a v  a2 s .c o m
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    this.sensorManager = (SensorManager) cordova.getActivity().getSystemService(Context.SENSOR_SERVICE);
}

From source file:com.android.talkback.SideTapManager.java

/**
 * @param context TalkBackService whose {@code performCustomGesture}
 * will be called when taps are detected
 *//*from  w  w  w .jav a 2  s .  co  m*/
public SideTapManager(TalkBackService context, GestureController gestureController) {
    if (gestureController == null)
        throw new IllegalStateException();
    mContext = context;
    mIntegratedTapDetector = new IntegratedTapDetector(
            (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE));
    mIntegratedTapDetector.addListener(this);
    mIntegratedTapDetector.setPostDelayTimeMillis(MIN_TIME_BETWEEN_TOUCH_AND_TAP_NANOS / MILIS_PER_NANO);
    mGestureController = gestureController;
}

From source file:com.android.screenspeak.SideTapManager.java

/**
 * @param context ScreenSpeakService whose {@code performCustomGesture}
 * will be called when taps are detected
 *///from w w  w.j a va  2 s  .com
public SideTapManager(ScreenSpeakService context, GestureController gestureController) {
    if (gestureController == null)
        throw new IllegalStateException();
    mContext = context;
    mIntegratedTapDetector = new IntegratedTapDetector(
            (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE));
    mIntegratedTapDetector.addListener(this);
    mIntegratedTapDetector.setPostDelayTimeMillis(MIN_TIME_BETWEEN_TOUCH_AND_TAP_NANOS / MILIS_PER_NANO);
    mGestureController = gestureController;
}

From source file:com.example.nate.cloudcar.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!LibsChecker.checkVitamioLibs(this))
        return;//from  w w  w . j  a v a 2  s .  c om
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //setSupportActionBar(toolbar);

    throttle = (SeekBar) findViewById(R.id.throttle); // Throttle slider
    gestureInfo = (TextView) findViewById(R.id.gestureInfo); // Temporary TextView for showing Camera Position
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); // Steering sensor manager
    tilt = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); // Steering seneor
    DetectMe = new GestureDetectorCompat(this, this); // Camera movement gesture detector

    mVideoView = (VideoView) findViewById(R.id.vitamio_videoView);
    path = "rtsp://192.168.10.200:8555/unicast";
    mVideoView.setVideoPath(path);

    mVideoView.setHardwareDecoder(true);
    //mVideoView.setBufferSize(50);
    //mVideoView.getBufferPercentage();
    //mVideoView.setDrawingCacheEnabled(true);
    //mVideoView.setMediaController(new MediaController(this));
    mVideoView.requestFocus();
    //throttle.requestFocus();

    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mediaPlayer) {
            mediaPlayer.setPlaybackSpeed(1.0f);
            //mediaPlayer.setBufferSize(50);

        }
    });

    throttle.setOnSeekBarChangeListener( // Seekbar listener for throttle slider
            new SeekBar.OnSeekBarChangeListener() {
                //int redValue;
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    socketSend("chan0", (progress + 8));
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {

                }
            });

}

From source file:com.achep.acdisplay.ui.fragments.PocketFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    mSensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
    mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    mProximityAvailable = mProximitySensor != null;

    if (mProximityAvailable) {
        mMaximumRange = mProximitySensor.getMaximumRange();
    }//  w ww  . ja va2  s .  co m
}

From source file:eu.geopaparazzi.core.ui.dialogs.GpsInfoDialogFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    SensorManager sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    orientationSensor = new OrientationSensor(sensorManager, null);
    orientationSensor.register(getActivity(), SensorManager.SENSOR_DELAY_NORMAL);

    gpsServiceBroadcastReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            onGpsServiceUpdate(intent);/*w  ww  .java 2 s .c o  m*/
        }
    };
    GpsServiceUtilities.registerForBroadcasts(getActivity(), gpsServiceBroadcastReceiver);
    GpsServiceUtilities.triggerBroadcast(getActivity());
}

From source file:rp.soi.dmsd.notextingwhilewalking.DetectedActivitiesIntentService.java

/**
 * Handles incoming intents./*  ww  w. j  av  a 2s.c o  m*/
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@Override
protected void onHandleIntent(Intent intent) {
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mSensorManager.registerListener(this, mOrientation, SensorManager.SENSOR_DELAY_NORMAL);
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    Intent localIntent = new Intent(rp.soi.dmsd.notextingwhilewalking.Constants.BROADCAST_ACTION);

    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    // Log each activity.
    Log.i(TAG, "activities detected");
    for (DetectedActivity da : detectedActivities) {
        Log.i(TAG, rp.soi.dmsd.notextingwhilewalking.Constants.getActivityString(getApplicationContext(),
                da.getType()) + " " + da.getConfidence() + "%");
        // trigger a notification if the walking activity has a confidence of > 50%

        //float[] xyz = mSensorManager.getOrientation();

        if (da.getType() == DetectedActivity.WALKING && da.getConfidence() > 15) {

            // For API 20 and higher
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Log.i(TAG, "Android version is HIGHER than 20 ");
                if (powerManager.isInteractive()) {
                    Log.i(TAG, "Screen is ON");
                    if (isPhoneFacingUp) {
                        Log.i(TAG, "Phone is facing UP.");
                        createNotification(true);
                    } else {
                        Log.i(TAG, "Phone is facing DOWN.");
                    }
                } else {
                    Log.i(TAG, "Screen is OFF");
                }
            } else {
                Log.i(TAG, "Android version is LOWER than 20 ");
                if (powerManager.isScreenOn()) {
                    Log.i(TAG, "Screen is ON");
                    if (isPhoneFacingUp) {
                        Log.i(TAG, "Phone is facing UP.");
                        createNotification(true);
                    } else {
                        Log.i(TAG, "Phone is facing DOWN.");
                    }
                } else {
                    Log.i(TAG, "Screen is OFF");
                }
            }
        }

    }

    // Broadcast the list of detected activities.
    localIntent.putExtra(Constants.ACTIVITY_EXTRA, detectedActivities);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}

From source file:com.mhennessy.mapfly.MainActivity.java

private void initSensors() {
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mOrientationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mAccelerationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mFlyingEnabled = false;//from   www. jav  a2s . com
}

From source file:com.javierarias.magnadroid.Magnadroid.java

@SuppressLint("MissingSuperCall")
@Override/*  w  w  w. j  a  v a 2  s  .  c  o m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Fabric.with(this, new Crashlytics());
    // Debug.startMethodTracing();
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    if (mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null) {
        // Success! There's a magnetometer.
        mMagnetic = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
        magneticMaxRange = mMagnetic.getMaximumRange();
    }
    setContentView(R.layout.activity_magnadroid);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    magneTabs fragment = new magneTabs();
    transaction.replace(R.id.frame_content, fragment);
    transaction.commit();
}

From source file:org.awokenwell.proximity.ProximitySensorListener.java

/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 *
 * @param cordova The context of the main Activity.
 * @param webView The CordovaWebView Cordova is running in.
 *///from w ww  . j ava 2  s.  c  om
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    this.sensorManager = (SensorManager) cordova.getActivity().getSystemService(Context.SENSOR_SERVICE);
    this.powerManager = (PowerManager) cordova.getActivity().getSystemService(Context.POWER_SERVICE);
    this.wakeLock = null;

}