1 /* 2 * Copyright (C) 2007 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.example.android.apis.graphics; 18 19 import android.app.Activity; 20 import android.opengl.GLSurfaceView; 21 import android.os.Bundle; 22 import android.view.View; 23 import android.view.View.OnClickListener; 24 import android.widget.Button; 25 26 //Need the following import to get access to the app resources, since this 27 //class is in a sub-package. 28 import com.example.android.apis.R; 29 30 /** 31 * Demonstration of overlays placed on top of a SurfaceView. 32 */ 33 public class SurfaceViewOverlay extends Activity { 34 View mVictimContainer; 35 View mVictim1; 36 View mVictim2; 37 38 @Override 39 protected void onCreate(Bundle savedInstanceState) { 40 super.onCreate(savedInstanceState); 41 42 setContentView(R.layout.surface_view_overlay); 43 44 GLSurfaceView glSurfaceView = 45 (GLSurfaceView) findViewById(R.id.glsurfaceview); 46 glSurfaceView.setRenderer(new CubeRenderer(false)); 47 48 // Find the views whose visibility will change 49 mVictimContainer = findViewById(R.id.hidecontainer); 50 mVictim1 = findViewById(R.id.hideme1); 51 mVictim1.setOnClickListener(new HideMeListener(mVictim1)); 52 mVictim2 = findViewById(R.id.hideme2); 53 mVictim2.setOnClickListener(new HideMeListener(mVictim2)); 54 55 // Find our buttons 56 Button visibleButton = (Button) findViewById(R.id.vis); 57 Button invisibleButton = (Button) findViewById(R.id.invis); 58 Button goneButton = (Button) findViewById(R.id.gone); 59 60 // Wire each button to a click listener 61 visibleButton.setOnClickListener(mVisibleListener); 62 invisibleButton.setOnClickListener(mInvisibleListener); 63 goneButton.setOnClickListener(mGoneListener); 64 } 65 66 @Override 67 protected void onResume() { 68 // Ideally a game should implement onResume() and onPause() 69 // to take appropriate action when the activity looses focus 70 super.onResume(); 71 } 72 73 @Override 74 protected void onPause() { 75 // Ideally a game should implement onResume() and onPause() 76 // to take appropriate action when the activity looses focus 77 super.onPause(); 78 } 79 80 class HideMeListener implements OnClickListener { 81 final View mTarget; 82 83 HideMeListener(View target) { 84 mTarget = target; 85 } 86 87 public void onClick(View v) { 88 mTarget.setVisibility(View.INVISIBLE); 89 } 90 91 } 92 93 OnClickListener mVisibleListener = new OnClickListener() { 94 public void onClick(View v) { 95 mVictim1.setVisibility(View.VISIBLE); 96 mVictim2.setVisibility(View.VISIBLE); 97 mVictimContainer.setVisibility(View.VISIBLE); 98 } 99 }; 100 101 OnClickListener mInvisibleListener = new OnClickListener() { 102 public void onClick(View v) { 103 mVictim1.setVisibility(View.INVISIBLE); 104 mVictim2.setVisibility(View.INVISIBLE); 105 mVictimContainer.setVisibility(View.INVISIBLE); 106 } 107 }; 108 109 OnClickListener mGoneListener = new OnClickListener() { 110 public void onClick(View v) { 111 mVictim1.setVisibility(View.GONE); 112 mVictim2.setVisibility(View.GONE); 113 mVictimContainer.setVisibility(View.GONE); 114 } 115 }; 116 } 117