pratiktest
7/10/2016 - 5:04 AM

android

android

Setup

Android project

create a simple android project in android studio which will create a simple Hello World app

  • app/res/layout/activity_my.xml

    This is the layout for main activity

  • app/manifests folder

    This contains the basic information of the app

  • app/build.gradle

    • This contains gradle scripts to compile and build the app
    • This is where apps build dependencies are set
    • Make sure you compile (compiledSdkVersion in gradle) is set to 4.1 or higher, else download sdk from android sdk manager
    • targetSdkVersion indicates the highest version of android against which you have tested your application. As new versions of android become available you need to test them against the newer versiona and update this field.
  • drawable-

    Directory for drawables like icons designed for different [densities] (https://developer.android.com/training/multiscreen/screendensities.html)

  • menu

  • minmap

    You can put launcher icons here instead of drawables

  • values

    Constant values like Strings and colors etc

#Android Sensors

  • There are two types of sensors in android
    • Hardware based
    • Software Based

Hardware based sensors directly interface with environment one to one. Software based sensors derive data from one or more hardware based sensor

  • We can access the sensors using Android Sensor Framework

  • Android sensor framework is part of android.hardware package

  • Two methods are important

    • OnAccuracyChanged
    • OnSensorChanged ... These are final methods that means they cannot be subclassed

Cordinate system

* Co-ordinate system is defined with respect to the default orientation. For some devices the default orientation is landscape hence we should not assume that the default orientation is potrait
* The coordinate system dosent change as the orientation changes. It is fixed. This behaviour is same as OpenGL systems
* The co-ordinate system is with respect to the default orientation of devide. X is horizontal and points to right, Y is vertical and points up, Z points towards outside of screen face

motion sensors

  • Motion sensors are important for measuring the device movement
  • device movement can be with respect to reference frame of device (tilting phone to tilt the ball in game), or the worlds reference frame (chaning sensors when you are moving in actual car)
  • All motion sensors return a multidimentional array of sensor values of SensorEvent
  • We are interested in rotation vector which measures the vector component of rotation along the x, y and z axis and scalar component , which is the actual value (this is actually sqrt (x^2 + y^2 + z^2)), so final value is not needed