Showing posts with label android info. Show all posts
Showing posts with label android info. Show all posts

Tuesday, 9 August 2011

How We Conduct The Android Tutorials & Course

Our experienced team of developers and tutors have created and refined the course based on a proven system that works and is recognized in the industry.

The course will train you via a step-by-step, fun and easy to learn methodology where our Tutors are available to you via live chat and email throughout the course.

The tutors are available to help you whenever you face a road block, or anytime you are stuck with understanding a conceptual problem or you face coding issues or you just simply need their guidance.

You are never charged any extra fees whatsoever, for any tutor support throughout the entire duration of the 8 week course.

” We confidently say (and our students testify this) that, there is simply no other Android Training Program or Off-the-shelf Book that can match our methodology, our highly organized course material, the online training videos, the weekly worksheets, the access to live projects and the level of one-on-one support that is available throughout the term of the course.”

[1] Online Video Training – Once a Week. Delivered via broadband or DVD / CD via postal mail.

[2] One-on-One Interactive Online Support – Get 24 hour access by posting your issues and get help from our expert tutors quickly.

[3] Weekly PDFs and Worksheets – Read material and practice real problems and assignments as you go along.

[4] Live Industrial Project – One to two Live projects, with a choice to distribute the developed properties through various channels, and earn money.

[5] 24 x 7 Forum Access – Come to the members only online forum to meet other developers and discuss ideas and coding issues.

[6] EDUmobile Certification – Get a Certificate at the end of the course from EDUmobile – a recognized entity in the wireless industry.

[7] Access The Source Code Repository – Access and download over 100 valuable Source Code snippets that you can use freely in any of your projects for life.

[8] DVD & CD by mail – At the end of the course, on request, we will send you all the content including bonus materials by postal mail.

Android Tutorial Blog - Learn How to Write Basic Android Applications




A person who is truly looking for efficiently set up online android course that is held by valid tutors and directs you through virtually every topic hand in hand. Then I can help you out here by giving you the characteristics of one such blog, which I had seen, and which sustains you on discovering android applications.

Anyone can see numbers of tutorials has published training for Android programming. The biggest issue is which one is perfect is important. Furthermore , you will observe that there is nearly excessive and ever-increasing number of information resources offered to you online You might have seen some free tutorials some very expensive. You may even see the subjects or even the testimonials of the training institutions. All of these are essential and foremost steps taken before deciding which one is the best.

I would really like to give you some details of android tutorials whose motive is to support candidates with a step-by-step training. They give guidance on every topic and keep specific interaction with the candidates, they can ask any questions as the developer or instructor is conveniently available to them. They have vibrant and descriptive training techniques, that really help to develop the specified skills to create an android professional.

This institute has their blog in which they have given details and even codings on applications. I can help you out by giving some example on one of the applications with little codings.That is to create a image gallery. The project explains how to implement gallery for your application.

Basic description of algorithm in systematic form

1) Create a Project Gallery Example
2) Open and insert following in main.xml
3) Create, Open and insert following in your res/values/attrs.xml
4) Add some image in your drawable folder.
5) Run the application.

For further important information about this blog kindly visit Android tutorials.

Android could allow mobile ad or phising pop says researchers

Sean Shulte, SSL developer at Trustwave, and Nicholas Percoco, the senior vice president and head of SpiderLabs at Trustwave, revealed at DefCon what they said was a design flaw in Android.

(Credit: Seth Rosenblatt/CNET )

LAS VEGAS--Researchers have discovered what they say is a design flaw in Android that could be used by criminals to steal data via phishing or by advertisers to bring annoying pop-up ads to phones.

Developers can create apps that appear to be innocuous but which can display a fake bank app log-in page, for instance, when the user is using the legitimate bank app, Nicholas Percoco, senior vice president and head of SpiderLabs at Trustwave, said ahead of his presentation on the research at the DefCon hacker conference today.

Currently, apps that want to communicate with the user while a different app is being viewed just push an alert to the notification bar on the top of the screen. But there is an application programming interface in Android's Software Development Kit that can be used to push a particular app to the foreground, he said.

"Android allows you to override the standard for (hitting) the back buttons," said Sean Schulte, SSL (Secure Sockets Layer) developer at Trustwave.

"Because of that, the app is able to steal the focus and you're not able to hit the back button to exit out," Percoco said, adding that they've named the issue the Focus Stealing Vulnerability.

The researchers have created a proof-of-concept tool that is a game but also triggers fake displays for Facebook, Amazon, Google Voice, and the Google e-mail client. The tool installs itself as part of a payload inside a legitimate app and registers as a service so it comes back up after the phone reboots, Percoco said.

In a demo showing a user opening up the app and seeing the log-in screen for Facebook, the only indication that something odd has happened is a screen blip so quick many users wouldn't notice. The fake screen completely replaces the legitimate one, so a user wouldn't be able to tell that anything is out of place.

With this design flaw, game or app developers can create targeted pop-up ads, Percoco said. The ads could be merely annoying, like most pop-ups are, but they could also be targeted to pop up an ad when a competitor's app is being used, he added.

"So the whole world of ads fighting with each other on the screen is possible now," said Percoco, who demonstrated an Android rootkit at DefCon last year.

The functionality would not raise any red flags in the permissions displayed when the user downloads the app because it is a legitimate function for apps to check the phone state in what is called the Activity Service, according to Schulte.

Percoco said the researchers spoke to someone at Google about their findings a few weeks ago and that the individual acknowledged that there was an issue and said the company was trying to figure out how to address it without breaking any functionality of legitimate apps that may be using it.

When contacted for comment, a Google representative said he would look into the matter.

Tutorial to develop text to speech app on Android

