Mercurial > MadButterfly
annotate 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 |
rev | line source |
---|---|
493
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 package org.madbutterfly; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 import android.view.SurfaceView; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 import android.view.SurfaceHolder; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 import android.content.Context; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 import android.graphics.Canvas; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 import android.graphics.Bitmap; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 import android.graphics.Paint; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 import android.graphics.Xfermode; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 import android.graphics.PorterDuff; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 import android.graphics.PorterDuffXfermode; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 class MBView extends SurfaceView { |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 redraw_man rdman; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 Canvas cr, backend; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
16 Bitmap cr_bmap, backend_bmap; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 Paint copy_pnt; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 int w, h; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 public MBView(Context context) { |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 super(context); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 Paint paint; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 Xfermode mode; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 rdman = null; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 cr = null; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 backend = null; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
29 mode = new PorterDuffXfermode(PorterDuff.Mode.SRC); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 copy_pnt = new Paint(); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 copy_pnt.setXfermode(mode); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 } |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 public redraw_man get_rdman() { |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 if(rdman != null) |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 return rdman; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 w = getWidth(); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 h = getHeight(); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 cr_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 cr = new Canvas(cr_bmap); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 backend_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 backend = new Canvas(backend_bmap); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 rdman = new redraw_man(cr, backend, this); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 return rdman; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 } |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
51 protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 this.w = w; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
53 this.h = h; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 cr_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
55 cr.setBitmap(cr_bmap); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 backend_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
57 backend.setBitmap(backend_bmap); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 } |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 public void redraw() { |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
61 SurfaceHolder holder; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
62 Canvas canvas; |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
63 |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
64 holder = getHolder(); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
65 canvas = holder.lockCanvas(); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
66 canvas.drawBitmap(backend_bmap, 0, 0, copy_pnt); |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
67 } |
1b6228092a57
Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
68 } |