Archive for June, 2010
29
Jun

Providing a good user experience is critical to mobile applications. UI Application development in Android requires that you have a good understanding of Layouts. In this blog post, we shall cover all about Android Layouts with code samples.

Android Layout is like a container; all the screen will use either of the one layout and all the view (components) on that screen are part of the layout. The fact that mobile screen is small in size it is very important to properly design the UI.

Let us look at the various layouts offered:

  • Linear Layout

This layout as name says is used to place the views in the linear flow one after the other. We can specify the manner in which view are placed linearly i.e. horizontally or vertically.

Let us have a look at the Linear Layout

<?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"
    	>
 <TextView
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
    	 android:text="First Text View"
    	 />

 <TextView
    	 android:layout_width="fill_parent"
    	 android:layout_height="wrap_content"
    	 android:text="Second Text View"
    	 />
 </LinearLayout>

As shown the above Linear Layout have two Text Views and have orientation set to vertical (android:orientation=“vertical”), hence the two Text Views will be drawn vertically one below the other.

Linear Layout Vertical Orientation

Figure 1: Linear Layout Vertical Orientation

Look at the above XML for Linear Layout, width for layout along with Text View with the layout is set to fill_parent (android:layout_width=“fill_parent”). And since Linear Layout is the top most layout and width set to fill parent it will be stretched to cover entire screen. Similarly both the Text Views also have width set to fill parent, and since they are child to Linear Layout they are stretched to entire screen width.

Now let us change the orientation of linear layout to horizontal (android:orientation=“horizontal”).  Just changing the orientation to horizontal will draw Text View next to each other, but since each of the text view is set to have width as fill parent and by default both are written from left to right (Gravity) only one Text View (First Text View) will be visible. To overcome this set width for both the Text View to wrap_content (android:layout_width=“wrap_content”).

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent"
    	>
<TextView
    		android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    		android:text="First Text View"
      />

    		<TextView
    		android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    	android:text="Second Text View"
    		android:paddingLeft="10px"
    		/>
  </LinearLayout>

Note: Since we have set width for both the Text View as wrap_content, 2nd Text View will start as soon as 1st end. Hence in the above xml we have provided left padding for 2nd Text View in order to have some space between the 2 Text View.

Linear Layout Horizontal Orientation

Figure 2 Linear Layout Horizontal Orientation

  • Table Layout

Using this layout we can place view/components in tabular format.  The best example to understand this layout is Login Screen. Below XML shows Table layout

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

		<TableRow android:id="@+id/TableRow01">
			<TextView android:id="@+id/TextView01"
			android:text="User Name:"
			android:width="100px"/>

			<EditText android:id="@+id/EditText01"
			android:width="220px"/>
		</TableRow>

		<TableRow android:id="@+id/TableRow02">
			<TextView android:id="@+id/TextView02"
			android:text="Password:"
			/>

			<EditText android:id="@+id/EditText02"
			android:inputType="textPassword"/>
		</TableRow>

		<TableRow android:id="@+id/TableRow03">
			<Button android:id="@+id/Button01"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:text="Login"/>

			<Button android:id="@+id/Button02"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:text="Reset"
			android:width="100px"/>
</TableRow>
</TableLayout>

As shown Table consist of three rows (Table Row) and each row as two views/components. Number of columns in table is determined by the maximum number of components in a single row.

Table Layout

Figure 3 : Table Layout

One more important point to note here is that even after specifying width of Reset button in xml to 100 pixel  (android:width=“100px”), it’s width is same as that of Edit Text. This is because width of Column is determined by the maximum width of the component in that column and here Reset button is same the column as Edit Text which has width set to 220 pixel.

  • Relative Layout

This layout is flexible layout of all. This layout as name suggest allow placing components relative to other component or layout. Let us see at the example

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name:"
android:width="100px"/>
<EditText android:id="@+id/EditText01"
android:layout_width="220px"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/TextView01"
android:layout_below="@+id/RelativeLayout01"
/>

<EditText android:id="@+id/EditText02"
android:layout_width="220px"
android:layout_height="wrap_content"
android:layout_below="@+id/EditText01"
android:layout_alignLeft="@+id/EditText01"
/>

<TextView android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"
android:width="100px"
android:layout_below="@+id/EditText01"
android:layout_toLeftOf="@+id/EditText02"
/>

<Button android:text="Login"
android:id="@+id/Button01"
android:layout_width="100px"
android:layout_height="wrap_content"
android:layout_below="@id/EditText02"
android:layout_alignLeft="@id/EditText02"
/>

<Button android:text="Reset"
android:id="@+id/Button02"
android:layout_width="100px"
android:layout_height="wrap_content"
android:layout_below="@id/EditText02"
android:layout_alignRight="@id/EditText02"
/>

</RelativeLayout>

As shown,  EditText 01 has attributes android:layout_toRightOf=“@+id/TextView01″ and android:layout_below=“@+id/RelativeLayout01” for placing Edit Text next to Text View (User Name) . Similarly check EditText02 as attributes android:layout_below=“@+id/EditText01″ and android:layout_alignLeft=“@+id/EditText01″ for placing Edit Text box below the Edit Text 01.

Relative Layout

Figure 4 Relative Layout

  • Absolute Layout

As name suggest this layout is used to place views/components at the exact location on the screen using x and y. Let us see example

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/AbsoluteLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:id="@+id/EditText01"
android:layout_width="200px" android:layout_height="wrap_content"
android:layout_x="12px"
android:layout_y="12px"/>
<Button android:text="Search"
android:id="@+id/Button01"
android:layout_width="100px" android:layout_height="wrap_content"
android:layout_x="220px"
android:layout_y="12px"/>
</AbsoluteLayout>

Absolute Layout

Figure 5 Absolute Layout

As seen we have specified android:layout_x and android:layout_y for both the components  their by providing the absolute location for the components.

  • Frame Layout

Frame Layout is one of the simplest layouts. It is like a single screen and all the views/components child to this layout will be drawn on same screen anchored to the top left corner of the screen. So it is likely that one view can overall another one and hides it unless it is transparent. Let see the example

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/FrameLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<ImageView android:id="@+id/ImageView01"
android:src="@drawable/taj_mahal"
android:scaleType="center"
android:layout_width="fill_parent" android:layout_height="fill_parent"/>

<TextView android:text="Taj Mahal"
android:id="@+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_gravity="center_horizontal|bottom"
android:padding="10dip"
android:textColor="#FFFFFF"
android:background="#AA0000"
/>
</FrameLayout>

Frame Layout

Figure 6 Frame Layout

Note: taj_mahal.jpg is in drawable folder

Conclusion

We looked at the basic android layouts and tried to understand them with their respective examples.


Prashant Thakkar
Prashant Thakkar– Team member – Xoriant Mobile Center of Excellence.

, , ,

16
Jun

In this blog we are going to introduce Agile methodology of software development. We would traverse through the Principles and Processes in Agile and Outcome of “Going Agile”.

Agile Methodology

Agile involves the best practices of Waterfall, Prototyping and Spiral methodologies. It is more focused on short cycles of build and release similar to Spiral methodology and each cycle undergoes through Waterfall process of planning and analysis, design, implementation and testing. Any task unit that is developed undergoes multiple refactoring and polishing similar to Prototype methodology until it evolves into a finished product or a feature.

Agile promotes teamwork and collaboration, encourages frequent evaluation, reduces risks and promotes adaptability to new requirements and company goals. Agile methods adopt planning that is adapted to accommodate inevitable changes early on into the project as compared to predictable planning methods that resists changes and thus suffer consequences between static plans and dynamic reality.

Agile is based on the following key principles:

  • Active user involvement:

The stakeholders – for whom the system is built, are involved in the development of such a system in defining requirements and review processes.

  • Empowerment of the team

Agile team is almost independent in making decisions in terms of ownership of the task and its estimation and design including what is being delivered at the end of the iteration is also agreed upon. The onus of achieving this “commitment” lies within the team.

  • Evolution of requirements

