Saturday 24 March 2012

How’s The View !!! – Part One



            It is long back since I did the last post. Let’s start the actual thing now. With all your development environment setup, it is time for some real android programming. User Interface (UI) is one of the most important aspects of the Android programming. It can give you’re the important edge that will attract users to your app and is taken to be seriously off. One of the reasons for popularity of Android platform is its simple-to-understand and highly interactive UI.

So how do you make UIs in Android?

This is such a huge topic that it will be taken in various parts.

The View and ViewGroup class
            View and ViewGroup Class are the basic building blocks of Android UI elements. ViewGroup Class takes care of grouping of various elements known as (YES!!! you guessed it) Views. Views are also known as widgets e.g. TextView, Button ListView etc. Each of the widget is a class in itself and has a set of properties and values that can be manipulated for defining its behaviour. ViewGroup also known as layouts contain these widgets within them and decide the positioning of these widgets within them and provide the final look and feel of the application.
That is about some basic background. Now let’s get down to some business. In Android programming, UI can be made using both Java i.e. programmatically and statically using XML (Extended Markup Language). The XML approach provides for clear separation of UI code so that Java can be used for the core code of your application.

A Basic XML Layout

We will edit the main.xml in our Hello World Application. All the layouts are placed in the res/layout/ folder in your project.(The code is in red color)


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#FFAA00"
     >
        <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text= "How's The View"  
        android:textSize="40dp"
        android:textColor="#0088FF"
        android:gravity="center_horizontal"
        android:layout_marginTop="40dp" 
        android:id="@+id/textview"
        />
<Button 
   android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:id="@+id/button1"
        android:text="Press Me"
        android:layout_gravity="center_horizontal" 
        android:layout_marginTop="40dp"
        />"


</LinearLayout>


You can view the code on github as well.


The XML code consists of tags (here LinearLayout , TextView, Button)
and attributes( layout_width, layout_height,textSize etc.android is a namespace).
Most of the attributes are self-explanatory.The output of the above code is :




The most important and highly used attributes are layout_width and layout_height which take values wrap_content and fill_parent .As the name suggests they make the size of the widgets wrap their content or fill their parent(i.e. their container) completely.Here LinearLayout is a ViewGroup which places the contents in a linear fashion.Here the orientation is vertical therefore the TextView and the Button are placed in the order they appear in the xml file in one below the other.


To set the layout to an Activity following function is used


setContentView(R.layout.main);


Next Part will talk about different layouts and referencing widgets in Java code.Till then 


Happy Droiding :-)



Thursday 15 December 2011

Hello Android !!

                       Its time for the next tutorial.You should have set up your development environment as shown in the previous post.Its time for the first project.This tutorial will deal with Hello Android which frankly is nothing but creating a project and running it.We will explore the contents of the project in this tutorial.What you require is Eclipse,an emulator and of course the ADT Plugin as described in the previous post.

New Project         
1)We start by making a new project in Eclipse
     File > New >  Android Project

2) A dialog box will appear as shown below


    3)   Give your Project a name.(Here Example)
    4)   Select a Target version representing your target android version.I have selected v1.6 and above as        this will make your app available for all above android versions.
    5)  Eclipse will automatically fill Min-SDK version and application name which you can change.You have to specify a package a name as well.It should be unique and don't use com.android.//something .This will be used to identify and search your application in android market.
    6)  There is also a field called Activity name.This Activity refers to a class that is going to be set as a launcher activity.Activity is something that a user views as his UI and has the control of UI thread.More on Activity in later posts.
   7)Once all this is done you are ready to create your project.Click on Finish to create the Project.

Setting up running Environment:
In order to run your program on eclipse you will have to setup  run/debug configurations.

1) Go to Run > Run Configurations 
The following dialog will open

2) Double Click on the Android Application and then the New_configuration
3) Give it a name and give the Project name for Project

4) Click on Target > select a target from the AVD you created as per the last post.Here donut. Click on Apply and Run to run your project.

That's it you successfully completed the Hello Android Project.Did you do anything ? Nothing actually told ya !! :)

Finally just an Overview of what all files were generated in the project:


1) src : as the name suggests contains your java package and the source code.You can see the 
           ExampleActivity.java in it.
2) gen: It contains self-generated R.java which holds the references of all the resources like TextView,strings,
   drawables,colors,layouts.
3) res: ->drawable(ldpi,mdpi,hdpi)->contains the images you want to use in your app(for different densities)
    res: ->layout ->contains the layout in an xml file made of views like textview , buttons etc.
    res:->values ->some values you want to be available throughout your app.like strings say your app name 
                             in xml files
The reference for these resources are stored in R.java in gen.
 4) AndroidManifest.xml : A very important file which has instructions for your application behaviour  and information for Android OS like how many Activities it has?what is the package name?What permissions are required?etc.

Thats the project environment you have.A more realistic app in the next tutorials till then,
Happy Droiding !!

Sunday 11 December 2011

Getting Started !!

              So are you all geared up for android development now ? Android Development is done in Java and if you don't ant to bang your head on a wall in an IDE more specifically in Eclipse IDE.
Pre-Requisites for android development:
1)Android SDK and ADT plugin:

2)Eclipse IDE :
You can Download it from here :  http://www.eclipse.org/downloads/
You will require Eclipse IDE for Java Developers => Galileo or Helios or Indigo will do. I use Galileo but newer versions will be preferred. 
3) Some basic knowledge of Java and xml .
This tutorial will mainly deal with setting up the development environment.

1) Download the Android SDK starter package downloaded from the above link.

2)Run the SDK manager  in your android-sdk  folder

3)In the SDK Manager , click on the Available Packages and download all of them or at least the sdk and  at least one emulator i.e API levels.



4)Installing ADT plugin in eclipse :
Start Eclipse:
Go to Help > Install New Software 

5) Click Add, in the top-right corner.In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location:

https://dl-ssl.google.com/android/eclipse/
 
 
 
6) Click OK.In the Available Software dialog, select the checkbox next to
Developer Tools and click Next.
 
7)In the next window, you'll see a list of the tools to be downloaded. Click
Next and Read and accept the license agreements, then click Finish.
      
Note: If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.
8)Restart Eclipse.
9)
Give the android sdk path in eclipse:
Go to Window > Preferences > Android >path to SDKi.e android sdk folder.
(Make sure no spaces are included in the path) 

10) Create an Android Virtual Device
Go to Window > Android SDK And AVD Manager > New > Choose an API Level give it name 
and choose Create AVD.This will be the emulator on which your projects will run.Choose
Screen size preferably HVGA(standard resolution).
This completes your configuration of android development environment.
Now you are all set to develop the next big app for android.More on that in the next post.
Till then 
Happy Droiding !!!! 
 
 













Friday 2 December 2011

Why Android???



                     The second post for this blog is coming after a very long time.A month and half in assignments and  exams makes it really hard to blog.The application development did take a backseat during this duration and hence the exams ended I went on and started work on updating Vocopedia.Now vocopedia has been updated to v1.5.Also I got Vocopedia copyrighted and a paid version will soon be up.Before we start with android application development it would be essential to know why Android ?

WHY ANDROID ?? 

 For a user:

         Android is an open source operating system based on Unix currently owned by Google.It is one of the most popular and probably the best Operating System for Mobile Smartphones and Tablets.No doubt
android was chosen for ultra low cost tablet Akash.It has multiple app stores the main among it being the Android Market managed by Google.It is known to have 2,00,000+ apps in April 2011 and is the fastest growing app-store behind apple's App Store only.Also there are many free apps for android available(say 60%). It has the best user interface,usability and a developer network in the word that develops applications,scripts for your phone to make it better day by day. There are Custom Roms (custom builds) available that make your phone fast ,smooth ,cool and awesome. Cyanogen Mod being the best of them with CM9( Android 4.0-ICS in development) being the latest.No doubt I am an all and all Android guy !!Android phones make other phones look obsolete.And the best part is you can get an android phone for as less as 6K while for iPhone in India you have to pay 50K.So you want to buy a phone?Go for Android anytime.

For a developer:

                 Android development can be a great decision as a hobby or even a full time profession.Android development is basically done in Java.For developing an Android Application there are mainly two requirements, Android SDK and Eclipse IDE 1.5 and above.Why develop for Android ? For anyone wanting to start into mobile application development android is ideal since no. of phones getting activated in a day is more than 4,00,000.Also a lot of tutorials and help is available online for Android.In order to publish your app in android market you need to pay 25$ one time only on the other hand for Iphone you have to pay 99$ every year which is also the same for windows phone 7 and for nokia-symbian apparently no one bothers.
Also the applications can be developed in Windows,Linux and Mac Os.For iPhone you require Mac and for Windows Phone 7 only Windows.From hardware point of view you can create hardware specific applications.Android development is not limited to apps but in kernel development,performance enhancements,and literally unleashing the power of your devices which cannot be done on other platforms.The Kernel development  for my made me a fan of Linux and that is why I have started studying Linux Kernels for the same.Plus it will improve my knowledge of  embedded systems programming (My Favourite Subject) .
           From next post onwards android application development tutorials will be coming. Till then

                                                             Happy Droiding !!! 

Thursday 8 September 2011

The Journey Begins.................

Before October 2010,If you would ask me what is Android , I would have said "come again?".Then I would have tried recalling and said "Oh ya ,that OS everyone keeps talking about on the gadget shows, good interface and all." I didn't bother about it much then because it was anyway out of my reach.Paying 10k+ for a phone didn't seem possible at that time.But now I bought an android.Probably did everything that is possible from it and here I am blogging maybe bragging about it. ;) :)

I bought my first (and only) Android phone in Nov 2010.I had to convince my father to buy samsung galaxy 3 while he was going for galaxy 5 .And guess what I got it Samsung Galaxy 3.I was a proud android phone owner.I actually had to wait for an hour in the Mobile Store in Dombivli while they had to bring it from Kalyan outlet.Apparently the model was in very great demand and why not 12K for a phone with android and that too with those features,it was a bargain.There weren't much androids in India then but now you see them everywhere.

My awesome Galaxy 3
In the beginning it was just cool apps and games and all things smartphone-like.My phone was shipped with android 2.1- Eclair. It is a good version but a Froyo(Android 2.2) upgrade would have been nice.After a lot of delay and public requests(a hell lot of them) finally they launched an upgrade and guess what it was full of bugs.A Little bit of disappointment there but I continued with using it as it is till I my yearnings for the awesome Live Wallpapers and a bug-free android made my find XDA-developers. That's when i became akdroid and since then there's no looking back.
      Since then I bravely rooted my phone,enavled live wallpapers,installed a custom ROM- Indroid v4
and its updates ,overclocked it,changed kernels,got great control over the phone hardware and vast options of customizations for my Apollo.There is even a USB On The Go in the menu and with that I  could even connect a pen-drive,mouse etc to my phone :O :) :)
      My love for programming resulted in eventually trying to develop an android app and i published app on the android market having more than 1000 downloads as of now......
Here's the link:
 Vocopedia--- Vocab Builder

In the upcoming  posts,I would be posting tutorials on android app development as well as all the things happening in the ever changing world of android.....
                                         Till then Happy Droiding...... :) :) :)