Finally it's time for some Java coding!
Start with removing the three "Toast.makeText" lines from JustRoidsActivity.java, as we already tested the page navigation and I only added them to show an example of the simplest possible tracing functionality.
I also set back "Project Build Target" to Android 2.1, so that Eclipse is able to stop me from writing code that won't work on 2.1.
Given that, I must also comment out the AdActivity from the manifest file. (I will put it back before publishing the app):
<!--
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
/>
-->
package com.ajomannen.justroids;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
public class GameEngine {
public float screenWidth;
public float screenHeight;
private Paint blackPaint;
private Paint textPaint;
private String currentTimeString;
public void Init(Context context) {
setSurfaceDimensions(240, 160);
blackPaint = new Paint();
blackPaint.setColor(Color.BLACK);
blackPaint.setStyle(Style.FILL);
textPaint = new Paint();
textPaint.setColor(Color.LTGRAY);
textPaint.setTextSize(40);
}
public void onDestroy() {
try {
} catch (Exception e) {
}
}
public void setSurfaceDimensions(int width, int height) {
screenWidth = width;
screenHeight = height;
}
public void Update() {
currentTimeString = new SimpleDateFormat("HH:mm:ss").format(new Date());
}
public void Draw(Canvas canvas) {
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), blackPaint);
canvas.drawText(currentTimeString, 30, 100, textPaint);
}
}
(Just to have something to update and draw, I put the current time into a text string and draw it onto screen.)
Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer