AndroidGraphics2D

AndroidGraphics2D.java

이걸 어떻게 해석해야 할까?

리플 하나 to “AndroidGraphics2D”

  1. 밤치 Says:

    아래 3개의 메소드를 중심으로 보면 될 것 같네요.
    생성자(3번째메소드)가 private이므로 static 메소드 getInstance를 호출해서 인스턴스를 얻을 수 밖에 없는 상황이네요.

    getInstance()메소드에 보면…
    mAg = new AndroidGraphics2D(ctx, c, p);
    이 부분이 이상하다고 하신것 같은데
    이 라인은 3번째 함수인 private 생성자 메소드를 호출하므로 특별히 이상한것 같진 않네요..

    public static AndroidGraphics2D getInstance() {
    if (mAg == null) {
    throw new RuntimeException(”AndroidGraphics2D not instantiated!”);
    }
    return mAg;
    }

    public static AndroidGraphics2D getInstance(Context ctx, Canvas c, Paint p) {
    if (c == null || ctx == null) {
    throw new RuntimeException(
    “Illegal argument, Canvas cannot be null!”);
    }
    mAg = new AndroidGraphics2D(ctx, c, p);
    return mAg;
    }

    private AndroidGraphics2D(Context ctx, Canvas c, Paint p) {
    super();
    mC = c;
    mP = p;
    mM = new Matrix();
    mM.reset();
    mM = mC.getMatrix();
    Rect r = mC.getClipBounds();
    int cl[] = {-1, r.top, r.left, -2, r.top, r.right, -2, r.bottom, r.right, -2, r.bottom, r.left};
    mCurrClip = new Area(createShape(cl));
    if(ctx != null) {
    WindowManager wm = (WindowManager)ctx.getSystemService(Context.WINDOW_SERVICE);
    Display d = wm.getDefaultDisplay();
    displayWidth = d.getWidth();
    displayHeight = d.getHeight();
    }
    blitter = new AndroidJavaBlitter(c);
    cm = new DirectColorModel(32, 0xff0000, 0xff00, 0xff, 0xff000000);
    sm = new SinglePixelPackedSampleModel(
    DataBuffer.TYPE_INT, displayWidth, displayHeight, cm.getMasks());
    wr = Raster.createWritableRaster(sm, null);
    dstSurf = new ImageSurface(cm, wr);
    }

댓글달기