Search This Blog

Thursday, 21 June 2012

Best book for learning android development

I am posting this article because so many people struggle for learning android development and they kept asking about material so called book for learning android development. This question has been asked so many times on almost every Q & A site. But there did not get best collective answer.

Here i am going to discuss best free book or paid book for android development.In the end i will give you link for some free book for advance and basic android development

I tried here to combined all resource to learn android development and finally i will give you link to book that i have collected by browsing internet for dozen of week. When ever i got something interesting about android i save it in my pen drive

Maximum answer is asked on Stack Over flow about resource of android development. There people discuss a lot about best book for android development

Although when you will passed two or three month in android development then you will come to know that best book is android development

First and recommend book or guide or mentor is Android Developer Official site

Second Resource to learn android
Question about discussion of best book  but in that maximum book are not free. But remember another case ,keep browsing and having one account on StackOverFlow   site will help you a lot in beginning


Sunday, 17 June 2012

Android Mobile Game Development Part II, Creating surface using android view and drawing some object on touch

This is next step in game development after  Game Development Basic Part I is to creating some real action.
Mobile game development is some what difficult as you need to consider its limitation of graphics and screen size but we will take it as challenge
There are three way to create surface and drawing object like circle, Rectangle and image

1) Using View  this is simplest way to design surface and drawing object on this. But its some what slow in comparison of next two option. Highly useful when you are creating game like Chess which does not require large number frame per second to draw

2) Using surface view Second option and say better option in comparison of first. But notable thing is that it is not much complex to step first but improve our game performance

3) Using Open GL or say GLSurface View  that is derived from c and c++. Highly recommend when your game include so many graphics and animation. And your game need huge amount of memory

So i will start from option at the end of this article we will learn  with source code of project and video

I. How to create simple surface
II. How draw some object
III. How to implement Touch event on View
IV.Drawing shape on touch dynamically

Start with basic step create one project Creating Surface.

Step 2). create another class called  OnsurfaceToDraw.java 

in this class , we create rectangle and circle and line. read little bit about Paint , View , Touch event


package com.ahmad;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;

public class OurSurfaceTodraw extends View {
    private Context context;

    public OurSurfaceTodraw(Context context) {
        super(context);
        this.context = context;
        setWillNotDraw(false);
        setFocusableInTouchMode(true);

    }
    long timedelay = SystemClock.currentThreadTimeMillis();
    @Override
    protected void onDraw(Canvas canvas) {
        // Setting canvas background
        setBackgroundColor(Color.WHITE);
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        // Drawing Line on canvas
        canvas.drawLine(50, 200, 0, 10, paint);
        if ((SystemClock.currentThreadTimeMillis() + 3) > timedelay) {
            paint.setColor(Color.BLACK);
            canvas.drawRect(100, 100, 140, 140, paint);
        }
        // Drawing Rectangle or square
        if ((SystemClock.currentThreadTimeMillis() + 6) > timedelay) {
            paint.setColor(Color.BLACK);
            canvas.drawRect(100, 100, 140, 140, paint);
        }
        // Drawing Rectangle or square
        if ((SystemClock.currentThreadTimeMillis() + 6) > timedelay) {
            paint.setColor(Color.BLACK);
            canvas.drawCircle(100, 250, 20, paint);
        }
        if (mDynamic.isEmpty()) {

        } else {
            paint.setColor(Color.RED);
            for (int i = 0; i < mDynamic.size(); i++) {
                canvas.drawRect(mDynamic.get(i), paint);
            }
        }
        super.onDraw(canvas);
      }

    private ArrayList<Rect> mDynamic = new ArrayList<Rect>();

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        int x = Math.round(event.getX());
        int y = Math.round(event.getY());
        Rect rect = new Rect(x, y, x + 30, y + 20);
        mDynamic.add(rect);
        invalidate();
        return super.onTouchEvent(event);
    }
}

Notable Line in above code are

 Drawing a circle,Rectangle and Line

 canvas.drawCircle(100, 250, 20, paint);
 canvas.drawRect(100, 100, 140, 140, paint);
 canvas.drawLine(50, 200, 0, 10, paint);

If we want to draw Rectangle dynamically then store all rectangle into one ArrayList and then draw by getting each element.

invalidate(); This will ensure that while you change something on touch it will draw to canvas

 Video will show how this out put will work


                             

 You can download complete source from below given link


                                  Download Source Code


Saturday, 16 June 2012

Game Development Part I - Basic of Mobile Game Development

Game development is tricky task to start with. Specially if we are doing game development in mobile then we have to deal with some constraint like

1) Dealing with limited system configuration
2) Dealing with limited and small screen size and graphics

So these two constraint will applied for every mobile game developer . We will take it as  a challenge not a constraint.I am going to post a complete series including some game demo at last until you become a mobile game developer. Initially article are not related to any specific platform like iPhone, Android, Window but in later article i will focus on Android Game Development

Before start making a killer game in android we will focus what basic we need to learn first. Game development is much different from business application.
To be a game developer we need to be good -

1)Physics                         2) Coordinate

Today we will discuss about coordinate system of phone and how it differ from plane system to which we are more aware.

Plane coordinate system that we study in our education system contain origin, and two side other then origin. So we can go into positive direction or in negative direction. Look at figure

Sunday, 10 June 2012

Checking network connection and performing operation in Thread

My this post is related to checking network connection  and how to handle if network connection is not available to make our application more responsive. Later on we will learn how to perform time taking operation in separate thread if connection is present.

First of all we two permission if your are checking wifi connection then you need one extra permission

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
If you want to check connection on click of particular button you can  call this function inside click listener of button

public void ahmadNetworkHanlder() {
   ConnectivityManager connMgr = (ConnectivityManager) 
        getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        // fetch data here as network is availble
    } else {
        // display error dialog to notify user ,connection is not present
    }
}
Now consider case, Network is available. Use one asynchronous task to perform network operation like downloading data

converting InputStream to string

We are very much aware about InputStream. InputStream is to  read to content from file or URL. If we handle file then we used FileInputStream and while reading from a URL, we used InputStream.


InputStream is a readable source of bytes. Once you get an InputStream it's common to decode or convert it into a target data type. For example, if you were downloading image data, you might decode and display it directly Read this post to know how to convert input stream to bitmap See How to convert InputStream to bitmap. But if we want to convert InputStream to string then we need to read it line by line like given code


// Reads an InputStream and converts it to a String.
  public static String convertStreamToString(InputStream is) throws Exception {
 BufferedReader reader = new BufferedReader(new InputStreamReader(is));
 StringBuilder sb = new StringBuilder();
 String line = null;
 while ((line = reader.readLine()) != null) {
     sb.append(line);
  }
       is.close();
 return sb.toString();
 }


Challenges against an android application developer

Starting android development is easy thing. Normally developer are fully aware about java language. It makes easy to learn and develop android application. Because of its open source nature so many tutorial are available on internet. after so many thing android development is pain for developer in comparison  of iPhone development in some cases

1) Device resolution and densities : In android thousand of android device available with different kind of densities and resolution. 



ldpimdpihdpixhdpi
small2.3%2.4%
normal0.7%26.2%57.8%0.9%
large0.3%2%
xlarge7.4%









see this picture. A developer can imagine the pain to make one application that runs perfectly in all. That's impossible.But if you see iPhone, its has only two densities iPhone or iPod And iPad


2)Its hard to earn with android : on Google play, there are so many of crap application are present.In iPhone, quality of application are much more better than android. Because of manner of uploading in android, its easy to upload application. I have seen android hello world application on Google market. that make hard to get notice




Android News and source code