Android Development

Tag: emulator

Playing with graphics in Android – Part VII

by Martin on Jul.06, 2009, under tutorial

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

In our last part of this series, I will present a mini “game” based on the very famous game “Rock, Paper, Scissors”.
The follow features are fully implemented:

  • Add a rock, paper or scissors by touching the screen
  • Define speed and direction by touch-drag-release
  • On collision the loser explodes
  • There’s a sound on explosion

(continue reading…)

  • Share/Bookmark
37 Comments :, , , , more...

Playing with graphics in Android – Part VI

by Martin on Jun.05, 2009, under tutorial

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

The sixth part of this series will let you move the item you will add. As long as you touch the screen, you can change the position of the bitmap you want to add.

We simply have to add a temporary class variable in our Panel class.

1
private GraphicObject _currentGraphic = null;

(continue reading…)

  • Share/Bookmark
7 Comments :, , , , more...

Playing with graphics in Android – Part V

by Martin on May.23, 2009, under tutorial

You are new to this series? Please start with the first part.
Also be aware of a minor bug in the last series.

The fifth part of this series will let the icons move around.
(continue reading…)

  • Share/Bookmark
14 Comments :, , , , more...

Playing with graphics in Android – Part IV

by Martin on May.18, 2009, under tutorial

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

The fourth part of the series will show you how to add more bitmaps on your screen.

First we have to add is graphic class containing a bitmap and the coordinates where it is located.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class GraphicObject {
    private Bitmap _bitmap;
    private Coordinates _coordinates;
 
    public GraphicObject(Bitmap bitmap) {
        _bitmap = bitmap;
        _coordinates = new Coordinates();
    }
 
    public Bitmap getGraphic() {
        return _bitmap;
    }
 
    public Coordinates getCoordinates() {
        return _coordinates;
    }
 
    /**
     * Contains the coordinates of the graphic.
     */
    public class Coordinates {
        private int _x = 100;
        private int _y = 0;
 
        public int getX() {
            return _x + _bitmap.getWidth() / 2;
        }
 
        public void setX(int value) {
            _x = value - _bitmap.getWidth() / 2;
        }
 
        public int getY() {
            return _y + _bitmap.getHeight() / 2;
        }
 
        public void setY(int value) {
            _y = value - _bitmap.getHeight() / 2;
        }
 
        public String toString() {
            return "Coordinates: (" + _x + "/" + _y + ")";
        }
    }
}

(continue reading…)

  • Share/Bookmark
17 Comments :, , , , more...

Playing with graphics in Android – Part III

by Martin on May.18, 2009, under tutorial

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

The third part of this series will add some interactivity to our little application. We will add the possibility the icon appears at the point you touch the screen.

Just to remember, we have 3 classes: Tutorial2D (our Activity class), Panel (our SurfaceView class) and TutorialThread (our Thread class).
Our interaction will be handled in our Panel class, so we must be sure, that the touch events will processed by the Panel class. To ensure that, we simply have to set the focus to our panel (line 5).

1
2
3
4
5
6
public Panel(Context context) {
    super(context);
    getHolder().addCallback(this);
    _thread = new TutorialThread(getHolder(), this);
    setFocusable(true);
}

(continue reading…)

  • Share/Bookmark
23 Comments :, , , , more...

Playing with graphics in Android – Part II

by Martin on May.12, 2009, under tutorial

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.

Just to remember, our last code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.droidnova.android.tutorial2d;
 
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
 
public class Tutorial2D extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(new Panel(this));
    }
 
    class Panel extends View {
        public Panel(Context context) {
            super(context);
        }
 
        @Override
        public void onDraw(Canvas canvas) {
            Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
            canvas.drawColor(Color.BLACK);
            canvas.drawBitmap(_scratch, 10, 10, null);
        }
    }
}

(continue reading…)

  • Share/Bookmark
26 Comments :, , , , more...

Playing with graphics in Android – Part I

by Martin on May.06, 2009, under tutorial

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 should look familiar to you.
(continue reading…)

  • Share/Bookmark
27 Comments :, , , , more...

Ever tried ‘localhost’ with the android emulator ?

by Claudio on Mar.12, 2009, under emulator, how to

It might be obvious linux savvy folks, but trying to access localhost or 127.0.0.1 with the android emulator in order to access a local server for testing won’t get you anywhere. That’s because the IP is used internally by the undlying linux as you might have guessed.

Luckily there’s an IP you can use to achieve hitting your local apache/tomcat/whatever : 10.0.2.2

  • Share/Bookmark
3 Comments :, , , , more...

Make use of simple multilanguage support

by Martin on Mar.06, 2009, under how to

In our little sample application we used the strings.xml to define static texts.
If you want to use the build-in multi-language support you just have to follow some easy conventions.
To use localization for strings you have to add a new directory to res/ and name it “values-de” for the german language.
Create a strings.xml in this directory and deploy your application. If you now change your language on the device or emulator, the phone picks the strings.xml with the matching local code and uses it – in the same manner you could provide images etc. for a specific language (i.e. graphical buttons).
Works well for our little sample.

Our strings.xml for the german language:

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Wähle einen Freund</string>
    <string name="button_info_text">Bitte wähle einen Kontakt aus</string>
    <string name="button_text">Auswahl</string>
    <string name="contacts">Kontakte</string>
    <string name="chosen">Sie haben ausgewählt:</string>
</resources>
  • Share/Bookmark
9 Comments :, , , , more...

Set up SD card for your android emulator

by Martin on Feb.27, 2009, under emulator, how to, tutorial

After the discussion about the restriction concerning downloading and installation of paid applications on developer devices we at least want to simulate installation of free applications on our emulator over the web.

This is the short tutorial how to accomplish that.
(continue reading…)

  • Share/Bookmark
Leave a Comment :, , , more...