• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
16 package com.example.plasma;
17 
18 import android.app.Activity;
19 import android.os.Bundle;
20 import android.content.Context;
21 import android.view.View;
22 import android.graphics.Bitmap;
23 import android.graphics.Canvas;
24 import android.view.Display;
25 import android.view.WindowManager;
26 
27 public class Plasma extends Activity
28 {
29     /** Called when the activity is first created. */
30     @Override
onCreate(Bundle savedInstanceState)31     public void onCreate(Bundle savedInstanceState)
32     {
33         super.onCreate(savedInstanceState);
34         Display display = getWindowManager().getDefaultDisplay();
35         setContentView(new PlasmaView(this, display.getWidth(), display.getHeight()));
36     }
37 
38     /* load our native library */
39     static {
40         System.loadLibrary("plasma");
41     }
42 }
43 
44 class PlasmaView extends View {
45     private Bitmap mBitmap;
46     private long mStartTime;
47 
48     /* implementend by libplasma.so */
renderPlasma(Bitmap bitmap, long time_ms)49     private static native void renderPlasma(Bitmap  bitmap, long time_ms);
50 
PlasmaView(Context context, int width, int height)51     public PlasmaView(Context context, int width, int height) {
52         super(context);
53         mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
54         mStartTime = System.currentTimeMillis();
55     }
56 
onDraw(Canvas canvas)57     @Override protected void onDraw(Canvas canvas) {
58         //canvas.drawColor(0xFFCCCCCC);
59         renderPlasma(mBitmap, System.currentTimeMillis() - mStartTime);
60         canvas.drawBitmap(mBitmap, 0, 0, null);
61         // force a redraw, with a different time-based pattern.
62         invalidate();
63     }
64 }
65