Wednesday, September 5, 2012

Advance Android Topics

Customizing Radio Buttons                                                      Increasing Size of Checkboxes
Customizing Toast In Android                                                   Using Android TextSwitcher
Showing Toast for Longer Time                                                Android ViewFlipper
Customizing Checkboxes In Android                                        Android ImageSwitcher     
Customizing ProgressBar                                                         Android TextWatcher

 Android Animation
   Animating A Button In Android
Animation Using  ViewFlipper
  Scheduling task Using AlrmManager
  Detect Missed Calls In Android


Handling Keyboard and Screen Swap Events
 Handling Keyboard Events                                        Handling/Detecting Swap Events
 Left to Right and Right to Left Swipe Events          Top to Bottom and Bottom to Top Swap Events  
Android Gesture Detector  


Menus In Android                                                                ListView:
Creating Option Menu                                                               Populating ListView With DataBase
Creating Context Menu In Android                                              Populating ListView with ArrayList
                                                                                               ListView with Custom Adapter

Alert Dialog                                                                            DataBase/Storage
Adding Radio Buttons In Dialog                                          SharedPreferences In Android
Adding Check Boxes In Dialog                                            Creating Table In Android
Creating Customized Dialogs in Android                    Inserting, Deleting and Updating Records In Table
Creating Dialog To Collect User Input                            

 File Handling
Reading and Writing files to Internal Stoarage
Reading and Writing files to External Stoarage / SD Card


             

Newest Added Android Tutorials

Customizing Radio Buttons  : In this Tutorial I have explained how we can customize the default /existing Android Radio Button to make it more beautiful and appealing.

Boot Reciever In Android : In this tutorial I have explained how to write a BootReciever and use it when Device/Phone finish booting procees. This is helpful and needed if you want to perform some task when device finishes booting.

Adding CheckBox in Dialog   : In this tutorial you will learn how to add checkboxes in dialog so that user can select/choose multiple options.

Cutomizeing ProgressBar:  In this tutorial How you can customize the Android Default ProgressBar.

Customizing Toast  : learn How we can customize (change Color, Style , Size ) Toast and add image in Toast.

Customizing Display Time of Toast : This tutorial explains about how can we show the Toast for longer time or for as much as we want.



Using EditText In Android

Hi Friends
In this post   we will learn to use the Buttons, EditText , and TextViews.
EditText are used to take input from user. (like Textbox in java).
TextViews are used to show something (like Label in java.)

Note :If you are new to android and have not create any application in Android the read this Create First Project in Android   and then proceed.

So what we are going to do ?
We will create an application "Calculator" which will perform addition and subtraction.
We will have two EditText to take inputs.
A text view to show the result
And two buttons:
Add Button : to perform addition
Subtract button: to perform subtraction.

Create a new Project named as "Calculator"  and give the name "CalculatorActivity" to your activity.

Edit the main.xml file

edit your main.xml file add "Butttons", "Textviews" and "Edittexts" ,
It should like below.( you can just copy the code and paste in amin.xml file)

                          

<?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" >
   

    <TextView
        android:layout_marginTop="30dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="First Number" />

    <EditText
        android:id="@+id/FirstNumber"
        android:hint="First Number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="phone" >

        <requestFocus />

    </EditText>
   
   
   

    <TextView
         android:layout_marginTop="15dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Second  Number" />
    <EditText
        android:id="@+id/SecondNumber"
        android:hint="Second Number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="phone" />
   
   
   

    <TextView
        android:id="@+id/result"
        android:layout_marginTop="30dp"
        android:textSize="25dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="" />
   
   
   <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:orientation="horizontal" >
        <Button
               android:id="@+id/buttonAdd"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="ADD" />
         <Button
             android:id="@+id/buttonSubtract"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="SUBTRACT" />

    </LinearLayout>
</LinearLayout>



Editing CalculatorActivity file


now open your CalculatorActivity file , it should look like 

public class CalculatorActivity extends Activity
{
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState)
            {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.main);
       
                   
                    // get the Id's for refference
                    final TextView result=(TextView)findViewById(R.id.result);
                    final EditText editTextFirstNumber=(EditText)findViewById(R.id.FirstNumber);
                    final EditText editTextSecondNumber=(EditText)findViewById(R.id.SecondNumber);
                    Button addButton=(Button)findViewById(R.id.buttonAdd);
                    Button subtractButton=(Button)findViewById(R.id.buttonSubtract);
                   
                    //  add Button OnclickListener
                   
                    addButton.setOnClickListener(new View.OnClickListener() {
                       
                        public void onClick(View v)
                        {
                              int firstNumber=Integer.parseInt(editTextFirstNumber.getText().toString());
                              int secondNumber=Integer.parseInt(editTextSecondNumber.getText().toString());
                              result.setText("Answer is : "+String.valueOf(firstNumber+secondNumber));
                        }
                    });
                   
                    subtractButton.setOnClickListener(new View.OnClickListener() {
                       
                        public void onClick(View v)
                        {
                              int firstNumber=Integer.parseInt(editTextFirstNumber.getText().toString());
                              int secondNumber=Integer.parseInt(editTextSecondNumber.getText().toString());
                              result.setText("Answer is : "+String.valueOf(firstNumber-secondNumber));
                        }
                    });
       
    }
}


