Android Development

Rapid android development from Berlin

Browsing Posts published by Martin

Most likely you all heard about SOPA and/or PIPA and the partly successful fight against it.

We still have another very similar fight against an idea that might be even worse than the two mentioned.

ACTA is not only an European version of SOPA/PIPA it is very likely that every single country in the world can and will be participating.

So I recommend to read about ACTA and if you are against it: Fight against ACTA!

Spread the word! Share it on Facebook, Google+, Twitter, Reddit… fight it! Fight for the Internet we all know! FIGHT!

Share

As a reader asked for it, I provide a tutorial on how to generate and save a simple screenshot from a SurfaceView.

This tutorial is based on the 2D Tutorial Series – Part V and the tutorial How to create an option menu. If you have no idea about how a SurfaceView works, please start the 2D Tutorial Series.

Lets start by getting the code from the 2D Tutorial.

We start by removing the animation from the code. That means strip the class Element to the bare bitmap and the used coordinates.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class Element {
    private float mX;
    private float mY;
 
    private Bitmap mBitmap;
 
    public Element(Resources res, int x, int y) {
        mBitmap = BitmapFactory.decodeStream(new BufferedInputStream(res.openRawResource(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

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

I tried a lot to prevent that but I couldn’t anymore :/

Facts:

  • I got caught by doing something not legal that a lot of people do anyway.
  • I now have a bill of 1.700€ to pay (lawyer costs not included)
  • I will remove the ads as soon as possible and as soon as I have payed the bill. Promised!

I don’t wait until I have the 1.700 bucks earned by the ads, its just a way to decrease the time until I have the bucks collected and until I am able to pay it.

I seriously hate it to do that, and it will stay by the one and only the time the bill isn’t payed… sorry :(

Share

While working on the fifth part of my 2d tutorial series, I was able to test it on the Samsung Galaxy Tab. What I found there was a bit shocking: My sample worked fluently on 60fps with the first 25 elements on the screen. The frame rate drops to less than a half to 25fps with the 26th element added to the screen.

I tried to improve everything, I tried different images and also did some tests with different, not really solid solutions. Nothing worth using removed or even explained the performance drop.

To be sure that my sample itself doesn’t have a bad performance, I tried to reach the 25fps on my Nexus One. I needed to add 400 Elements to reach 25fps. That 16 times more elements on the screen than the Samsung needed to reach 25fps…

So finally I am totally confused and asked for help on Stackoverflow. Maybe you have an idea, than participate and help! Any help is really appreciated.

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

Sorry guys, this is a post for german guys only, cause all links in this post are german only, too.


Der gute Caschy feiert mit seinem Blog sein sechsjähriges bestehen mit einem fettem Gewinnspiel.

Der Caschy is bekannt für gute Texte, super Berichte und (auffällig extrem oft) neutraler und objektiver Berichterstattung. Davor verneige ich mich, denn ich bin hier bei mir immer nur subjektiv unterwegs.

Auch von mir daher: Alles gute und auf die nächsten 6 Jahre!

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
Powered by WordPress Web Design by SRS Solutions © 2012 Android Development Design by SRS Solutions