• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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.google.oboe.samples.rhythmgame;
18 
19 import android.content.Context;
20 import android.opengl.GLSurfaceView;
21 import android.util.AttributeSet;
22 import android.view.MotionEvent;
23 import android.view.SurfaceHolder;
24 
25 public class GameSurfaceView extends GLSurfaceView {
26 
native_onTouchInput(int eventType, long timeSinceBootMs, int pixel_x, int pixel_y)27     public static native void native_onTouchInput(int eventType, long timeSinceBootMs, int pixel_x, int pixel_y);
native_surfaceDestroyed()28     public static native void native_surfaceDestroyed();
29     private final RendererWrapper mRenderer;
30 
GameSurfaceView(Context context)31     public GameSurfaceView(Context context) {
32         super(context);
33         setEGLContextClientVersion(2);
34         mRenderer = new RendererWrapper();
35         // Set the Renderer for drawing on the GLSurfaceView
36         setRenderer(mRenderer);
37     }
38 
GameSurfaceView(Context context, AttributeSet attrs)39     public GameSurfaceView(Context context, AttributeSet attrs) {
40         super(context, attrs);
41         setEGLContextClientVersion(2);
42         mRenderer = new RendererWrapper();
43         // Set the Renderer for drawing on the GLSurfaceView
44         setRenderer(mRenderer);
45     }
46 
47     @Override
surfaceDestroyed(SurfaceHolder holder)48     public void surfaceDestroyed(SurfaceHolder holder) {
49         native_surfaceDestroyed();
50         super.surfaceDestroyed(holder);
51     }
52 
53     @Override
onTouchEvent(MotionEvent e)54     public boolean onTouchEvent(MotionEvent e) {
55         // MotionEvent reports input details from the touch screen
56         // and other input controls. In our case we care about DOWN events.
57         switch (e.getAction()) {
58             case MotionEvent.ACTION_DOWN:
59                 native_onTouchInput(0, e.getEventTime(), (int)e.getX(), (int)e.getY());
60                 break;
61         }
62         return true;
63     }
64 }
65