Android

Nico Heid's picture

An Android SeekBar for your MediaPlayer

android logoWe all like a playback progress bar underneath our media players, so we can see how far we are and, if necesary, drag the thumb to were we want it to be.

Lets do this on Android: enter http://developer.android.com/reference/android/widget/SeekBar.html

As we will need a Runnable to update the bar regularly, let you class implement Runnable. Let's look at the run() method.

  1.    @Override
  2.     public void run() {
  3.         // mp is your MediaPlayer
  4.         // progress is your ProgressBar
  5.  
  6.         int currentPosition = 0;
  7.         int total = mp.getDuration();
  8.         progress.setMax(total);
  9.         while (mp != null && currentPosition < total) {
  10.             try {
  11.                 Thread.sleep(1000);
  12.                 currentPosition = mp.getCurrentPosition();
  13.             } catch (InterruptedException e) {
Read more

Nico Heid's picture

Android UI testing with robotium

android logo
I will base this post on the last article: Android ViewFlipper within TabHost for Tabs with different Views ... and better memory footprint, where we had a TabHost and a ViewFlipper. To test that our example is still working, we have to start the app, start the tab example, click on the ViewFlipper then change to Tab2 and press the button. Of course you can do this by hand if you must, which basically always happens when you're in the middle of development -unless you're doing test driven development. But later on, you don't really want to sit there and click a lot, or even worse, enter text with your thick fingers on a tiny android device screen. So a good idea to test the UI is to get it automated in some way. That is where robotium comes into the game.Read more

Nico Heid's picture

Android ViewFlipper within TabHost for Tabs with different Views ... and better memory footprint

android
This article is a follow up of Use Android ActivityGroup within TabHost to show different Activity. As you probably noticed or read in the comments, the provided solution in the last article was less than ideal. Even though it does work, it uses multiple activies and therefor has a bigger memory consumption than necessary.

What happens when you use ActivityGroup with Tabhost

In the previous example we had one Activiy per tab. One tab was even holding two Activies and using ActivityGroup to switch between them. That's a total of five Activites that end up on the activity stack. Also the hierarchy was more nested than needed.Read more

The improvement

Nico Heid's picture

Use Android ActivityGroup within TabHost to show different Activity

android

there is an updated version to this article with some improvements. please also read: Android ViewFlipper within TabHost for Tabs with different Views ... and better memory footprint.

When you're using a TabHost each tab has it's own Activity. Now image you want to change the Activity for a certain tab. If you just go on and create a new Activity and display it, your Tab Layout is no longer visible.

For that reason you need a ActivityGroup within the Tab where you want to change the Activity. Read more

Nico Heid's picture

Show ProgressBar in Notification Area like Google does when downloading from Android market

android download progressWhen you download from the Market you get informed about the progress in the notification area.

That's a really nice feature, which you may want for your own download or processing progress. I will show you the basics of generating such a Notification. All you need to do is add it to your code.

I included a screenshot. You can find the code at github.

First of all, you need your Notification object:

  1.         // configure the notification
  2.         final Notification notification = new Notification(R.drawable.icon, "simulating a download", System
  3.                 .currentTimeMillis());
  4.         notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
Read more

Phillip Steffensen's picture

Android: Dealing with ListActivities, customized ListAdapters and custom-designed items

Due to its ListActivity class the Android SDK helps developers to create List-GUIs easily. Therefore the ListActivity uses a ListView. But what about customized lists? What about own list-designs? In this post I'll try to show how to extend a standard ListView to create a custom list-design. To create your own list-design, you should define how an item in your list should look like. As an example I'll use a list of Twitter-updates (also called „tweets“).

Read more

Syndicate content