Mercurial > MadButterfly
changeset 517:82c1ea2ba929 Android_Skia
Implement SurfaceHolder.Callback for waiting surface creature.
SurfaceView should wait for surface being created. After that, user
of SurfaceView can be used to draw graphics.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 01 Dec 2009 22:55:27 +0800 |
parents | 0d9f1f4d3154 |
children | 3a7bce43ec6e |
files | Android/examples/testpath/src/org/madbutterfly/android/examples/testpath/testpath.java |
diffstat | 1 files changed, 35 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/Android/examples/testpath/src/org/madbutterfly/android/examples/testpath/testpath.java Tue Dec 01 22:55:27 2009 +0800 +++ b/Android/examples/testpath/src/org/madbutterfly/android/examples/testpath/testpath.java Tue Dec 01 22:55:27 2009 +0800 @@ -1,47 +1,59 @@ package org.madbutterfly.android.examples.testpath; import android.app.Activity; +import android.view.SurfaceHolder; import android.content.Context; import android.os.Bundle; import android.graphics.Canvas; +import android.util.Log; import org.madbutterfly.MBView; import org.madbutterfly.redraw_man; import org.madbutterfly.coord; import org.madbutterfly.shape; import org.madbutterfly.paint; -public class testpath extends Activity +public class testpath extends Activity implements SurfaceHolder.Callback { - class myview extends MBView { - public myview(Context ctx) { - super(ctx); - } - - protected void onDraw(Canvas canvas) { - redraw_man rdman; - shape path; - coord _coord; - paint pnt; - - rdman = get_rdman(); - path = rdman.shape_path_new("M 100 100 L 150 100 L 150 150 z"); - _coord = rdman.get_root(); - _coord.add_shape(path); - pnt = rdman.paint_color_new(1, 1, 1, 1); - pnt.stroke(path); - rdman.redraw(); - } - } - MBView main_view; + String TAG = "testpath"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + SurfaceHolder holder; + // setContentView(R.layout.main); - main_view = new myview(this); + main_view = new MBView(this); + holder = main_view.getHolder(); + holder.addCallback(this); setContentView(main_view); } + + public void surfaceChanged(SurfaceHolder holder, int format, + int w, int h) { + } + + public void surfaceCreated(SurfaceHolder holder) { + redraw_man rdman; + shape path; + coord _coord; + paint pnt; + + Log.v(TAG, "surfaceCreated enter"); + rdman = main_view.get_rdman(); + path = rdman.shape_path_new("M 100 100 L 150 100 L 150 150 z"); + path.set_stroke_width(2); + _coord = rdman.get_root(); + _coord.add_shape(path); + pnt = rdman.paint_color_new(1, 0, 1, 1); + pnt.stroke(path); + Log.v(TAG, "surfaceCreated before redraw"); + rdman.redraw(); + Log.v(TAG, "surfaceCreated leave"); + } + + public void surfaceDestroyed(SurfaceHolder holder) { + } }