OLD | NEW |
(Empty) | |
| 1 package com.example; |
| 2 |
| 3 import java.util.Timer; |
| 4 import java.util.TimerTask; |
| 5 |
| 6 import android.app.Activity; |
| 7 import android.content.Context; |
| 8 import android.graphics.Bitmap; |
| 9 import android.graphics.Canvas; |
| 10 import android.os.Bundle; |
| 11 import android.os.SystemClock; |
| 12 import android.util.Log; |
| 13 import android.view.View; |
| 14 |
| 15 public class HelloSkiaActivity extends Activity |
| 16 { |
| 17 private SkiaDrawView fMainView; |
| 18 |
| 19 /** Called when the activity is first created. */ |
| 20 @Override |
| 21 public void onCreate(Bundle savedInstanceState) { |
| 22 super.onCreate(savedInstanceState); |
| 23 |
| 24 fMainView = new SkiaDrawView(this); |
| 25 setContentView(fMainView); |
| 26 |
| 27 try { |
| 28 // Load skia and then the app shared object in this order |
| 29 System.loadLibrary("skia_android"); |
| 30 System.loadLibrary("hello_skia_ndk"); |
| 31 |
| 32 } catch (UnsatisfiedLinkError e) { |
| 33 Log.d("HelloSkia", "Link Error: " + e); |
| 34 return; |
| 35 } |
| 36 |
| 37 // Set a timer that will periodically request an update of the SkiaDrawV
iew |
| 38 Timer fAnimationTimer = new Timer(); |
| 39 fAnimationTimer.schedule(new TimerTask() { |
| 40 public void run() |
| 41 { |
| 42 // This will request an update of the SkiaDrawView, even from ot
her threads |
| 43 fMainView.postInvalidate(); |
| 44 } |
| 45 }, 0, 5); |
| 46 } |
| 47 |
| 48 private class SkiaDrawView extends View { |
| 49 public SkiaDrawView(Context ctx) { |
| 50 super(ctx); |
| 51 } |
| 52 |
| 53 @Override |
| 54 protected void onDraw(Canvas canvas) { |
| 55 // Create a bitmap for skia to draw into |
| 56 Bitmap skiaBitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.ge
tHeight(), |
| 57 Bitmap.Config.ARGB_8888); |
| 58 |
| 59 drawIntoBitmap(skiaBitmap, SystemClock.elapsedRealtime()); |
| 60 |
| 61 // Present the bitmap on the screen |
| 62 canvas.drawBitmap(skiaBitmap, 0, 0, null); |
| 63 } |
| 64 } |
| 65 |
| 66 |
| 67 private native void drawIntoBitmap(Bitmap image, long elapsedTime); |
| 68 } |
OLD | NEW |