Android 4.0 SDK is available now!

Posted by Unknown Rabu, 19 Oktober 2011 0 komentar
As we all know the next version of Android was publicly released on 19 October 2011!
It's Android 4.0 Ice Cream Sandwich!
Ice Cream Sandwich is designed for use with both phones and tablets. This will level the gap between 2.x and 3.x Android versions that we have now for phones and tablets respectively.



Android 4.0 new features:
  • Virtual buttons in the UI, instead of taking up a capacitive screen
  • Voice typing, capable of recognizing speech and converting it into text
  • Widgets in a new tab, listed in a similar list to apps
  • Easier-to-create folders, with a drag-and-drop style
  • A customizable launcher
  • In a new phone app, visual voicemail functionality that lets user speed up or slow down *voicemail messages
  • Pinch-to-zoom functionality in the calendar
  • Offline search, a two-line preview, and new action bar at the bottom of the Gmail app
  • Ability to swipe left or right to switch between Gmail conversations
  • Integrated screenshot capture (accomplished by holding Power and Volume-Down buttons)
  • Improved error correction on the keyboard
  • Ability to access apps directly from lock screen (similar to HTC Sense 3.x)
  • Improved copy and paste functionality
  • Better voice integration and continuous dictating capability
  • Face Unlock, a facial recognition service
  • New tabbed web browser, allowing up to 16 tabs
  • Automatic syncing of browser with user's Chrome bookmarks
  • Modern Roboto font
  • Data Usage section in settings that lets user set warnings when he reaches a certain amount of use and disable data when exceeding the limit
  • Ability to shut down apps that are using data in the background
  • Camera app: zero shutter lag, time lapse settings, zoom while recording
  • Built-in photo editor
  • New gallery layout, organized by location and person
  • Refreshed 'People' app with social network integration, status updates and hi-res images
  • Android Beam, a NFC feature that lets user exchange websites, contact info, directions, YouTube, etc.

Android 4.0 SDK already available for download! Blazing fast! ;-)
http://developer.android.com/sdk/android-4.0.html


Baca Selengkapnya ....

Android: XML parsing thoughts, part 2

Posted by Unknown Senin, 17 Oktober 2011 0 komentar
This is the second part of the article about XML parsing. The first part of it is available here.

In this post I want to tell you about one 3rd party XML handling lib that you may want to use in Android development.

It's Simple framework. Simple is a high performance XML serialization and configuration framework originally from Java world. But it can be used in Android too. It offers full object serialization and deserialization, maintaining each reference encountered.
So, what is the feature of Simple? Simple framework uses annotations to describe correspondence between Java objects and their XML representation in a declarative manner. As a result we have very demonstrable Java code without weird boilerplate stuff! :)







To use Simple in your Android project just add .jar file as a library (Project properties -> Java Build Path -> Libraries tab). Now you are ready! For example we need to parse XML like this:
<ninja>
<name>Katakuna</name>
<weapon type="melee">sword</weapon>
</ninja>

 No problems, it's easy! Just create Java class that describes ninja:
@Root(name="ninja")
public class Ninja
{
@Element(name="name")
public String name;
 
@Element(name="weapon")
public String weapon;
 
@Attribute(name="type")
public String weaponType;
}
Looks very demonstrable, isn't it? ;)

Finally deserialization is pretty simple:
Reader reader = new StringReader(xmlStream);
Persister serializer = new Persister();
try
{
Ninja ninja = serializer.read(Ninja.class, reader, false);
}
catch (Exception e)
{
Log.e("XML with Simple demo", e.getMessage());
}
I think this small example has intrigued you with Simple framework! You can learn more about Simple framework features (which are so cool!) at tutorials and articles pages. Download it here (it's free and licensed under Apache license).

Baca Selengkapnya ....

Android: XML parsing thoughts, part 1

Posted by Unknown Minggu, 09 Oktober 2011 0 komentar
Today I want to share my thoughts about XML parsing on Android. It's true, that XML parsing is one of the most frequent task in Android development - a lot of web-services have their data responses in XML format.
So, what do we have in Android to parse XML data?
Out of the box we have DOM, SAX and XMLPull parsers. 
DOM (Document Object Model) parser is the well-known (especially for web developers) parser and in fact it worse then SAX and PULL: it's slower and has awful and verbose (in my opinion) usage syntax.
Just a short example (part of the RSS parser):

try {
            DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(this.getInputStream());
Element root = dom.getDocumentElement();
NodeList items = root.getElementsByTagName(ITEM);
            for (int i = 0; i < items.getLength(); i++){
Message message = new Message();
Node item = items.item(i);
NodeList properties = item.getChildNodes();
                for (int j = 0; j < properties.getLength(); j++){
Node property = properties.item(j);
String name = property.getNodeName();
                    if (name.equalsIgnoreCase(TITLE)){
message.setTitle(property.getFirstChild().getNodeValue());
} else if (name.equalsIgnoreCase(LINK)){
message.setLink(property.getFirstChild().getNodeValue());
} else if (name.equalsIgnoreCase(DESCRIPTION)){
StringBuilder text = new StringBuilder();
NodeList chars = property.getChildNodes();
                        for (int k = 0; k < chars.getLength(); k++){
text.append(chars.item(k).getNodeValue());
}
                        message.setDescription(text.toString());
} else if (name.equalsIgnoreCase(PUB_DATE)){
message.setDate(property.getFirstChild().getNodeValue());
}
}
                messages.add(message);
}
} catch (Exception e) {
// place any execption handling code here
}
As you can see, the structure of this code is not so simple as you can expect for parsing such simple XML as RSS data. In real live you can have more complex XML structure and then DOM parser code will have a lot of weird if/else constructions that turns entire code into mess!
So, let's forget about DOM parser and move to the better alternatives! ;-)

XML Pull Parser is an interface that defines parsing functionality provided in XMLPULL V1 API.
It's faster than DOM and has lower memory usage.
The same example code of the RSS parsing:
try {
parser.setInput(this.getInputStream(), null);
int eventType = parser.getEventType();
Message currentMessage = null;
boolean done = false;
while (eventType != XmlPullParser.END_DOCUMENT && !done){
String name = null;
switch (eventType){
case XmlPullParser.START_DOCUMENT:
messages = new ArrayList<Message>();
break;
case XmlPullParser.START_TAG:
name = parser.getName();
if (name.equalsIgnoreCase(ITEM)){
currentMessage = new Message();
} else if (currentMessage != null){
if (name.equalsIgnoreCase(LINK)){
currentMessage.setLink(parser.nextText());
} else if (name.equalsIgnoreCase(DESCRIPTION)){
currentMessage.setDescription(parser.nextText());
} else if (name.equalsIgnoreCase(PUB_DATE)){
currentMessage.setDate(parser.nextText());
} else if (name.equalsIgnoreCase(TITLE)){
currentMessage.setTitle(parser.nextText());
}
}
break;
case XmlPullParser.END_TAG:
name = parser.getName();
if (name.equalsIgnoreCase(ITEM) &&
currentMessage != null){
messages.add(currentMessage);
} else if (name.equalsIgnoreCase(CHANNEL)){
done = true;
}
break;
}
eventType = parser.next();
}
} catch (Exception e) {
             // place any execption handling code here
}
While it's better than the DOM parser, still it has boilerplate if/else statements which can turn complex XML data parser code into mess. 

Finally, there is a SAX parser. SAX is an event-based sequential access parser API. SAX provides a mechanism for reading data from an XML document which is an alternative to the one provided by the Document Object Model (DOM). Big advantage of SAX is a lower memory consumption: SAX parsers operate on each piece of the XML document sequentially, while the DOM  parser operates on the document as a whole.
Android SDK has two build-in SAX parsers implementation. And one of them (from android.sax package) is pretty good: it's faster than DOM, has better usage syntax (still verbose) and (it's main advantage!) it's really easy to define an XML structure with it.
The same sample of the RSS parser could look like this:

public void parse(BufferedReader in) {
RootElement root = new RootElement(ITEM)
;
root.setStartElementListener(new StartElementListener() {
public void start(Attributes attributes) {
            currentMessage = new Message();
}
});
root.setEndElementListener(new EndElementListener() {
public void end() {
result.add(currentItem);
	}
});
 
root.getChild(TITLE).setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
  currentMessage.title = body;
      }
});
 
root.getChild(LINK).setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
currentMessage.link = body;
}
});
 
root.getChild(DESCRIPTION).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
currentMessage.description = body;
}
});
 
root.getChild(PUB_DATE).setEndTextElementListener(new EndTextElementListener() {
  public void end(String body) {
            currentMessage.publicationDate = body;
      }
});
 
try {
  Xml.parse(in, root.getContentHandler());
      } catch (Exception e) {
             // place any execption handling code here
}
}
While SAX parser code has a little bit more lines (mainly due to curly brackets and parenthesis), this code is more readable and can be extended to handle complex XML data easily! For example, imagine that we have title publication date node with nested nodes:

Element linkNode = root.getChild(LINK);
linkNode.getChild(LINK_CHILD_1).setEndTextElementListener(
new EndTextElementListener() {
public void end(String body) {
currentItem.linkChild1 = body;
}
});
linkNode.getChild(LINK_CHILD_2).setEndTextElementListener(
new EndTextElementListener() {
public void end(String body) {
currentItem.linkChild2 = body;
}
});
...

As you can see it's easy to define and handle any XML structure without chains of if/else statements.


So, android.sax parser is my favorite one for Android! :)


A few words about performance:
DOM is the slowest one. SAX is slightly faster than Pull.
Android XML parsers performance chart (lower is better):
For chart composing big thanks to Shane Conder.

p.s. To keep this article in a readable size I decided to split my post into two parts. Second part is coming soon. ;-)

Baca Selengkapnya ....
Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android illegal.