This tutorial will show how to develop simple Text to speech application on
android(tested on htc droid incredible). It assumes that you have already
managed to develop hello world(or default project ) in Eclipse per http://android-java.blogspot.com/

  • Step 1 - Create default android project in Eclipse. Run it to make
sure it works.

  • Step 2- Replace below code in your main(activity class). You may need to change package and class name.(This code is tweak of sdk sample - ie its simplified )


package com.test;//change this
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.test.R; //change this
import java.util.Locale;
import java.util.Random;
public class TestAct extends Activity implements TextToSpeech.OnInitListener {
private static final String TAG = "TextToSpeechDemo";
private TextToSpeech mTts;
private Button mAgainButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Initialize text-to-speech. This is an asynchronous operation.
// The OnInitListener (second argument) is called after initialization completes.
mTts = new TextToSpeech(this,
this //TextToSpeech.OnInitListener
);
mAgainButton = (Button) findViewById(R.id.again_button);
mAgainButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
sayHello();
}
});
}
@Override
public void onDestroy() {
// Don't forget to shutdown!
if (mTts != null) {
mTts.stop();
mTts.shutdown();
}
super.onDestroy();
}
// Implements TextToSpeech.OnInitListener.
public void onInit(int status) {
// status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
if (status == TextToSpeech.SUCCESS) {
int result = mTts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA ||
result == TextToSpeech.LANG_NOT_SUPPORTED) {
// Lanuage data is missing or the language is not supported.
Log.e(TAG, "Language is not available.");
} else {
// Check the documentation for other possible result codes.
// For example, the language may be available for the locale,
// but not for the specified country and variant.
// The TTS engine has been successfully initialized.
// Allow the user to press the button for the app to speak again.
mAgainButton.setEnabled(true);
// Greet the user.
sayHello();
}
} else {
// Initialization failed.
Log.e(TAG, "Could not initialize TextToSpeech.");
}
}
private static final Random RANDOM = new Random();
private static final String[] HELLOS = {
"Hello World",
"This is Text to speech demo by Zahid Shaikh"
};
int i =0;
private void sayHello() {
// Select a random hello.
int helloLength = HELLOS.length;
String hello = HELLOS[i];
i++;
if(i == helloLength) i =0;
mTts.speak(hello,
TextToSpeech.QUEUE_FLUSH, // Drop allpending entries in the playback queue.
null);
}
}
  • Step 3 - Change res/main/layout.xml (or equivalent)
          
  • Step 4 - change res/values/string.xml
     hi world     test Again red  #FF00FF   
  • Run your code - and press on the again button!!!

Sunday, 7 August 2011

Google Android-based TV Software?

The Wall Street Journal writes:

Google Inc. is planning to introduce Android-based television software to developers at an event in May, according to people familiar with the matter.

The technology – designed to open set-top boxes, TVs and other devices to more content from the Internet – is attracting interest from partners that include Sony Corp., Intel Corp. and Logitech International SA, which are expected to offer products that support the software, these people said. (..)

[Google] is currently planning on sharing some details about the technology with more than 3,000 developers expected to attend its Google I/O conference in San Francisco May 19 and 20.

Android Developers Lose Money Because Apps Can’t Be Bought In Most Countries, Pingdom Says

Pingdom writes:

Google is talking about fighting piracy, but perhaps the first thing they should focus on is actually making it possible for users to buy apps. All users. Sounds rather logical, doesn’t it? So what are we talking about? The problem lies with Android Market.

You can only pay for apps in 13 out of the 46 or so countries where Android phones are available. For those of you who like stats, 13 in 46 works out to less than 30%. Contrast this with Apple’s App Store, which supports paid apps in 90 countries. This is a huge advantage iPhone developers currently have over Android developers.

Then again, from what I’ve heard in various iPhone-related discussions, selling your app in Apple’s store is also far, far from easy...

Thursday, 4 August 2011

WHY ANDROID


A simple and powerful SDK
  • No licensing, distribution, or development fees
  • Development over many platform
  • Linux, Mac OS, windows
  • Excellent documentation
  • Thriving developer community

  • For us
  • Java-based, easy to import 3rdparty Java library
  • Funding (40+ G1 phones)
  • Prize (amazon’skindle)
  • Job opportunity

WHAT IS ANDROID?

Google - OHA (Open Handset Alliance)
  • The first truly openand comprehensiveplatform for mobile devices, all of the software to run a mobile phone but without the proprietary obstaclesthat have hindered mobile innovation.
  • Linux OS kernel
  • Java programming
  • Open source libraries: SQLite, WebKit, OpenGL

Thursday, 28 July 2011

Main component of android application


�� Activities: The building block of the user interface is the activity. You
can think of an activity as being the Android analogue for the window
or dialog box in a desktop application. While it is possible for activities
to not have a user interface, most likely your “headless” code will be
packaged in the form of content providers or services.

�� Content providers: Content providers provide a level of abstraction for
any data stored on the device that is accessible by multiple
applications. The Android development model encourages you to
make your own data available to other applications, as well as your
own. Building a content provider lets you do that, while maintaining
complete control over how your data is accessed.

�� Services: Activities and content providers are short-lived and can be
shut down at any time. Services, on the other hand, are designed to
keep running, if needed, independent of any activity. You might use a
service for checking for updates to an RSS feed or to play back music
even if the controlling activity is no longer operating.

�� Intents: Intents are system messages, running around the inside of the
device, notifying applications of various events, from hardware state
changes (e.g., an SD card was inserted), to incoming data (e.g., an
SMS message arrived), to application events (e.g., your activity was
launched from the device’s main menu). Not only can you respond to
intents, but you can create your own to launch other activities or to let
you know when specific situations arise (e.g., raise such-and-so intent
when the user gets within 100 meters of this-and-such location).

Thursday, 21 July 2011

Android Platform Differences

Android is hailed as “the first complete, open, and free mobile platform”:

1) Complete: The designers took a comprehensive approach when they developed the
Android platform.They began with a secure operating system and built a robust software
framework on top that allows for rich application development opportunities.

2) Open: The Android platform is provided through open source licensing. Developers
have unprecedented access to the handset features when developing applications.

3) Free: Android applications are free to develop.There are no licensing or royalty fees
to develop on the platform. No required membership fees. No required testing fees.
No required signing or certification fees.Android applications can be distributed
and commercialized in a variety of ways.

Wednesday, 20 July 2011

Simple Mistakes Android Developer

I would really like to write more tips, tricks, and tutorial posts relating to Android, but I’ve been extremely busy on apps both professionally and personally, and I am also doing technical review on an Android dev book due out later this year. So, while I don’t have time to go in the level of depth I’d like to, I thought I could work on a post with a bunch of short pieces that could be written when I have a few free minutes here and there and save the longer posts that require a greater chunk of continuous focus for later.

This post talks about some challenges that you may run into early in your foray into Android development. There isn’t really any sense of order to these; they’re more-or-less a brain dump of issues I’ve experienced or seen that take seconds to solve if you know what you’re doing or hours if you don’t. OMG! The emulator is slow! There are two things to note here: the default AVDs tend to have limited resources and the devices you’re targeting are likely running with a different chipset than the computer you’re developing on.

The first limitation can be easily overcome; the second is a much bigger issue, particularly with Android 3.x and attempting to develop for Honeycomb tablets without actually having a Xoom, Asus Eee Pad Transformer, etc.

Currently, it’s not very feasible to develop a 3.x app without a tablet. Back to that first limitation: When creating a new AVD, you can specify hardware settings, which can dramatically improve performance. The most important setting is the device RAM size; I tend to want the emulator to be as fast as possible, relying on on-device testing for a sense of “real-world speed,” so I usually give my phone emulators 512MB of RAM. That’s the equivalent of most good smartphones from 2010. The 1.x AVDs seem to run fine on 256MB, so you can potentially drop to that if your machine is limited (the Motorola Droid/Milestone had 256MB of RAM as well).

You can also try upping the cache partition size (128MB is a good start) and the max VM application heap size (48 is plenty) for a minor improvement. LinearLayout mistakes LinearLayout is a very useful and very simple ViewGroup. It essentially puts one View after another either horizontally or vertically, depending on the orientation you have set. Set an orientation! LinearLayout defaults to horizontal, but you should always manually specify an orientation. It’s very easy to throw two Views in there and not see one because the first View is set to match_parent for width.

That said, LinearLayout also processes layouts linearly, which is what you’d expect, but that means that setting a child View to match_parent can leave no room for subsequent Views. If you aren’t seeing one of your Views in a LinearLayout, verify you’ve set the orientation and that none of the Views are taking up all the available space. Within a LinearLayout, you should generally rely on layout_weight to “grow” the View.

Here’s an example: The heights are set to 0, but both child Views have weights. The first has a weight of 2 and the second has a weight of 3. Out of a total of 5, the first is taking 2 (40%) and the second gets 3 (60%), so their heights will actually use that portion of the parent View’s space (if that View has a 100px height, the first child will be 40px tall). The weights are relative, so you can set whatever values make sense for you.

In this example, the second layout could have had a set height and no weight and the first could have had a weight of 1, which would have made the first take up all space that the second didn’t use. Stupid Android! It keeps restarting my Activity! The default behavior when a configuration change happens (e.g., orientation change, sliding out the keyboard, etc.) is to finish the current Activity and restart it with the new configuration.

If you’re not getting any dynamic data, such as loading content from the web, this means you probably don’t have to do any work to support configuration changes; however, if you are loading other data, you need to pass it between configuration changes. Fortunately, there’s already a great post on Faster screen orientation changes. Read it and remember that you should not pass anything via the config change methods that is tied to the Activity or Context. Density Density should only be considered in terms of density not size. In other words, don’t decide that MDPI means 320px wide. It doesn’t.

It means that the device has around 160dpi like the G1 (320px wide) and the Xoom (1280px wide). Fortunately, you can combine multiple qualifiers for your folders to give precise control, so you can have a drawable-large-land-hdpi/ containing only drawables that are used on large HDPI devices that are in landscape orientation. One other important thing to note: Support for different screen sizes and densities came in Android 1.6. Android 1.5 devices are all MDPI devices, but they don’t know to look in drawable-mdpi/ because there were no different densities then.

So, if you’re supporting Android 1.5, your MDPI drawables should go in drawables/. If your minSdkVersion is 1.6 or above, put the MDPI drawables in drawable-mdpi/. What the heck is ListView doing? A full explanation of ListView would take quite a while, but here’s a quick summary: A ListView’s associated Adapter’s getView method is called for each child View it needs to construct to fill the ListView.

If you scroll down, the top View that leaves the screen is not garbage collected but is instead passed back to the getView method as the “convertView” (second param). Use this View! If you don’t, not only does it need to be garbage collected, you have to inflate new Views. You should also use the ViewHolder paradigm where you use a simple class to store View references to avoid constant findViewById() calls.

Here’s an example: @Override public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder holder;

if (convertView == null) {
convertView = mInflater.inflate(R.layout.some_layout, null);
holder = new ViewHolder();
holder.thumbnail = (ImageView) convertView.findViewById(R.id.thumbnail);
holder.title = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
final MyObject obj = (MyObject) getItem(position);
holder.thumbnail.setImageDrawable(obj.getThumbnail());
holder.title.setText(Html.fromHtml(obj.getTitle()));
return convertView;
} /** * Static ViewHolder class for retaining View references*/

private static class ViewHolder {
ImageView thumbnail; TextView title;
}

