Tampilkan postingan dengan label source. Tampilkan semua postingan
Tampilkan postingan dengan label source. Tampilkan semua postingan

Solution for Android ViewPager inside a ScrollView

Posted by Unknown Minggu, 02 Juni 2013 0 komentar
I really like Android ViewPager component. It can be used in so many ways: from app navigation to gallery like screens. 

ViewPager scrolling issue.
However, as I mentioned in my previous article ViewPager is not very usable if it's nested into a container with vertical scrolling. E.g. ViewPager inside ScrollView or ListView with ViewPager as a list item view. Imagine the case: you drag the ViewPager's page to view the next one, and booms! page horizontal scrolling is interrupted and parent vertical scrolling begins. 

Why? The issue is caused by intercepting of touch events from ViewPager by parent container. Parent scroll container listens for scroll touch events and if there vertical shift it steals the event from it's child views. It just thinks that user wants to scroll the parent container vertically.
So, let's help him with a more accurate decision!

Solution.
Full source code of my ViewPager subclass that resolves scrolling directions much much better is available here: SmartViewPager.java
It doesn't require any special configuration or actions from you. Just use it instead of the regular ViewPager and your users will be happy with a new smooth and expected scrolling behavior! ;-)
So, how it's done? There are two extras to help.
  1. custom SimpleOnGestureListener subclass helps us to detect the initial direction of scrolling. If the X-axis shift greater than the Y-axis shift, it will tell ViewPager to call requestDisallowInterceptTouchEvent at the parent.
  2. if the scroll gesture was initiated horizontally then ViewPager will be "locked" until gesture completion (finger up). So the parent scroll container will not be able to intercept ViewPager's events. It's somewhat similar to iOS scroll view behavior which locks the scrolling axis when the scrolling direction (horizontal or vertical) was resolved.
Will that extras break the original parent vertical scrolling? No, don't worry, all scroll directions are perfectly accessible. Here is the sample video from my Urban Curiosity application:



Check out that article to read more about the pitfalls you may encounter during 4-directions swipe navigation implementation:
http://vision-apps.blogspot.com/2013/05/4-directions-swipe-navigation.html

Sample project is available here:
https://bitbucket.org/NxAlex/swipes-navigation-demo 

Thanks for your attention! :-)

Baca Selengkapnya ....

4-directions swipe navigation

Posted by Unknown Senin, 27 Mei 2013 0 komentar
Gestures navigation.
I like fresh approach. And while I was developing my Urban Curiosity application I wanted to make it fresh by solving the common issue in a different manner . So I decided to make the application navigation based on swipe gestures and not on ActionBar, which is cool and handy navigation pattern that is used in near all modern applications.

Why gestures? Well, gestures can be performed on a larger screen area, so you can make a desired action faster and easier if to compare with a finger tap. Just swipe with your finger from any place to the desired direction! Also gestures are fun to use. :-)

In Urban Curiosity application you may navigate across all 4 main parts (Places, Profile, History and More) with a swipe gesture. Regular tap navigation is also available. I've prepared a short demo of the 4-directions (left, right, top, bottom) swipe navigation. The video itself is jaggy a little bit due to the video recording frame rate limitation. You may play with the real app to see how smooth it is. The demo video:



So in this article I want to share how to implement this in your projects.

Implementation.
Horizontal swipes are trivial - ViewPager class from the support library is perfect for this purpose. But what about vertical swipes and how to mix it with horizontal VerticalPager?

I've played with several open source implementations of vertical pagers for Android.
Not so buggy one as others is implementation by Grantland Chew: https://github.com/grantland/android-verticalpager 

So I have chosen it as a base for vertical paging. However, to reach my needs I needed to extend it a little bit:
  • remove the code that shrinks the first page a little bit to make the beginning of the next page visible
  • change onMeasure to a better mesuring pages height
  • add method to request page snap with a custom duration
  • add method to lock/unlock pages switching 
Now, we have the following choice: embed VerticalPager into ViewPager or vice versa. For the sake of simplicity and usage of nested fragments I decided to embed ViewPager into the VerticalPagerThat way, our activity will have a VerticalPager with three fragments: top,  central and bottom. Central fragment is a composite fragment and has three nested fragments: left, central and right. Pretty simple. Why fragments? More than likely each page will be completely different from thee others and has a custom behavior logic. In order not to overburden Activity object with all that stuff - fragments will help you to separate your code into smart reusable modules.

Next, we need to notify somehow VerticalPager (it's part of the activity) from the ViewPager (it's part of the fragment) about pages swipes to allow/disallow vertical scrolling. E.g. for left and right pages there should be no (i.e. disabled) vertical scrolling, while for central page there should be one (swipe to the top or bottom pages). 

