Android: Reading, using and working with XML data and web services in Android

Posted July 19th @ 8:37 pm by Boyan Tsolov

One of the most powerful aspects of any mobile application for a 3G phone is that it can connect to the Internet. By connecting to the Internet the application can offer much more value to the user since it becomes an interface for a web-based component, e.g. using Twitter’s API to create a Twitter application so that you can get your Twitter updates without having to open the mobile browser. The most common way of interfacing with a web-based component is by using web services in XML format.

While trying to developer my own app which reads a web service from my own server, I ran into a lot of difficulties in implementing the client that consumes the web service. Android does not have libraries for XPath handling of XML documents, so it makes deciphering XML data a little bit more difficult. From what I’ve read online the Android team is currently working on including such libraries in future versions.

After some digging around I found an amazing link that shows different methods for consuming an XML file in Android and parsing through it without the use of XPaths. The link is this: Working with XML on Android. To start off, this link is an absolute must-read. Everything that I am going to write in my post here relates to this link. The code offered on that webpage uses polymorphism to show you 4 different methods of working with XML data. It provides a fully-functional Android application and all the source code for it. The source code can be found here: AndroidXML.zip.

My post today will concentrate on how to customize the code from the application in the above link, in order to read and parse your own XML data. If you are a Java pro, you might not need this post. My Java is a little rusty, so I needed some time to figure out exactly what I had to change and where in order to get this to work with my own web service XML. Now that I’ve figured it out, I thought I’d share it. In my next post I will give the simplified version of this code – where there is no polymorphism, and thus there are only the minimum number of classes needed to implement this XML-reading solution. I can’t offer this simplified code right now – because I haven’t coded it yet :).

So until I post the simplified source code for working with XML data in Android, here are some tips on getting through the larger polymorphism-based source code and customizing it for your own XML data:

Read the rest of this entry »


Advertisement


Android: Creating TableRow rows inside a TableLayout programatically

Posted July 1st @ 10:07 pm by Boyan Tsolov

In my quest to create a “Taxman” Android application I ran into the following problem:

I want to ask the user to enter their yearly income, after which the screen will flip and their after-tax income will be displayed in a table format for all Canadian provinces. (And for the future: all US states). The problem I ran into is creating a TableRow for each Canadian province in my main.xml. There are 13 provinces and territories, so 13 is not that bad to copy & paste in the main.xml; however, as soon as I have to copy & paste more than 2 times I start cringing and nausea kicks in. Personally I think “copy & paste” should not be in the programming vocabulary. Not only that, but I have 13 provinces now, what about when I have to enter 50 states! So, I had to find a way to create these new TableRow rows programmatically inside my TableLayout layout.

A great source for code snippets and answers to Android questions is http://www.anddev.org. I’m sure if you’re dabbling with Android then you’ve already come across this site. The particular post I read to do this is this one: Dynamically add rows to TableLayout. Commenters on that post were having problems getting this to work, but after I imported all the correct classes (android.widget.TableRow.LayoutParams is an important one to use) everything worked from the first time. I forced Eclipse to find most of the classes for me.

Below is the code from anddev.org, with my changes for my Taxman Android app. I’m too lazy to do a full-out beginning-to-end tutorial for this code snippet.

First I set my constants at the top of the Activity class:

public class Activity1 extends Activity implements OnTouchListener{

    int PROVINCE_Alberta = 0;
    int PROVINCE_BC = 1;
    int PROVINCE_Manitoba = 2;
    int PROVINCE_NewBrunswick = 3;
    int PROVINCE_Newfoundland = 4;
    int PROVINCE_Northwest = 5;
    int PROVINCE_NovaScotia = 6;
    int PROVINCE_Nunavut = 7;
    int PROVINCE_Ontario = 8;
    int PROVINCE_PEI = 9;
    int PROVINCE_Quebec = 10;
    int PROVINCE_Saskatchewan = 11;
    int PROVINCE_Yukon = 12;

