Friday, September 27, 2013

Android-Dialog Window

Android-Dialog Window

Displaying a Dialog Window

There are times where you need to display a dialog window to get a confirmation from the user. In this case, you can override the onCreateDialog() protected method defined in the base Activity class to display a dialog window. The following Try It Out shows you how. Displaying a Dialog Window Using an Activity

1. Using Eclipse, create a new Android project and name it Dialog.
2. Add the following statements in bold to the main.xml file:
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” >
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello” />

Android-Dialog Window

3. Add the following statements in bold to the MainActivity.java file:
package net.learn2develop.Dialog;
import android.app.Activity;
import android.os.Bundle;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
CharSequence[] items = { “Google”, “Apple”, “Microsoft” };
boolean[] itemsChecked = new boolean [items.length];
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.btn_dialog);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(0);
}
});
}

Android-Dialog Window

@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0:
return new AlertDialog.Builder(this)
.setIcon(R.drawable.icon)
.setTitle(“This is a dialog with some simple text...”)
.setPositiveButton(“OK”, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
“OK clicked!”, Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton(“Cancel”, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
“Cancel clicked!”, Toast.LENGTH_SHORT).show();
}
})
.setMultiChoiceItems(items, itemsChecked, new
DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
Toast.makeText(getBaseContext(),
items[which] + (isChecked ? “ checked!”:
“ unchecked!”),
Toast.LENGTH_SHORT).show();
}
}
)
.create();
}
return null;
}
}

Android-Dialog Window

4. Press F11 to debug the application on the Android Emulator. Click the button to display the dialog. Checking the various checkboxes will cause the Toast class to display the text of the item  checked/ unchecked. To dismiss the dialog, click the OK or Cancel button

Android-Dialog Window



To display a dialog, you first override the onCreateDialog() method in the Activity class:
@Override
protected Dialog onCreateDialog(int id) {
//...
}
This method is called when you call the showDialog() method:
Button btn = (Button) findViewById(R.id.btn_dialog);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(0);
}
});

Android-Dialog Window

The onCreateDialog() method is a callback for creating dialogs that are managed by the activity. When you call the showDialog() method, this callback will be invoked. The showDialog() method accepts an integer argument identifying a particular dialog to display.
To create a dialog, you use the AlertDialog class’s Builder constructor. You set the various properties,
such as icon, title, and buttons, as well as checkboxes:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0:
return new AlertDialog.Builder(this)
.setIcon(R.drawable.icon)
.setTitle(“This is a dialog with some simple text...”)
.setPositiveButton(“OK”, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
“OK clicked!”, Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton(“Cancel”, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
“Cancel clicked!”, Toast.LENGTH_SHORT).show();
}
})
.setMultiChoiceItems(items, itemsChecked, new
DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
Toast.makeText(getBaseContext(),
items[which] + (isChecked ? “ checked!”:
“ unchecked!”),
Toast.LENGTH_SHORT).show();
}
}
)
.create();
}
return null;
}
The preceding code sets two buttons: OK and Cancel, using the setPositiveButton() and setNegativeButton() methods, respectively. You also set a list of checkboxes for users to choose via the setMultiChoiceItems() method. For the setMultiChoiceItems() method, you passed in two arrays: one for the list of items to display and another to contain the value of each item to indicate if they are checked. When each item is checked, you use the Toast class to display a message

Android-Hiding Activity Title

Hiding the Activity Title

You can also hide the title of an activity if desired (such as when you just want to display a status update to the user). To do so, use the requestWindowFeature() method and pass it the Window.FEATURE_NO_ TITLE constant, like this:
package net.learn2develop.Activities;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
public class MainActivity extends Activity {
String tag = “Events”;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//---hides the title bar---
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Log.d(tag, “In the onCreate() event”);
}
}
This will hide the title bar, as shown in Figure

Android-Activity Style and Themes

Android-Activity Style and Themes

Applying Styles and themes to Activity

By default, an activity occupies the entire screen. However, you can also apply a dialog theme to an activity so that it is displayed as a floating dialog. For example, you might want to customize your activity  to display as a pop-up, warning the user about some actions that they are going to perform. In this case, displaying the activity as a dialog is a good way to get their attention.
To apply a dialog theme to an activity, simply modify the element in the AndroidManifest.xml file by adding the android:theme attribute:

Android-Activity Style and Themes

package=”net.learn2develop.Activities”
android:versionCode=”1”
android:versionName=”1.0”>
android:name=”android.intent.category.LAUNCHER” />

Android-Activity Style and Themes

Doing so will make the activity appear as a dialog, as shown in Figure

Android-Life Cycle of an Activity

Android-Life Cycle of an Activity

Understanding the Life Cycle of an Activity

1. Using Eclipse, create a new Android project and name it as shown

Android-Life Cycle of an Activity