The common way for fragment-activity or fragment-fragment communication is to:

  1. declare an interface into a fragment
  2. implement it into an activity
  3. provide that implementation to the fragment
  4. finally, the fragment will trigger it when needed (e.g. page changed). 
I like that way in general, it allows to keep things loosely coupled. However, that approach is pretty verbose. So there is another way to establish a "blind" communication between application parts. It's an event bus.

There are several Android event bus implementations. I wish to highlight three of them here. They were created specifically for Android and I used each of them extensively in a lot of projects. So feel free to choose the one you like more.


For this sample project I chose Otto. It has proven history of usage (at least by me and my team and by Square guys in their apps :-) and pretty easy to integrate and use.

So all communications are pretty easy now: 

  1. fragment with a ViewPager will post an PageChangedEvent event
  2. activity with a VerticalPager will receive that event and decide whether there is any need to lock the vertical paging or not. 
Do you see the cool thing here? Activity knows nothing about the fragment internals, it just declares "hey, notify me about page changes. I don't care where they came from, just notify me - I will do the rest". However, I want to warn you to use event bus very carefully. With a bad project design and events usage it can be hard to understand what and why happens in the project. Yes, there is a plugin for Intellij IDEA to navigate between events posted by Otto. But, you know, tools are never smart enough to make all the things for you.
So, event bus is a powerful tool in your arsenal, but use it with caution. 

The last thing I want to mention is ViewPager scrolling behavior. The default ViewPager from support library is a good and mature component. However, when it's used in a scroll based container it becomes hardly usable due to the scroll container touch events interception. I will write a note about soon. Right now you can find here my ViewPager extension that is much much better at resolving scrolling directions.

Sources.
The full sample project with 4-directions swipe navigation is shared at my Bitbucket account:
https://bitbucket.org/NxAlex/swipes-navigation-demo

Let me to know if it helps you or you have some question related to the topic! :-)

Baca Selengkapnya ....

Android: possible issues & solutions with configuration changes, part 2

Posted by Unknown Senin, 05 Maret 2012 0 komentar
Hello! Last time I was quite busy by creation of very cool and dynamic Android application for one of the world's largest mobile telecommunications company.
That is why the second part of the article about possible issues & solutions with configuration changes is coming only now. To be familiar with the topic I recommend you to read the first part of this article.

And now I want to share with you my solution for the mentioned topic. It's easy to use and it solves the task! This solution was evoked by Adobe Flex event model. As you may know I have extensive experience with Adobe Flex (it's Adobe's framework for creating Rich Internet Application). And one of the coolest Adobe Flex feature is its powerful event model. In general all Adobe Flex is event-driven, which gives us the perfect environment for creating loosely coupled components and system.

The same approach I wanted to apply in Android development.
The core idea of my solution is to have some kind of event bus:


















Ah no, not like this! I am joking! :D
The event bus we will have can be used to post results and subscribe to results of some specified event type. Thereby we will have loosely coupled system: components can notify and be notified by other components even without knowledge about each other.

So, let's take a look at this approach by example.
Imagine the common situation: you should make some work in the background thread. When a background task is completed you want to notify the caller about it.
How do we handle it with the suggested solution? Fairly simple!
1) define some event name, e.g. STOCKS_UPDATED
2) add a listener (which is a realization of EventCallback interface) to that event:
EventBus.subscribe(STOCKS_UPDATED, stocksCallback);
3)just post the result from the background task, when you want to notify listeners about some events (e.g. in onPostExecute method of some AsyncTask):
EventBus.postResult(STOCKS_UPDATED, result);
That's all! As you can see you can wire up your application components with minimum lines of code in an easy and reliable way!

Few notes:
a) you can add as many event listeners as you want
b) if you don't need listener anymore, just remove it:
EventBus.unsubscribe(STOCKS_UPDATED, mStocksCallback);
c) BaseEventResult is a base class for events results. It already has status and data fields.
If needed you can extend it to carry any kind of data you like. Or just subclass BaseEventResult to more specifiс event results (e.g. StockResult, BondResult, etc.)
d) if you keep event listeners as an Activity fields, then, as you already know, they will be destroyed with Activity itself when configuration changes occurs. To handle it: just add a listener at onResume and remove it at onPause.
@Override
protected void onResume() {
super.onResume();
EventBus.subscribe(STOCKS_UPDATED, mStocksCallback);
}

@Override
protected void onPause() {
EventBus.unsubscribe(STOCKS_UPDATED, mStocksCallback);
super.onPause();
}


I've prepared a sample project that demonstrates usage of my EventBus solution. You can download it here.