This method is first checking if the convertView exists (when the ListView is first laid out, convertView will not exist). If it doesn’t exist, a new layout is inflated with the LayoutInflater. A ViewHolder object is instantiated and the View references are set. Then, the holder is assigned to the View with the setTag method (which essentially allows you to associate an arbitrary object with a View).

If the convertView already exists, all that has already been done, so you just have to call getTag() to pull that ViewHolder out. The “bulk” of the method is just grabbing MyObject (whatever object your Adapter is connecting to) and setting the thumbnail ImageView and the title TextView.

You could also make the ViewHolder fields final and set them in the constructor, but I tried to keep this example as simple as possible. This method no longer requires View inflation while scrolling nor does it require looking through the Views for specific IDs each time. This little bit of work can make a huge different on scrolling smoothness. One last thing about ListViews… never set the height of a ListView to wrap_content.

If you have all your data locally available, it might not seem so bad, but it becomes particularly troublesome when you don’t. Consider the above example but instead of the setImageDrawable call, it triggers an image download (though it’s better to have the Adapter handle that).

If you use wrap_content on your ListView, this is what happens: The first getView call is done, convertView is null, and position 0 is loaded. Now, position 1 is loaded, but it is passed the View you just generated for position 0 as its convertView. Then position 2 is loaded with that same View, and so on. This is done to lay out the ListView since it has to figure out how tall it should be and you didn’t explicitly tell it.

Once it has run through all of those positions, that View is passed back to position 0 for yet another getView call, and then position 1 and on are loaded with getView and no convertView. You’re going to end up seeing getView called two or three times as often as you would have expected.

Not only does that suck for performance, but you can get some really confusing issues (e.g., if you had been passing a reference to an ImageView with an image download request, that same ImageView could be tied to all of the download requests, causing it to flicker through the images as they return).

Saturday, 9 July 2011

Android App Basics – Activity Lifecycle

1. Android App Basics – Activity Lifecycle
As resources are limited on a mobile phone, the operating system
must be able to destroy an activity, which is not active (meaning:
in the foreground of the screen), at any time.

Therefore, every Activity has a lifecycle which is handled by the
Android operating system.

To avoid losing data or the state of an activity, you must override
lifecycle methods to save your data when your activity is paused
(not in the foreground anymore but still visible) or stopped (not
visible anymore).


Thursday, 30 June 2011

Simple Android Developer Mistakes

I would really like to write more tips, tricks, and tutorial posts relating to Android, but I’ve been extremely busy on apps both professionally and personally, and I am also doing technical review on an Android dev book due out later this year. So, while I don’t have time to go in the level of depth I’d like to, I thought I could work on a post with a bunch of short pieces that could be written when I have a few free minutes here and there and save the longer posts that require a greater chunk of continuous focus for later.

This post talks about some challenges that you may run into early in your foray into Android development. There isn’t really any sense of order to these; they’re more-or-less a brain dump of issues I’ve experienced or seen that take seconds to solve if you know what you’re doing or hours if you don’t.OMG! The emulator is slow!There are two things to note here: the default AVDs tend to have limited resources and the devices you’re targeting are likely running with a different chipset than the computer you’re developing on.

The first limitation can be easily overcome; the second is a much bigger issue, particularly with Android 3.x and attempting to develop for Honeycomb tablets without actually having a Xoom, Asus Eee Pad Transformer, etc.

Currently, it’s not very feasible to develop a 3.x app without a tablet.Back to that first limitation: When creating a new AVD, you can specify hardware settings, which can dramatically improve performance. The most important setting is the device RAM size; I tend to want the emulator to be as fast as possible, relying on on-device testing for a sense of “real-world speed,” so I usually give my phone emulators 512MB of RAM. That’s the equivalent of most good smartphones from 2010. The 1.x AVDs seem to run fine on 256MB, so you can potentially drop to that if your machine is limited (the Motorola Droid/Milestone had 256MB of RAM as well).

You can also try upping the cache partition size (128MB is a good start) and the max VM application heap size (48 is plenty) for a minor improvement.LinearLayout mistakesLinearLayout is a very useful and very simple ViewGroup. It essentially puts one View after another either horizontally or vertically, depending on the orientation you have set. Set an orientation!LinearLayout defaults to horizontal, but you should always manually specify an orientation. It’s very easy to throw two Views in there and not see one because the first View is set to match_parent for width.

That said, LinearLayout also processes layouts linearly, which is what you’d expect, but that means that setting a child View to match_parent can leave no room for subsequent Views. If you aren’t seeing one of your Views in a LinearLayout, verify you’ve set the orientation and that none of the Views are taking up all the available space. Within a LinearLayout, you should generally rely on layout_weight to “grow” the View.

Here’s an example: The heights are set to 0, but both child Views have weights. The first has a weight of 2 and the second has a weight of 3. Out of a total of 5, the first is taking 2 (40%) and the second gets 3 (60%), so their heights will actually use that portion of the parent View’s space (if that View has a 100px height, the first child will be 40px tall). The weights are relative, so you can set whatever values make sense for you.

In this example, the second layout could have had a set height and no weight and the first could have had a weight of 1, which would have made the first take up all space that the second didn’t use.Stupid Android! It keeps restarting my Activity!The default behavior when a configuration change happens (e.g., orientation change, sliding out the keyboard, etc.) is to finish the current Activity and restart it with the new configuration.

If you’re not getting any dynamic data, such as loading content from the web, this means you probably don’t have to do any work to support configuration changes; however, if you are loading other data, you need to pass it between configuration changes. Fortunately, there’s already a great post on Faster screen orientation changes. Read it and remember that you should not pass anything via the config change methods that is tied to the Activity or Context.DensityDensity should only be considered in terms of density not size. In other words, don’t decide that MDPI means 320px wide. It doesn’t.

It means that the device has around 160dpi like the G1 (320px wide) and the Xoom (1280px wide). Fortunately, you can combine multiple qualifiers for your folders to give precise control, so you can have a drawable-large-land-hdpi/ containing only drawables that are used on large HDPI devices that are in landscape orientation.One other important thing to note: Support for different screen sizes and densities came in Android 1.6. Android 1.5 devices are all MDPI devices, but they don’t know to look in drawable-mdpi/ because there were no different densities then.

So, if you’re supporting Android 1.5, your MDPI drawables should go in drawables/. If your minSdkVersion is 1.6 or above, put the MDPI drawables in drawable-mdpi/.What the heck is ListView doing?A full explanation of ListView would take quite a while, but here’s a quick summary: A ListView’s associated Adapter’s getView method is called for each child View it needs to construct to fill the ListView.

If you scroll down, the top View that leaves the screen is not garbage collected but is instead passed back to the getView method as the “convertView” (second param). Use this View! If you don’t, not only does it need to be garbage collected, you have to inflate new Views. You should also use the ViewHolder paradigm where you use a simple class to store View references to avoid constant findViewById() calls.

Here’s an example: 

@Override
public View getView(int position, View convertView, ViewGroup parent) 
{ final ViewHolder holder;

if (convertView == null) {
convertView = mInflater.inflate(R.layout.some_layout, null);
holder = new ViewHolder();
holder.thumbnail = (ImageView) convertView.findViewById(R.id.thumbnail);
holder.title = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
final MyObject obj = (MyObject) getItem(position);
holder.thumbnail.setImageDrawable(obj.getThumbnail());
holder.title.setText(Html.fromHtml(obj.getTitle()));
return convertView;
} /** * Static ViewHolder class for retaining View references*/

private static class ViewHolder {
ImageView thumbnail; TextView title;
}

This method is first checking if the convertView exists (when the ListView is first laid out, convertView will not exist). If it doesn’t exist, a new layout is inflated with the LayoutInflater. A ViewHolder object is instantiated and the View references are set. Then, the holder is assigned to the View with the setTag method (which essentially allows you to associate an arbitrary object with a View).

If the convertView already exists, all that has already been done, so you just have to call getTag() to pull that ViewHolder out. The “bulk” of the method is just grabbing MyObject (whatever object your Adapter is connecting to) and setting the thumbnail ImageView and the title TextView.

You could also make the ViewHolder fields final and set them in the constructor, but I tried to keep this example as simple as possible. This method no longer requires View inflation while scrolling nor does it require looking through the Views for specific IDs each time. This little bit of work can make a huge different on scrolling smoothness.One last thing about ListViews… never set the height of a ListView to wrap_content.

If you have all your data locally available, it might not seem so bad, but it becomes particularly troublesome when you don’t. Consider the above example but instead of the setImageDrawable call, it triggers an image download (though it’s better to have the Adapter handle that).

If you use wrap_content on your ListView, this is what happens: The first getView call is done, convertView is null, and position 0 is loaded. Now, position 1 is loaded, but it is passed the View you just generated for position 0 as its convertView. Then position 2 is loaded with that same View, and so on. This is done to lay out the ListView since it has to figure out how tall it should be and you didn’t explicitly tell it.

Once it has run through all of those positions, that View is passed back to position 0 for yet another getView call, and then position 1 and on are loaded with getView and no convertView. You’re going to end up seeing getView called two or three times as often as you would have expected.

Not only does that suck for performance, but you can get some really confusing issues (e.g., if you had been passing a reference to an ImageView with an image download request, that same ImageView could be tied to all of the download requests, causing it to flicker through the images as they return).

It’s very easy to send email via an Android intent. Here’s an example where we already have the subject and body prepared but want to let the user decide on the recipient:

(It’s important to note that this should be attempted on a real device.)

I ran into some trouble with sending HTML in an email because it was being interpreted as plain text both in the user’s email client and in the recipient’s. Simply changing the MIME type didn’t help, but I eventually came across the solution:

Note that both the MIME type is changed and the EXTRA_TEXT is now set as Html.fromHtml(body) instead of just being passed a string with HTML in it. As long as the mail app that is selected is able to properly handle the Intent (e.g., the Gmail app can, the default mail app cannot), then HTML email can be sent.

Saturday, 25 June 2011

Step 1. Preparing Your Development Computer

Before getting started with the Android SDK, take a moment to confirm that your development computer meets the System Requirements. In particular, you might need to install the JDK, if you don't have it already.

If you will be developing in Eclipse with the Android Development Tools (ADT) Plugin—the recommended path if you are new to Android—make sure that you have a suitable version of Eclipse installed on your computer as described in the System Requirements document. If you need to install Eclipse, you can download it from this location:

http://www.eclipse.org/downloads/

The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.
Step 2. Downloading the SDK Starter Package

The SDK starter package is not a full development environment—it includes only the core SDK Tools, which you can use to download the rest of the SDK components (such as the latest Android platform).

If you haven't already, get the latest version of the SDK starter package from the SDK download page.

If you downloaded a .zip or .tgz package (instead of the SDK installer), unpack it to a safe location on your machine. By default, the SDK files are unpacked into a directory named android-sdk-.

If you downloaded the Windows installer (.exe file), run it now and it will check whether the proper Java SE Development Kit (JDK) is installed (installing it, if necessary), then install the SDK Tools into a default location (which you can modify).

Make a note of the name and location of the SDK directory on your system—you will need to refer to the SDK directory later, when setting up the ADT plugin and when using the SDK tools from the command line.
Step 3. Installing the ADT Plugin for Eclipse

Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT), that is designed to give you a powerful, integrated environment in which to build Android applications. It extends the capabilites of Eclipse to let you quickly set up new Android projects, create an application UI, debug your applications using the Android SDK tools, and even export signed (or unsigned) APKs in order to distribute your application. In general, developing in Eclipse with ADT is a highly recommended approach and is the fastest way to get started with Android.

