Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 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 | |
| 17 | package com.android.modelviewer; |
| 18 | |
| 19 | import java.io.Writer; |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.concurrent.Semaphore; |
| 22 | |
| 23 | import android.renderscript.RSSurfaceView; |
| 24 | import android.renderscript.RenderScript; |
| 25 | import android.renderscript.RenderScriptGL; |
| 26 | |
| 27 | import android.content.Context; |
| 28 | import android.content.res.Resources; |
| 29 | import android.graphics.Bitmap; |
| 30 | import android.graphics.drawable.BitmapDrawable; |
| 31 | import android.graphics.drawable.Drawable; |
| 32 | import android.os.Handler; |
| 33 | import android.os.Message; |
| 34 | import android.util.AttributeSet; |
| 35 | import android.util.Log; |
| 36 | import android.view.Surface; |
| 37 | import android.view.SurfaceHolder; |
| 38 | import android.view.SurfaceView; |
| 39 | import android.view.KeyEvent; |
| 40 | import android.view.MotionEvent; |
| 41 | |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 42 | public class SimpleModelView extends RSSurfaceView { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 43 | |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 44 | public SimpleModelView(Context context) { |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 45 | super(context); |
| 46 | //setFocusable(true); |
| 47 | } |
| 48 | |
| 49 | private RenderScriptGL mRS; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 50 | private SimpleModelRS mRender; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 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 | mRS = createRenderScript(true); |
| 57 | mRS.contextSetSurface(w, h, holder.getSurface()); |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 58 | mRender = new SimpleModelRS(); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 59 | mRender.init(mRS, getResources(), w, h); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | protected void onDetachedFromWindow() { |
| 65 | if(mRS != null) { |
| 66 | mRS = null; |
| 67 | destroyRenderScript(); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public boolean onKeyDown(int keyCode, KeyEvent event) |
| 73 | { |
| 74 | // break point at here |
| 75 | // this method doesn't work when 'extends View' include 'extends ScrollView'. |
| 76 | return super.onKeyDown(keyCode, event); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | @Override |
| 81 | public boolean onTouchEvent(MotionEvent ev) |
| 82 | { |
| 83 | boolean ret = true; |
| 84 | int act = ev.getAction(); |
| 85 | if (act == ev.ACTION_UP) { |
| 86 | ret = false; |
| 87 | } |
| 88 | |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 89 | mRender.touchEvent((int)ev.getX(), (int)ev.getY()); |
| 90 | return ret; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | |