Porting JavaME to Android

I am trying to port an application from javaME to Android. I have a part that uses a graphics class.

I used the Android J2ME modem ( http://www.assembla.com/wiki/show/j2ab/Converting_From_J2ME/8 ) to access the Graphics class. Im still missing some methods like:

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

Also how to use Vector?

example: Vector polylines = g.getPolylines();

+3
source share
2 answers

In our company, I created an automatic J2ME-> Android converter. Comparing J2ME graphics (javax.microedition.ldcui.Graphics) with Android graphics (android.graphics.Canvas) is very simple.

setStrokeStyle - change the path effect on a 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 - Canvas

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 -

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);
} 

java.util.Vector? Android API ...

+1

, onDraw

protected void onDraw(Canvas canvas) {
    canvas.drawCircle(cx, cy, radius, paint)
} 
+1

Source: https://habr.com/ru/post/1791198/


All Articles