2. In the MainActivity.java file, add the following statements in bold:
package net.learn2develop.Activities;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
String tag = “Events”;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(tag, “In the onCreate() event”);
}
public void onStart()
{
super.onStart();
Log.d(tag, “In the onStart() event”);
}
public void onRestart()
{
super.onRestart();
Log.d(tag, “In the onRestart() event”);
}
public void onResume()
{
super.onResume();
Log.d(tag, “In the onResume() event”);
}
public void onPause()
{
super.onPause();
Log.d(tag, “In the onPause() event”);
}
public void onStop()
{
super.onStop();
Log.d(tag, “In the onStop() event”);
}
public void onDestroy()
{
super.onDestroy();
Log.d(tag, “In the onDestroy() event”);
}
}

Android-Life Cycle of an Activity

3. Press F11 to debug the application on the Android Emulator.
4. When the activity is first loaded, you should see the following in the LogCat window (click on the Debug perspective; see also Figure.
12-28 13:45:28.115: DEBUG/Events(334): In the onCreate() event
12-28 13:45:28.115: DEBUG/Events(334): In the onStart() event
12-28 13:45:28.115: DEBUG/Events(334): In the onResume() event



5 .  When you now press the back button on the Android Emulator, observe that the following is printed:
12-28 13:59:46.266: DEBUG/Events(334): In the onPause() event
12-28 13:59:46.806: DEBUG/Events(334): In the onStop() event
12-28 13:59:46.806: DEBUG/Events(334): In the onDestroy() event

Android-Life Cycle of an Activity

6. Click the Home button and hold it there. Click the Activities icon and observe the following:
12-28 14:00:54.115: DEBUG/Events(334): In the onCreate() event
12-28 14:00:54.156: DEBUG/Events(334): In the onStart() event
12-28 14:00:54.156: DEBUG/Events(334): In the onResume() event
7.  Press the Phone button on the Android Emulator so that the activity is pushed to the background.
Observe the output in the LogCat window:
12-28 14:01:16.515: DEBUG/Events(334):  In the onPause() event

Android-Life Cycle of an Activity

12-28 14:01:17.135: DEBUG/Events(334):  In the onStop() event
8.  Notice that the onDestroy() event is not called, indicating that the activity is still in memory. Exit the phone dialer by pressing the Back button. The activity is now visible again. Observe the output in the LogCat window:
12-28 14:02:17.255: DEBUG/Events(334): In the onRestart() event
12-28 14:02:17.255: DEBUG/Events(334): In the onStart() event
12-28 14:02:17.255: DEBUG/Events(334): In the onResume() event
The onRestart() event is now fi red, followed by the onStart() and onResume() events.

How It Works

As you can see from this simple experiment, an activity is destroyed when you press the Back button.
This is crucial to know, as whatever state the activity is currently in will be lost; hence, you need to write additional code in your activity to preserve its state when it is destroyed (Chapter 3 will show you how).
At this point, note that the onPause() event is called in both scenarios — when an activity is sent to the background, as well as when it is killed when the user presses the Back button.
When an activity is started, the onStart() and onResume() events are always called, regardless of whether the activity is restored from the background or newly created.

Android-Activities Understanding

Android-Activities Understanding 

Understanding Activities

 To create an activity, you create a Java class that extends the Activity base class:
package net.learn2develop.Activities;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

Android-Activities Understanding 

Your activity class would then load its UI component using the XML file defined in your res/layout folder. In this example, you would load the UI from the main.xml file:
setContentView(R.layout.main); Every activity you have in your application must be declared in your AndroidManifest.xml file, like this:
package=”net.learn2develop.Activities”
android:versionCode=”1”
android:versionName=”1.0”>
android:label=”@string/app_name”>
android:label=”@string/app_name”>
android:name=”android.intent.category.LAUNCHER” />

Android-Activities Understanding 

The Activity base class defines a series of events that governs the life cycle of an activity. The Activity
class defines the following events:
➤ onCreate() — Called when the activity is first created
➤ onStart() — Called when the activity becomes visible to the user
➤ onResume() — Called when the activity starts interacting with the user
➤ onPause() — Called when the current activity is being paused and the previous activity is being resumed
➤ onStop() — Called when the activity is no longer visible to the user
➤ onDestroy() — Called before the activity is destroyed by the system (either manually or by the system to conserve memory)
➤  onRestart() — Called when the activity has been stopped and is restarting again.
By default, the activity created for you contains the onCreate() event. Within this event handler is the code that helps to display the UI elements of your screen.
Figure shows the life cycle of an activity and the various stages it goes through — from when the activity is started until it ends.


The best way to understand the various stages experienced by an activity is to create a new project, implement the various events, and then subject the activity to various user interactions

Android -Activity

Android -Activity

What  is activities 

You learned that an activity is a window that contains the user interface of your applications. An application can have zero or more activities. Typically, applications have one or more activities, and the main aim of an activity is to interact with the user. From the moment an activity appears on the screen to the moment it is hidden, it goes through a number of stages, known as an activity’s life cycle. Understanding the life cycle of an activity is vital to ensuring that your application works correctly. In this chapter, you will learn more about how activities work and the things that you need to take note of when designing your Android application.
Apart from activities, another unique concept in Android is that of an intent. An intent is basically the “glue” that enables different activities from different applications to work together seamlessly, ensuring that tasks can be performed as though they all belong to one single application. In the second part of this chapter, you will learn more about this very important concept and how you can use it to call built-in applications such as the Browser, Phone, Maps, and more.

Android-Anatomy of an Android Application

Anatomy of an Android Application

Now that you have created your first Hello World Android application, it is time to dissect the innards of the Android project and examine all the parts that make everything work.
First, note the various files that make up an Android project in the Package Explorer in Eclipse as shown in figure
The various folders and their files are as follows:
➤ src — Contains the .java source files for your project. In this example, there is one file, MainActivity.java. The MainActivity.java file is the source file for your activity. You will write the code for your application in this file.
➤ Android 2.3 library — This item contains one file, android.jar, which contains all the class libraries needed for an Android application.
➤ gen — Contains the R.java file, a compiler-generated file that references all the resources found in your project. You should not modify this file.
➤ assets — This folder contains all the assets used by your application, such as HTML, text files, databases, etc.
➤ res — This folder contains all the resources used in your application. It also contains a few other subfolders: drawable-, layout, and values. 
➤ AndroidManifest.xml — This is the manifest file for your Android application. Here you specify the permissions needed by your application, as well as other features (such as intent-filters, receivers, etc.).


Anatomy of an Android Application

android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello” />
The @string in this case refers to the strings.xml file located in the res/values folder. Hence, @string/hello refers to the hello string defined in the strings.xml file, which is “Hello World, MainActivity!”:
Hello World, MainActivity!
HelloWorld
It is recommended that you store all the string constants in your application in this strings.xml file and reference these strings using the @string identifier. That way, if you ever need to localize your application to another language, all you need to do is replace the strings stored in the strings.xml file with the targeted language and recompile your application. Observe the content of the AndroidManifest.xml file:
package=”net.learn2develop.HelloWorld”
android:versionCode=”1”
android:versionName=”1.0”>
android:icon=”@drawable/icon” android:label=”@string/app_name”>

Anatomy of an Android Application

The AndroidManifest.xml file contains detailed information about the application:
➤ it defines the package name of the application as net.learn2develop.HelloWorld.
➤ the version code of the application is 1. This value is used to identify the version number of   your application. It can be used to programmatically determine whether an application needs to be upgraded.
➤ the version name of the application is 1.0. This string value is mainly used for display to the user. You should use the format: .. for this value.
➤ the application uses the image named icon.png located in the drawable folder.
➤ The name of this application is the string named app_name defined in the strings.xml file.

Anatomy of an Android Application

➤ There is one activity in the application represented by the MainActivity.java file. The label displayed for this activity is the same as the application name.
➤ Within the definition for this activity, there is an element named :
➤ The action for the intent filter is named android.intent.action.MAIN to indicate that this activity serves as the entry point for the application.
➤ The category for the intent-filter is named android.intent.category.LAUNCHER
to indicate that the application can be launched from the device’s Launcher icon.
➤ Finally, the android:minSdkVersion attribute of the element specifies the minimum version of the OS on which the application will run.
As you add more fi les and folders to your project, Eclipse will automatically generate the content of
R.java, which at the moment contains the following:
package net.learn2develop.HelloWorld;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

package net.learn2develop.HelloWorld;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
You are not supposed to modify the content of the R.java file; Eclipse automatically generates the content for you when you modify your project.

Finally, the code that connects the activity to the UI (main.xml) is the setContentView() method, which is in the MainActivity.java file:

Anatomy of an Android Application

package net.learn2develop.HelloWorld;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

Here, R.layout.main  refers to the main.xml file located in the res/layout folder. As you add additional
XML files to the res/layout folder, the filenames will automatically be generated in the R.java file. The  onCreate() method is one of many methods that are fired when an activity is loaded.



Wednesday, September 25, 2013

Android-Creating Your First Application

CREATING YOUR FIRST APPLICATION

With all the tools and the SDK downloaded and installed, it is now time to start your engine! As in all programming books, the first example uses the ubiquitous Hello World application. This will enable you to have a detailed look at the various components that make up an Android project. So, without any further ado, let’s dive straight in!
1 Using Eclipse, create a new project by selecting File ➪ Project…



CREATING YOUR FIRST APPLICATION

2. Expand the Android folder and select Android Project


CREATING YOUR FIRST APPLICATION

3. Name the Android project as shown in Figure


CREATING YOUR FIRST APPLICATION

4. The Eclipse IDE should now look like Figure.
5. In the Package Explorer (located on the left of the Eclipse IDE), expand the Hello World project by clicking on the various arrows displayed to the left of each item in the project. In the res/layout folder, double-click the main.xml file.





6 The main.xml file defines the user interface (UI) of your application. The default view is the Layout view, which lays out the activity graphically. To modify the UI, click the main.xml tab located at the bottom.

CREATING YOUR FIRST APPLICATION

7. Add the following code in bold to the main.xml file:

android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” >
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello” />
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”This is my first Android Application!” />


8. To save the changes made to your project, press Ctrl+s.
9. You are now ready to test your application on the Android Emulator. Select the project name in Eclipse and press F11. You will be asked to select a way to debug the application. Select Android Application  and click OK

CREATING YOUR FIRST APPLICATION

10. The Android Emulator will now be started (if the emulator is locked, you need to slide the unlock button to unlock it first). Figure shows the application running on the Android Emulator.
11. Click the Home button (the house icon in the lower-left corner above the keyboard) so that it now shows the Home screen




12. Click the application Launcher icon to display the list of applications installed on the device. Note that the HelloWorld application is now installed in the application launcher (see Figure 1-28).



CREATING YOUR FIRST APPLICATION

How It Works
To create an Android project using Eclipse, you need to supply the information shown in Table

In Android, an Activity is a window that contains the user interface of your applications. An application can have zero or more activities; in this example, the application contains one activity: MainActivity
This MainActivity is the entry point of the application, which is displayed when the application is started.
In this simple example, you modified the main.xml file to display the string “This is my first Android Application!” and a button. The main.xml file contains the user interface of the activity, which is displayed when MainActivity is loaded.
When you debug the application on the Android Emulator, the application is automatically installed on the emulator. And that’s it — you have developed your first Android application!
The next section unravels how all the various files in your Android project work together to make your application come alive.






Android-Creating Android Virtual Devices (AVD s)

Creating Android Virtual Devices (AVD s)

The next step is to create AVD to be used for testing your Android applications.

Android Virtual Devices. 

An AVD is an emulator instance that enables you to model an actual device. Each AVD consists of a hardware profile, a mapping to a system image, as well as emulated storage, such as a secure digital (SD) card.  You can create as many AVDs as you want in order to test your applications with several different configurations. This testing is important to confirm the behavior of your application when it is run on different devices with varying capabilities. To create an AVD, go to Windows ➪ Android SDK and AVD Manager.
Select the Available packages option in the left pane and expand the package name shown in the right pane. Figure  shows the various packages available for you to create AVDs to emulate the different versions of an Android device.



Check the relevant tools, documentation, and platforms you need for your project. Once you have selected the items you want, click the Install Selected button to download them. Because it takes a while to download from Google’s server, it is a good idea to download only whatever you need immediately, and download the rest when you have more time Each version of the Android OS is identified by an API level number. For example, Android 2.3 is level 9 (API 9), while Android 2.2 is level 8 (API 8), and so on. For each level, two platforms are available. For example, level 9 offers the following:

➤ SDK Platform Android 2.3
➤  Google APIs by Google Inc.
The key difference between the two is that the Google APIs platform contains the Google Maps library. Therefore, if the application you are writing requires Google Maps, you need to create an AVD using the Google APIs platform.
Click the Virtual Devices item in the left pane of the window. Then click the New… button located in the right pane of the window.
In the Create new

Android Virtual Device (AVD) 

window, enter the items as shown in Figure

Click the Create AVD button when you are done.





In this case, you have created an AVD (put simply, an Android emulator) that emulates an Android device running version 2.3 of the OS. In addition to what you have created, you also have the option to emulate the device with an SD card and different screen densities and resolutions.
It is preferable to create a few AVDs with different API levels so that your application can be tested
on different devices. The example shown in Figure 1-18 shows the many AVDs created to test your applications on a wide variety of different Android platforms.


Tuesday, September 24, 2013

Android-ADT

Android-ADT

Android Development Tools (ADT )

The Android Development Tools (ADT) plug-in for Eclipse is an extension to the Eclipse IDE that supports the creation and debugging of Android applications. Using the ADT, you will be able to do the following in Eclipse:
➤ Create new Android application projects.
➤ Access the tools for accessing your Android emulators and devices.
➤ Compile and debug Android applications.
➤ Export Android applications into Android Packages (APK).
➤ Create digital certificates for code-signing your APK.
To install the ADT, first launch Eclipse by double-clicking on the eclipse.exe file located in the eclipse folder.

Android-ADT

When Eclipse is first started, you will be prompted for a folder to use as your workspace. In Eclipse, a workspace is a folder where you store all your projects. Take the default suggested and click OK.
Once Eclipse is up and running, select the Help ➪ Install New Software… menu item (see Figure 1-8).
In the Install window that appears, type http://dl-ssl.google.com/android/eclipse in the text box (see Figure 1-9) and click Add….
After a while, you will see the Developer Tools item appear in the middle of the window (see Figure 1-10). Expand it, and it will reveal its content: Android DDMS, Android Development Tools, and Android Hierarchy Viewer. Check all of them and click next. 







When you see the installation details, as shown in Figure, click next.

You will be asked to review the licenses for the tools. Check the option to accept the license agreements  Click Finish to continue.



Eclipse will now proceed to download the tools from the Internet and install them. This will take some time, so be patient.



Once the ADT is installed, you will be prompted to restart Eclipse. After doing so, go to Window ➪ Preferences .


In the Preferences window that appears, select Android. You will see an error message saying that the SDK has not been set up. Click OK to dismiss it.


Enter the location of the Android SDK folder. In this example, it would be C:\Android\android-sdk-windows. Click OK.


Android -SDK

Android SDK

The next important piece of software you need to download is, of course, the Android SDK. The Android SDK contains a debugger, libraries, an emulator, Documentation, sample code, and tutorials. You can download the Android SDK from http://developer.android.com/sdk/index.html.Once the SDK is downloaded, unzip its content (the android-sdk-windows folder) Into the C:\Android\ folder, or whatever name you have given to the folder you just Created.


Android-Eclipse

Android-Eclipse

Eclipse


The first step towards developing any applications is obtaining the integrated development environment (IDE). In the case of Android, the recommended IDE is Eclipse, a multi-language software development environment featuring an extensible plug-in system. It can be used to develop various types of applications,
using languages such as Java, Ada, C, C++, COBOL, Python, etc.
For Android development, you should download the Eclipse IDE for Java EE. Developers (www.eclipse .org/downloads/packages/eclipse-ide-java-eedevelopers/heliossr1). Six editions are available: Windows (32 and 64-bit), Mac OS X (Cocoa 32 and 64), and Linux (32 and 64-bit). Simply select the relevant one for your operating system. All the examples in this book were tested using the 32-bit version of Eclipse for Windows. Once the Eclipse IDE is downloaded, unzip its content (the eclipse folder) into a folder, say C:\Android\. 



Android-Tools

Android-Tools

OBTAINING THE REQUIRED TOOLS

Now that you know what Android is and its feature set, you are probably anxious to get your hands dirty and start writing some applications! Before you write your first app, however, you need to download the required tools and SDKs.

Android-Tools

For Android development, you can use a Mac, a Windows PC, or a Linux machine. All the tools needed are free and can be downloaded from the Web. Most of the examples provided in this book should work fine with the Android emulator, with the exception of a few examples that require access to the hardware.
For this book, I will be using a Windows 7 computer to demonstrate all the code samples. If you are using a Mac or Linux computer, the screenshots should look similar; some minor differences may be present, but you should be able to follow along without problems.
So, let the fun begin!

Android-Tools



Android-The Android market

The Android market


As mentioned earlier, one of the main factors determining the success of a smart phone platform is the applications that support it. It is clear from the success of the I Phone that applications play a very vital role in determining whether a new platform swims or sinks. In addition, making these applications accessible to the general user is extremely important.

The Android market

As such, in August 2008, Google announced the Android Market, an online application store for Android devices, and made it available to users in October 2008. Using the Market application that is preinstalled on their Android device, users can simply download third-party applications directly onto their devices. Both paid and free applications are supported on the Android Market, though Paid applications are available only to users in certain countries due to legal issues.

The Android market

Similarly, in some countries, users can buy paid applications from the Android Market, but developers cannot sell in that country. As an example, at the time of writing, users in India can buy apps from the Android Market, but developers in India cannot sell apps on the Android Market. The reverse may
also be true; for example, users in South Korea cannot buy apps, but developers in South Korea can sell apps on the Android Market.

Android-Architecture

Android-Architecture 

ARCHITECTURE OF ANDROID


In order to understand how Android works, take a look at figure , which shows the various layers that make up the Android operating system (OS).

Android-Architecture -Discritpion

The Android OS is roughly divided into five sections in four main layers:-

Linux kernel 

 this is the kernel on which Android is based. This layer contains all the low level device drivers for the various hardware components of an Android device.

Libraries 

— these contain all the code that provides the main features of an Android OS. For example, the SQLite library provides database support so that an application can use it for data storage. The Web Kit library provides functionalities for web browsing.

Android runtime

 — at the same layer as the libraries, the Android runtime provides a set of core libraries that enable developers to write Android apps using the Java programming language. The Android runtime also includes the dalvik virtual machine, which enables every Android application to run in its own process, with its own instance of  the  Dalvik virtual machine (Android applications are compiled into the Dalvik executables). Dalvik is a specialized virtual machine designed specifically for Android and optimized for battery-powered mobile devices with limited memory and CPU.

Application framework

 — exposes the various capabilities of the Android OS to application developers so that they can make use of them in their applications.

Applications 

— At this top layer, you will find applications that ship with the Android device (such as Phone, Contacts, Browser, etc.), as well as applications that you download and install from the Android Market. Any applications that you write are located at this layer.



Android-Features

Android-Features

Application framework enabling reuse and replacement of components
Dalvik virtual machine optimized for mobile devices
Integrated browser based on the open source Web Kit engine

Android-Features

Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES            1.0 specification (hardware acceleration optional)
SQLite for structured data storage

Android-Features

Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR,         JPG, PNG, GIF)
GSM Telephony (hardware dependent)
Bluetooth, EDGE, 3G, and Wi-Fi (hardware dependent)

Android-Features

Camera, GPS, compass, and accelerometer (hardware dependent)
Rich development environment including a device emulator, tools for debugging, memory and                         performance profiling, and a plug-in for the Eclipse IDE

Android-Gingerbread

Android-Gingerbread

Android 2.3

Based on Linux  kernel  2.6.35. On 6 December 2010, the 2.3 (Gingerbread) SDK was released.

Android 2.3-Features

System: Updated user interface design for simplicity and speed
Display: Support for extra-large screen sizes and resolutions (WXGA and higher)
Internet calling: Native support for SIP VoIP telephony
Virtual Keyboard: Faster, more intuitive text input, improved accuracy, better suggested text. Voice               input mode
Copy/Paste: Enhanced. Select a word by press-hold, copy, and paste
Near Field Communication lets the user read an NFC tag embedded in a poster, sticker, or                           advertisement
New audio effects such as reverb, equalization, headphone virtualization, and bass boost
New Download Manager giving users easy access to any file downloaded from the browser, email, or           another application
Camera: Access multiple cameras on the device, including a front-facing camera, if available
Media: Support for Web M/VP8 video playback, and AAC audio encoding
System: Improved power management with a more active role in managing apps that are keeping the             device awake for too long
System: Enhanced support for native code development
System: Switched from YAFFS to ext4 on newer devices
Audio, graphical, and input enhancements for game developers
Concurrent garbage collection for increased performance
Native support for more sensors (such as gyroscopes and barometers)

Android-Ice cream sandwich

Android-Ice cream sandwich


Android-Ice cream sandwich

As officially announced during the 2011 Google I/O, the upcoming version of Android is called Ice Cream Sandwich, a combination of Gingerbread and Honeycomb into a "cohesive whole". Google is targeting an official release in Q4 2011. Android Head of Engineering, Mike Claren called it the company’s “most ambitious release to date.”  Features include facial recognition and new APIs to reduce fragmentation.



Android-Honeycomb

Android Honeycomb


Android 3.0

3.0.1 Based on Linux kernel 2.6.36. On 22 February 2011, the 3.0 (Honeycomb) SDK was released for tablets. This is a tablet-only release of Android. The first device featuring this version, the Motorola xoom tablet, was released on February 24, 2011.

Android Honeycomb-Features

Optimized tablet support with a new virtual and “holographic” user interface
System Bar: Quick access to notifications, status, and soft navigation buttons available at the bottom of the screen
Action Bar: Access to contextual options, navigation, widgets, or other types of content at the top of the screen
Multitasking: Tap Recent Apps in the System Bar, to see snapshots of the tasks underway and quickly jump from one app to another
Redesigned keyboard: To make entering text fast and accurate on larger screen sizes with greater accuracy and efficiency
Copy/Paste: Simplified, more intuitive
Browser: Multiple tabs replace browser windows, form auto-fill, and a new “incognito” mode allows anonymous browsing
Camera: Quick access to exposure, focus, flash, zoom, front-facing camera, time-lapse, and more
Gallery: View albums and other collections in full-screen mode, with easy access to thumbnails for other photos
Contacts: New two-pane UI and Fast Scroll to let users easily organize and locate contacts
Email: New two-pane UI to make viewing and organizing messages more efficient. The app lets users select one or more messages
Support for video chat using Google Talk
Hardware acceleration
Support for multi-core processors

Android Honeycomb

3.1

The 3.1 SDK was released on 10 May 2011. Changes included:
UI refinements
Connectivity for USB accessories
Expanded Recent Apps list
Resizable Home screen widgets
Support for external keyboards and pointing devices
Support for joysticks and gamepads
Media: Support for FLAC audio playback.
High-performance Wi-Fi lock maintains high-performance Wi-Fi connections when device screen is off
Support for HTTP proxy for each connected Wi-Fi access point

Android Honeycomb

 3.2

The 3.2 SDK was released on 15 July 2011. Changes included:
Improved hardware support, including optimizations for a wider range of tablets
Easier access for apps to files on the SD card, e.g. for synchronization
Compatibility display mode for apps that have not yet been optimized for tablet screen resolutions
New display support functions that give developers more control over the look and feel on different Android devices.

Android-Froyo

Froyo


Android-Froyo

2.2.2 latest release. Based on Linux kernel 2.6.32. On 20 May 2010, the 2.2 (Froyo) SDK was released.

Android-Froyo-Features

System: Speed, memory, and performance optimizations
Additional application speed improvements courtesy of JIT implementation
Integration of Chrome's V8 JavaScript engine into the Browser application
Improved Microsoft Exchange support (security policies, auto-discovery, GAL look-up, calendar                 synchronization, remote wipe)
Improved application launcher with shortcuts to Phone and Browser applications
USB tethering and Wi-Fi hotspot functionality
Added an option to disable data access over mobile network
Updated Market application with batch and automatic update features
Quick switching between multiple keyboard languages and their dictionaries
Voice dialing and contact sharing over Bluetooth
Support for numeric and alphanumeric passwords
Support for file upload fields in the Browser application
Support for installing applications to the expandable memory
Adobe Flash support


Android-Éclair



Éclair

Android Eclair

Based on Linux kernel 2.6.29 on 26 October 2009, the 2.0 (Eclair) SDK was released.

Android Eclair-Features


Sync: Expanded Account sync. Multiple accounts can be added to a device for email and contact synchronization
Email: Exchange support, combined inbox to browse email from multiple accounts in one page.
Bluetooth: 2.1 support
Contacts: Tap a contact photo and select to call, SMS, or email the person.
Messaging: Search all saved SMS and MMS messages. Auto-delete oldest messages in a conversation when a defined limit is reached.
Camera: Flash support, Digital zoom, Scene mode, White balance, Color effect, Macro focus
Virtual keyboard: Improved typing speed, smarter dictionary learns from word usage and includes contact names as suggestions.
Browser: Refreshed UI, Bookmark thumbnails, Double-tap zoom, Support for HTML5
Calendar: Agenda view enhanced, attending status for each invitee, Invite new guests to events.
System: Optimized hardware speed, Revamped UI
Display: Support for more screen sizes and resolutions, Better contrast ratio
Maps: Improved Google Maps 3.1.2
Motion Event class enhanced to track multi-touch events
Live Wallpapers: Home screen background images can be animated to show movement

Android 2.0.1

The 2.0.1 SDK was released on 3 December 2009.
Android 2.0.1 is a minor platform release deployable to Android-powered handsets starting in December 2009. This release includes minor API changes, bug fixes and framework behavioral changes.

Android-Donut


Donut

Android Donut

Based on Linux kernel 2.6.29 on 15 September 2009, the 1.6 (Donut) SDK was released. Included in the update were:

Donut-Features

Search: Voice Search & text entry search enhanced to include bookmarks & history, contacts, the web, and more
Search: Developers can now include their content in search results
Text to speech: Features a multi-lingual speech synthesis engine to allow any Android application to "speak" a string of text
Android Market: Allows easier searching, app screenshots, etc.
Camera, camcorder, and Gallery: Updated integrated with faster camera access
Gallery: Now enables users to select multiple photos for deletion
System: Updated technology support for CDMA/EVDO, 802.1x, VPNs, and a text-to-speech engine
Display: Support for WVGA screen resolutions
Speed improvements in searching and camera applications
Expanded Gesture framework and new Gesture Builder development tool
Google free turn-by-turn navigation

Android-Cupcake

Cupcake


Based on Linux  kernel  2.6.27. On 30 April 2009, the official 1.5 (Cupcake) update for Android was released.

Cupcake-Features

There were several new features and UI updates included in the 1.5 update:
Virtual keyboard: Support for 3rd party keyboards with text prediction & user dictionary for custom              words
Widgets: Are miniature application views that can be embedded in other applications (such as the                 Home screen) and receive periodic updates
Camera: Video recording
Gallery: Video playback (MPEG-4 & 3GP formats)
Bluetooth: Stereo support added (A2DP and AVRCP profiles), Auto-pairing
Browser: Copy and paste features added
Contacts: Shows user picture for Favorites
Dialer: Specific date/time stamp for events in call log and one-touch access to a contact card from call           log event.
System: Animated screen transitions
Upload videos to YouTube
Upload photos on Picasa

Android-Versions

HTML-Versions

The version history of the Android operating system began with the release of version 1.0 in September 2008. Android is a mobile operating system developed by Google and the Open Handset Alliance. Android has seen a number of updates since its original release. These updates to the base operating system typically fix bugs and add new features. Generally, each version is developed under a code name based on a dessert item. The code names are in alphabetical order (Cupcake, Donut, Eclair,  Froyo, Gingerbread, Honeycomb, and the future version, Ice Cream Sandwich).

Android-Versions

Android-Versions-Beta


Released 5 November 2007 Conference Call transcript SDK Released 12 November 2007 1.0
Released 23 September 2008 The first Android device, the HTC Dream (G1),had these Android 1.0 features:
Android Market application download and updates through the Market app
Web browser to show, zoom and pan full HTML and XHTML web pages – multiple pages show as             windows ("cards")Video
Camera support, but no way to change resolution, white balance, quality, etc.
Folders allow the grouping of a number of app icons into a single folder icon on the Home screen.
Gmail synchronization with the Gmail app.
Google Contacts synchronization with the People app
Google Calendar synchronization with the Calendar app
Google Maps with Latitude and Street View to view maps and satellite imagery, as well as find local             business and get driving directions using GPS
Google Sync allows management of over-the-air synchronization of Gmail, People, and Calendar
Google Search of the internet and phone apps, contacts, calendar, etc
Google Talk instant messaging

Android-Versions

Android Versions




Android-Introduction

Android-Introduction

      Android

  • Android is a mobile operating system that is based on a modified version of Linux. It was originally developed by a startup of the same name, Android, Inc. In 2005, as part of its strategy to enter the mobile space, Google purchased Android and took over its development work (as well as its development team).

     Android

  • Google wanted Android to be open and free; hence, most of the Android code was released under the open-source Apache License, which means that anyone who wants to use Android can do so by downloading the full Android source code. Moreover, vendors (typically hardware manufacturers) can add their own proprietary extensions to Android and customize Android to differentiate their products from others. This simple development model makes Android very attractive and has thus piqued the interest of many vendors. This has been especially true for companies affected by the phenomenon of Apple’s I Phone, a hugely successful product that revolutionized the smart phone industry. Such companies include Motorola and Sony Ericsson, which for many years have been developing their own mobile operating systems. When the I Phone was launched, many of these manufacturers had to scramble to find new ways of revitalizing their products. These manufacturers see Android as a solution — they will Continue to design  their own hardware and use Android as the operating system that powers it.

         Android

  • The main advantage of adopting Android is that it offers a unified approach to application development. Developers need only develop for Android, and their applications should be able to run on numerous different devices, as long as the devices are powered using Android. In the world of smart phones, applications are the most important part of the success chain. Device manufacturers therefore see Android as their best hope to challenge the onslaught of the I Phone, which already commands a large base of applications.