If you'd like to use ADT for developing Android applications, install it now. Read Installing the ADT Plugin for step-by-step installation instructions, then return here to continue the last step in setting up your Android SDK.

If you prefer to work in a different IDE, you do not need to install Eclipse or ADT. Instead, you can directly use the SDK tools to build and debug your application. The Introduction to Android application development outlines the major steps that you need to complete when developing in Eclipse or other IDEs.
Step 4. Adding Platforms and Other Components

The last step in setting up your SDK is using the Android SDK and AVD Manager (a tool included in the SDK starter package) to download essential SDK components into your development environment.

The SDK uses a modular structure that separates the major parts of the SDK—Android platform versions, add-ons, tools, samples, and documentation—into a set of separately installable components. The SDK starter package, which you've already downloaded, includes only a single component: the latest version of the SDK Tools. To develop an Android application, you also need to download at least one Android platform and the associated platform tools. You can add other components and platforms as well, which is highly recommended.

If you used the Windows installer, when you complete the installation wizard, it will launch the Android SDK and AVD Manager with a default set of platforms and other components selected for you to install. Simply click Install to accept the recommended set of components and install them. You can then skip to Step 5, but we recommend you first read the section about the Available Components to better understand the components available from the Android SDK and AVD Manager.

You can launch the Android SDK and AVD Manager in one of the following ways:

From within Eclipse, select Window > Android SDK and AVD Manager.
On Windows, double-click the SDK Manager.exe file at the root of the Android SDK directory.
On Mac or Linux, open a terminal and navigate to the tools/ directory in the Android SDK, then execute:

android

Figure 1. The Android SDK and AVD Manager's Available Packages panel, which shows the SDK components that are available for you to download into your environment.
Available Components


To download components, use the graphical UI of the Android SDK and AVD Manager to browse the SDK repository and select new or updated components (see figure 1). The Android SDK and AVD Manager installs the selected components in your SDK environment. For information about which components you should download, see Recommended Components.


By default, there are two repositories of components for your SDK: Android Repository and Third party Add-ons.

The Android Repository offers these types of components:

SDK Tools — Contains tools for debugging and testing your application and other utility tools. These tools are installed with the Android SDK starter package and receive periodic updates. You can access these tools in the /tools/ directory of your SDK. To learn more about them, see SDK Tools in the developer guide.
SDK Platform-tools — Contains platform-dependent tools for developing and debugging your application. These tools support the latest features of the Android platform and are typically updated only when a new platform becomes available. You can access these tools in the /platform-tools/ directory. To learn more about them, see Platform Tools in the developer guide.
Android platforms — An SDK platform is available for every production Android platform deployable to Android-powered devices. Each SDK platform component includes a fully compliant Android library, system image, sample code, and emulator skins. To learn more about a specific platform, see the list of platforms that appears under the section "Downloadable SDK Components" on the left part of this page.
USB Driver for Windows (Windows only) — Contains driver files that you can install on your Windows computer, so that you can run and debug your applications on an actual device. You do not need the USB driver unless you plan to debug your application on an actual Android-powered device. If you develop on Mac OS X or Linux, you do not need a special driver to debug your application on an Android-powered device. See Using Hardware Devices for more information about developing on a real device.
Samples — Contains the sample code and apps available for each Android development platform. If you are just getting started with Android development, make sure to download the samples to your SDK.
Documentation — Contains a local copy of the latest multiversion documentation for the Android framework API.

The Third party Add-ons provide components that allow you to create a development environment using a specific Android external library (such as the Google Maps library) or a customized (but fully compliant) Android system image. You can add additional Add-on repositories by clicking Add Add-on Site.
Recommended Components

The SDK repository contains a range of components that you can download. Use the table below to determine which components you need, based on whether you want to set up a basic, recommended, or full development environment:
Environment SDK Component Comments
Basic SDK Tools If you've just installed the SDK starter package, then you already have the latest version of this component. The SDK Tools component is required to develop an Android application. Make sure you keep this up to date.
SDK Platform-tools This includes more tools that are required for application development. These tools are platform-dependent and typically update only when a new SDK platform is made available, in order to support new features in the platform. These tools are always backward compatible with older platforms, but you must be sure that you have the latest version of these tools when you install a new SDK platform.
SDK platform You need to download at least one platform into your environment, so that you will be able to compile your application and set up an Android Virtual Device (AVD) to run it on (in the emulator). To start with, just download the latest version of the platform. Later, if you plan to publish your application, you will want to download other platforms as well, so that you can test your application on the full range of Android platform versions that your application supports.
+
Recommended
(plus Basic) Documentation The Documentation component is useful because it lets you work offline and also look up API reference information from inside Eclipse.
Samples The Samples components give you source code that you can use to learn about Android, load as a project and run, or reuse in your own app. Note that multiple samples components are available — one for each Android platform version. When you are choosing a samples component to download, select the one whose API Level matches the API Level of the Android platform that you plan to use.
Usb Driver The Usb Driver component is needed only if you are developing on Windows and have an Android-powered device on which you want to install your application for debugging and testing. For Mac OS X and Linux platforms, no special driver is needed.
+
Full
(plus Recommended) Google APIs The Google APIs add-on gives your application access to the Maps external library, which makes it easy to display and manipulate Maps data in your application.
Additional SDK Platforms If you plan to publish your application, you will want to download additional platforms corresponding to the Android platform versions on which you want the application to run. The recommended approach is to compile your application against the lowest version you want to support, but test it against higher versions that you intend the application to run on. You can test your applications on different platforms by running in an Android Virtual Device (AVD) on the Android emulator.

Once you've installed at least the basic configuration of SDK components, you're ready to start developing Android apps. The next section describes the contents of the Android SDK to familiarize you with the components you've just installed.

For more information about using the Android SDK and AVD Manager, see the Adding SDK Components document.
Step 5. Exploring the SDK (Optional)

Once you've installed the SDK and downloaded the platforms, documentation, and add-ons that you need, we suggest that you open the SDK directory and take a look at what's inside.

The table below describes the full SDK directory contents, with components installed.
Name Description
add-ons/ Contains add-ons to the Android SDK development environment, which let you develop against external libraries that are available on some devices.
docs/ A full set of documentation in HTML format, including the Developer's Guide, API Reference, and other information. To read the documentation, load the file offline.html in a web browser.
platform-tools/ Contains platform-dependent development tools that may be updated with each platform release. The platform tools include the Android Debug Bridge (adb) as well as other tools that you don't typically use directly. These tools are separate from the development tools in the tools/ directory because these tools may be updated in order to support new features in the latest Android platform.
platforms/ Contains a set of Android platform versions that you can develop applications against, each in a separate directory.
/ Platform version directory, for example "android-11". All platform version directories contain a similar set of files and subdirectory structure. Each platform directory also includes the Android library (android.jar) that is used to compile applications against the platform version.
samples/ Sample code and apps that are specific to platform version.
tools/ Contains the set of development and profiling tools that are platform-independent, such as the emulator, the Android SDK and AVD Manager, ddms, hierarchyviewer and more. The tools in this directory may be updated at any time using the Android SDK and AVD Manager and are independent of platform releases.
SDK Readme.txt A file that explains how to perform the initial setup of your SDK, including how to launch the Android SDK and AVD Manager tool on all platforms.
SDK Manager.exe Windows SDK only. A shortcut that launches the Android SDK and AVD Manager tool, which you use to add components to your SDK.

Optionally, you might want to add the location of the SDK's tools/ and platform-tools to your PATH environment variable, to provide easy access to the tools.
How to update your PATH
Next Steps

Once you have completed installation, you are ready to begin developing applications. Here are a few ways you can get started:

Set up the Hello World application

If you have just installed the SDK for the first time, go to the Hello World tutorial. The tutorial takes you step-by-step through the process of setting up your first Android project, including setting up an Android Virtual Device (AVD) on which to run the application.

Following the Hello World tutorial is an essential first step in getting started with Android development.

Learn about Android

Take a look at the Dev Guide and the types of information it provides.
Read an introduction to Android as a platform in What is Android?
Learn about the Android framework and how applications run on it in Application Fundamentals.
Take a look at the Android framework API specification in the Reference tab.

Explore the development tools

Get an overview of the development tools that are available to you.
Read the Introduction to Android application development.
Read Using Hardware Devices to learn how to set up an Android-powered device so you can run and test your application.

Follow the Notepad tutorial

The Notepad Tutorial shows you how to build a full Android application and provides helpful commentary on the Android system and API. The Notepad tutorial helps you bring together the important design and architectural concepts in a moderately complex application.

Following the Notepad tutorial is an excellent second step in getting started with Android development.

Explore some code

The Android SDK includes sample code and applications for each platform version. You can browse the samples in the Resources tab or download them into your SDK using the Android SDK and AVD Manager. Once you've downloaded the samples, you'll find them in /samples//.

Visit the Android developer groups

Take a look at the Community pages to see a list of Android developers groups. In particular, you might want to look at the Android Developers group to get a sense for what the Android developer community is like.

Troubleshooting
Ubuntu Linux Notes

If you need help installing and configuring Java on your development machine, you might find these resources helpful:
https://help.ubuntu.com/community/Java
https://help.ubuntu.com/community/JavaInstallation
Here are the steps to install Java and Eclipse, prior to installing the Android SDK and ADT Plugin.
If you are running a 64-bit distribution on your development machine, you need to install the ia32-libs package using apt-get::

apt-get install ia32-libs

Next, install Java:

apt-get install sun-java6-jdk