New requirements on the project are identified based on the latest trends in the market. Various tools for automation and continuous build and integration support development processes and help control regression.

  • Shorter Delivery cycles

Due to short delivery cycles of the project, advantage of ‘Time to Market’ is available to the stakeholders. Moreover, most of the risks are identified and mitigated at quite an early stage of the project.

Agile methods usually follow the given processes:

  • Task break ups

Team picks up tasks based on priority defined by the stakeholders. The task is broken up into smaller units and each unit is estimated. The estimate includes analysis, design and approach, unit testing and acceptable criteria. Once the task estimation is done and the delivery date identified, it’s the Team’s responsibility to stick to the commitment.

  • Iterations

Usual iteration cycles for delivery range from 2 weeks to 4 weeks with usually shorter timelines preferable. Single Iteration involves a complete SDLC right from planning, analysis, design, development and testing. A feature may involve multiple iterations before it is production quality.

  • Team

Team composition in agile projects is cross-functional. The team takes up the responsibility of required functionality during delivery of tasks in the iteration. Usual size of team is 4 to 9 people to promote team communication and collaboration. Agile emphasizes on face to face communication between team members, however in case of distributed teams, communication methods like video-conferencing, voice, email, IM etc are suggested.

  • Progressive product maturity

Usually any feature or product involves multiple iterations before it is ready to be deployed into production.  Agile encourages usages of tools and techniques like early and continuous integration, team estimation, test driven design and development, code refactoring etc to improve project quality.

Outcome of “Going Agile”

  • Early ROI for stakeholders on project with all round early risk mitigation.
  • Provide a competitive edge and adaptability to new and additional requirements during project development.
  • According to the survey from Dr Dobbs Journal, Agile methodology provides far better productivity compared to other methodologies.
  • Self Organizing team with better collaboration and communication.

In summary, Agile is a Win-Win for all the parties involved in the development and execution of the project.

Well-known agile methods are:

  • DSDM
  • SCRUM
  • Extreme Programming (XP)

Look for more in this space on DSDM, Scrum and Extreme Programming.


Anand Ved
Anand Ved– Technical Lead – Cloud Computing Project

, , ,

15
Jun

In this blog post, we shall take a look at how to get started with programming for the BlackBerry device. We shall cover what the device is, give you an overview of BlackBerry development and then provide you with detailed steps to setup your development environment. Future blog posts will focus on programming on the BlackBerry.

What is a BlackBerry Device?

The BlackBerry is a wireless handheld device developed by the Canadian company known as Research In Motion (RIM) and was launched in year 1999. It holds 20.8% market share in worldwide Smartphone sales, making it the second most popular platform after Nokia. It is known as the most popular Smartphone around the world for its connectivity and security.

Its primary goal is to support push e-mail, web browsing, text messaging and other wireless internet services in a secure manner. Now a days the BlackBerry devices are integrated with advanced software’s which enable access to wide range of data, communications services, Email, phone, maps, GPS, organizer, social networking, games and other applications. These features of a Smartphone make life easy by allowing access to everything on the move at any place in the world on your fingertips.

The BlackBerry software development kit is a wide collection of examples, documentation, and mature set of APIs and tools grown in an extensive manner, which have shown the directions to develop all kinds of great applications. BlackBerry community and its App World help to get your application noticed and downloaded by users worldwide.

The list of BlackBerry device and its models:

BlackBerry Development Platform consists of:

BlackBerry Development Environment is completely based on the Java Platform. It is collectively integrated with BlackBerry RIM APIs, J2ME APIs and basic Java SE APIs. It is built on top of Java Micro Edition (Java ME) which itself is derived from Java SE.  In order to get into the BlackBerry Application development one need to know Object Oriented programming with the basic understanding of J2ME concepts of configurations and profiles, and in particular the CLDC and MIDP standards.

The BlackBerry Development Environment tools:

The BlackBerry application can be developed on any platform, even in Linux, OSX, the easiest and best supported is Windows 32bit platform. RIM provides two BlackBerry development environments such as:

  • BlackBerry Java Development Environments (JDEs) and
  • BlackBerry Eclipse Plug-in.

