What's Happening Today Working with Images What does this mean for the UI? What does this mean for resources? What about shaking things up? What happens when you slip the schedule? … ...
Android Sensors https://developer.android.com/guide/topics/sensors/sensors_overview.html Sensors come in several flavors We'll only use accelerometer in examples Use is similar to other Android features Register Sensor in AndroidManifest.XML <uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
Registering/Using Sensor Typical of Observable Design Pattern https://en.wikipedia.org/wiki/Observer_pattern AKA Publish Subscribe Observer is registered with Observable, which typically could have several observers See code for getting SensorManager and the sensor/accelerometer RecyclerViewActivity
Create SensorEventListener This is the Observer in design pattern Standard Android, we use ShakeDetector and implement the Interface http://jasonmcreynolds.com/?p=388 Notice nested Interface in ShakeDetector Register a listener with this detector, what is doing the listening? Activity indirectly
Activity Life Cycle Code in onResume and onPause to handle the SensorManager and ShakeDetector What might happen in onPause if not unregistered? What does "listening" do? What's important in App management? Sensor can continue to collect data, but not be able to do anything with data
Android aside in ShakeDetector Notice float values in SensorManager What about value returned Math.sqrt? Is there an issue between float and double? Documentation for Android says … https://developer.android.com/training/articles/perf-tips.html What are the key take-aways on that page?
Code to handle shakes … Anonymous inner class to implement the OnShakeListener interface Expedient (?) way to call a method in the Activity, note the local method Take advantage of RecylerView Adapter Attention to all components in Adapter, e.g., The ViewHolder What happens in method updateList ?
Handling ClickEvents Another example of Observer pattern How does this happen with CardView? Examine RecyclerView.ViewHolder … Is this bound to position? How to test? What if we wanted to do more with click, not simply create a Toast How do we notify another Activity?
What is an Intent? Start one activity from another Start a service Launch when something happens Start a service Camera, phone, music player Broadcast message (app or service) Apps can respond
Intent basics Create Intent, provide Activity class Launch with method startActivity Store "extras" in intent to pass information from one activity to another Can also start activity and "wait" for result See these examples later