now run your application  and perform add or subtract action.

                                             

 Hope you enjoyed the post .
Comments are Welcome






Using Buttons in Android

Hi Friends today  we will learn to use the Buttons, EditText , and TextViews.
EditText are used to take input from user. (like Textbox in java).
TextViews are used to show something (like Label in java.)

Note :If you are new to android and have not create any application in Android the read this Create First Project in Android   and then proceed.

So what we are going to do ?
We will create an application "Calculator" which will perform addition and subtraction.
We will have two EditText to take inputs.
A text view to show the result
And two buttons:
Add Button : to perform addition
Subtract button: to perform subtraction.

Create a new Project named as "Calculator"  and give the name "CalculatorActivity" to your activity.

Edit the main.xml file

edit your main.xml file add "Butttons", "Textviews" and "Edittexts" ,
It should like below.( you can just copy the code and paste in amin.xml file)

                          

<?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" >
   

    <TextView
        android:layout_marginTop="30dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="First Number" />

    <EditText
        android:id="@+id/FirstNumber"
        android:hint="First Number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="phone" >

        <requestFocus />

    </EditText>
   
   
   

    <TextView
         android:layout_marginTop="15dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Second  Number" />
    <EditText
        android:id="@+id/SecondNumber"
        android:hint="Second Number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="phone" />
   
   
   

    <TextView
        android:id="@+id/result"
        android:layout_marginTop="30dp"
        android:textSize="25dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="" />
   
   
   <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:orientation="horizontal" >
        <Button
               android:id="@+id/buttonAdd"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="ADD" />
         <Button
             android:id="@+id/buttonSubtract"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="SUBTRACT" />

    </LinearLayout>
</LinearLayout>



Editing CalculatorActivity file


now open your CalculatorActivity file , it should look like 

public class CalculatorActivity extends Activity
{
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState)
            {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.main);
       
                   
                    // get the Id's for refference
                    final TextView textViewResult=(TextView)findViewById(R.id.result);
                    final EditText editTextFirstNumber=(EditText)findViewById(R.id.FirstNumber);
                    final EditText editTextSecondNumber=(EditText)findViewById(R.id.SecondNumber);
                    Button addButton=(Button)findViewById(R.id.buttonAdd);
                    Button subtractButton=(Button)findViewById(R.id.buttonSubtract);
                   
                   //  add Button OnclickListener
     
        addButton.setOnClickListener(new View.OnClickListener() {
         
            public void onClick(View v)
            {
                String strFirstNumber=editTextFirstNumber.getText().toString();
                String strSecondNumber=editTextSecondNumber.getText().toString();
              
                // If user has Entered Nothing
                if(strFirstNumber.equals("")||strSecondNumber.equals(""))
                {
                    Toast.makeText(getApplicationContext(), "Please Eneter Both the Numbers", Toast.LENGTH_LONG).show();
                    return;
                }
              
                int firstNumber=Integer.parseInt(strFirstNumber);
                int secondNumber=Integer.parseInt(strSecondNumber);
                  textViewResult.setText("Answer is : "+String.valueOf(firstNumber+secondNumber));
            }
        });
     
        subtractButton.setOnClickListener(new View.OnClickListener() {
         
            public void onClick(View v)
            {
                 String strFirstNumber=editTextFirstNumber.getText().toString();
                 String strSecondNumber=editTextSecondNumber.getText().toString();
               
                 // If User has Entered Nothing
                 if(strFirstNumber.equals("")||strSecondNumber.equals(""))
                 {
                     Toast.makeText(getApplicationContext(), "Please Eneter Bothe the Numbers", Toast.LENGTH_LONG).show();
                     return;
                 }
               
                 int firstNumber=Integer.parseInt(strFirstNumber);
                 int secondNumber=Integer.parseInt(strSecondNumber);
                  textViewResult.setText("Answer is : "+String.valueOf(firstNumber-secondNumber));
            }
        });

       
    }
}


now run your application  and perform add or subtract action.

                                             

 Hope you enjoyed the post .
Comments are Welcome






Tuesday, September 4, 2012

Creating Your First Android Project

Before starting creating android application you must have setup environment for android development.
I hope that you have already  done that if not then do it  by following this link .

Creating a new Android Project in Eclipse  

1: Click On File  ->  New -> Project
         you will see a dialog, click on  Android Project  See picture


  2: Click on Next  button.
  3: Write the name your project or application . Here for this project I am using "My First App"
 4: Click on Next   choose a target
 5: Click on next.
  
          You see following dialog.   Fill in the fields:  see  picture

 
 Click on Finish buttton.

Your project named "My First App" is created and you can see in left pane under Package Explorer.
You will see some folders that are automatically created like Gen, Res,bin, Src etc.

Now you have to edit your main.xml file.

Editing  main.xml file

1.  Double click on"Res" folder in left pane under Package Explorer.
2. Double Click on "Layout"
3. click on main.xml.
modify the  main.xml file , it should look like( you can just copy this and paste in main.xml)

