Prof. Christopher Rasmussen
May 9, 2017
CISC 181
Android:
Sensors, camera, faces
The Project
List<Sensor> getSensorList(Sensor.TYPE_ALL)
List<Sensor> getSensorList(Sensor.TYPE_ALL)
Sensors: Accelerometer
SensorManager SM = (SensorManager)
getApplicationContext().getSystemService(Context.SENSOR_SERVICE);�SM.registerListener(
new SensorListener(), // this is our custom class
SM.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SM.SENSOR_DELAY_NORMAL);
Sensors: Accelerometer
SensorManager SM = (SensorManager)
getApplicationContext().getSystemService(Context.SENSOR_SERVICE);�SM.registerListener(
new SensorListener(), // this is our custom class
SM.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SM.SENSOR_DELAY_NORMAL);
class SensorListener implements SensorEventListener {� public void onSensorChanged(SensorEvent event) {� if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {� aX = event.values[0]; aY = event.values[1];� aZ = event.values[2]; haveAccel = true;� }� }
� public void onAccuracyChanged(Sensor sensor, int accuracy) { }
}
And if you're really bored...
And if you're really bored...
VIBRATION!!!
The Camera
Review: Starting an activity
Review: Returning information
Starting an "external" photo activity
Starting an "external" photo activity
Starting an "external" photo activity
Intent takePictureIntent =
new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null)
Starting an "external" photo activity
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
mImageView.setImageBitmap(imageBitmap);
}
}
Starting an "external" video activity
Intent takeVideoIntent =
new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
Uri videoUri = intent.getData();
mVideoView.setVideoURI(videoUri);
}
}
Ever Wonder How This Works?
FaceDetector detector = new FaceDetector.Builder(context)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
.setTrackingEnabled(true)
.setMode(FaceDetector.FAST_MODE)
.setProminentFaceOnly(mIsFrontFacing)
.setMinFaceSize(mIsFrontFacing ? 0.35f : 0.15f)
.build();
FaceDetector detector = new FaceDetector.Builder(context)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
.setTrackingEnabled(true)
.setMode(FaceDetector.FAST_MODE)
.setProminentFaceOnly(mIsFrontFacing)
.setMinFaceSize(mIsFrontFacing ? 0.35f : 0.15f)
.build();