Both Blackberry development environment tools work with standard Java Software Development Kit (Java SDK) and fully integrated with development tools, simulators and provides to necessary to create, package, compile, test and debug the Blackberry application. You don’t even need the real handheld device to test the application, because it also includes the full featured Blackberry device simulator. A complete set of BlackBerry JDE API Doc is available for referring available packages and classes for development. Both the development tools are being used by many professional developers to develop BlackBerry applications. We will look into both the tools in detail. The best thing about BlackBerry development tools is that they are absolutely free.

Now we will see the step by step installations for both BlackBerry Java Development Environments (JDEs) and BlackBerry Eclipse Plug-in.

Let’s Start with Installation process:

BlackBerry Java Development Environments (JDEs)

Installing the BlackBerry JDE is very easy as compared to any other tools:

  1. Before installing the Blackberry development tools, you will need to install Java SE Development Kit (JDK) version 5 or later from http://java.sun.com. Which version has to be downloaded will depend on the version of Blackberry platform you want to target. The Java SE JDK v6.0 helps you to develop for BlackBerry Device Software version 4.2 or later. More specific information is available on the BlackBerry Developer page at http://na.blackberry.com/eng/developers/javaappdev/javadevenv.jsp
  2. Now you download appropriate version of BlackBerry Java Development Environment (JDE) from BlackBerry Developer Zone at http://www.blackberry.com/developers/ , you have to register an account. Free Developer tools, whitepapers, the developer Knowledge base and the Blackberry Developer forums are found here. (BlackBerry JDE versions: The BlackBerry OS is backward compatible, So something developed on OS 4.2 will work on OS 4.3 and later without requiring code changes done. It may be the case where certain features are only supported on higher versions. But most of the basic features are covered from OS 4.2)
  3. Once the BlackBerry JDE installer is downloaded, run the installer and follow the on-screen instructions. It will be installed to the default path C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0, which can be changed during installation.
  4. Launch the BlackBerry JDE from Start>Program Files>Research In Motion> BlackBerry JDE 4.5>JDE.
  5. Once the BlackBerry JDE is launched it will look as shown in Figure 1.0. The left hand pane shows sample.jdw workspace, the right hand side shows the HelloWorldDemo.java file in editor. The sample.jdw workspace contains the Blackberry sample examples and it is located in the BlackBerry JDE folder at C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\samples. The BlackBerry API reference doc can be found in via Help>API Reference in the JDE.

BlackBerry JDE v4.2.1 with workspace in left hand side pane, source code editor in right hand side and console at the bottom

The BlackBerry JDE v4.2.1 with workspace in left hand side pane, source code editor in right hand side and console at the bottom.

BlackBerry Eclipse Plug-in installation:

You can download the Eclipse IDE at http://www.eclipse.org/downloads/ . Don’t forget to install the Java Development Kit as a pre-requisite as explained in step 1 of the BlackBerry JDE installation. And download the plug-in from BlackBerry tools at http://na.blackberry.com/eng/developers/resources/devtools.jsp

Perform the following steps to install the BlackBerry Eclipse Plug-in with Eclipse IDE of Java Development version 3.4.0.

  1. Start Eclipse
  2. From the main menu, Select Help > Software Updates.
  3. In the Software Updates and Add-ons dialog, click the Available Software tab.
  4. Click the Add Site button.
  5. In the Add Site dialog, click the Archive button.
  6. In the Repository archive dialog, select the .zip file to install.
  7. Click Open.
  8. In the Add Site dialog, click OK.
  9. Select the check box for the BlackBerry JDE Plug-in for Eclipse. All subcomponents should be checked automatically.
  10. Click Install.
  11. Click Finish.
    When the installation completes, the Software Updates dialog is displayed.
  12. Click Yes to restart Eclipse.

I hope this post is helpful in understanding the BlackBerry Environment, tools and its installation process. If you have any queries feel free to comment.

Siddhesh Bingi
Siddhesh Bingi– Member of Mobile Center of Excellence

, , , ,