<?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" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="My First Android Application" />

</LinearLayout>




FirstActivty.java 



public class FirstActivty.java extends Activity
{

           @Override
            protected void onCreate(Bundle savedInstanceState)
            {
                       super.onCreate(savedInstanceState);
                      setContentView(R.layout.main);

           }
}

Now right click on your project name and select "Run As"  then click on "Android Application".

It will start the emulator, wait for the emulator to show the output.
You will see following

 Hence you have created your first Android Application..

I have tried to make the things clear  hope you enjoyed it.
Comments are welcome.


Monday, September 3, 2012

Configuring Eclipse for Android Development

Before you start developing in  android,you need to setup the environment for Android Development.
You will need an IDE(Integrated Development Environment) to start . Eclipse is considered as one of the best IDE for android development. If you have not installed the eclipse , install it .
If you need to download Eclipse download it from   http://www.eclipse.org/downloads/


Installing the Eclipse Plugin



Once you downloaded and installed Eclipse, you need to install eclipse plugin.


Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT). This plugin is designed to give you a powerful, integrated environment in which to develop Android apps. It extends the capabilities of Eclipse to let you quickly set up new Android projects, build an app UI, debug your app, and export signed (or unsigned) app packages (APKs) for distribution.

How to install Eclipse plugin



1: Open the Eclipse
2. select Help > Install New Software.
3. Click Add, in the top-right corner
4. 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/
see image 



Click OK.


In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
In the next window, you'll see a list of the tools to be downloaded. Click Next.
Read and accept the license agreements, then click Finish.


If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.
When the installation completes, restart Eclipse.


Once the plugin is installed you will see some additional buttons below the menu bar. see image

Configure the ADT Plugin


After you've installed ADT and restarted Eclipse, you must specify the location of your Android SDK directory:
  1. Select Window > Preferences... to open the Preferences panel (on Mac OS X, select Eclipse > Preferences).
  2. Select Android from the left panel.
  3. You may see a dialog asking whether you want to send usage statistics to Google. If so, make your choice and clickProceed.
  4. For the SDK Location in the main panel, click Browse... and locate your downloaded Android SDK directory (such as android-sdk-windows).
  5. Click Apply, then OK.
If you haven't encountered any errors, you're done setting up ADT and can continue to the next step of the SDK installation.
Now eclipse is ready for android development.
Click on file -> new -> android project  and start developing.
Creating first application in android see  Creating First Application in Eclipse

                                        "All the Best"

you can see here for more explanation.

Thursday, August 23, 2012

Understanding Android Manifest File

Android Manifest file is at the heart of the (structure of) android app. If you do not pay attention to androidmanifest.xml file and its role, you will not be able to design and develop your app and further you will not be able to reuse the platform and its services.
To put it succinctly, the Android Manifest file lists out all the modules of your android application. The platform (android) regulates the life cycle of your app using intent, intent filters, activities, content providers, intent receivers, your app’s permissions and even instrumentation (enterprise enablement) for your app using the manifest file

Every Android application must have an AndroidManifest.xml file. The manifest presents essential information about the application to the Android system, information the system must have before it can run any of the application's code. Among other things, the manifest does the following:
  • It names the Java package for the application. The package name serves as a unique identifier for the application.
  • It describes the components of the application — the activities, services, broadcast receivers, and content providers that the application is composed of. It names the classes that implement each of the components and publishes their capabilities (for example, which Intent messages they can handle). These declarations let the Android system know what the components are and under what conditions they can be launched.
  • It determines which processes will host application components.
  • It declares which permissions the application must have in order to access protected parts of the API and interact with other applications.
  • It also declares the permissions that others are required to have in order to interact with the application's components.
  • It lists the Instrumentation classes that provide profiling and other information as the application is running. These declarations are present in the manifest only while the application is being developed and tested; they're removed before the application is published.
  • It declares the minimum level of the Android API that the application requires.
  • It lists the libraries that the application must be linked against.
Elements of manifest File:

All the elements that can appear in the manifest file are listed below . These are the  elements that you can add in manifest file ; you cannot add your own elements or attributes.


 
 You can add all or some of the elements depending on your requirement
See the detail description of manifest file and elements  here

Beginning with Android

                                      Welcome to the world of android !




When I joined Samsung as an Engineer I had many questions in my mind that generally a fresh college graduate have, I was fresh graduate too. I had to work with android and thought were going in my mind "How will learn android"," Will I able to develop good android apps", and many more. 

gradually I go on  learning, trying, doing mistakes and able to develop my first android app which has been published on play and got 1000+ downloads in first 10 days.

So you will be thinking
.
.
.

what is the best way to learn android ?

Learning programming is much different that learning other subjects where we just read books keeping a pen and marker with us , making notes side by side, highlighting important lines .

Programming is learned by doing(and by just reading the theory and code) , and android so.

I have experienced this that whatever you read do it. Once you do , you will learn and enjoy.
Learning android and developing apps in android is always enjoying.
Trying , doing mistakes, reading again , goggling, will make you a good android developer .

I will advise you have a good book or eBook  of android to consult when you need.

So "All The Best"