1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.example.plasma;
17
18import android.app.Activity;
19import android.os.Bundle;
20import android.content.Context;
21import android.view.View;
22import android.graphics.Bitmap;
23import android.graphics.Canvas;
24
25public class Plasma extends Activity
26{
27    /** Called when the activity is first created. */
28    @Override
29    public void onCreate(Bundle savedInstanceState)
30    {
31        super.onCreate(savedInstanceState);
32        setContentView(new PlasmaView(this));
33    }
34
35    /* load our native library */
36    static {
37        System.loadLibrary("plasma");
38    }
39}
40
41class PlasmaView extends View {
42    private Bitmap mBitmap;
43    private long mStartTime;
44
45    /* implementend by libplasma.so */
46    private static native void renderPlasma(Bitmap  bitmap, long time_ms);
47
48    public PlasmaView(Context context) {
49        super(context);
50
51        final int W = 200;
52        final int H = 200;
53
54        mBitmap = Bitmap.createBitmap(W, H, Bitmap.Config.RGB_565);
55        mStartTime = System.currentTimeMillis();
56    }
57
58    @Override protected void onDraw(Canvas canvas) {
59        //canvas.drawColor(0xFFCCCCCC);
60        renderPlasma(mBitmap, System.currentTimeMillis() - mStartTime);
61        canvas.drawBitmap(mBitmap, 0, 0, null);
62        // force a redraw, with a different time-based pattern.
63        invalidate();
64    }
65}
66