blob: ba09421c0967bf3dc45fb77a8f774bd3c6cf94f9 [file] [log] [blame]
Jason Samse5f2f662012-05-16 15:43:25 -07001/*
2 * Copyright (C) 2008 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
17package com.example.android.rs.fountain;
18
19import java.io.Writer;
20import java.util.ArrayList;
21import java.util.concurrent.Semaphore;
22
23import android.renderscript.RSTextureView;
24import android.renderscript.RenderScript;
25import android.renderscript.RenderScriptGL;
26
27import android.content.Context;
28import android.content.res.Resources;
29import android.graphics.Bitmap;
30import android.graphics.drawable.BitmapDrawable;
31import android.graphics.drawable.Drawable;
32import android.os.Handler;
33import android.os.Message;
34import android.util.AttributeSet;
35import android.util.Log;
36import android.view.Surface;
37import android.view.SurfaceHolder;
38import android.view.SurfaceView;
39import android.view.KeyEvent;
40import android.view.MotionEvent;
41
42public class FountainView extends RSTextureView {
43
44 public FountainView(Context context) {
45 super(context);
46 //setFocusable(true);
47 }
48
49 private RenderScriptGL mRS;
50 private FountainRS mRender;
51
52 @Override
53 protected void onAttachedToWindow() {
54 super.onAttachedToWindow();
55 android.util.Log.e("rs", "onAttachedToWindow");
56 if (mRS == null) {
57 RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
58 mRS = createRenderScriptGL(sc);
59 mRender = new FountainRS();
60 mRender.init(mRS, getResources());
61 }
62 }
63
64 @Override
65 protected void onDetachedFromWindow() {
66 super.onDetachedFromWindow();
67 android.util.Log.e("rs", "onDetachedFromWindow");
68 if (mRS != null) {
69 mRS = null;
70 destroyRenderScriptGL();
71 }
72 }
73
74
75 @Override
76 public boolean onTouchEvent(MotionEvent ev)
77 {
78 int act = ev.getActionMasked();
79 if (act == ev.ACTION_UP) {
80 mRender.newTouchPosition(0, 0, 0, ev.getPointerId(0));
81 return false;
82 } else if (act == MotionEvent.ACTION_POINTER_UP) {
83 // only one pointer going up, we can get the index like this
84 int pointerIndex = ev.getActionIndex();
85 int pointerId = ev.getPointerId(pointerIndex);
86 mRender.newTouchPosition(0, 0, 0, pointerId);
87 }
88 int count = ev.getHistorySize();
89 int pcount = ev.getPointerCount();
90
91 for (int p=0; p < pcount; p++) {
92 int id = ev.getPointerId(p);
93 mRender.newTouchPosition(ev.getX(p),
94 ev.getY(p),
95 ev.getPressure(p),
96 id);
97
98 for (int i=0; i < count; i++) {
99 mRender.newTouchPosition(ev.getHistoricalX(p, i),
100 ev.getHistoricalY(p, i),
101 ev.getHistoricalPressure(p, i),
102 id);
103 }
104 }
105 return true;
106 }
107}
108
109