开发者

Porting JavaME to Android

I am trying to port an app from javaME to Android. I have a part where graphics cla开发者_JAVA技巧ss 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();


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...


you can draw shapes by overwriting the onDraw method in a layout for example

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