Presentation is loading. Please wait.

Presentation is loading. Please wait.

Vijay Kumar Kolagani Dr. Yingcai Xiao

Similar presentations


Presentation on theme: "Vijay Kumar Kolagani Dr. Yingcai Xiao"— Presentation transcript:

1 Vijay Kumar Kolagani Dr. Yingcai Xiao
Android Vijay Kumar Kolagani Dr. Yingcai Xiao

2 Architecture of Smart Phone APPS

3 Programming Smart Phone APPS: OO-EDP
Smart phones are computers that support advanced HCI (Human Computer Interaction), more than just GUI. HCI: input, output Input: A/V, touch, sensors, remote, composite events (key entry), … Output: screen, mirroring, VR, haptic, text (Internationalization), … EDP: implement event-handlers. Look for interested input events to start. OOP: Android apps written in Java (object-oriented), so look for needed parent classes to start.

4 Development Tools Android software are developed with IDEs (Integrated Development Environment). Java Development Kit (JDK) Android Software Development Kit includes the Eclipse Android IDE / Android Studio and the Android Development Toolkit (ADT) Eclipse for Android developers : Android Studio :

5 Programming Using Android Studio IDE

6 Setup Android Studio Android studio : For Macs, download the dmg file and open it to install. Select standard installation. Start Android Studio. Select an existing sample (say, Universal Music Player). Update any components when asked to do so. Try other examples in the studio.

7 Setup Android Studio To interact with your Android phone on a computer, download the Vysor Chrome app. On your Android phone: Settings Develop options (if your don’t see the options, go to “About Phone”, click “Build number” several times until it says you are now a developer. :-). Turn on USB Debugging Connect you phone to the computer’s USB port. Now go to Chrome (After installing the plugin) chrome://apps/ Select Vysor When asked on the phone for connection type: select MIDI

8 EDP: Input/EVENTS

9 Android Interactions Voice Control Touch Screen Sensor Control

10 Sensors Overview The Android platform supports three broad categories of sensors: Motion sensors: these sensors measure acceleration forces and rotational forces along three axes. This category includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors. Environmental sensors: these sensors measure various environmental parameters, such as ambient air temperature and pressure, illumination, and humidity. This category includes barometers, photometers, and thermometers. Position sensors: these sensors measure the physical position of a device. This category includes, GPS, orientation sensors and magnetometers.

11 OOP: Classes

12 Sensor Framework The sensor framework is part of the android.Hardware package and includes the following classes and interfaces: Sensormanager You can use this class to create an instance of the sensor service. This class provides various methods for accessing and listing sensors, registering and unregistering sensor event listeners, and acquiring orientation information. This class also provides several sensor constants that are used to report sensor accuracy, set data acquisition rates, and calibrate sensors. Sensor You can use this class to create an instance of a specific sensor. This class provides various methods that let you determine a sensor's capabilities. Sensorevent The system uses this class to create a sensor event object, which provides information about a sensor event. A sensor event object includes the following information: the raw sensor data, the type of sensor that generated the event, the accuracy of the data, and the timestamp for the event. Sensoreventlistener You can use this interface to create two callback methods that receive notifications (sensor events) when sensor values change or when sensor accuracy changes.

13 OO-EDP Identifying sensors and sensor capabilities.
To use sensor-related APIs we perform two basic tasks: Identifying sensors and sensor capabilities. Write handlers for identified events/sensors by extending existing classes.

14 Identifying sensors and sensor capabilities
Create an instance of the sensormanager class by calling the getsystemservice() method and passing in the sensor_service argument. We can determine whether A specific type of sensor exists on A device by using the getdefaultsensor() method and passing in the type constant for A specific sensor for example: private SensorManager mSensorManager; ... mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); if (mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null){ // Success! There's a Accelerometer. } else { // Failure! No Accelerometer. }

15 Monitoring Sensor Events
To monitor raw sensor data you need to implement two callback methods that are exposed through the sensoreventlistener interface: onaccuracychanged() and onsensorchanged() this methods are called whenever the following occurs: A sensor's accuracy changes. In this case the system invokes the onaccuracychanged() method, providing you with a reference to the sensor object that changed and the new accuracy of the sensor. Accuracy is represented by one of four status constants SENSOR_STATUS_ACCURACY_LOW, SENSOR_STATUS_ACCURACY_MEDIUM,SENSOR_STATUS_ACCURACY_HIGH, or SENSOR_STATUS_UNRELIABLE. A sensor reports a new value. In this case the system invokes the onsensorchanged() method, providing you with a sensorevent object. A sensorevent object contains information about the new sensor data, including: the accuracy of the data, the sensor that generated the data, the timestamp at which the data was generated, and the new data that the sensor recorded.

16 Accelerometer It measures the acceleration force in m/s2 that is applied to a device on all three physical axes (x, y, and z), including the force of gravity. Public void onsensorchange(sensorevent sensorevent) {     sensor mysensor = sensorevent.Sensor;     If (mysensor.Gettype() == sensor.Type_accelerometer) {         float x = sensorevent.Values[0];         Float y = sensorevent.Values[1];         Float z = sensorevent.Values[2];     } }

17 Map Example Start Android Studio Start a new project
Select the Map project from the examples Import anything it asks you Two files will be generated: google_map_api.xml MapsActivity.java Run->Run ‘app’ (the paly button). It will ask you create an emulator if you have not done so. Select a smart phone to emulate.

18 Map Example

19 Resources Resources are non-coding elements of the application
String resources (for Internationalization) Configuration resources (for GUI setting and DB connections) Get a Google Map key by following the instructions in google_map_api.xml Modify the google_maps_key. Run ‘app’ again. <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyD-eK-tf32qnGIS4RueDX09aG6EuyZclnE</string>

20 Resources

21 Using Unity

22 Check if it is android platform or not
#if UNITY_ANDROID Currentplatformandroid = true; #Else Currentplatformandroid = false; #Endif Measure linear acceleration of a device in three-dimensional space. Input.Acceleration.X; // X axis Input.Acceleration.Y; // Y axis Input.Acceleration.Z; // Z axis

23 References mobile-22125


Download ppt "Vijay Kumar Kolagani Dr. Yingcai Xiao"

Similar presentations


Ads by Google