Showing posts with label tablet. Show all posts
Showing posts with label tablet. Show all posts

Thursday, December 29, 2011

Bonus on How To: Building Android Application - Part 3


After going through the Part 1 and Part 2 of “How To: Building Android Application”, we will go explore more on the android sample and some tips to improve the performance of the emulator.

Playing with Android Sample Application


In this tutorial, we will setup the Android sample application which will help you play with most of the android components.

Step1: click on File->New->Other and then select Android->Android Sample Project

click Next and Finish.

in case you see “ This target has no samples. Please select another target.” message, you should click Windows->Android SDK Manager and select the sample and other versions (if needed) and Install the packages. This step will take a while. After that is done, retry Step 1.

useful emulator Shortcuts:


Alt+Enter maximizes the emulator. Nice for demos.

Ctrl+F11 changes the orientation of the emulator.

F8 turns network on / off.

F6 to turn on / off the trackball

Performance Considerations


Try to use a smaller resolution for your emulator as for example HVGA. The emulator gets slower the more pixels its needs to render as it is using software rendering.
While creating device (e.g. myDevice), set the flag "Enabled" for Snapshots. This will save the state of the emulator and let it start much faster.

Saturday, December 17, 2011

How To: Building Android Application with easy steps–Part 2

This is in the continuation of my previous post “How To: Building Android Application with easy steps–Part 1”. In this tutorial, we will go over creating the sample application using the environment we have already setup.

Here is the details of the application we will build:
Number Counting: providing the buttons to increment/decrement the number present in the text box

 

Step 1: create Android project


Select File → New → Other → Android → Android Project and create the Android project named

com.hashfold.android.numbercounting

image

click Next and select the Android SDK version on which your application will be build and compiled.

image

note: selecting the Android 2.1 is the best options as 90% of Android devices till date are based on this version.

Click next and make sure the information filled is matching with below:

image

and then click Finish

note: numbercountingActivity is the name of the activity which will get started when the application starts

here is the final project view after above steps:

image

 

image

 

Step 2: writing application code


so far we have completed creating the project space. Now its time to do some coding and creating the GUI components.

2.1 AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hashfold.android.numbercounting"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name="com.hashfold.android.numbercountingActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

2.2 strings.xml


<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="details">number counting application</string>
<string name="hello">Hello! number counting!</string>
<string name="app_name">NumberCounting</string>
<color name="bgcolor">#000000</color>
</resources>

2.3 main.xml layout – the GUI component


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@color/bgcolor">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="+" android:id="@+id/Plus"></Button>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:id="@+id/Minus" android:text="-"></Button>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:id="@+id/Value" android:text="value"></TextView>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="Ok" android:id="@+id/Ok"></Button>
</LinearLayout>

</LinearLayout>

2.4 numbercountingActivity.java


package com.hashfold.android;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.hashfold.android.numbercounting.R;

public class numbercountingActivity extends Activity implements OnClickListener
{
Button Plus, Minus, Ok;
TextView Value;
int score = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Plus = (Button) findViewById(R.id.Plus);
Minus = (Button) findViewById(R.id.Minus);
Ok = (Button) findViewById(R.id.Ok);
Value = (TextView) findViewById(R.id.Value);

Plus.setOnClickListener(this);
Minus.setOnClickListener(this);
Ok.setOnClickListener(this);

}

public void onClick(View v)
{
boolean showText = false;

switch(v.getId())
{
case R.id.Plus: score++; showText = true; break;
case R.id.Minus: score--; showText = true; break;
case R.id.Ok: showText = true; break;
}
if(showText)
Value.setText(String.valueOf(score));
}
}

The R.java is the resource file which is auto generated based on strings.xml and other related resource changes.

Step 3: running the application


setup the run configuration: click on Run->Run configurations

image

and then click on ‘New launch configuration’ and then fill in the information needed as below:

image

image

now click on Apply button and then Run button to run the application.

It will take a while in starting up the Android device emulator with the device select in above step “myDevice”.

Once the device is started, it will look like below:

image

now click on the plus “+” button and see how the application performs

image

If you wish you could start device in full screen mode by pressing Alt+Enter.

image

This helps in having full view of the application.

Having a different orientation view (click Ctrl+F11)

image

turn off the internet (click F8)

image

toggle the internet (click F8)

image

Monday, December 12, 2011

How To: Building Android Application with easy steps–Part 1

What is Android?





Android is a software stack for mobile devices that includes an operating system, middleware and key applications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.

Below are the steps to prepare the Android environment before really getting into the development:



Step 1. Download Eclipse


1.1 click Eclipse Classic


1.2 save the .zip file and extract it to your preferred location


image

Step 2. Installing Android SDK


2.1 start eclipse by clicking on the eclipse application extracted as shown in the above image.


2.2 now click on Help->Install New Software… option which will launch the below window:


image

2.3 now put https://dl-ssl.google.com/android/eclipse/ under “Work with” option and click on Add button.


2.4 type name ‘android’ in the new popup window and click OK


image

2.5 select All components and click Next


image

2.6 Click next in the next screen and then select “I Accept the terms…” and click Finish


image

the new window will popup to start downloading of the SDK ad shown below:

image

2.7 click OK on any warning message window


image

2.8 restart the eclipse


image

2.9. eclipse restart done and a new window shown to select where to install the SDK


image
select the location and click Finish

2.10 have patience, the installation step will take a while to download Android SDK as well as Google APIs.


Eclipse will now look like this…

image

2.11 make sure things are installed correctly.


click on Window->Preferences->Android

the details should show what you have just downloaded

image

Step 3. creating Android device


Android emulator runs on a specific device type. There are lots of android devices available on market.
The AVD Manager (AVD – android virtual device) have almost all of them configured. What you need to do is to create one of them in AVD Manager for your testing purposes. You can always create different device types and test the application before publishing to the android market.

Click on Windows->AVD Manager

image

Now click on New and fill the device information and click Create Device

image

image

At this moment, the eclipse is setup with the Android SDK and it is ready to be used.

Add-On: how to download and install


different version of the Android SDK?


So far we know that SDK version is used in creating the virtual device (using AVD Manager mentioned in Step 3 above). If there is a requirement to test the application on different device, then you need to make sure you have that version of the SDK available in your system. In order to download the new version, do below:

1. click Windows->Android SDK Manager
2. select required packages and then click “Install *** packages…”
3. in the next window, click on “Accept all” and click Install button
it will take a while to download and setup new SDK

In our next tutorial, we will go through the steps and create a sample application from scratch.

put your comments in case you have any questions for me to answer about these steps.

 

reference: http://developer.android.com/index.html