While this approach may be not perfect, I think it is quite good, because of it covers most of the common issues with configuration changes. Also it's very easy to use and highly extensible! Feel free to use it or share your thoughts about it with me! ;-)


Baca Selengkapnya ....

Android: better way to apply custom fonts

Posted by Unknown Senin, 27 Februari 2012 0 komentar

In one application I had to apply customer's brand font for all controls of the user interface.
Sounds like a pretty common task, right? Yeah, I was thinking the same.
But then I was surprised that Android doesn't provide simply and elegant way to do this.

So, in this article I will show you what Android provides us by default. Then I will share with you my solution, which allows you to apply custom fonts in a more simple and elegant way.

Situation:
you have a custom font that should be applied for entire application screen.

Solution:
1) Android's default #1:
You can refer by id view controls, and apply typeface for each of them. In case of one view it looks not so scary:
Typeface customFont = Typeface.createFromAsset(this.getAssets(), "fonts/YourCustomFont.ttf");
TextView view = (TextView) findViewById(R.id.activity_main_header);
view.setTypeface(customFont);
But in case of many TextView, Buttons, etc. view at your screen you will not love this approach, I can assure you! :D

2) Android's default #2:
You can create subclass for each TextView, Button, etc. and apply custom font in the constructor:
public class BrandTextView extends TextView {

public BrandTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public BrandTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public BrandTextView(Context context) {
super(context);
}
public void setTypeface(Typeface tf, int style) {
if (style == Typeface.BOLD) {
super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/YourCustomFont_Bold.ttf"));
} else {
super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/YourCustomFont.ttf"));
}
}
}

Then just use that custom views instead of standard ones (i.e. BrandTextView instead of TextView).
<com.your.package.BrandTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View with custom font"/>
<com.your.package.BrandTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="View with custom font and bold typeface"/>
Also, you can even add your own attribute to set required font directly via XML. To make you will need to define your own declare-styleable attributes and parse attributes in the constructor.
In order not to describe the basic things, I just point for a good article by Kevin Dion with an
example of custom attributes implementation:
http://kevindion.com/2011/01/custom-xml-attributes-for-android-widgets/

In general solution #2 not so bad and has it's own advantages (for example, to switch between regular, bold, etc. fonts based on specified "typeface" attribute value). But in my opinion it's still too heavy and requires a lot of boilerplate-code for such a simple task as applying custom font.

3) My solution:
the ideal solution would be to define custom theme and apply it to entire application or Activity.
But unfortunately Android's android:typeface attribute can only use inbuilt fonts, but not the custom fonts (e.g. from the assets). That is why we can't get away from the loading and applying fonts at runtime in Java code.
So I decided to create a helper class to make it as simple, as possible.
The usage of it looks like:
FontHelper.applyFont(context, findViewById(R.id.activity_root), "fonts/YourCustomFont.ttf");
And this one string will apply custom font for all TextView based controls (TextView, Button, RadioButton, ToggleButton, etc.) at your screen regardless of their layout hierarchy! ;-)
Standard (left) and Custom (right) fonts usage.

How this was done? Fairly simple:
public static void applyFont(final Context context, final View root, final String fontName) {
try {
if (root instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) root;
for (int i = 0; i < viewGroup.getChildCount(); i++)
applyFont(context, viewGroup.getChildAt(i), fontName);
} else if (root instanceof TextView)
((TextView) root).setTypeface(Typeface.createFromAsset(context.getAssets(), fontName));
} catch (Exception e) {
Log.e(TAG, String.format("Error occured when trying to apply %s font for %s view", fontName, root));
e.printStackTrace();
}
}
As you can see there is nothing more then looking for TextView based views at all levels of layout hierarchy.
You can download sample project with usage of FontHelper here.



Baca Selengkapnya ....

Adobe Flex: useful stuff for mobile development, part 2

Posted by Unknown Selasa, 13 Desember 2011 0 komentar
This is the second part of my post about Adobe Flex usage at mobile platforms.
In this post I want to show you several good sample projects of Adobe Flex usage on mobile platforms. All of them have source codes available for download. So if you're interested in cross-platform application creation with Adobe Flex this is a good way for a quick dive! ;)

Adobe engineers team has made a great progress with AIR runtime, and now Adobe Flex applications on mobile platforms (Android, iOS, etc.) show good performance and list of available features. At the same time, evangelists team has prepared a bunch of demo projects for popularizing of Adobe Flex as technology for cross-platform development.


Expense tracker application