    int numProvinces = 13;

Read the rest of this entry »


Android: Switching screens by dragging over the touch screen

Posted May 29th @ 12:17 am by Boyan Tsolov

In this post I will show you how to use the touch screen so that you can drag your finger across the screen, and it will switch the screen for you – “iPhone style”!

For this I will be implemented OnTouchListener and overrided the method OnTouch().

To start off, we need to create an Activity with two screens. The two screens will be implemented using a ViewFlipper in the main.xml layout file. Follow the steps in this blog post to set yourself up: Android: Switching screens in an Activity with animations (using ViewFlipper).

1. Now that you have yourself set up, open the Activity1 class.

2. Make the class implement OnTouchListener. The top of the class will look like this:

...
import android.view.View.OnTouchListener;

public class Activity1 extends Activity implements OnTouchListener{
...

2. You will have to override the OnTouch() method as well. If you were using eclipse, it might have created the method stub for you:

    @Override
    public boolean onTouch(View arg0, MotionEvent arg1) {
        // TODO Auto-generated method stub
        return false;
    }

Here is the method that you need to use instead:

    public boolean onTouch(View arg0, MotionEvent arg1) {

        // Get the action that was done on this touch event
        switch (arg1.getAction())
        {
            case MotionEvent.ACTION_DOWN:
            {
                // store the X value when the user's finger was pressed down
                downXValue = arg1.getX();
                break;
            }

            case MotionEvent.ACTION_UP:
            {
                // Get the X value when the user released his/her finger
                float currentX = arg1.getX();            

                // going backwards: pushing stuff to the right
                if (downXValue < currentX)
                {
                    // Get a reference to the ViewFlipper
                     ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
                     // Set the animation
                      vf.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
                      // Flip!
                      vf.showPrevious();
                }

                // going forwards: pushing stuff to the left
                if (downXValue > currentX)
                {
                    // Get a reference to the ViewFlipper
                    ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
                     // Set the animation
                     vf.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));
                      // Flip!
                     vf.showNext();
                }
                break;
            }
        }

        // if you return false, these actions will not be recorded
        return true;
    }

What I’ve done is added a CASE statement. On press down of the finger we save the current X value. On press up of the finger, after the dragging motion has finished, I check the X value again. I compare the two X values and I make a logical decision whether I should switch the screens forwards or backwards.

Read the rest of this entry »


Android: Switching screens in an Activity with animations (using ViewFlipper)

Posted May 26th @ 11:48 pm by Boyan Tsolov

In this post I’ll show you how to add animations when trying to switch between screens. Usually when you switch between screens it’s a direct “poof” and the new screen appears in a very un-graceful way. The SDK offers a bunch of easy-to-use animations, and I’ll show you how to use them here.

I tried doing animations on the opening and closing of activities, but I haven’t figured that out yet fully. So instead, I will show you how to use animations when switching on objects/layers inside the same activity. It will still look like you are switching screens, but all the layout data will be in one single XML. If we were to switch between activities, each activity would have had (usually) its own layout XML.

And in the post coming after this one, I’ll show you how to start this animation and switch the screen while dragging your fingers on the touch screen. Let me be a little more precise: while dragging one finger on the touch screen. I’m not sure if the OS handles multi-touch right now – or if that’s something the device has to enable – or both.

Back to the topic: how to switch between layers using animations to make it look like you are changing screens… we will be using a ViewFlipper widget in the layout XML.

1. Create a new Android project, unless you already have one

01 new project

2. Create a new Activity class that extends android.app.Activity.

02 new class

Read the rest of this entry »


Android: Reading Logs and Exceptions

Posted May 24th @ 11:21 pm by Boyan Tsolov

While developing my Android apps I routinely, regularly, almost every time, without a miss, get some kind of exception. And the error you see on screen is not developer friendly, though it is very end-user friendly:

01 error

WTF? Why? What did I do wrong this time, again?

Read the rest of this entry »


Android: How to switch between Activities

Posted May 24th @ 10:38 pm by Boyan Tsolov

In my great expectations of Google Android coming to Canada on June 2nd, I’ve started experimenting with developing some apps for the Android platform. My first app is called “The Taxman” and will calculate the amount of tax you owe per year in your province/state – well only Canada for now.

I had trouble adjusting to what an “Activity” was and how to handle it. Here is a quick and dirty way to create an Activity, and to switch to another Activity (think of it as another screen) on the click of a button.

1. Create a new Android project – or you might already have one created.

01 new project

2. Add a new Class that extends android.app.Activity. You need a total of two classes that extend Activity. You will switch from one Activity to another.

02 new class

03 new class 2

Read the rest of this entry »


Developer’s Perspective on Android: Getting Started

Posted May 24th @ 9:49 pm by Boyan Tsolov

Google Android

I’ve been a fan of Google’s mobile operating system Android for quite a while – technically since I heard about it 2 years ago. I’ve been unfortunate to live in Canada, because none of the telco companies here have carried any phones with Android (only HTC phones for now, but Samsung seems to be coming out with something soon).

But, on June 2nd 2009 Rogers is coming out with the HTC Dream and the HTC Magic and Google Android will be here! And on June 3rd Google Android will be in my hands. [I’m not going to be a geek and get it on the very first day it comes out, come on!]

So, in expectation of this date, I started playing around with Android and developing my own applications. To start off, it’s been absolutely easy, pleasant, and a breeze to setup. It was like stealing candy from a kid. I followed the instructions from the Android – Developers website and using Eclipse as my environment I was creating mobile applications in less than 30 mins.

To get the SDK follow this link: http://developer.android.com/sdk/1.5_r2/index.html
To read the installation instructions follow this link: http://developer.android.com/sdk/1.5_r2/installing.html
And I recommend using Eclipse if you do want to get the “30 mins effect”.

I wanted to test out the different functions/features that Android offers out of the box, so I thought of a simple app which would allow me to have a goal and thus opportunities to experiment. I am going to write a “tax” application. Unfortunately, this tax application will not fill out your taxes. It will calculate how much the government has to take from you each year. You will enter your country (Canada only for now), you will enter your income, and the result will be a summary of your take-home pay and taxes due, by province (or states for the US – eventually). I’m going to call it “The Taxman”.

I’ve just started this mini app, and as I go along I will post snippets of code that I found difficult to come up with – to help out anyone that is looking for the exact same solution. Also, I have a full-time job, so it will take me a month to complete this silly app :), so my posts might be infrequent.

This weekend I had a chance to start it off and I had trouble with a couple of things. I will write a separate post on each one over the next couple of weeks. Here’s three of those things:

1. How to switch from one screen to another (also called Activities)

2. How to switch screens with an animation effect

3. How to switch screens using a dragging motion with your finger – you know, iPhone stylez.

That’s it for now… those 3 posts will be coming out very, very soon!



Advertisement

Options:

