Archive

Posts Tagged ‘android’

Comparison of Google’s Honeycomb OS with Apple OS

February 17th, 2011 No comments

Apple has enjoyed highest market share pie in its OS market for Tablets & Phones for the past few years. But Google’s Android OS is proving to be the tough contender for them by launching better version at consistent interval & Honeycomb OS version is the one such new product by them. Honeycomb OS version has many features which is unavailable in the Apple’s OS & is currently seen as the next biggest market player in OS market. Some of the comparison between Apple OS and Google’s Honeycomb OS are as follows:-

Read more…

Categories: Tech news Tags: ,

Google Android Honeycomb OS Features

February 17th, 2011 No comments

Google has recently released some new attractive features in the newly launched honeycomb version of Android OS and since then public is vying to get a glimpse of the newly introduced Honeycomb OS features. So if you are geekozoid & looking for the quick run down on Honeycomb features then the complete ready reckoner is here for you:-

Fastest version: Google other Android OS versions like Gingerbread is faster but the Honeycomb version gives you fastest speed, letting the customers to demand more such version.

Compatible with all previous apps: - Android Honeycomb OS version is compatible with all the previously launched application whereas this feature is unavailable in Google’s other Android OS version.

Compatible with Tablets & Phones: - You can run your Android honeycomb OS on your tablet with as much ease as on phone.

Button free Tablets: - Honeycomb version has completely removed the requirement of physical button in Tablets thus making the Tablets all the more light weight in comparison to previous Tablets. By installing honeycomb version button in tablets would appear on the tablets screen & its position is smartly designed so that it will always appear on the bottom side no matter in which direction you are rotating your tablet.

Widget Friendly: - Customers often complained about limited option in Android OS widget features but you don’t have to any more as Honeycomb comes with some very handy, smooth widgets full of customized graphics & range of attractive widget features. Email widgets, calendar widgets are some of the widgets you have to watch for in the honeycomb version.

Video chat in Google talk: - Android OS honeycomb version gives you option of doing video chat in your gtalk apps which has been much awaited by customers. Read more…

Categories: Tech news Tags:

How to develop games on Android

February 14th, 2011 7 comments

One of the biggest markets in smart phones is games.  I am sure most of us would have played around with “Angry Birds” .  In this games tutorial you will learn different methods of developing  “Android Games”

At the end of the post is the video on how the code below works and the zip of all the source files used in this example.

Android Games can be developed in 3 ways

1)   Developing games using Android/Java libraries

2)   Developing games using External Libraries like OpenGL

3)   Developing games by porting existing c-game (pc game) to android.

Before getting started I assume that the reader is familiar with the basics of android programming like using activity, creating views, handling motion/touch events etc.

Also, apart from android sdk and eclipse some other tools are required for the game development. Details of the tools required, how to configure and use them will be explained as and when required. I will recommend to check out our last posts

Before starting with the game development lets understand the term “Main Loop”.

Main Loop:

Not just android any game written on any language consists of a set of custom views which are constantly refreshed/re-painted/re-drawn.  In some games we need to update the screen or re-draw the view elements at regular intervals.

E.g. consider two games (i) Android Snake Game (ii) Android Number Game for kids as shown.

In android snake game the snake has to move irrespective of the user input. Here the screen has to regularly re-drawn/re-painted to create the motion effect of the snake. Where as in the Number  game we need not redraw the screen now and then. The screen must be updated/re-drawn only when the user clicks/touches the screen.

So in the snake game we must re-draw the screen at regular intervals say 1sec in order to do that we make use of threads, while loops etc. and create a refresh/re-draw handler that updates screen regularly. This refresh/re-draw loop created is called “Main Loop”. Read more…

Categories: Programming / tutorials Tags: ,

Parsing JSON Results in Android

January 26th, 2011 8 comments

One of the common requirements for an android programmer is how to parse incoming JSON results from another web service or application into android. JSON is a data interchange format, and serves the same purpose as that of XML. XML is slowly being replaced by JSON because it’s easy to parse, light weight, and efficient too. We had talked about SOAP vs JSON earlier and not going to go into details again.

Let us focus on how to parse JSON results in Android.

We can parse JSON by 2 methods

i)  Using JSONObject and JSONTokener classes provided by Android SDK.
ii) Using external libraries. E.g GSON, Jackson etc.
(for more details refer http://json.org)

Let’s consider JSON data of the form:

{
“name”: “myName”,
“message”: [“myMessage1″,”myMessage2″],
“place”: “myPlace”,
“date”:  “thisDate”
}

Parsing JSON data using JSONTokener


public
class main extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

try {

/* Inflate TextView from the layout */

TextView tv = (TextView)findViewById(R.id.TextView01);

/* JSON data considered as an example. Generally this data is obtained

from a web service.*/

String json = “{”

+ ”  \”name\”: \”myName\”, ”

+ ”  \”message\”: [\”myMessage1\”,\”myMessage2\”],”

+ ”  \”place\”: \”myPlace\”, ”

+ ”  \”date\”: \”thisDate\” ”

+ “}”;

/* Create a JSON object and parse the required values */

JSONObject object = (JSONObject) new JSONTokener(json).nextValue();

String name = object.getString(“name”);

String place = object.getString(“place”);

String date = object.getString(“date”);

JSONArray message = object.getJSONArray(“message”);

tv.setText(“Name: “+ name +”\n\n”);

tv.append(“Place: “+ place +”\n\n”);

tv.append(“Date: “+ date +”\n\n”);

for(int i=0;i<message.length();i++)

{

tv.append(“Message: “+ message.getString(i) +”\n\n”);

}

} catch (JSONException e) {e.printStackTrace();}

catch(Exception ex){ex.printStackTrace();}

}

}

