Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting JavaME to Android

I am trying to port an app from javaME to Android. I have a part where graphics class is used.

I have used J2ME Android bridge (http://www.assembla.com/wiki/show/j2ab/Converting_From_J2ME/8) to gain access to Graphics class. Im still missing some of the methods such as:

  • getStrokeStyle()
  • setStrokeStyle()
  • drawRGB()
  • fillTriangle()

Also how do i use Vector?

example: Vector polylines = g.getPolylines();

like image 692
no9 Avatar asked Mar 25 '26 03:03

no9


1 Answers

I created an automatic J2ME->Android convertor in our company. Mapping J2ME graphics (javax.microedition.ldcui.Graphics) to Android graphics (android.graphics.Canvas) is really easy.

setStrokeStyle - change path effect on your Paint instance

PathEffect EFFECT_DOTTED_STROKE = new DashPathEffect(new float[] {2, 4}, 4);

if (style == SOLID) {
    strokePaint.setPathEffect(null);
}
else {
    strokePaint.setPathEffect(EFFECT_DOTTED_STROKE);
}

drawRGB - directly calling a Canvas method

public void drawRGB(int[] rgbData, int offset, int scanLength, int x, int y, int width, int height, boolean processAlpha) {
    canvas.drawBitmap(rgbData, offset, width, x + translateX, y + translateY, width, height, processAlpha, null);
}

fillTriangle - using a path

public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
    Path path = new Path();
    path.moveTo(x1 + translateX, y1 + translateY);
    path.lineTo(x2 + translateX, y2 + translateY);
    path.lineTo(x3 + translateX, y3 + translateY);
    path.close();

    strokePaint.setStyle(Paint.Style.FILL);
    canvas.drawPath(path, strokePaint);
} 

By Vector you mean java.util.Vector? Android API contains exactly the same class...

like image 96
Sulthan Avatar answered Mar 27 '26 17:03

Sulthan