Saturday, June 30, 2012

Specify your widget margin/padding property values in “dip” units

This one baffled me for a while.  I had an Android layout open in the Eclipse graphical layout editor with a TextView component.  Every time I changed any of the Margin or Padding properties the widgets disappeared off the layout, even if I entered the smallest non-zero value of 1.  Turns out that I needed to add the string “dip” after the number.  I guess the default units for margin is something that translates to a huge distance on the layout.  For example, instead of 4 enter 4dip.

Debugging NullPointerException exceptions in Android


Debugging a NullPointerException can be a huge annoyance when debugging an Android application.  I use Eclipse 3.2 for my Android/Java programming.  An Android application by default is a highly event driven multi-threaded program (aka 3-ring circus).  If you find that you are getting a NullPointerException in some weird part of your code or worse in the Android library with your code nowhere to be found in the stack trace, it is most likely due to the exception actually occurring in some other part of your code.  However, the NullPointerException doesn’t get raised in the debugger until  some background event or other thread occurs making it hard to figure out where your code went wrong.  The two main suggestions I found in this area on this wonderfully helpful StackOverflow post are:
1) Check Eclipse’s LogCat to see what part of your code was running at the time of the exception.
2)  Execute the following steps to make sure “Suspend On Caught Exceptions” is active.
  • Run -> Add Java Exception Breakpoint
  • Find NullPointerException (or whatever else you might be debugging , that is, the “Caused by” exception)
  • Make sure Suspend On Caught Exceptions is checked. Click OK.
  • You should see a new breakpoint in your view

  • Read the full post for further comments and details.

    Name Shadowing and Conflicts – better Eclipse Settings


    Today I fought a nasty bug that was caused when I accidentally declared a Class method local variable with the same name as a Class level variable.  Eclipse 3.5.2 in its stock configuration ignores this kind of a name shadowing/conflict.  Fortunately there’s an IDE setting that you can use to have these kinds of errors flagged.  Go to the following location in the IDE:
    Eclipse -> Preferences -> Java -> Compiler -> Errors/Warnings -> Name shadowing and conflicts
    And set Field declaration hides another field or variable and Local variable declaration hides another field or variable to Error or Warning, whichever you prefer.  Here’s the StackOverflow question I asked that got me that solution.

    Put persistent objects in the Application object in Android


    The way objects can reference each other can lead to subtle memory leaks as discussed inthis Android document.  Objects that are used by Activities, for example static Class members, can end up making it impossible for the garbage collector to free the Activity since that Activity may be referenced by the object in a cyclic way.  For example, Drawables in Android have a callback reference to the widget in the Activity’s layout that it is tied to.  If the object is a memory hog you can end up leaking memory badly, especially if the Activity is tied to hordes of other memory consuming objects that are now unable to be freed.  Rather than try to analyze every object reference or Activity chain in your application, it is better to follow one simple rule of thumb religiously:
    If you plan on keeping long-lived objects that need a context, remember the Application object.
    The Application object is create only once in an Android application and persists through the application’s life cycle.  Put any objects that you want to persist, including those you don’t want reloaded every time a particular Activity starts due to excessive loading times, in the Application object and reference them through that class.

    ADB Shell – “Device Not Found”

    This one threw me for a short while.  I wanted to go in to the adb shell and whenever I ran it from a (Mac) Terminal window, I got “device not found”.  The reason for this is that you have to have the emulator already running or there is no device for the adb shell to connect to.  I’m guessing that if I had a phone connected that would work too but I have not tested that yet.

    Hands on with The Amazing Spiderman on the Nexus 7

    We just showed you a hands on demo of Frontline Commando on the Nexus 7 but figured we wouldn’t stop there. Many of you have questions about gaming on Google’s new 7-inch tablet and we have another demo video to show you how great the experience really is. Gameloft’s The Amazing Spiderman game just launched in the Play Store for $6.99 and looks awesome on the 7-inch form factor. Jump past the break to check it out and be sure to let us know what you think! Are you surprised to see such high quality games for the Nexus 7 already?



    Google I/O day one keynote highlights now available on YouTube



    Interested in seeing some video from the Google I/O day one keynote, but not enough time to sit through the hour long video? Check out the highlights video that has been released by Google via YouTube. And yes

    Android 4.1 Jelly Bean Overview On The Nexus 7


    The Nexus 7 tablet was not the only star at Google I/O this year. Android 4.1 Jelly Beanshared the spotlight and is just as impressive, if not more so. In this video, we walk through some of the standout features of Google’s latest mobile OS, including recommendation widgets, flick to delete, icon and widget interactions, Google Now, and more.
    Even though Jelly Bean only moves Android up to 4.1, there are enough new features to consider this much more than a minor release.
    Hit the break to see Jelly Bean in action on the Nexus 7.

    Zombie thriller, Dead Trigger blasts its way onto Android July 2




    Zombie-mania has hit many a geek lately, myself included, and Android zombie lovers will get what looks to be a great first person shooter title as soon as Monday, July 2. Dead Trigger appears to be a cross between Resident Evil and AMC’s The Walking Dead, and it looks awesome! You will fight off hordes of undead with many different weapons in your arsenal.
    The game is only $.99 and promises to deliver updates with new missions,  weapons, characters and more. Hit the break for the official presser and check out the video below for yourself and see why I will be buying this game on release.

    Liveness Check added to Jelly Bean Face Unlock security feature


    We all remember how cool the new Face Unlock feature was for Android 4.o Ice Cream Sandwich when it was announced a while back. Today it’s still a nifty trick to show off to your iPhone buddies or at parties, but we all know that it’s far from foolproof. The fact that one could just simply use a still photo of the phone owner to access all their content was a little disappointing and relegated this security feature to basic social entertainment.
    Well Google listened to the constructive criticism and updated Face Unlock with their new ‘Liveness Check‘ function for Android 4.1 Jelly Bean devices. Liveness Check will wait for the phone owner to blink before proceeding to unlock the phone.
    Now I know some of you are going to go out on the highest tree limb and say that someone could just present a video of the phone owner to access the forbidden. Sure, I guess that’s true but how many of you actually have videos of people that are simply looking directly into the camera. If you have that intimate of a video, it’s probably safe to assume that you are close enough to the person that the Face Unlock is not intended for you in the first place.
    So all in all, I think Liveness Check is a great additional security measure taken by Google to further protect Android user content.

    1 App, 3 Opinions: What Do Our Experts Think of Evernote Food?



    Another week, another app. Every week three members of our amazing editorial team share their expert opinion about a specific app including the good and the bad. Here at AndroidPIT we're all about providing a variety of different viewpoints with changing panel of Android judges. Today we've got AlessandroIsabel and Kamal sharing their impressions of Evernote Food.

    Exciting Changes Coming to Andromo App Maker for Android


    It’s been an exciting journey here at Andromo. In just a few short months:
    • We’ve gone from zero to 84,718 awesome users.
    • You’ve created 77,387 app projects.
    • Our cloud servers have run 109,323 app build processes without missing a beat. Each time generating custom source code for your app, plus compiling, linking and emailing it to you. And we manage to do that all in 5 minutes or less – most of the time anyways!
    • You’ve already published over 4,000 Android apps on Google Play. And the apps you’re making just keeping getting better and better.
    • We’ve gone from offering you a handful of powerful app activities to almost 20 now. And we’ve got ideas for dozens more.
    • Apps made with Andromo have served up hundreds of millions of ads.
    • Our downtime can be measured in minutes, and that’s only been due to deploying feature updates so you can make cooler apps.
    Like I said, it’s been a crazy fun adventure already, and we’re just getting started.
    But, as you no doubt already know, we’re not the sort of people who like to stick with “good enough.”
    Heck, we don’t want Andromo to be 2nd best at anything – and that includes being the best value app maker too. So, when you spoke, we listened.

    What You Asked For…

    • You asked for an “all the apps you can make” plan, and we’re going to give it to you.
    • You asked for an “I keep 100% of the advertising” plan, and we’re going to give it to you.
    • You asked for a “sell as many apps on Google Play as you can make” plan, and we’re going to give it to you.
    • You asked for a “premium/Gold activities for all my projects” plan, and we’re going to give it to you.
    • You asked for a “Google Analytics in all my projects” plan, and we’re going to give it to you.
    And of course, you wanted all of those things at a super affordable price…
    So we’re going to give it to you.

    What We’re Going to Do…

    On Monday June 25, Andromo will be switching over to a new developer membership/subscription format. Here’s how it will work.
    For only $25/month or $99/year (limited time introductory offer – a savings of $200) you’ll get full access to everything listed below:
    • Make as many apps as you want. Whether you want to make one app or a hundred, it’s all the same price.
    • Use all the activities in Andromo, including what were previously ‘Gold’ activities, like Phone, Email and Contact.
    • Access to all future activities, including Podcast, SHOUTcast Radio, Audio Playlists and PDF Viewer (which were slated to be ‘Gold’ activities) – which will be released shortly!
    • Turn off the advertising in any app you make.
    • Sell any app you make on Google Play.
    • Keep 100% of the advertising space/revenue for yourself instead of just 50%.
    • Enable Google Analytics in all your apps and start understanding your users better.
    • Access to all feature enhancements, bug fixes, improvements, and updates.
    • As long as you keep your subscription active, you’ll be grandfathered in to that pricing plan. So, when we raise the price in the future, you won’t need to worry about it.
    All told, it’s a crazy, awesome, amazing deal.
    But that’s not all. Every current Andromo developer will be receiving an email when we switch over that will include a one-time offer to sign up for an annual subscription plan at an even further, super discount. How much? Let’s just say you won’t be able to say no to it. It’s just our way of saying thanks to you for your loyalty.

    What Happens Otherwise?

    First off, don’t worry. Any app you’ve already built is safe and sound. We’re not jerks.
    Once you build an app with Andromo, it’s yours. Andromo apps won’t just stop working or anything weird like that.
    However, if you want to continue to improve your app, add new features, release a new version of it etc., you’ll need to have an active subscription in order to ‘Build’ the final app (the .APK file). If you don’t – the ‘Build’ button will not work for you.
    Consider for a moment that other less-awesome app makers are charging $29 – $99 per month for every app you make. Some of them charge much more than that too. Plus, they’ll shut down your app if you stop paying. In fact, that’s a huge difference between Andromo’s native Android app generation versus a ‘cross platform’ hosted/HTML pseudo-app. We can’t just ‘turn off’ your app remotely – that was a choice we made when we started this whole thing. It’s not fair to you and we don’t support it.
    Once you build an app with Andromo it’s yours forever. We’re not here to mess around with you. We know you’ll keep coming back and making apps (and telling your friends and colleagues) if we’re fair, honest and up-front with you…and we keep giving you the best deal anywhere. If we ever don’t live up to that expectation, you can cancel your subscription anytime and we won’t bill your next payment. It’s that simple.

    How to delete a contact in android?


    Hello all previously I have shown how to list all contacts in your phone and in another post I showed how to programatically create a contact in android.
    In today’s tutorial I will show you how to delete a contact in android programatically.
    This simple code does that.
     public static boolean deleteContact(Context ctx, String phone, String name) {
            Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone));
            Cursor cur = ctx.getContentResolver().query(contactUri, null, null, null, null);
            try {
                if (cur.moveToFirst()) {
                    do {
                        if (cur.getString(cur.getColumnIndex(PhoneLookup.DISPLAY_NAME)).equalsIgnoreCase(name)) {
                            String lookupKey = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
                            Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
                            ctx.getContentResolver().delete(uri, null, null);
                            return true;
                        }
    
                    } while (cur.moveToNext());
                }
    
            } catch (Exception e) {
                System.out.println(e.getStackTrace());
            }
            return false;

    Top 5 Android Games of Android

    It’s that time again. Time to bust a rhyme? Naw, B… Time to suck a lime? Naw, B… It’s time for the Top 10 Android Games of the Week. This weeks list has an 80s classic movie made into a game, some battling brutes, cats in the clouds, and of course a few zombies. If you got ancient SNL reference at the begging of this intro I give you props, and if not that’s okay too. Either way, this week was a good week to be a gamer and here’s our Top picks for last week… 


    1. Wargames Would you like to play a game? I’m sure you’re going to hear a lot of that (especially from me) as Be-Rad Entertainment has released WarGames: WOPR for Android. Yup, it’s a Wargames game based on the classic 80s movie and I for one am beyond thrilled. I’m a little ashamed that I haven’t mentioned this one sooner as it’s been out since the 14th and I’ve known about it since Wednesday, but am just getting around to talking about it. As I’m a huge fan of all things 80′s (have a store to prove it), you can bet your bottom dollar that they’ll be a nice glowing review of this one next week. Until then you can pick up Wargames: WOPR for $0.99 on Google Play


     2. Carnivores: Dinosaur Hunter Ever since Jurrasic Park came out, we’ve all wanted to hunt dinosaurs. Admit it… they’re big, scary, mean, and will rip you to shreds but you’d still want to hunt them if you could. Carnivores: Dinosaur Hunter HD from Tatem games you the chance to do just that, and it’s quite a bit of fun as well. If you want to try and kill a T-Rex or two, head on over to Google Play and try this one out. 


    3. Mexi Cannon If you’ve ever wanted to fire humans from a cannon this week was a good week for you. If you’ve ever wanted to fire Mexican Wrestlers from a cannon… you can now die happy and cross that one of your bucket list. Mexi Cannon let’s you fire Luchadores from cannons and to be quite honest, it’s a damn good time. You can grab Menue Games Mexi Cannon for free on Google Play.


     4. Toon Summer Games 2012 Toon Summer Games 2012 lets you take on the Olympics, but in animal form as you’ll get to play as a sheep, cat, turtle, and even a gorilla. There are a lot of cool events like BMX, Swimming, and Ping Pong and the game even runs well on my aging Captivate. No free version is available, but you can get the full version of Toons Summer Games 2012 for only $0.99.


     5. Garfields Diner First it was Garfield Defense, and this week we got Garfields Diner to celebrate the fat cat’s birthday. Garfields Diner is a time management game similar to Diner Dash where you’ll have to meet & greet customers while...

    Trigger Games releases Warlock Defense for Android



    They eyes of the enemy are over your lands, you must defend it! That’s the opening line in the description for Warlock Defense, a new Tower Defense game from Trigger Games. We know there is Magic involved and it’s a Tower Defense game, but is it a good one? Read on to find out…

    What is your favorite app on your Galaxy Tab?

    My favorite app is Chrome Beta. I made a post about it in May. Chrome Beta is by far the best web browser available on Android 4.0 in my opinion.
    I thought it would be fun to read what some of your favorite apps are though. It can be any kind of application, game, or widget. Leave a comment with your favorite app!

    ClockworkMod Touch for the International Galaxy S III


    The Samsung Galaxy S III, successor to the popular Galaxy S II, now has an official ClockworkMod Touch recovery.  And now thanks to XDA Senior Moderator and Recognized Developer mskip, it is flashable via Odin and Elite Recognized Developer Chainfire‘s Mobile Odin. If the name mskip sounds familiar to you, it’s because he also developed both the Galaxy S III and Galaxy Nexus Toolkits, all while pwning noobs around the forums.
    This recovery has all the features you would expect in a normal recovery, with the obvious addition of touch functionality. As mentioned earlier, it can be installed through Odin or Mobile Odin. However, this release is only compatible with the international GSM edition. Those with other SGS3 variants will likely have to wait a little 

    Samsung Galaxy S II Android 4.0 Ice Cream Sandwich Update Available


    Grab your USB cable…again. Samsung has made the AT&T Galaxy S II Android 4.0 Ice Cream Sandwich update available via Samsung Kies. Earlier this week, we excitedly reported that AT&T had released this update, sadly to see it removed without a trace. Samsung and AT&T were apparently just “testing” the release and preparing their servers for distribution. Don’t worry SGS2 owners, this time, the update isn’t going anywhere.
    To get started, follow the instructions below:
    Download and install Samsung Kies to your computer.
    NOTE: Any previously downloaded versions of Samsung Kies will not work correctly for this upgrade. Please ensure you are downloading the most recent Kies software from the link above.Once installed, read and accept the License agreement, and then click Next.
    NOTE: If prompted to update to a newer version, click Update and wait for new files to load.
    Once all updates have been processed, the program will close and relaunch itself.
    Update your Galaxy S II
    Plug your phone into the computer using the included Micro USB cable.
    Once Kies recognizes your device, you will receive a pop-up requesting to update to a new firmware version.
    Click Update to continue.
    Read through the Caution pop-up, and if you agree, click to check “I have read all the above information.” and select your desired information saving option, and then click Start Upgrade.
    A notice will display. Read through the information, and then click Next to proceed.
    The update will begin and may take 10-15 minutes to complete. The phone will be unusable during this time. Do not disconnect your mobile phone from your PC or power the PC off. If interrupted, your device could become inoperable.
    Please wait until your phone reboots completely, and then select OK to finish.
    Congratulations, you now have Android 4.0.3 running on your AT&T Galaxy S II.

    Image Switcher View for Android


    Now we will explore ImageSwitcher View. It is a view useful to switch smoothly between two images and thus provides ways of transitioning from one to another through appropriate animations.

    We will implement the same concept of showing a gallery of images that scrolls at the top of the android screen landscape and upon selection of one image, it gets displayed as a larger image in the lower part through the use of an ImageSwitcher. This is what I had done earlier in the GalleryView tutorial but now instead of showing the selected picture through an ImageView, I will show it using a ImageSwitcher. Though the output may seem very similar, lot of other methods are available on the ImageSwitcher that can be used, if required.

    Here is how the output would look (NOTE that I have not used the default gallery background provided by Android in the Gallery images)



    So, to begin with, first we need to declare the layout xml to have a gallery and the ImageSwitcher:

    <Gallery
          android:id="@+id/Gallery01"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"></Gallery>
    <ImageSwitcher
          android:id="@+id/ImageSwitcher01"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
    </ImageSwitcher>

    The next thing that we need to do is create a class that not only extends Activity but also implementsViewFactory. The ViewFactory is a Interface that creates views that need to be shown in theImageSwitcher. So it has one method makeView() which we need to implement. It is here that we can set the attributes of the ImageView that would be shown within the ImageSwitcher -  like its background, it scale, its layout parameters etc. – typically those attributes that we would have otherwise statically set through a layout xml.

    Here is the class declaration and the method makeView():

    public class ImageSwitcherView extends Activity implements ViewFactory {

    and
          @Override
          public View makeView() {
                ImageView iView = new ImageView(this);
                iView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                iView.setLayoutParams(new
                            ImageSwitcher.LayoutParams(
                                       LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
                iView.setBackgroundColor(0xFF000000);
                return iView;
          }
    This alone is the real difference from the Gallery example.

    Other smaller things we need to do is get a handle to the ImageSwitcher in the onCreate() method:

                iSwitcher = (ImageSwitcher) findViewById(R.id.ImageSwitcher01);
                iSwitcher.setFactory(this);
                iSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
                            android.R.anim.fade_in));
                iSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
                            android.R.anim.fade_out));

    Here we also set the animation on how the image should fly in and fly out of the area. Then, we get a handle to the gallery and set an ImageAdapter to it. The ImageAdpater is as described in my Gallery Example. If you have not seen that, please go through that and then try this example, as I would not want to repeat myself here.
    Now on the click of a gallery image, we would want to pass the selected image to the ImageSwitcher and this is what we do here:

                gallery.setOnItemClickListener(new OnItemClickListener() {

                      @Override
                      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
                            iSwitcher.setImageResource(pics[arg2]);
                      }
                });
          }

    Android 4.1 Jelly Bean


    Welcome to Android 4.1, Jelly Bean!
    Android 4.1 is the fastest and smoothest version of Android yet. We’ve made improvements throughout the platform and added great new features for users and developers. This document provides a glimpse of what's new for developers.
    See the Android 4.1 APIs document for a detailed look at the new developer APIs,
    Find out more about the Jelly Bean features for users atwww.android.com

    Faster, Smoother, More Responsive


    Android 4.1 is optimized to deliver Android's best performance and lowest touch latency, in an effortless, intuitive UI.
    To ensure a consistent framerate, Android 4.1 extends vsync timing across all drawing and animation done by the Android framework. Everything runs in lockstep against a 16 millisecond vsync heartbeat — application rendering, touch events, screen composition, and display refresh — so frames don’t get ahead or behind.
    Android 4.1 also adds triple buffering in the graphics pipeline, for more consistent rendering that makes everything feel smoother, from scrolling to paging and animations.
    Android 4.1 reduces touch latency not only by synchronizing touch to vsync timing, but also by actually anticipatingwhere your finger will be at the time of the screen refresh. This results in a more reactive and uniform touch response. In addition, after periods of inactivity, Android applies a CPU input boost at the next touch event, to make sure there’s no latency.
    Tooling can help you get the absolute best performance out of your apps. Android 4.1 is designed to work with a new tool called systrace, which collects data directly from the Linux kernel to produce an overall picture of system activities. The data is represented as a group of vertically stacked time series graphs, to help isolate rendering interruptions and other issues. The tool is available now in the Android SDK (Tools R20 or higher)


    Enhanced Accessibility


    New APIs for accessibility services let you handle gestures and manage accessibility focus as the user moves through the on-screen elements and navigation buttons using accessibility gestures, accessories, and other input. The Talkback system and explore-by-touch are redesigned to use accessibility focus for easier use and offer a complete set of APIs for developers.
    Accessibility services can link their own tutorials into the Accessibility settings, to help users configure and use their services.
    Apps that use standard View components inherit support for the new accessibility features automatically, without any changes in their code. Apps that use custom Views can use new accessibility node APIs to indicate the parts of the View that are of interest to accessibility services.


    Wednesday, June 27, 2012

    Animated Slideshow on Android

    After a brutal day of running into many Android bugs and misdocumentations, I’ve finally figured out how to create a slideshow of images for Android, with each imaging fading to the next. This is not unlike AnimationDrawable, except with a smoother and slower transition between images.
    First, you need a resource file with something like this in it. The FrameLayout is the clever bit: it stacks everyone of its children on top of each other.
    <FrameLayout
     android:id="@+id/frame"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
    >
     <ImageView
     android:id="@+id/slide_1"
     android:layout_gravity="center_vertical"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     />
     <ImageView
     android:id="@+id/slide_2"
     android:layout_gravity="center_vertical"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     />
    </FrameLayout>
    Then you need code that looks like this:
    public class TopListActivity
      extends Activity
    {
      private static class AnimationAlphaTimer
        extends TimerTask
        implements Animation.AnimationListener
      {
        TopListActivity topList;
        Vector<BitmapDrawable> images;
        int count = 0;
    
        public AnimationAlphaTimer(TopListActivity _topList)
        {
          this.topList = _topList;
    
          this.images = new Vector<BitmapDrawable>();
          for (int i = 0; ; i++) {
          // LOAD IMAGES HERE
          }
    
          if (this.images.size() > 0) {
            this.topList.slide_0.setBackgroundDrawable(this.images.get(0));
    
            if (this.images.size() > 1) {
              this.topList.slide_1.setBackgroundDrawable(this.images.get(1));
            }
          }
    
          this.count = 1;
        }
    
        public void launch()
        {
          if (this.images.size() >= 2) {
            (new Timer(false)).schedule(this, 100);
          }
        }
    
        @Override
        public void run()
        {
          this.doit();
          this.cancel();
        }
    
        private void doit()
        {
          if ((this.count % 2) == 0) {
            AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
            animation.setStartOffset(3000);
            animation.setDuration(3000);
            animation.setFillAfter(true);
            animation.setAnimationListener(this);
    
            this.topList.slide_1.startAnimation(animation);
          } else {
            AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
            animation.setStartOffset(3000);
            animation.setDuration(3000);
            animation.setFillAfter(true);
            animation.setAnimationListener(this);
    
            this.topList.slide_1.startAnimation(animation);
          }
        }
    
        public void onAnimationEnd(Animation animation)
        {
          if ((this.count % 2) == 0) {
            this.topList.slide_1.setBackgroundDrawable(
              this.images.get((this.count + 1) % (this.images.size()))
            );
          } else {
            this.topList.slide_0.setBackgroundDrawable(
              this.images.get((this.count + 1) % (this.images.size()))
            );
          }
    
          this.count++;
          this.doit();
        }
    
        public void onAnimationRepeat(Animation animation)
        {
        }
        public void onAnimationStart(Animation animation)
        {
        }
      }
    
      @Override
      public void onResume()
      {
        super.onResume();
    
        (new AnimationAlphaTimer(this)).launch();
      }
    }
    The “create a Timer trick” in onResume is courtesy of Diego Torres. If you just try to run the animation, it’s likely just to choke

    How to use custom fonts in Android applications

    Here’s how to use custom fonts in your Android application.
    1. Select your font – for example, Ubuntu. Make sure you use a royalty-free font (such as that one) or you pay the appropriate licensing fee (because you could get in a world of legal pain and because don’t be a dick)
    2. In the root folder of your Android project, make sure there’s a folder called assets/fonts. The fonts subdirectory is entirely optional but to my taste.
    3. You cannot specify the font (really the typeface) in your resources, so you have to do in code as follows
    Typeface font = Typeface.createFromAsset(_activity.getAssets(), "fonts/Ubuntu-Bold.ttf");
    textView.setTypeface(font);
    
    And that’s it.

    Creating Android UI Programmatically

    So far, in all my examples, I have been using the declarative way of creating an Android UI using XML. However, there could arise certain situations when you may have to create UI programmatically. Sincere advice would be to avoid such a design since android has a wonderful architecture where the UI and the program are well separated. However, for those few exceptional cases where we may need too… here is how we do it.
    Every single view or viewgroup element has an equivalent java class in the SDK. The structure and naming of the classes and methods is very similar to the XML vocabulary that we are used to so far.
    Let us start with a LinearLayout. How would we declare it in an XML?
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello"
        />
    </LinearLayout>
    This just contains a TextView embedded in a LinearLayout. A very trivial example. But serves the purpose intended. Let me show how almost every single element here corresponds to a class or a method call in the class.  So the equivalent code in the onCreate(…)  method of an activity would be like this:
             super.onCreate(savedInstanceState);
          
            lLayout = new LinearLayout(this);
            lLayout.setOrientation(LinearLayout.VERTICAL);
            //-1(LayoutParams.MATCH_PARENT) is fill_parent or match_parent since API level 8
            //-2(LayoutParams.WRAP_CONTENT) is wrap_content
            lLayout.setLayoutParams(new LayoutParams(
    LayoutParams.MATCH_PARENT,
    LayoutParams.MATCH_PARENT));
            tView = new TextView(this);
            tView.setText("Hello, This is a view created programmatically! " +
                      "You CANNOT change me that easily :-)");
            tView.setLayoutParams(new LayoutParams(
    LayoutParams.MATCH_PARENT,
    LayoutParams.WRAP_CONTENT));
            lLayout.addView(tView);
            setContentView(lLayout);

    Like this any layout view can be created. But from this small example you can notice two outstanding things – very tedious to code for every attribute of the view. And any simple change in the view, you need to change the code, compile, deploy and only then you see the effect of the change – unlike in a layout editor.