diff Android/java/org/madbutterfly/MBView.java @ 493:1b6228092a57 Android_Skia

Java code for MadButterfly JNI. This is Java code that access MadButterfly JNI interface.
author Thinker K.F. Li <thinker@branda.to>
date Thu, 26 Nov 2009 15:02:51 +0800
parents
children 2d7df44e6299
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Android/java/org/madbutterfly/MBView.java	Thu Nov 26 15:02:51 2009 +0800
@@ -0,0 +1,68 @@
+package org.madbutterfly;
+
+import android.view.SurfaceView;
+import android.view.SurfaceHolder;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Bitmap;
+import android.graphics.Paint;
+import android.graphics.Xfermode;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
+
+class MBView extends SurfaceView {
+    redraw_man rdman;
+    Canvas cr, backend;
+    Bitmap cr_bmap, backend_bmap;
+    Paint copy_pnt;
+    int w, h;
+    
+    public MBView(Context context) {
+	super(context);
+	Paint paint;
+	Xfermode mode;
+	
+	rdman = null;
+	cr = null;
+	backend = null;
+	
+	mode = new PorterDuffXfermode(PorterDuff.Mode.SRC);
+	copy_pnt = new Paint();
+	copy_pnt.setXfermode(mode);
+    }
+    
+    public redraw_man get_rdman() {
+	if(rdman != null)
+	    return rdman;
+
+	w = getWidth();
+	h = getHeight();
+
+	cr_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
+	cr = new Canvas(cr_bmap);
+	backend_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
+	backend = new Canvas(backend_bmap);
+	
+	rdman = new redraw_man(cr, backend, this);
+
+	return rdman;
+    }
+
+    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+	this.w = w;
+	this.h = h;
+	cr_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
+	cr.setBitmap(cr_bmap);
+	backend_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
+	backend.setBitmap(backend_bmap);
+    }
+
+    public void redraw() {
+	SurfaceHolder holder;
+	Canvas canvas;
+
+	holder = getHolder();
+	canvas = holder.lockCanvas();
+	canvas.drawBitmap(backend_bmap, 0, 0, copy_pnt);
+    }
+}