Android Development

Rapid android development from Berlin

Browsing Posts in tutorial

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

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

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

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

I am in the final month of my bachelor thesis and I have written a benchmark. I would like to ask if you could run the benchmark on your pc/mac so that I can get the result data.
The written benchmarks measure the performance of WebGL of your browser in the first part. The second part is used as a reference where the same test is written in a Java applet. The data of the benchmark is finally submittable with the final form.

As you all have technical background you should be able to enable WebGL in your browser. I appreciate it if you would run the test in all three possible settings (radio buttons on top left) and on all operation systems/browser you have.

The benchmark can be found here with a short FAQ:
WebGL Benchmark
If you experience errors with the java applet, please just try the test again.

If you can spread the word on a mailing list or a tech list at work, I would be happy!

Thanks in advance!
Martin

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