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.android.modelviewer; 18 19import java.io.Writer; 20import java.util.ArrayList; 21import java.util.concurrent.Semaphore; 22 23import android.renderscript.RSSurfaceView; 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 SceneGraphView extends RSSurfaceView { 43 44 public SceneGraphView(Context context) { 45 super(context); 46 //setFocusable(true); 47 } 48 49 private RenderScriptGL mRS; 50 private SceneGraphRS mRender; 51 52 53 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 54 super.surfaceChanged(holder, format, w, h); 55 if (mRS == null) { 56 RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); 57 sc.setDepth(16, 24); 58 mRS = createRenderScriptGL(sc); 59 mRS.setSurface(holder, w, h); 60 mRender = new SceneGraphRS(); 61 mRender.init(mRS, getResources(), w, h); 62 } 63 } 64 65 @Override 66 protected void onDetachedFromWindow() { 67 if (mRS != null) { 68 mRS = null; 69 destroyRenderScriptGL(); 70 } 71 } 72 73 @Override 74 public boolean onKeyDown(int keyCode, KeyEvent event) 75 { 76 // break point at here 77 // this method doesn't work when 'extends View' include 'extends ScrollView'. 78 return super.onKeyDown(keyCode, event); 79 } 80 81 82 @Override 83 public boolean onTouchEvent(MotionEvent ev) 84 { 85 boolean ret = true; 86 int act = ev.getAction(); 87 if (act == ev.ACTION_UP) { 88 ret = false; 89 } 90 91 mRender.touchEvent((int)ev.getX(), (int)ev.getY()); 92 return ret; 93 } 94} 95 96 97