Android Development

Rapid android development from Berlin

Browsing Posts tagged android

While working on a project, the customer asked for full honeycomb compatibility. I found two issues today that kept me at least a bit wondering.

“text/html” vs. “html/text”
The following way of loading data into a WebView was used since month and it worked in all ways:

1
mWebView.loadData(myHtmlContent, "html/text", "utf-8");

With honeycomb, the WebView presented a blank page. While not seriously checking the order of “html/text” I debugged the app and couldn’t find an issue like an empty content or an issue while reading files which contains the html code. Than I saw the switched order, changed it to the correct one and it worked.

1
2
//working call
mWebView.loadData(myHtmlContent, "text/html", "utf-8");

I thought that a wrong type definition should be handled with a fall back to at least text/html, because a WebView should always fall back to display html, right? Well, they seem to have changed it on honeycomb…

loadData vs loadDataWithBaseURL

The next issue was wrong encoding when the html content was displayed using the method loadData with the call shown above. I tried to dig deeper into it, but was lost until I found a question on stackoverflow about this encoding issue.
This question is not very new, but I am wondering why it worked on Android < 3.x in my case. Beside that, I can't find a good reason why it failed with one call but not with the other. This issue is the reason why I filed my very first bug report on Android.

Share

This tutorial series is build against Android 2.1 and should also work on newer versions. This version is still supported because of the amount of devices that still run this version. There is an earlier, but a bit outdated version of this part.

You are new to this series? Please start with the first part.

The fifth part shows you how to animate the bitmaps. That means you touch the screen and from there on the icons move around the screen. The direction of the movement and the speed itself will be random. The animation will be constant and independent of the frames per seconds (FPS). The FPS will be displayed on the left top corner of the screen so that everybody can see the changes in the performance over time.
continue reading…

Share

This tutorial series is build against Android 2.1 and should also work on newer versions. This version is still supported because of the amount of devices that still run this version. There is an earlier, but a bit outdated version of this part.

You are new to this series? Please start with the first part.

The fourth part will introduce how to add more bitmaps than the just the one. At the end you should be able to have dozens of bitmaps on the screen.

First of all we need to encapsulate the bitmap handling into a separate class. We will name the class Element. It will contains the coordinate and the bitmap and it will have its own drawing method.

The basic class looks like that and the content of the methods should be already familiar.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class Element {
    private int mX;
    private int mY;
 
    private Bitmap mBitmap;
 
    public Element(Resources res, int x, int y) {
        mBitmap = BitmapFactory.decodeResource(res, R.drawable.icon);
        mX = x - mBitmap.getWidth() / 2;
        mY = y - mBitmap.getHeight() / 2;
    }
 
    public void doDraw(Canvas canvas) {
        canvas.drawBitmap(mBitmap, mX, mY, null);
    }
}

continue reading…

Share

This tutorial series is build against Android 2.1 and should also work on newer versions. This version is still supported because of the amount of devices that still run this version. There is an earlier, but a bit outdated version of this part.

You are new to this series? Please start with the first part.

The third part of the tutorial will introduce some interaction to our sample application. We will implement the possibility to display the bitmap at the touched position.

First of all we need some member variables to store where the touch happened. That will be mX and mY of type integer.

1
2
private int mX;
private int mY;

continue reading…

Share

This tutorial series is build against Android 2.1 and should also work on newer versions. This version is still supported because of the amount of devices that still run this version. There is an earlier, but a bit outdated version of this part.

You are new to this series? Please start with the first part.

The second part of this series will show what you have to change to switch from using the View class to SurfaceView class.
The advantage of switching the parent class is the easy possibility, to draw everything you want on the display without working with layouts and XML files. It is also the best way to do custom animations and, of course, games.

continue reading…

Share

This tutorial series is build against Android 2.1 and should also work on newer versions. This version is still supported because of the amount of devices that still run this version. There is an earlier, but a bit outdated version of this part.

The first part of this series will show you, how to display an image in a normal View.

First we create a new Project with the activity named Tutorial2D.
We will see this:

1
2
3
4
5
6
7
8
9
10
11
12
13
package com.droidnova.android.tutorial2d;
 
import android.app.Activity;
import android.os.Bundle;
 
public class Tutorial2D extends Activity {
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

This maybe looks familiar to you.
continue reading…

Share

This part is not a real part 3 but it is an enhanced implementation of Part II by Dave ( drbixler [at] gmail [dot] com ) who wrote this part as a guest author. Thank you Dave!

While reading the post, you should already look at the code so first download it: Cell Map Enhanced

I’ve been working on my first Android application for a few months now (evening work so it’s taking me a little longer than I had hoped). My game requires a 2D map of cells that can scroll in any direction. Having looked around for examples I stumbled across this series and went to work. I tend to be the type of person that “adopts, changes, and enhances” when I use code I find on the internet. I’m very particular about what my code looks like, how it’s commented, etc. What I ended up with was a reusable 2D map scrolling framework that could smoothly scroll in any direction and also supported “fling” scrolling. I’ve also put in the basics of zooming, though didn’t take the plunge into pinch zoom. Again, I completely redid a lot of the code from the 2nd part of this series but there are still some similarities.
I’m going to only really focus on one or two specific classes because most of the code provided is very short and self-explanatory. I make it a point to comment verbosely so that should help as well.
continue reading…

Share

Sorry about the delay but I have finally managed to find the time to complete the Sound effect Tutorial which I hope you all enjoy.If you have not already check out the first tutorial here before reading this one, as it reuses a lot of the code.

In the previous tutorial we had a basic working sound system, but it was limited in scope. it could only be used in the class it was declared in and could not be used between activity’s easily. Ideally we would like one instance of the Sound Manager that could be used across the entire app life-cycle.

The solution is the Singleton design pattern explained better here.In essence, we will create only one instance of the Sound Manager class that can be accessed anywhere within the application.
continue reading…

Share

The second part of this series will show you how you can scroll smoothly over the simple 2D Map which was created in the first part.

Note: I changed my coding style to fit the Java/Android coding style. Please be aware that variables like _mapSize are now mMapSize.

The performance issue we discovered in the first part was awful and no one will play a game which needs seconds to draw another frame. But why do we have this performance issue?
Do you remember how we draw the Map? We go trough the map in a loop and draw each cell. If our map has only a size of 10, everything is fine, but if we go to 100 and more, we draw a lot of cells and most of them are not on our display. And thats the mistake: We use resources and time to draw cells we don’t see.
continue reading…

Share

Android 2.1 SDK is out. The API level changed to 7 but its mainly a minor update.
New stuff: the animated background you already know from Nexus One and a new SignalStrength class which provides information about the device’s current network signal.

Anything else are mainly new methods on already existing classes.

The update is available as a download or as an update in your SDK Manager.

Share
Powered by WordPress Web Design by SRS Solutions © 2012 Android Development Design by SRS Solutions