Read more…

Categories: Programming / tutorials Tags: ,

Creating a Custom Widget in android

January 20th, 2011 3 comments

Apart from using text box buttons and widgets provided in android widget tool kit we can create custom UI that suits the user needs. In this post , I will explain how to to create a custom widgetstep by step.

Custom views can be created by using two classes “View” and “SurfaceView”. Both classes are used exactly the same way, but surface encapsulated by SurfaceView supports OpenGL ES library (Using OpenGL we can draw 2D and 3D objects). Also, all application views run in the main application thread, whenever you want to update View’s UI rapidly the code blocks the GUI thread.  But SurfaceView can update from the background thread. Thus SurfaceView is most commonly used in gaming and applications with heavy graphics.

To start drawing custom widgets 3basic drawing components are required

1)    Canvas : provides surface for drawing your widgets

2)    Paint: While physically drawing a picture we make use of paint brushes of different sizes and different brushes for different colors. Similarly Paint object is used to draw widgets of different colors and textures.

3)    Bitmap: Bitmap is the surface under the canvas. It holds the raw pixel values of the images draw on the canvas. While drawing on the canvas we do not color individual pixels we draw upon continuous area, the corresponding pixel values are then placed on the Bitmap.

Apart from this developers are provided with different methods to draw on the canvas.

Some of the commonly used methods are described below:

1)    drawCircle: draws circle on the canvas.

2)    drawRect: to draw a rectangle on the  canvas.

3)    drawLine: Draws a line on the canvas.

4)    drawOval: Draws an oval bounded by specified rectangle.

5)    drawBitmap: to draw bitmap on the canvas.

6)    drawPicture: to draw picture object within specified rectangle.

7)    drawText: Draws a string on the canvas.

Now lets start creating over own widgets.

Step 1: Create a View class.

public class MyView extends View{

}

Step 2: Your class may require 3 different constructors. So lets create it. Read more…

Categories: Programming / tutorials Tags:

Understanding Explicit Intent in android

January 18th, 2011 1 comment

In last post we had explained the concepts of intent understanding intent in android.

In an explicit intent, we actually specify the activity that is required to respond to the intent. In other words, we explicitly designate the target component. This is typically used for application internal messages. The code of this post can be found at end.

In an implicit intent, the main power of the android design, we just declare an intent and leave it to the platform to find an activity that can respond to the intent. Here, we do not declare the target component and hence is typically used for activating components of other applications seamlessly

Let’s look at our example:

This example has 2 activities:

  • InvokingActivity
  • InvokedActivity

The InvokingActivity has a button “Invoke Next Activity” which when clicked explicitly calls the InvokedActivity class. The relevant part of the code is here: Read more…

Understanding Implicit Intent in android

January 18th, 2011 5 comments

In last post we had explained the concepts of intent understanding intent in android. Now, we will move on to a more interesting concept of Implicit Intents and Intent Filters. The code of this post can be found at end.

As described earlier, an implicit intent does not name a target component that should act upon the intent. Android resolves as to which component is best suited to respond to an Implicit Intent. How does this happen?

Basically, an Intent object has the following information (among other things like Component name, extras and flags) which is of interest for implicit intents:

  • Action
  • Category
  • Data

So, Android compares the three (action, category and data) to something called Intent Filters that are declared by probable target components who are willing to accept Implicit Intent calls. i.e. Intent Filters are the way of any component to advertise its own capabilities to the Android system. This is done declaratively in the AndroidManifest.xml file.

So here are some important points to remember:

  1. Implicit Intents do not specify a target component.
  2. Components willing to receive implicit intents have to declare their ability to handle a specific intent by declaring intent filters.
  3. A component can declare any number of Intent Filters.
  4. There can be more than one component that declares the same Intent Filters and hence can respond to the same implicit intent. In that case, the user is presented both the component options and he can choose which one he wants to continue with.
  5. We can set priorities for the intent filters to ensure the order of responses. Read more…

Currency Converter Tutorial in Android

January 18th, 2011 7 comments

This tutorial will give you a brief introduction to developing a GUI application on Android. This tutorial assumes that you have downloaded and installed the Android SDK. This tutorial also assumes that you are reasonably familiar with concepts in GUI programming and the Java programming language. The complete project can be found at end of post

Step One:

In Eclipse create a new android project as CurrencyConverter. Open the contents of res/layout/main.xml.Delete everything except  <?xml version=“1.0” encoding=“utf-8″?>    from the main.xml file.

