1/* 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.fountainfbo; 18 19 20import android.renderscript.RSTextureView; 21import android.renderscript.RenderScriptGL; 22import android.content.Context; 23import android.view.MotionEvent; 24 25public class FountainFboView extends RSTextureView { 26 27 public FountainFboView(Context context) { 28 super(context); 29 } 30 31 private RenderScriptGL mRS; 32 private FountainFboRS mRender; 33 34 @Override 35 protected void onAttachedToWindow() { 36 super.onAttachedToWindow(); 37 android.util.Log.e("rs", "onAttachedToWindow"); 38 if (mRS == null) { 39 RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); 40 mRS = createRenderScriptGL(sc); 41 mRender = new FountainFboRS(); 42 mRender.init(mRS, getResources()); 43 } 44 } 45 46 @Override 47 protected void onDetachedFromWindow() { 48 super.onDetachedFromWindow(); 49 android.util.Log.e("rs", "onDetachedFromWindow"); 50 if (mRS != null) { 51 mRS = null; 52 destroyRenderScriptGL(); 53 } 54 } 55 56 57 @Override 58 public boolean onTouchEvent(MotionEvent ev) 59 { 60 int act = ev.getActionMasked(); 61 if (act == ev.ACTION_UP) { 62 mRender.newTouchPosition(0, 0, 0, ev.getPointerId(0)); 63 return false; 64 } else if (act == MotionEvent.ACTION_POINTER_UP) { 65 // only one pointer going up, we can get the index like this 66 int pointerIndex = ev.getActionIndex(); 67 int pointerId = ev.getPointerId(pointerIndex); 68 mRender.newTouchPosition(0, 0, 0, pointerId); 69 } 70 int count = ev.getHistorySize(); 71 int pcount = ev.getPointerCount(); 72 73 for (int p=0; p < pcount; p++) { 74 int id = ev.getPointerId(p); 75 mRender.newTouchPosition(ev.getX(p), 76 ev.getY(p), 77 ev.getPressure(p), 78 id); 79 80 for (int i=0; i < count; i++) { 81 mRender.newTouchPosition(ev.getHistoricalX(p, i), 82 ev.getHistoricalY(p, i), 83 ev.getHistoricalPressure(p, i), 84 id); 85 } 86 } 87 return true; 88 } 89} 90 91 92