Colors

  • lesbians fingering anus
  • Amira casar sex scene
  • Spice girls naked
  • sexy asian wemon
  • indian saree sex galleries
  • fresh young teen butt videos
  • hubby films wife gets pussy cream
  • mom teaches teen hardcore tactics
  • latina mature sex mpegs
  • short fuck sex video free
  • vin deisel naked pics
  • free latino bikini pics
  • pullon stretch womens petite pants
  • school girl bus teen
  • amatuer teen sexy wife vid
  • cause for wife to decrease sex
  • preachers wife pics
  • girls who love black cock
  • street bike pics girls
  • xxx creampie mature
  • blacks and teens simone claire
  • Naked ladies breasts
  • paris hilton shows her pussy pictures
  • teen self pics
  • three chicks sucking on a dick
  • young teen cheerleader pics
  • xxx moms fuck
  • naked amsterdam girls
  • dana delaney pussy pics
  • what is the best amateur videos
  • free british justine pussy
  • sex crazed couples vhs
  • kiwi black retire
  • college girls have sex for books
  • wife big dominican dick
  • shemale feet movies
  • called jungle girl
  • Nancy ajram nude photos
  • massive dick shemale
  • mile aged women movies
  • asian teenage girls thumbs
  • school boy and girl xxx
  • teen in sexy lace thong
  • girls shaking their ass in underwear
  • First time lesbian kisses
  • nude mexican teen girls
  • Very old hairy pussy
  • hub skinny girl anal
  • young girls toying ass
  • girls pictures special lovely softcore
  • ebony big booty galleries
  • femdom ass eating videos
  • titty and pussy
  • pictures fat bikini woman
  • hot asian girlfriends
  • teen blonde cums
  • teen nudism photos
  • passed out sex movies
  • Huge ass getting fucked
  • penn state girls naked
  • nude ebony sucking white dick
  • chess video
  • sex aunty video
  • free men anal penetration video
  • hot ass volleyball pussy walsh
  • gymnast teens gallery
  • girls flashing at a supermarket
  • sex between lesbians
  • Brandi c naked video
  • Big breasts pregnant
  • free teen exposing all video
  • party sex outdoor
  • picture of barack obama wife
  • japanese pink vibrator orgasm
  • anna nichole smith video
  • goat milking womens tits video
  • Udita goswami hot sex
  • spanking teen girl punish linik
  • young miss
  • her first time have sex video
  • amateur housewife tries lesbian
  • amateur first time videos
  • dallas pussy reviews
  • scarlett johanssen bikini pictures
  • fat girls teens
  • Saudi hot girls
  • wife friend fuck video
  • red tube homemade sex movies
  • cute blonde teens nude
  • pussy eat out
  • free amature wife with blacks videos
  • tiny teen fuck s
  • erotic stocking gallery
  • Banana girl kiss
  • pussy on bicycle seat
  • hig qualtiy videos
  • teens kissing galleries
  • young teen movie thumb
  • hardcore dry sex
  • asian guys white girls
  • peurto rican beauties videosxxx
  • red haired teens sucking dick
  • asian crossdressers pics
  • long asian vids
  • petite womens athletic wear
  • mom eats daughters pussy
  • mature sex call back
  • home made amateur anal
  • asian japanese transexual videos
  • naked asian men galleries
  • wife gave some pussy
  • teens fucking free galleries
  • lets get fucked by black dick
  • cheap mature sex
  • hot sexy naked lesbain hardcore
  • Sarah vandella interracial
  • young tiny slut fuck movie
  • young girl holding a grizzly cub
  • pool suck dick spurts
  • fisting gaping pussy video
  • asian creampie gallery
  • hot naked girls playing with boobs
  • Jamie lee curtis nude movie
  • beauty and the sex
  • free videos rough mom
  • Reality stars nude pictures
  • black dick fuck me
  • old couples fuck party
  • remus and sirius video mature
  • pussy taking big cock
  • leanardo de caprio french movie sex
  • teen free pictures
  • ebony hub
  • free softcore movies index
  • young black teen virgin
  • black beauty sandblast health
  • flatchested teen galleries
  • teen kat naked
  • huge latina tits video
  • hot babes lesbains gallery
  • torrent sex young girls
  • top asian
  • korean erotic massage pictures
  • maria silva anal movies
  • hot naked free webcams
  • mo girl sex
  • woman sex real orgasm
  • cow sex videos
  • little girl with huge tits
  • free pussy pics vids
  • free big tit college girl vids
  • teen with small tits sucks dick
  • how do hatian girls have sex
  • free online big tits videos
  • erotic tit pics
  • Lectii de sex oral
  • free asian shemale gallery
  • the ebony black
  • asian face sit pussy pov
  • rema sexy pakistani girl video
  • Naked sexy
  • anal sex free vidios
  • sucking on tits webcam
  • beautifull breasts pics
  • can glrls xxx sex video
  • under table licking pussy
  • lezley zen black cock sex
  • Jap teen pics
  • naked girls small tits
  • How to fuck a girl good
  • free hot black teen vids
  • black women with big butts
  • black opal facial treatment
  • petite zipped thumbs
  • pictures girls in the shower
  • young bald pussy
  • black sea gallery stockton
  • hungry amateur sex tapes
  • Sex scene tia carrere
  • free topless aussi girl movies
  • videos girls in shower
  • lake havasu bikini pics
  • pussy wet lips
  • photos topless australian beach party
  • pretty hardcore girls
  • old movies about sex teens
  • sex girls strip poker lounge
  • teen hardcore blowjobs
  • young lil fuck pics
  • lesbian anal penetration tube
  • free mature vs twinks videos
  • young spycam
  • amateur bikini galleries
  • sandra bullock movies
  • bad girls fuck boys
  • old man lick young girl pussy
  • best all girl three way sex
  • hot ass girls havig sex
  • petite plus size apparel women
  • erotic nude male pics
  • shaggy pussy round ass ebony
  • simi from sexy babes
  • Iran sex movies
  • sex girl father tiny tits
  • amateur photographs girlfriends
  • young girl art gallery
  • Sri lankan hot sex videos
  • Rough interracial sex
  • black mom and daughter xxx movies
  • girls like men for sex
  • lesbian sucking boobs pics
  • free mature women videos
  • girls showing lovely breasts
  • hd young fuck
  • video teen girl blowjob swallow
  • alt binaries petite teen
  • amanda seyfried pussy
  • is anal sex is wright
  • teen briana pics
  • marry younger wife bad
  • eva angelina tube videos
  • interracial double black cocks in ass
  • Nude african pussy
  • anal sex abortion priceless
  • black stud and wife
  • extremely beautiful naked young girls
  • Shaved pussy fucking
  • black strapon free videos
  • black men sucking whie womens tits
  • pussy lick by
  • mom teaching teens fuck
  • horney pussy fucking
  • free hardcore star pics
  • free lindsay lohan naked pics
  • amateyr submit videos
  • toons sex tube shemale
  • hot flat young girls
  • Model teen bbs
  • disaster movie
  • anal bdms compilation
  • free flashing girls videos
  • Lesbian deep kiss contest
  • crimson crescents throat picture
  • free fetish licking pussy
  • free sex picture in the mud
  • naked asian girl striptease
  • gigantic tits free galleries
  • free xxx black shemale tubes
  • jesus what a pussy
  • guy gets t grab boobs video
  • young sweet sex
  • white cock in girls ass
  • bilara fuck galleries
  • hardcore on exam table
  • puffy nipples video for marriage
  • glamour lesbian love scene
  • young girl models gallery
  • hot anime girls bikini
  • moyher and son sex videos
  • old granny big tits pictures
  • teen pics shower
  • in the vip videos
  • young asian boys pics
  • women stretched oral sex
  • adult video free asian
  • danica pateric sex videos
  • ethinic girls breasts
  • hot ass teen girls
  • pretty girl backround picture
  • pussy fucked socks
  • video of giants beating patriots ass
  • wife tit fuck
  • asian teen kyoto fuck white dick
  • s young teens videos
  • audio erotic sex stories
  • xxx stunning girls
  • young girl slit
  • black girls and mtg
  • video of girl fights without clothes
  • Pretty girls make graves new romance
  • tube star free videos
  • blonde teen couple
  • hour long movies
  • asian teen first time fuck
  • nicole scherzinger naked pictures
  • craziest website video forum
  • pimping my wife to black men
  • xxx free mature rooms
  • home videos of couples having sex
  • true amateur nude picture
  • mature amateur pee
  • Photo sex story