Wednesday, July 20, 2011

Cloud To Device Messaging

C2DM -  Cloud To Device Messaging.



    what is the Requirment?
  • We want to keep the data on the device fresh.

    What is Cloud to Device Messaging?
  • To push infromation from intrenet to android phone.This is called C2DM.

    When was it Intrduced?
  • From Android2.2 or API 8

    Why was this introduced?
  • The standard mechanism of application which requiers information from internet requires to poll periodically. which involves consumtion unnessary usage of bandwidth and battary use.

    How it works?
  • To use C2DM on your Android device you have to write an Android application.
  • This application should be registered with Google server to able to recive push messages from Google server.
  • Your server registers with the Google server and authenticates himself. Then your server can push messages to Google Server in turn push messages to the infromation to the devices.
  • For this authentication you reqire a Google user.

    what are the device Requirments?
  • C2DM only works only on Android2.2
  • Requires Android Market application is installed on the device.
  • To use C2DM on the Android emultor you also need to use a google device with API 8 or higher (Android 2.2 or above) and to register with a Google account on the emulator via the settings.
    What are C2DM Limitations?
  • Still in Labs
  • Message payload limited to 1024 bytes
  • Message be get last or be delivered out of order
  • No Support for TTL's - i cannot say that message expires if the devices is not avaiable in 2min .. but it will develiver the messages even the message is outdated
  • Quota limits are not clear

    How does the Information Flow?
  • In a C2DM you have three parties involved.
            1. The server which wants to push messages to the Android Device - Application server
            2. Google C2DM Server
            3. Android Application

  • To enable C2DM for an Android application, your application must register with the Google C2DM servers. After registration it receives a registration ID from Google C2DM Servers.
  • The Android Applicatoin must then send the registration ID to its application server.
  • When the application server needs to push a message to the Android application, it sends the message via HTTP GET to Google C2DM servers.
  • The C2DM servers route the message to the device once the device is available, and an intent broadcast is sent to the Android application.

    How the registration process takes place?
  • To register your application for the C2DM service your application needs fire an registration intent "com.google.android.c2dm.intent.REGISTER" to C2DM server.
    This intent includes a Google mail address and the application ID.
  • Upon successful registration the C2DM server broadcast a REGISTRATION intent to the application which includes a registration ID. Each registration ID represents
          a particular device, e.g. every Android phone will recive its own registration code.

Open GL Concepts


OpenGLES From the Ground Up, Part 1: Basic Concepts

OpenGL Data Types:
  •  OpenGL is a cross-platform API, and the size of data types can vary depending on the programming language being used as well as the underlying processor (64bit, 32bit,16bit).
  •  OpenGL maintains in own custom data types. When passing data to the OpenGL you need thru the OpenGL Data types.
Here are OpenGL ES Data types:-

GLenum: An unsigned integer used for GL-specific enumerations. Most commonly used to tell OpenGL the type of data stored in an array passed by pointer to indicate that the array is made up GLfloats.

GLboolean: Used to hold a single Boolean value.  OpenGLES also declares its own true and false values (GL_TRUE and GL_FALSE) to avoid platform and language differences. You can also pass YES or NO it won't heart you but it is good to following the GL defined values.

GLbitfield: These are four-byte integers used to pack multiple Boolean values (up to 32) into single variables using bitwise operators.

GLbyte: A Signed, one-byte integer capable of holding a value from -128 to 127

GLShort: A Signed, two-byte integer capable of holding a value between -32,768 to 32,767

GLint: A Signed four-byte integer capable of holding a value between -2,147,483,648 and 2,147,483,647

GLsizei: A signed, four-byte integer used to represent the size of data, similar to size_t in C.

GLubyte: An unsigned, two-byte integer capable of holding a value between 0 and 255

GLushort: A unsigned, two-byte integer capable of holding a value between 0  and 65,535

GLuint: An unsigned, fout-byte integer capable of holding value between 0 and 4,294,967,295

GLfloat:

GLclampf:

GLvoid:

GLfixed:

GLclampx:


The Point or Vertex:    
  • The atomic unit in 3D graphics is called the point or vertex.
  • These represent a single spot in three dimensional space and are used to build more complex objects.
            Definition of Polygon: In geometry polygon is a  plane figure that is bounded by a closed path or circuit, composed of finite sequence of straight line segments.
  • Polygons are prepared out of these points and objects prepared out of these polygons.
  • Open GL ES only supports the use of three sided polygon (Aka triangle)


  • Select an arbitrary point in space and call it the Origin.
  • You can then designate any point in space referencing the origin
  •  Core Graphics, which is another framework for doing graphics on iPhone uses a slightly different coordinate system in that the y axis decreases as it goes up from the origin, and increases as it goes down.
  • Since any object's location in three-dimensional space can be represented by three values, an object's position is generally represented in OpenGL by the use of three GLfloat variables.
                        GLfloat vertex [3];
                        vertex [0] = 10.0;        - > x-position
                        vertex [1] = 23.75;      - > y-position
                        vertex [2] = -12.532;   - > z-position

  • In OpenGL ES, you generally submit all the vertices that make up some or all the objects in your scene as a vertex array.
  • A vertex array is simply an array of values that contains the vertex data for some or all of the objects in the world.
  • we can define a data structure to hold a single vertex, like this
            typedef struct {
GLfloat x;
                        GLfloat y;
                        GLfloat z;
            } Vertex3D;

By doing this, our code becomes much more readable:

                        Vertex3D vertex;
                        vertex.x = 10.0;
                        vertex.y = 13.75;
                        vertex.z = -12.532;
  • Distance between two points in three-dimensional space with this simple inline function:
                      
            We can implement this formula to calculate the straight-line distance between any two points in three-dimensional space with this simple inline function:
static inline GLfloat Vertex3DCalculateDistanceBetweenVertices (Vertex3D first, Vertex3D second)
{
    GLfloat deltaX = second.x - first.x;
    GLfloat deltaY = second.y - first.y;
    GLfloat deltaZ = second.z - first.z;
    return sqrtf(deltaX*deltaX + deltaY*deltaY + deltaZ*deltaZ );
};
 -------------------------------------------------------------------------------------------------------------------------
 -------------------------------------------------------------------------------------------------------------------------
Triangles:
Since OpenGL ES only support Triangles, we can also create a data structure to group three vertices into single triangle object.
typedef struct {
            Vertex3D v1;
            Vertex3D v2;
            Vertex3D v3;
}Triangle3D;

Winding: which just means that the order in which the vertices are drawn matters.

Front Face: Unlike the objects in the real world which is having two sides. The objects in the OpenGL have one side, which is considered the front face, which is facing the viewer.

Blackface: The side which is not visible and the side which isn’t drawn are called a blackface.

-          OpenGL determines which front face and which is the back face by looking at the drawing order of the vertices.






Sunday, June 12, 2011

How to display the maps in the Android Maps

1. How to display the maps in the Android Maps?

To display the Google Maps we use the follwoing Code the view

   <com.google.android.maps.MapView android:id="@+id/myGMap"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:enabled="true"
         android:clickable="true"
         android:apiKey="ANDROID KEY"/>

in this the main part is "android:apiKey" this will be unique of each user

How to Generate this?
1. Identify the .android folder (Normally this will be available in the C:\Users\puneethkhanna.sakshi)
2. C:\Users\puneethkhanna.sakshi>keytool -list -alias androiddebugkey -keystore .android\debug.keystore -storepass android -keypass android

androiddebugkey, Nov 23, 2010, PrivateKeyEntry,

Certificate fingerprint (MD5): 72:B2:12:54:1D:B4:49:3F:C7:13:C4:7F:F1:29:3B:27
3. http://code.google.com/android/maps-api-signup.html
4. place the generated key in the  "android:apiKey". Now the map appears in the app.

Wednesday, January 5, 2011

Android Layouts....

Android Layouts ....


Here in this post i want to talk about the android Layouts in short want to give 360 Degrees view of Layouts ...


There are total Five Layouts in Android.

1. Absolute Layout
2. Frame Layout
3. Linear Layout
4. Relative Layout
5. Table Layout

AbsoluteLayout

Absolute Layout is based on the simple idea of placing each control at an absolute position.  You specify the exact x and y coordinates on the screen for each control.  This is not recommended for most UI development (in fact Absolute Layout is currently deprecated) since absolutely positioning every element on the screen makes an inflexible UI that is much more difficult to maintain.  Consider what happens if a control needs to be added to the UI. You would have to change the position of every single element that is shifted by the new control.

Here is a sample Layout XML using AbsoluteLayout.

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button 
     android:id="@+id/backbutton"
     android:text="Back"
     android:layout_x="10px"
     android:layout_y="5px"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
    <TextView
     android:layout_x="10px"
     android:layout_y="110px"
     android:text="First Name"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
    <EditText
     android:layout_x="150px"
     android:layout_y="100px"
     android:width="100px"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
    <TextView
     android:layout_x="10px"
     android:layout_y="160px"
     android:text="Last Name"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
     <EditText
     android:layout_x="150px"
     android:layout_y="150px"
     android:width="100px"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
</AbsoluteLayout>

Note how each element has android:layout_x and android:layout_y specified. Android defines the top left of the screen as (0,0) so the layout_x value will move the control to the right, and the layout_y value will move the control down. Here is a screenshot of the layout produced by this XML.

FrameLayout

FrameLayout is designed to display a single item at a time. You can have multiple elements within a FrameLayout but each element will be positioned based on the top left of the screen. Elements that overlap will be displayed overlapping. I have created a simple XML layout using FrameLayout that shows how this works.

<FrameLayout 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 xmlns:android="http://schemas.android.com/apk/res/android">
 <ImageView 
  android:src="@drawable/icon"
  android:scaleType="fitCenter"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"/>
 <TextView
  android:text="Learn-Android.com"
  android:textSize="24sp"
  android:textColor="#000000"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"
  android:gravity="center"/>
</FrameLayout>
 
Here is the result of this XML.
 
 
You can see I had both the ImageView and TextView fill the parent in both horizontal and vertical layout. Gravity specifies where the text appears within its container, so I set that to center. If I had not set a gravity then the text would have appeared at the top left of the screen.

FrameLayout can become more useful when elements are hidden and displayed programmatically. You can use the attribute android:visibility in the XML to hide specific elements. You can call setVisibility from the code to accomplish the same thing. The three available visibility values are visible, invisible (does not display, but still takes up space in the layout), and gone (does not display, and does not take space in the layout).
So you could, for example, have a game in a FrameView where text displayed to the user is visible in the middle of the screen at appropriate times (e.g. “Game Over”).

LinearLayout

LinearLayout organizes elements along a single line. You specify whether that line is verticle or horizontal using android:orientation. Here is a sample Layout XML using LinearLayout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="horizontal"
 android:layout_width="fill_parent"
    android:layout_height="fill_parent">
     <Button 
     android:id="@+id/backbutton"
     android:text="Back"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
    <TextView
     android:text="First Name"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
    <EditText
     android:width="100px"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
    <TextView
     android:text="Last Name"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
    <EditText
     android:width="100px"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" /> 
</LinearLayout>
 
Here is a screenshot of the result of the above XML.
 
Here is a screenshot of the same XML except that the android:orientation has been changed to horizontal.
 
You might note that the EditText field at the end of the line has had its width reduced in order to fit. Android will try to make adjustments when necessary to fit items on screen. The last page of this tutorial will cover one method to help deal with this. I mentioned on the first page that Layouts can be nested. LinearLayout is frequently nested, with horizontal and vertical layouts mixed. Here is an example of this.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
    android:layout_height="fill_parent">
     <Button 
     android:id="@+id/backbutton"
     android:text="Back"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
    <LinearLayout
     android:orientation="horizontal"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content">
     <TextView
      android:text="First Name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
     <EditText
      android:width="100px"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" /> 
    </LinearLayout>
    <LinearLayout
     android:orientation="horizontal"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content">    
     <TextView
      android:text="Last Name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
     <EditText
      android:width="100px"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
    </LinearLayout> 
</LinearLayout>

           You might note that the EditText field at the end of the line has had its width reduced in order to fit. Android will try to make adjustments when necessary to fit items on screen. The last page of this tutorial will cover one method to help deal with this. I mentioned on the first page that Layouts can be nested. LinearLayout is frequently nested, with horizontal and vertical layouts mixed. Here is an example of this.

 Nested Layouts do not have to be of one type. I could, for example, have a LinearLayout as one of the children in a FrameLayout.

 

RelativeLayout

RelativeLayout lays out elements based on their relationships with one another, and with the parent container. This is arguably the most complicated layout, and we need several properties to actually get the layout we want.

Relative To Container

These properties will layout elements relative to the parent container.
  • android:layout_alignParentBottom – Places the bottom of the element on the bottom of the container
  • android:layout_alignParentLeft – Places the left of the element on the left side of the container
  • android:layout_alignParentRight – Places the right of the element on the right side of the container
  • android:layout_alignParentTop – Places the element at the top of the container
  • android:layout_centerHorizontal – Centers the element horizontally within its parent container
  • android:layout_centerInParent – Centers the element both horizontally and vertically within its container
  • android:layout_centerVertical – Centers the element vertically within its parent container

Relative To Other Elements