The Ubuntu package manager does not currently offer an Eclipse 3.3 version for download, so we recommend that you download Eclipse from eclipse.org (http://www.eclipse.org/ downloads/). A Java or RCP version of Eclipse is recommended.
Follow the steps given in previous sections to install the SDK and the ADT plugin.

Other Linux Notes

If JDK is already installed on your development computer, please take a moment to make sure that it meets the version requirements listed in the System Requirements. In particular, note that some Linux distributions may include JDK 1.4 or Gnu Compiler for Java, both of which are not supported for Android development.

Thursday, 23 June 2011

Android User Interface Development: Beginner's Guide

On 9th January, 2007, Apple officially launched the iPhone, and the world of user
interface design shifted. While tablet PCs had been around for a while, the iPhone was
the first device to give so many people a portable touchscreen, and people loved it. Just
over a year later, Google and the Open Handset Alliance announced Android which in
many ways is the direct competitor to iPhone.
What is it about touchscreen phones that we love? The answer is simple—feedback.
Touchscreens offer a way to directly manipulate on-screen objects, which in the past had
to be driven through a keyboard, mouse, joystick, or other input device. The touchscreen
model of direct manipulation has a large impact on the way we think about our user
interfaces as developers, and changes the expectations a user has for the application.
Touchscreen devices require us to stop thinking in terms of forms, and start thinking
about object-oriented user interfaces.
Android is used as the primary operating system for a rapidly expanding range of
consumer electronics, including:
• Smartphones
• Netbooks
• Tablets
• Some desktop systems
While all of these devices have different purposes and specifications, all of them run
Android. This is unlike many other operating environments which are almost always
have a special purpose. The services and the APIs they provide to developers generally
reflect their target hardware. Android on the other hand makes the assumption that a
single application may be required to run on many different types of devices, with very
different hardware capabilities and specifications, and makes it as easy as possible for
developers to handle the differences between these devices simply and elegantly.
New challenges
As Android and the touchscreen devices it powers become increasingly common, they
will bring a new set of challenges to user interface design and development:
• You generally don't have a mouse
• You may have more than one pointing device
• You often don't have a keyboard
• Any keyboard that does exist may be a software keyboard
• A software keyboard may consume some of your application's screenspace
The software keyboard reduces the amount of screen space available to your application,
and in much the same vein, if there is a hardware keyboard present it may or may not
always be exposed to the user. Therefore, not only are different Android devices
different, but they may also appear to change features while your application is running.
The rule of finger
Most Android devices have touchscreens (although this is not a requirement). The first
restriction placed on any touchscreen user interface is the size of the human forefinger,
which of course varies widely from one person to another. If a widget is too small on the
screen, it won't be clear what the user is trying to touch. You'll notice that most Android
widgets take up plenty of space, and have more than the normal amount of padding
around them. On a touchscreen device, you can't rely on pixel-perfect precision. You
need to make sure that when the user touches a widget, they make contact, and they don't
accidentally touch another widget.
The magic touch
Another impact touchscreens have on user interface design is that an application and all
the widgets that it uses must be entirely self-explanatory (even more than usual). Far too
often, we substitute good user interface planning and design with a roll-over or tooltip to
indicate a widget's function. On a touchscreen device, there is no mouse or pointing
device. The first interaction it has with the user is when they touch it, and they will
expect something to happen.
A touchy subject
Most Android devices have a touchscreen, but it's not a requirement.
The quality of a touchscreen also varies wildly from device to device.
The category of touchscreens and their capabilities will also vary from
one device to the next, depending on the intended use of the device and
often its intended market segment.
A smaller view on the world
Most Android devices are small, and as a result have smaller screens and generally fewer
pixels than a normal PC or laptop. This lack of size limits the size of the widgets.
Widgets must be big enough to touch safely, but we also need to pack as much
information onto the screen as possible. So don't give your users information that they
don't want, and also avoid asking them for information you don't need.
Classic user interface principals
Here are some core guidelines which every user interface should follow. These guidelines
are what will keep your users happy, and ensure your application is successful.
Throughout the rest of the book, we'll be walking through these guidelines with practical
examples of improvements that can be made to a user interface.
Consistency
This is the cornerstone of good user interface design. A button should look like a button.
Make sure that the layout of each screen has a relationship with every other screen in
your application. People often mistake this principle for "stick to the platform look and
feel". Look and feel is important, consistency mostly applies to the layout and overall
experience of the application, rather than the color scheme.
Recycling your interface
The easiest way to maintain a consistent user interface, is to recycle as much of it as
possible. At first glance, this suggestion looks merely like a "good object-oriented"
practice. However, a closer look will reveal ways to reuse graphical widgets in ways you
hadn't thought of. By changing the visibility of various widgets, or you can reuse an edit
screen to view list items of the intended type.
Simplicity
This is especially important in a phone-based application. Often, when a user encounters
a new application, it's because they are looking for something. They may not have the
time (or more often patience) to learn a new user interface. Make sure that your
application asks for as little as possible, and guides the user to the exact information they
want in as few steps as possible.
The Zen approach
Generally, when you are using a mobile device, your time is limited. You may also be
using an application in less-than-ideal circumstances (perhaps, in a train). The lesser
information a user needs to give an application, and the lesser they need to absorb from it,
the better. Stripping away options and information also leads to a shorter learning-curve.
Android's hidden menu
A very useful feature of Android is the hidden menu structure. The menu is only visible
when the user presses the "Menu" button, which would generally mean, they're looking
for something that isn't currently on the screen. Typically, a user shouldn't need to open a
menu. However, it's a good way of hiding advanced features until they are needed.
Feedback
Feedback is what makes a touchscreen device exciting. When you drag an object, it sticks
to your finger across the screen until you let go of it. When the users puts their finger on
your application, they expect some reaction. However, you don't want to get in their
way—instead of showing an error message when they touch a button, disable the button
until it's valid to use, or don't show it at all.
Location and navigation
When you're in a place you've never been to previously, it's easy to get disoriented, or
lost. The same is true for a piece of software. Just because the application makes sense to
you, the developer, it doesn't mean it seems logical to your user. Adding transition
animations, breadcrumbs, and progress gauges help the user to identify where in the
application they are, and what's happening.
The road to recovery
A common way to tell users that something is wrong on a desktop application, or on the
web is to open an error dialog. On a mobile device, people want smoother use of an
application. While in a normal application you may inform the user that they selected an
invalid option, in a mobile application, you generally want to make sure they can't select
that option in the first place. Also, don't make them scroll through huge lists of options.
Instead, allow them to filter through the list using an auto-complete or something similar.
When something goes wrong, be nice, and be helpful—don't tell the user, "I couldn't find
any flights for your search". Instead tell them, "There were no available flights for your
search, but if you're prepared to leave a day earlier, here is a list of the available flights".
Always make sure your user can take another step forward without having to go "Back"
(although the option to go backwards should always exist).
The Android way
The Android platform is in many ways similar to developing applications for the web.
There are many devices, made by many manufactures, with different capabilities and
specifications. Yet as a developer, you will want your users to have the most consistent
experience possible. Unlike a web browser, Android has built-in mechanisms for coping
with these differences, and even leveraging them.
We'll be looking at Android from the point of view of a user rather than having a purely
development-centric approach. We'll cover topics such as:
• What user interface elements Android provides
• How an Android application is assembled
• Different types of Android layouts
• Presenting various types of data to the user
• Customising of existing Android widgets
• Tricks and tools to keep user interfaces looking great
• Integration between applications
We're about to take a jump into building user interfaces for Android devices—all
Android devices, from the highest speed CPU to the smallest screen.

Twitter Delicious Facebook Digg Stumbleupon Favorites More