Step Two

Select the “Graphical Layouts” tab.

Step Three

Drag and drop a Relative Layout object from the Layouts panel into the screen and click on the screen. You will see the following things:

Step Four

Drag and drop a Linear Layout object from the Layouts panel into the screen top border line .

Step Five

Select the Linear Layout object and click on the properties tab to begin editing the layout properties. Change the width to “200px” and the height to “280px”and Orientation as vertical.

Step Six

Drag and drop two TextView objects and two EditText objects into the LinearLayout so that they alternate

Step Seven

Edit the properties of each TextView object. Make text for the upper one read “Dollars” and make its style “bold”. Make the lower one read: “Euros” and make its style bold also.

Step Eight

Edit the properties of the upper EditText as follows:

  • Change the id to read: “@+id/dollars”
  • Change the text to be empty
  • Change the width to be “100px”.
  • Change the height to be “50px”
  • Add lines as “1”

Step Nine and a half

  • Repeat step Eight with the second EditText under the “Euros” TextView, but make the id be “@+id/euros”

Step Ten

Drag and drop a RadioGroup object into the LinearLayout. Drag and drop two RadioButton objects into the RadioGroup.

Step Eleven

Edit the first RadioButton so that its text reads: “Dollars to Euros” and its id is “@+id/dtoe”.
Edit the second RadioButton so that its text reads: “Euros to Dollars” and its id is “@+id/etod”.

Step Twelve

Drag and drop a Button object into the root RelativeLayout below the LinearLayout object. It should align with the right edge of the LinearLayout.

Important Note:
You must get the ids exactly correct, because this is how you will look up the widgets in source code.

Step Thirteen

The  main.xml file will look something like this.

<?xml version=“1.0” encoding=“utf-8″?>

<RelativeLayout android:id=“@+id/RelativeLayout01″

android:layout_width=“fill_parent” android:layout_height=“fill_parent”

xmlns:android=“http://schemas.android.com/apk/res/android”>

<LinearLayout android:layout_alignParentTop=“true” android:layout_width=“200px” android:orientation=“vertical” android:layout_height=“280px” android:id=“@+id/linearlayoutId”><TextView android:id=“@+id/TextView01″ android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:text=“Dollars” android:textStyle=“bold”></TextView>

<EditText android:layout_width=“100px” android:layout_height=“50px” android:id=“@+id/dollars” android:lines=“1”></EditText>

<TextView android:id=“@+id/TextView02″ android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:text=“Euros” android:textStyle=“bold”></TextView>

<EditText android:lines=“1” android:layout_height=“50px” android:layout_width=“100px” android:id=“@+id/euros”></EditText>

<RadioGroup android:id=“@+id/RadioGroup01″ android:layout_width=“wrap_content” android:layout_height=“wrap_content”><RadioButton android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:text=“Dollars to Euros” android:id=“@+id/dtoe”></RadioButton><RadioButton android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:text=“Euros to Dollars” android:id=“@+id/etod”></RadioButton>

</RadioGroup>

</LinearLayout>

<Button android:layout_height=“wrap_content” android:layout_width=“wrap_content” android:layout_below=“@+id/linearlayoutId” android:layout_alignRight=“@+id/linearlayoutId” android:text=“Convert” android:id=“@+id/convert”></Button>

</RelativeLayout>

Step Fourteen

At this point you should be able to run your GUI in Android. It should look something like this:

Step Fifteen

The last step is to actually code the currency conversion. There’s not much to it, you can look up your GUI elements with:
this.findViewById(R.id.<id>).

Here is the complete code for the CurrencyConverter activity:

package com.droidbd.currencyconverter;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.RadioButton;

public class CurrencyConverter extends Activity implements OnClickListener {

/** Called when the activity is first created. */

EditText dollars;

EditText euros;

RadioButton dtoe;

RadioButton etod;

Button convert;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

dollars = (EditText)findViewById(R.id.dollars);

euros = (EditText)findViewById(R.id.euros);

dtoe = (RadioButton)this.findViewById(R.id.dtoe);

dtoe.setChecked(true);

etod = (RadioButton)this.findViewById(R.id.etod);

convert = (Button)this.findViewById(R.id.convert);

convert.setOnClickListener(this);

}

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

if (dtoe.isChecked()) {

convertDollarsToEuros();

}

if (etod.isChecked()) {

convertEurosToDollars();

}

}

protected void convertEurosToDollars() {

// TODO Auto-generated method stub

double val = Double.parseDouble(euros.getText().toString());

// in a real app, we’d get this off the ‘net

dollars.setText(Double.toString(val/0.67));

}

protected void convertDollarsToEuros() {

// TODO Auto-generated method stub

double val = Double.parseDouble(dollars.getText().toString());

// in a real app, we’d get this off the ‘net

euros.setText(Double.toString(val*0.67));

}

}

Step Sixteen

Well, that’s it. I hope you enjoyed the tutorial.

Currency Converter Code sample_

Categories: Programming / tutorials Tags: