Example usage for android.hardware Sensor TYPE_ACCELEROMETER

List of usage examples for android.hardware Sensor TYPE_ACCELEROMETER

Introduction

In this page you can find the example usage for android.hardware Sensor TYPE_ACCELEROMETER.

Prototype

int TYPE_ACCELEROMETER

To view the source code for android.hardware Sensor TYPE_ACCELEROMETER.

Click Source Link

Document

A constant describing an accelerometer sensor type.

Usage

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!LibsChecker.checkVitamioLibs(this))
        return;/*w  w w.j a v  a 2  s. c o  m*/
    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:de.sopamo.triangula.android.GameActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    App.setActivityContext(this);

    Bundle b = getIntent().getExtras();//from  w w w  .ja  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:pubsub.io.android.example.Pubsub_exampleActivity.java

/** Called when the activity is first created. */
@Override/*from   w  w w.  jav a2s  .  c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    timer = System.currentTimeMillis();

    mPubsub = new Pubsub(this, mHandler);
    mPubsub.connect("android");

    // Sensors
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

    mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 5, this);

    // UI
    Button publish_message = (Button) findViewById(R.id.button1);
    publish_message.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            JSONObject doc = new JSONObject();
            try {
                JSONArray authors = new JSONArray();
                authors.put("mathias");
                authors.put("ian");
                doc.put("authors", authors);
                doc.put("version", 0.1);
            } catch (JSONException e) {
                e.printStackTrace();
            }

            mPubsub.publish(doc);
        }
    });

    txtAccelerometer = (TextView) findViewById(R.id.textView2);
    txtAccelerometer.setText((publishing_acc == true ? "ON" : "OFF"));
    txtAccelerometer.setBackgroundColor((publishing_acc == true ? Color.GREEN : Color.RED));
    Button publish_accelerometer = (Button) findViewById(R.id.button2);
    publish_accelerometer.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            publishing_acc = !publishing_acc;
            txtAccelerometer.setText((publishing_acc == true ? "ON" : "OFF"));
            txtAccelerometer.setBackgroundColor((publishing_acc == true ? Color.GREEN : Color.RED));
        }
    });

    txtGps = (TextView) findViewById(R.id.textView3);
    txtGps.setText((publishing_gps == true ? "ON" : "OFF"));
    txtGps.setBackgroundColor((publishing_gps == true ? Color.GREEN : Color.RED));
    Button publish_gps = (Button) findViewById(R.id.button3);
    publish_gps.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            publishing_gps = !publishing_gps;
            txtGps.setText((publishing_gps == true ? "ON" : "OFF"));
            txtGps.setBackgroundColor((publishing_gps == true ? Color.GREEN : Color.RED));
        }
    });

    json_messages = new ArrayList<String>();
    mArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, json_messages);
    ListView mListView = (ListView) findViewById(R.id.listView1);
    mListView.setAdapter(mArrayAdapter);
}

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;// ww  w  . j a v  a2  s .com
}

From source file:org.cocos2dx.lib.Cocos2dxAccelerometer.java

public Cocos2dxAccelerometer(Context context) {
    mContext = context;//from  www .  j  a v  a2  s .c om

    //Get an instance of the SensorManager
    mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

    Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    mNaturalOrientation = display.getOrientation();
}

From source file:com.example.android.camera2video.CameraActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);
    if (null == savedInstanceState) {
        getFragmentManager().beginTransaction().replace(R.id.container, Camera2VideoFragment.newInstance())
                .commit();//from   w  ww  .  j a va2  s.com
    }

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                TAG_PERMISSION_FINE_LOCATION);
    } else {
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0f, this);
    }

    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mSensorManager.registerListener(this, mAccSensor, SensorManager.SENSOR_DELAY_GAME);
    //        mGraSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
    //        mSensorManager.registerListener(this, mGraSensor, SensorManager.SENSOR_DELAY_GAME);
    //        mLinSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
    //        mSensorManager.registerListener(this, mLinSensor, SensorManager.SENSOR_DELAY_GAME);
    //        mGyrSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    //        mSensorManager.registerListener(this, mGyrSensor, SensorManager.SENSOR_DELAY_GAME);
    mUgySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE_UNCALIBRATED);
    mSensorManager.registerListener(this, mUgySensor, SensorManager.SENSOR_DELAY_GAME);
    //        mMagSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    //        mSensorManager.registerListener(this, mMagSensor, SensorManager.SENSOR_DELAY_GAME);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.acquire();
}

From source file:com.kircherelectronics.gyroscopeexplorer.activity.filter.Orientation.java

@Override
public void onSensorChanged(SensorEvent event) {

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        // Get a local copy of the raw magnetic values from the device
        // sensor.

        event.values[2] = event.values[2] + 90;
        System.arraycopy(event.values, 0, this.vAcceleration, 0, this.vGyroscope.length);

        if (meanFilterSmoothingEnabled) {

            this.vAcceleration = meanFilterAcceleration.addSamples(this.vAcceleration);
        }//from www  .j a  va 2 s  .c om

        // We fuse the orientation of the magnetic and acceleration sensor
        // based on acceleration sensor updates. It could be done when the
        // magnetic sensor updates or when they both have updated if you
        // want to spend the resources to make the checks.
        calculateOrientationAccelMag();
    }

    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        // Get a local copy of the raw magnetic values from the device
        // sensor.
        System.arraycopy(event.values, 0, this.vMagnetic, 0, this.vGyroscope.length);

        if (meanFilterSmoothingEnabled) {
            this.vMagnetic = meanFilterMagnetic.addSamples(this.vMagnetic);
        }
    }

    if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
        System.arraycopy(event.values, 0, this.vGyroscope, 0, this.vGyroscope.length);

        if (meanFilterSmoothingEnabled) {
            this.vGyroscope = meanFilterGyroscope.addSamples(this.vGyroscope);
        }

        timeStampGyroscope = event.timestamp;

        onGyroscopeChanged();
    }

    if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) {
        System.arraycopy(event.values, 0, this.vGyroscope, 0, this.vGyroscope.length);

        if (meanFilterSmoothingEnabled) {
            this.vGyroscope = meanFilterGyroscope.addSamples(this.vGyroscope);
        }

        timeStampGyroscope = event.timestamp;

        onGyroscopeChanged();
    }

}

From source file:com.polyvi.xface.extension.XAccelerometerExt.java

/**
 * ?accelerometer sensor/*from   w  w  w . j a  v  a 2s.  c  om*/
 */
private void start() {
    if ((mStatus == RUNNING) || (mStatus == STARTING)) {
        return;
    }

    mStatus = STARTING;
    if (null == mSensorManager) {
        mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
    }

    List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);

    if ((list != null) && (list.size() > 0)) {
        mSensor = list.get(0);
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_UI);
    } else {
        mStatus = ERROR_FAILED_TO_START;
        mCallbackCtx.error("No sensors found to register accelerometer listening to.");
    }

    // Wait until running
    long timeout = 2000;
    while ((this.mStatus == STARTING) && (timeout > 0)) {
        timeout = timeout - 100;
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    if (timeout == 0) {
        mStatus = ERROR_FAILED_TO_START;
        mCallbackCtx.error("Accelerometer could not be started.");
    }
}

From source file:se.toxbee.sleepfighter.challenge.shake.ShakeChallenge.java

@Override
public void start(Activity activity, ChallengeResolvedParams params, Bundle state) {
    super.start(activity, params);

    this.activity().setContentView(R.layout.challenge_shake);

    // Get view references
    this.progressBar = (ProgressBar) this.activity().findViewById(R.id.progressBar);
    this.progressText = (TextView) this.activity().findViewById(R.id.progressText);

    // Check if required sensor is available
    boolean hasAccelerometer = activity.getPackageManager()
            .hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);
    if (!hasAccelerometer) {
        // Complete right away, for now. Checking if device has required
        // hardware could perhaps be done before the challenge is started.
        Log.e(TAG, "Device lacks required sensor for ShakeChallenge");
        this.complete();
        return;/*  ww  w.  j  av  a 2  s  .  c  om*/
    }

    // Register to get acceleration events
    this.sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
    this.accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

    // Get last progress from bundle, if it exists
    if (state != null) {
        this.progress = state.getFloat(KEY_PROGRESS_FLOAT);
    }
    updateProgress();
}

From source file:com.mruddy.devdataviewer.SensorFragment.java

/**
 * @see android.support.v4.app.Fragment#onResume()
 *//*from w w w. j a  va  2 s.co  m*/
@Override
public void onResume() {
    super.onResume();
    this.accelerometerTextView = (TextView) this.getActivity().findViewById(R.id.textViewAccelerometer);
    this.gpsTextView = (TextView) this.getActivity().findViewById(R.id.textViewGPS);
    this.sensorManager = (SensorManager) this.getActivity().getSystemService(Context.SENSOR_SERVICE);
    final Sensor accelerometerSensor = this.sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    if (null != accelerometerSensor) {
        this.accelerometerTextView.setText("waiting for data...");
        this.sensorManager.registerListener(this, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL);
    } else {
        this.accelerometerTextView.setText("accelerometer not found");
    }
    this.locationManager = (LocationManager) this.getActivity().getSystemService(Context.LOCATION_SERVICE);
    this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}