The Expense Tracker Reference Application is a sample application created with Flex 4.6. It will introduce you to the major updates in the Flex 4.6 SDK, and demonstrate best practices for designing and developing a CRUD-based experience for mobile, tablet, and web platforms. The three Flex 4.6 Reference Applications use the ViewNavigatorApplication class as an application base for screen management, the ItemRenderer and LabeltItemRenderer/IconItemRenderer classes for list controls, and the MultiDPIBitmapSource and RuntimeDPI providers as means to manage different DPIs on different devices.
More info and source code:


Shopping cart application























The Shopping Cart Reference Application is a sample application created with Flex 4.5. It will introduce you to the major updates in the Flex 4.5 SDK, and demonstrate best practices for designing and developing a shopping experience for both mobile and web platforms. The three Flex 4.5 Reference Applications use the ViewNavigatorApplication class as an application base for screen management, the ItemRenderer and LabeltItemRenderer/IconItemRenderer classes for list controls, and the MultiDPIBitmapSource and RuntimeDPI providers as means to manage different DPIs on different devices.
More info and source code:
http://www.adobe.com/devnet/flex/samples/shopping-cart-application.html


Sales dashboard application























The Sales Dashboard Reference Application is a sample application created with Flex 4.6. It will introduce you to the major updates in the Flex 4.6 SDK, and demonstrate best practices for designing and developing an enterprise sales dashboard experience for mobile, tablet, and web platforms. The three Flex 4.6 Reference Applications use the ViewNavigatorApplication class as an application base for screen management, the ItemRenderer and LabeltItemRenderer/IconItemRenderer classes for list controls, and the MultiDPIBitmapSource and RuntimeDPI providers as means to manage different DPIs on different devices.
More info and source code:
http://www.adobe.com/devnet/flex/samples/sales-dashboard-application.html


Sample application for tablet with latest Flex 4.6 components





















The Flex 4.6 SDK features used in the application are:
  • SplitViewNavigator with state handling (uses new properties to put the first view in a Callout when in portrait mode due to screen space)
  • New Callout component
  • New CalloutButton component
  • New SpinnerList component (and corresponding SpinnerListContainer)
  • New ToggleSwitch component
  • Dynamic Splash Screen
  • Soft Keyboard Type handling (showing the numeric soft keyboard for example)
More info and source code:
http://devgirl.org/2011/10/31/flex-mobile-development-building-tablet-apps-full-example-with-source-code/


Game of Flex for tablets























If you want to check the source code of the app, you’ll learn:
  • How to use the new SplitViewNavigator architecture (portrait and landscape layouts on tablet devices)
  • How to display HTML content inside a Flex app
  • How to access the camera to take pictures
  • How to use the BusyIndicator, ToggleSwitch and List components
  • How to enable multi-touch
  • How to manage your views
  • How to use the accelerometer
  • How to create custom AS3 item renderers for your lists
  • How to access the local SQLite database
  • How to use native extensions
  • How to set up the new DateSpinner component
  • How to display callout popups
  • How to set up the software keyboard to match your needs
  • How to declare spinner lists
More info and source code:
http://www.riagora.com/2011/12/game-of-flex-on-tablets/



Blue Chips application





















The application demonstrates extensive usage of chart components and new Flex 4.6 components that target tablet development.
Description and video:
http://www.riaspace.com/2011/12/flex-4-6-bluechips-demo/
Source code:
https://github.com/pwalczyszyn/BlueChips


When you will start creation of your own mobile application with Adobe Flex, don't forget about performance optimization. It's quite important to provide responsive user interface with seamless interaction.
There is an article that will be quite useful for that purpose:
Flex mobile performance checklist

Have fun! :)


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 ....

Android: easy trick to make beautiful background for you Android application

Posted by Unknown Rabu, 28 September 2011 0 komentar

Nice screen background, isn't it? :)
Today I will show you an easy Android design trick how to create very beautiful backgrounds for your Android applications in just 2 minutes!

For example, imagine that you have some simple form like this:
It's pretty boring, huh?

Now let's make this UI screen more attractive. ;-) What we can do with background? Yeah, we can set some fancy solid color or even gradient fill. But it doesn't change entire situation too much.

What is the solution? I recommend you to apply pattern fill for background. All you need is just an seamless pattern image and 1 minute for coding! :)

  1. Find any seamless pattern image that you like and put it into drawable folder (or in drawable-ldpi, drawable-mdpi, etc. folders if you have several images of the same pattern for different screens). 
  2. Create new XML file and put it into drawable folder: (e.g. drawable/background_pattern_fill.xml)

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/background_pattern"
  android:tileMode="repeat">
</bitmap>

where is "background_pattern_image" is your favorite seamless pattern for custom background.
     3. Apply created custom background to any View component:
<LinearLayout
...
android:background="@drawable/background_pattern_fill"
...>


Voilà! Now our UI screen looks much better! You can download the source code here.


More examples:




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