Rev 71 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 32 | chris | 1 | package com.gebauz.pingK; |
| 2 | |||
| 3 | import com.gebauz.framework.util.GLUtil; |
||
| 4 | import com.gebauz.framework.util.ResourceManager; |
||
| 42 | chris | 5 | import com.gebauz.pingK.game.GameConsts; |
| 32 | chris | 6 | import com.gebauz.pingK.gamestates.GameStateManager; |
| 101 | chris | 7 | import com.google.ads.AdRequest; |
| 8 | import com.google.ads.AdSize; |
||
| 9 | import com.google.ads.AdView; |
||
| 32 | chris | 10 | |
| 11 | import android.app.Activity; |
||
| 12 | import android.content.pm.ActivityInfo; |
||
| 13 | import android.graphics.PixelFormat; |
||
| 14 | import android.opengl.GLSurfaceView; |
||
| 15 | import android.os.Bundle; |
||
| 16 | import android.os.Handler; |
||
| 17 | import android.view.MotionEvent; |
||
| 18 | import android.view.View; |
||
| 19 | import android.view.Window; |
||
| 20 | import android.view.WindowManager; |
||
| 21 | import android.view.View.OnTouchListener; |
||
| 101 | chris | 22 | import android.widget.LinearLayout; |
| 32 | chris | 23 | |
| 24 | public class GameActivity extends Activity implements OnTouchListener |
||
| 25 | { |
||
| 101 | chris | 26 | public static final String ADMOB_PUBLISHER_ID = "a14ea091b1a94ea"; |
| 27 | |||
| 28 | private AdView mAdView; |
||
| 29 | |||
| 32 | chris | 30 | private GLSurfaceView mGameView = null; |
| 31 | |||
| 32 | final Handler mHandler = new Handler(); |
||
| 33 | |||
| 34 | // Create runnable for posting |
||
| 35 | final Runnable mUpdateResults = new Runnable() { |
||
| 36 | public void run() { |
||
| 71 | chris | 37 | //TextView text = (TextView)findViewById(R.id.debug_text); |
| 38 | //text.setText(MultitouchInput.getInstance().getDebugText()); |
||
| 32 | chris | 39 | } |
| 40 | }; |
||
| 41 | |||
| 42 | /** Called when the activity is first created. */ |
||
| 43 | @Override |
||
| 44 | public void onCreate(Bundle savedInstanceState) |
||
| 45 | { |
||
| 46 | super.onCreate(savedInstanceState); |
||
| 47 | |||
| 48 | getWindow().setFormat(PixelFormat.TRANSLUCENT); |
||
| 49 | getWindow().setWindowAnimations(0); |
||
| 50 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
||
| 51 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); |
||
| 52 | |||
| 53 | setContentView(R.layout.main); |
||
| 101 | chris | 54 | |
| 55 | |||
| 56 | // Create the adView |
||
| 57 | mAdView = new AdView(this, AdSize.BANNER, ADMOB_PUBLISHER_ID); |
||
| 58 | |||
| 59 | // Lookup your LinearLayout assuming it’s been given |
||
| 60 | // the attribute android:id="@+id/mainLayout" |
||
| 61 | LinearLayout layout = (LinearLayout)findViewById(R.id.adContainer); |
||
| 62 | |||
| 63 | // Add the adView to it |
||
| 64 | layout.addView(mAdView); |
||
| 65 | |||
| 66 | // Initiate a generic request to load it with an ad |
||
| 67 | mAdView.loadAd(new AdRequest()); |
||
| 68 | |||
| 69 | |||
| 32 | chris | 70 | /* |
| 71 | mGameView = new GLSurfaceView(this); |
||
| 72 | mGameView.setRenderer(new GameRenderer(this)); |
||
| 73 | mGameView.setOnTouchListener(this); |
||
| 74 | setContentView(mGameView); |
||
| 75 | */ |
||
| 76 | |||
| 77 | mGameView = (GLSurfaceView)findViewById(R.id.glsurfaceview); |
||
| 41 | chris | 78 | mGameView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); |
| 32 | chris | 79 | mGameView.setRenderer(new GameRenderer(this)); |
| 80 | mGameView.setOnTouchListener(this); |
||
| 81 | |||
| 82 | // set landscape mode |
||
| 83 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
||
| 84 | |||
| 85 | // set the current context |
||
| 86 | ResourceManager.getInstance().setCurrentContext(this); |
||
| 87 | |||
| 88 | // queue initial game state |
||
| 68 | chris | 89 | GameStateManager.getInstance().setContext(this); |
| 32 | chris | 90 | GameStateManager.getInstance().switchState(getResources().getString(R.string.initial_state)); |
| 91 | |||
| 92 | //Log.v("TEST", "i: " + R.integer.integer_name); |
||
| 93 | } |
||
| 94 | |||
| 95 | protected void onResume() |
||
| 96 | { |
||
| 97 | super.onResume(); |
||
| 98 | |||
| 99 | mGameView.onResume(); |
||
| 100 | } |
||
| 101 | |||
| 102 | protected void onPause() |
||
| 103 | { |
||
| 104 | super.onPause(); |
||
| 105 | |||
| 106 | mGameView.onPause(); |
||
| 107 | } |
||
| 108 | |||
| 109 | public boolean onTouch(View v, MotionEvent event) |
||
| 110 | { |
||
| 111 | MultitouchInput.getInstance().handleInput(event); |
||
| 112 | return true; |
||
| 113 | } |
||
| 114 | |||
| 115 | public void onSurfaceChanged(int w, int h) |
||
| 116 | { |
||
| 117 | GLUtil.getInstance().setWidth(w); |
||
| 118 | GLUtil.getInstance().setHeight(h); |
||
| 42 | chris | 119 | |
| 120 | MultitouchInput.getInstance().setVirtualScreenRatio(GameConsts.VIRTUAL_SCREEN_WIDTH / (float)w, GameConsts.VIRTUAL_SCREEN_HEIGHT / (float)h); |
||
| 32 | chris | 121 | |
| 122 | GameStateManager.getInstance().onSurfaceChanged(w, h); |
||
| 123 | } |
||
| 124 | |||
| 45 | chris | 125 | public void update(float deltaTime) |
| 32 | chris | 126 | { |
| 127 | // Fire off a thread to do some work that we shouldn't do directly in the UI thread |
||
| 37 | chris | 128 | Thread t = new Thread() |
| 129 | { |
||
| 130 | public void run() |
||
| 131 | { |
||
| 32 | chris | 132 | mHandler.post(mUpdateResults); |
| 133 | } |
||
| 134 | }; |
||
| 135 | t.start(); |
||
| 136 | |||
| 45 | chris | 137 | GameStateManager.getInstance().update(deltaTime); |
| 138 | MultitouchInput.getInstance().update(deltaTime); |
||
| 32 | chris | 139 | } |
| 140 | |||
| 141 | public void render() |
||
| 142 | { |
||
| 143 | GameStateManager.getInstance().render(); |
||
| 144 | MultitouchInput.getInstance().render(); |
||
| 145 | } |
||
| 146 | |||
| 147 | } |
||
| 148 | |||
| 149 | |||
| 150 | |||
| 151 |