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.miscsamples;
18import android.renderscript.RSSurfaceView;
19import android.renderscript.RenderScriptGL;
20
21import android.content.Context;
22import android.view.MotionEvent;
23
24public class RsListView extends RSSurfaceView {
25
26    public RsListView(Context context) {
27        super(context);
28        ensureRenderScript();
29    }
30
31    private RenderScriptGL mRS;
32    private RsListRS mRender;
33
34    private void ensureRenderScript() {
35        if (mRS == null) {
36            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
37            mRS = createRenderScriptGL(sc);
38            mRender = new RsListRS();
39            mRender.init(mRS, getResources());
40        }
41    }
42
43    @Override
44    protected void onAttachedToWindow() {
45        super.onAttachedToWindow();
46        ensureRenderScript();
47    }
48
49    @Override
50    protected void onDetachedFromWindow() {
51        mRender = null;
52        if (mRS != null) {
53            mRS = null;
54            destroyRenderScriptGL();
55        }
56    }
57
58    @Override
59    public boolean onTouchEvent(MotionEvent ev)
60    {
61        boolean ret = false;
62        int act = ev.getAction();
63        if (act == MotionEvent.ACTION_DOWN) {
64            mRender.onActionDown((int)ev.getX(), (int)ev.getY());
65            ret = true;
66        } else if (act == MotionEvent.ACTION_MOVE) {
67            mRender.onActionMove((int)ev.getX(), (int)ev.getY());
68            ret = true;
69        }
70
71        return ret;
72    }
73}
74
75
76