CIS 470 Mobile App Development

Slides:



Advertisements
Similar presentations
Android Sensors & Async Callbacks Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
Advertisements

Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
EEC-492/592 Kinect Application Development Lecture 10 Wenbing Zhao
Getting Started with Android APIs Ivan Wong. Motivation - “Datasheet” - Recently exposed to what’s available in Android - So let’s see what API’s are.
Mobile Programming Lecture 9 Bound Service, Location, Sensors, IntentFilter.
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
Cosc 5/4730 Introduction: Threads, Android Activities, and MVC.
Doodlz App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
DUE Hello World on the Android Platform.
1 CMSC 628: Introduction to Mobile Computing Nilanjan Banerjee Introduction to Mobile Computing University of Maryland Baltimore County
로봇을 조종하자 3/4 UNIT 17 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 스마트 폰의 센서를 사용할 수 있다. 2.
Android Using Menus Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
New Activity On Button Click via Intent. App->res->Layout->Blank Activity A new xml file is created and a new class is added to java folder. In manifest.xml.
Sensors in android. App being more applicable Keeping track of your heart beat while jogging. Pointing the phone camera towards the night sky to know.
Android Application Lifecycle and Menus
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors Date: Feb 11, 2016.
CPE 490/590 – Smartphone Development
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
CS499 – Mobile Application Development Fall 2013 Location & Maps.
Android Android Sensors Android Sensors: – Accelerometer – Gravity sensor – Linear Acceleration sensor – Magnetic Field sensor – Orientation.
Sensors in Android.
Vijay Kumar Kolagani Dr. Yingcai Xiao
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors
Introduction to android
Android Mobile Application Development
Java Examples Embedded System Software
GUI Programming Fundamentals
Queues Rem Collier Room A1.02
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors.
Harvesting Runtime Values in Android Applications That Feature Anti-Analysis Techniques Presented by Vikraman Mohan.
CS499 – Mobile Application Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
EEC-693/793 Applied Computer Vision with Depth Cameras
Android Topics Sensors Accelerometer and the Coordinate System
CIS 470 Mobile App Development
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors.
CIS 493/EEC 492 Android Sensor Programming
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Sensor Programming
CIS 470 Mobile App Development
EEC-693/793 Applied Computer Vision with Depth Cameras
CIS 493/EEC 492 Android Sensor Programming
CIS 470 Mobile App Development
CIS 493/EEC 492 Android Sensor Programming
Mobile Programming Sensors in Android.
Data Structures & Algorithms
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Mobile Programming Broadcast Receivers.
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 470 Mobile App Development
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

CIS 470 Mobile App Development Lecture 24 Wenbing Zhao Department of Electrical Engineering and Computer Science Cleveland State University wenbing@ieee.org 11/17/2018 CIS 470: Mobile App Development

Step Counting (Pedometer) Taken from Android Sensor Programming By Example, Packt Publishing, 2016 Step detector and step counter sensors A custom algorithm using the accelerometer sensor’s data to detect walking, jogging, and fast running activities 11/17/2018 CIS 470: Mobile App Development

CIS 470: Mobile App Development Step Counter Sensor The step counter sensor is used to get the total number of steps taken by the user since the last reboot of the phone The value of the step counter sensor is reset to zero on reboot In the onSensorChanged() method, the number of steps is given by event.value[0] The event timestamp represents the time at which the last step was taken This sensor is especially useful for those applications that don't want to run in the background and maintain the history of steps themselves This sensor works in the batch and continuous modes. If we specify 0 or no latency in the SensorManager.registerListener() method, then it works in continuous mode, otherwise, if we specify any latency, then it groups the events in batches and reports them at a specified latency 11/17/2018 CIS 470: Mobile App Development

CIS 470: Mobile App Development Step Counter APIs protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.stepcounter_layout); mStepsSinceReboot = (TextView)findViewById(R.id.stepssincereboot); mSensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE); if(mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER) != null) { mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); isSensorPresent = true; } else { isSensorPresent = false; } } public void onSensorChanged(SensorEvent event) { mStepsSinceReboot.setText("Steps since reboot:" + String.valueOf(event.values[0])); } 11/17/2018 CIS 470: Mobile App Development

CIS 470: Mobile App Development Step Detector Sensor The step detector sensor triggers an event each time a step is taken by the user The value reported in the onSensorChanged() method is always one, the fractional part is always zero, and the event timestamp is the moment that the user's foot hits the ground The step detector sensor has lower accuracy and produces more false positives compared to the step counter sensor The step counter sensor is more accurate, but it has more latency in reporting the steps, as it uses extra time after each step to remove any false positive values The step detector sensor is recommended for those applications that want to track the steps in real time and maintain their own history of each and every step with their timestamp 11/17/2018 CIS 470: Mobile App Development

CIS 470: Mobile App Development Step Detector APIs public void onCreate() { super.onCreate(); mSensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE); if(mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR) != null) { mStepDetectorSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR); mSensorManager.registerListener(this, mStepDetectorSensor, SensorManager.SENSOR_DELAY_NORMAL); mStepsDBHelper = new StepsDBHelper(getApplicationContext()); } } public void onSensorChanged(SensorEvent event) { mStepsDBHelper.createStepsEntry(); } onSensorChanged() is called for every step 11/17/2018 CIS 470: Mobile App Development

Custom Step Counting and Activity Detection Step counting: count number of peaks/valleys Types of activities: highest peak values private static final int WALKINGPEAK = 18; private static final int JOGGINGPEAK = 25; private static final int RUNNINGPEAK = 32; Green circle: true peak Red circle: valley Yellow circle: false peak (to be filtered out) 11/17/2018 CIS 470: Mobile App Development

CIS 470: Mobile App Development Detect Peaks public void findHighPeaks() { //Calculating the High Peaks boolean isAboveMeanLastValueTrue = false; int dataSize = mRawDataList.size(); for (int i = 0; i < dataSize; i++) { if(mRawDataList.get(i).value > WALKINGPEAK) { // add all continuous data points that are bigger than WALKINGPEAK to the array // One of these points include both the true peak and the false peaks, and many other points that are not peaks mAboveThresholdValuesList.add(mRawDataList.get(i)); isAboveMeanLastValueTrue = false; } else { // Once we see a point that is below the threshold, we are falling out of the peak region // Now time to find the peaks if(!isAboveMeanLastValueTrue && mAboveThresholdValuesList.size()>0) { // Sort the temporary data array. The last one in the array has the biggest value, which is the peak // which could be true or false peak Collections.sort(mAboveThresholdValuesList,new DataSorter()); mHighestPeakList.add(mAboveThresholdValuesList.get(mAboveThresholdValuesList.size()-1)); mAboveThresholdValuesList.clear(); } isAboveMeanLastValueTrue = true; } } } 11/17/2018 CIS 470: Mobile App Development

CIS 470: Mobile App Development public void removeClosePeaks() { for (int i = 0; i < mHighestPeakList.size()-1; i++) { if(mHighestPeakList.get(i).isRealPeak) { if(mHighestPeakList.get(i+1).time - mHighestPeakList.get(i).time < 400) { if(mHighestPeakList.get(i+1).value > mHighestPeakList.get(i).value) { mHighestPeakList.get(i).isRealPeak = false; } else { mHighestPeakList.get(i+1).isRealPeak = false; } } } } } Observation: false peaks are very close to the true peak. Use this fact to filter them out 11/17/2018 CIS 470: Mobile App Development

CIS 470: Mobile App Development The Pedometer app Create an app and name it MyPedometer Replace existing manifests, activity_main.xml, styles.xml, strings.xml, MainActivity.java with the source code provided in the course webpage Add the following java files: AccelerometerData.java, CustomAlgoResultsActivity.java, DateStepsModel.java, ListAdapter.java, StepsCounterActivity.java, StepsDBHelper.java, StepsHistoryActivity.java, StepsService.java, StepsTrackerDBHelper.java, StepsTrackerService.java Add the following xml files: capability_layout.java, list_rows.xml, pedomesterlist_layout.xml, stepcounter_layout.xml, list_raw_divider_gradient.xml 11/17/2018 CIS 470: Mobile App Development

CIS 470: Mobile App Development The Pedometer app 11/17/2018 CIS 470: Mobile App Development

CIS 470: Mobile App Development Exercise If you compare the step count using the API and that from the custom algorithm, you will see they are different depending on where you place the phone Make the three parameters for activity detection for walking, jogging, and running (18, 25, 32) customizable in the app itself dynamically, e.g., by adding three TextEdits and a button, so that the result from the custom algorithm is similar to result from the APIs 11/17/2018 CIS 470: Mobile App Development