159206df88081556d0bf538234da0b455cc7bb095Romain Guy/*
259206df88081556d0bf538234da0b455cc7bb095Romain Guy * Copyright (C) 2009 The Android Open Source Project
359206df88081556d0bf538234da0b455cc7bb095Romain Guy *
459206df88081556d0bf538234da0b455cc7bb095Romain Guy * Licensed under the Apache License, Version 2.0 (the "License");
559206df88081556d0bf538234da0b455cc7bb095Romain Guy * you may not use this file except in compliance with the License.
659206df88081556d0bf538234da0b455cc7bb095Romain Guy * You may obtain a copy of the License at
759206df88081556d0bf538234da0b455cc7bb095Romain Guy *
859206df88081556d0bf538234da0b455cc7bb095Romain Guy *      http://www.apache.org/licenses/LICENSE-2.0
959206df88081556d0bf538234da0b455cc7bb095Romain Guy *
1059206df88081556d0bf538234da0b455cc7bb095Romain Guy * Unless required by applicable law or agreed to in writing, software
1159206df88081556d0bf538234da0b455cc7bb095Romain Guy * distributed under the License is distributed on an "AS IS" BASIS,
1259206df88081556d0bf538234da0b455cc7bb095Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1359206df88081556d0bf538234da0b455cc7bb095Romain Guy * See the License for the specific language governing permissions and
1459206df88081556d0bf538234da0b455cc7bb095Romain Guy * limitations under the License.
1559206df88081556d0bf538234da0b455cc7bb095Romain Guy */
1659206df88081556d0bf538234da0b455cc7bb095Romain Guy
1759206df88081556d0bf538234da0b455cc7bb095Romain Guy
1859206df88081556d0bf538234da0b455cc7bb095Romain Guypackage com.android.wallpaper.fall;
1959206df88081556d0bf538234da0b455cc7bb095Romain Guy
2059206df88081556d0bf538234da0b455cc7bb095Romain Guyimport android.content.Context;
2159206df88081556d0bf538234da0b455cc7bb095Romain Guyimport android.view.SurfaceHolder;
2259206df88081556d0bf538234da0b455cc7bb095Romain Guyimport android.view.MotionEvent;
2359206df88081556d0bf538234da0b455cc7bb095Romain Guyimport android.renderscript.RenderScript;
24b418c5c443dc18fbdc7d644c407fada2be78c50fJason Samsimport android.renderscript.RenderScriptGL;
2559206df88081556d0bf538234da0b455cc7bb095Romain Guyimport android.renderscript.RSSurfaceView;
2659206df88081556d0bf538234da0b455cc7bb095Romain Guy
2759206df88081556d0bf538234da0b455cc7bb095Romain Guyclass FallView extends RSSurfaceView {
2859206df88081556d0bf538234da0b455cc7bb095Romain Guy    private FallRS mRender;
2959206df88081556d0bf538234da0b455cc7bb095Romain Guy
3059206df88081556d0bf538234da0b455cc7bb095Romain Guy    public FallView(Context context) {
3159206df88081556d0bf538234da0b455cc7bb095Romain Guy        super(context);
3259206df88081556d0bf538234da0b455cc7bb095Romain Guy        setFocusable(true);
3359206df88081556d0bf538234da0b455cc7bb095Romain Guy        setFocusableInTouchMode(true);
3459206df88081556d0bf538234da0b455cc7bb095Romain Guy    }
3559206df88081556d0bf538234da0b455cc7bb095Romain Guy
3659206df88081556d0bf538234da0b455cc7bb095Romain Guy    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
3759206df88081556d0bf538234da0b455cc7bb095Romain Guy        super.surfaceChanged(holder, format, w, h);
3859206df88081556d0bf538234da0b455cc7bb095Romain Guy
39b418c5c443dc18fbdc7d644c407fada2be78c50fJason Sams        RenderScriptGL RS = createRenderScript(false);
4059206df88081556d0bf538234da0b455cc7bb095Romain Guy        mRender = new FallRS(w, h);
410ac0b3f704bedde5c3a117ac68e7cd4956cd73efRomain Guy        mRender.init(RS, getResources(), false);
4259206df88081556d0bf538234da0b455cc7bb095Romain Guy        mRender.start();
4359206df88081556d0bf538234da0b455cc7bb095Romain Guy    }
4459206df88081556d0bf538234da0b455cc7bb095Romain Guy
4559206df88081556d0bf538234da0b455cc7bb095Romain Guy    @Override
4659206df88081556d0bf538234da0b455cc7bb095Romain Guy    public boolean onTouchEvent(MotionEvent event) {
4759206df88081556d0bf538234da0b455cc7bb095Romain Guy        switch (event.getAction()) {
4859206df88081556d0bf538234da0b455cc7bb095Romain Guy            case MotionEvent.ACTION_DOWN:
492cfcc6d11db96fa035ed61da3a913a25c101af49Jason Sams            //case MotionEvent.ACTION_MOVE:
5059206df88081556d0bf538234da0b455cc7bb095Romain Guy                mRender.addDrop(event.getX(), event.getY());
5159206df88081556d0bf538234da0b455cc7bb095Romain Guy                try {
5259206df88081556d0bf538234da0b455cc7bb095Romain Guy                    Thread.sleep(16);
5359206df88081556d0bf538234da0b455cc7bb095Romain Guy                } catch (InterruptedException e) {
5459206df88081556d0bf538234da0b455cc7bb095Romain Guy                    // Ignore
5559206df88081556d0bf538234da0b455cc7bb095Romain Guy                }
5659206df88081556d0bf538234da0b455cc7bb095Romain Guy                break;
5759206df88081556d0bf538234da0b455cc7bb095Romain Guy        }
5859206df88081556d0bf538234da0b455cc7bb095Romain Guy        return true;
5959206df88081556d0bf538234da0b455cc7bb095Romain Guy    }
6059206df88081556d0bf538234da0b455cc7bb095Romain Guy}