Monday, September 23, 2013

HTML-Table Attributes

Table Attributes   

Table Border

Type <.Table Border> tag in your HTML document to create a table with a thin border around all of the table cell

Caption

 You can type in a caption for your table, which most browsers will display at the top. It's sometimes easier to think of the caption as the title of your table.

Table Row

   Tables are built row by row using the <.TR> and <./TR> tag pair. To start your first table row, type <.TR>.    Now it's time to enter in the data for the individual cells of the table. Because this is the first row of the table, it's likely that you'll want this row to contain headings for each of the columns of data. Table headings are    created using the <.TH> and <./TH> tag pair. To create a heading for a column of last names, you would type <.TH>Last Name<./TH>.
You can type all of your column headings one after another, each contained in its own <.TH> and <./TH> tag pair.    After you've completed your first row, type <./TR> to finish it. Since you'll be adding another row immediately after it, you can type <.TR> on the next line to start the new row.

Table Data

   Now you can start adding the actual table data cell by cell using the <.TD> and <./TD> tag pair. To enter the data in the first cell of the second row, type <.TD> followed by the actual data and the closing <./TD>
   tag.    Type in your remaining data, using the <.TD> and <./TD> tags to separate each cell and the <.TR> and <./TR> tags to separate each row. When you're finished, type <./TABLE> to signal the end of the table.   Type in your remaining data, using the <.TD> and <./TD> tags to separate each cell and the <.TR> and <./TR> tags to separate each row. When you're finished, type <./TABLE> to signal the end of the table.

 

HTML-Table Creation Steps

Steps to Create a Table in HTML


Creating a simple table in HTML

is fairly straightforward. All you need to do is supply the data. The client-side Web browser takes care of all the dirty work by determining how to display it.
The key thing to remember about tables in HTML is that they are organized in rows, which go horizontally from left to right. Once you begin to think of the data you want to place in your table in terms of rows, you'll beall set to perform some HTML wizardry.

.

HTML-Table

HTML-Table

 Tables 

give HTML authors much greater control over the display and layout of their pages. Typically, you would use tables to display any type of data that looks best in rows and columns. A good rule of thumb is if it looks good as a spreadsheet, then it belongs in a table. 
Tables aren't just for numerical data. They can be used to creatively solve a number of challenges with presenting information in HTML. Tables can be used to enhance a number of existing HTML elements, such as lists and forms. You can even use tables to gain precision control over the layout of your HTML document. 

Friday, September 20, 2013

HTML-List-Combined List

Combining List Types

There are times when it's necessary to use sublists of more than one type within a single list. For instance, you may have a numbered list that includes a list as one of the numbered elements. Instead of just creating an ordered sublist, which numbers each of its items, you might prefer to display an unordered list to differentiate the sublist (while avoiding ordering the information as well). HTML supports embedded combinations of all list types.

HTML-List-Definition List

Creating Definition Lists

Definition lists, also called glossary lists, are a special type of list in HTML. They provide a format like a dictionary entry, with an identifiable term and indented definition paragraph. This format is especially useful when listing items with extensive descriptions, such as catalog items or company departments. The
element provides both a beginning and ending line break. In the
container, the
tag marks the term and the
tag defines the paragraph. These are both open tags, meaning they don't require a closing tag to contain text.

The standard format of a definition list is as follows:


Term

Definition of term

The
tag's text should fit on a single line, but it wraps to the next line without indenting if it runs beyond the boundary of the browser window. The
tag displays a single paragraph, continuously indented one or two spaces beneath the term element's text (depending on how the browser interprets a definition list).

The HTML 4.0 specification provides an important optional attribute for
: COMPACT. This attribute is supposed to be interpreted as a list with a different style, presumably with a smaller font size or more compact character spacing. This could be useful for embedded definition lists (those inside other definition, numbered, or bulleted lists), or for graphic effect. Most browsers, however, ignore the attribute, displaying the definition list to the standard format.

Definition lists can include other HTML elements. The most common are physical and logical styles and other list containers. Although Web browsers can correctly interpret elements such as headings, this is bad HTML; their forced line breaks are not pretty and heading tags are usually meant to define relationships in paragraphs, not within lists. Listing 9.8 shows examples of how you can create definition lists.

Upload UIImage as base64 String

Upload UIImage as Base64 String (Upload UIImage as string) //Select Pic From Camera or Gallery       @objc func btnPro...