These properties allow you to layout elements relative to other elements on screen. The value for each of these elements is the id of the element you are using to layout the new element. Each element that is used in this way must have an ID defined using android:id=”@+id/XXXXX” where XXXXX is replaced with the desired id. You use “@id/XXXXX” to reference an element by its id. One thing to remember is that referencing an element before it has been declared will produce an error.
  • android:layout_above – Places the element above the specified element
  • android:layout_below – Places the element below the specified element
  • android:layout_toLeftOf – Places the element to the left of the specified element
  • android:layout_toRightOf – Places the element to the right of the specified element

Alignment With Other Elements

These properties allow you to specify how elements are aligned in relation to other elements.
  • android:layout_alignBaseline – Aligns baseline of the new element with the baseline of the specified element
  • android:layout_alignBottom – Aligns the bottom of new element in with the bottom of the specified element
  • android:layout_alignLeft – Aligns left edge of the new element with the left edge of the specified element
  • android:layout_alignRight – Aligns right edge of the new element with the right edge of the specified element
  • android:layout_alignTop – Places top of the new element in alignment with the top of the specified element
Here is a sample XML Layout

<RelativeLayout 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 xmlns:android="http://schemas.android.com/apk/res/android">
 <Button 
   android:id="@+id/backbutton"
   android:text="Back"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content" />
 <TextView
     android:id="@+id/firstName"
     android:text="First Name"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_below="@id/backbutton" />
 <EditText
  android:width="100px"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toRightOf="@id/firstName"
  android:layout_alignBaseline="@id/firstName" />
 <TextView
  android:id="@+id/lastName"
  android:text="Last Name"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_below="@id/firstName" />
 <EditText
  android:width="100px"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toRightOf="@id/lastName"
  android:layout_alignBaseline="@id/lastName" />
</RelativeLayout>
 
Here is the screen produced by that XML.
 
 
 I wanted to show this to you because the first time I made a RelativeLayout I did exactly this and then looked at the screen and said, “Hang on a minute, that’s not what I wanted!” The problem here is that when Android draws the TextView lastName below the TextView firstName it only sets aside the space it needs for the TextView. Android only reads the Layout XML one time so it doesn’t know that an EditView is the next item and doesn’t plan for it. So when the EditView is drawn to the right of the TextView it only has the height of the TextView to work with so it overlaps the EditView above it. Here is the Layout XML I wrote to create the form the way it should look.


<RelativeLayout 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 xmlns:android="http://schemas.android.com/apk/res/android">
 <Button 
   android:id="@+id/backbutton"
   android:text="Back"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content" />
 <TextView
     android:id="@+id/firstName"
     android:text="First Name"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_below="@id/backbutton" />
 <EditText
  android:id="@+id/editFirstName"
  android:width="100px"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toRightOf="@id/firstName"
  android:layout_below="@id/backbutton"/>
 <EditText
  android:id="@+id/editLastName"
  android:width="100px"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_below="@id/editFirstName"
  android:layout_alignLeft="@id/editFirstName"/>
 <TextView
  android:id="@+id/lastName"
  android:text="Last Name"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toLeftOf="@id/editLastName"
  android:layout_below="@id/editFirstName" /> 
</RelativeLayout>
 
You probably noticed that I had to rearrange the elements in the XML since, as I already mentioned, you cannot reference an element that has not already been laid out. Here is what the updated RelativeLayout
produces.


 

TableLayout

TableLayout organizes content into rows and columns. The rows are defined in the layout XML, and the columns are determined automatically by Android. This is done by creating at least one column for each element. So, for example, if you had a row with two elements and a row with five elements then you would have a layout with two rows and five columns.

You can specify that an element should occupy more than one column using android:layout_span. This can increase the total column count as well, so if we have a row with two elements and each element has android:layout_span=”3″ then you will have at least six columns in your table.
By default, Android places each element in the first unused column in the row. You can, however, specify the column an element should occupy using android:layout_column.

Here is some sample XML using TableLayout.

<TableLayout 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 xmlns:android="http://schemas.android.com/apk/res/android">
 <TableRow>
  <Button 
      android:id="@+id/backbutton"
      android:text="Back"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
 </TableRow>
 <TableRow>
  <TextView
      android:text="First Name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_column="1" />
      <EditText
      android:width="100px"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
 </TableRow>
 <TableRow>
  <TextView
      android:text="Last Name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_column="1" />
      <EditText
      android:width="100px"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" /> 
 </TableRow>
</TableLayout>

This is the result of that XML.




 thanks
puneeth khanna sakshi