Subversion Repositories AndroidProjects

Rev

Rev 68 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.gebauz.pingK;

import com.gebauz.framework.util.GLUtil;
import com.gebauz.framework.util.ResourceManager;
import com.gebauz.pingK.game.GameConsts;
import com.gebauz.pingK.gamestates.GameStateManager;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnTouchListener;
import android.widget.TextView;

public class GameActivity extends Activity implements OnTouchListener
{
        private GLSurfaceView mGameView = null;
       
    final Handler mHandler = new Handler();

    // Create runnable for posting
    final Runnable mUpdateResults = new Runnable() {
        public void run() {
                //TextView text = (TextView)findViewById(R.id.debug_text);
                //text.setText(MultitouchInput.getInstance().getDebugText());
        }
    };
       
        /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        getWindow().setWindowAnimations(0);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);
        /*
                mGameView = new GLSurfaceView(this);
        mGameView.setRenderer(new GameRenderer(this));
        mGameView.setOnTouchListener(this);
                setContentView(mGameView);
        */

       
        mGameView = (GLSurfaceView)findViewById(R.id.glsurfaceview);
        mGameView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
        mGameView.setRenderer(new GameRenderer(this));
        mGameView.setOnTouchListener(this);
       
        // set landscape mode
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
       
        // set the current context
        ResourceManager.getInstance().setCurrentContext(this);
       
                // queue initial game state
        GameStateManager.getInstance().setContext(this);
                GameStateManager.getInstance().switchState(getResources().getString(R.string.initial_state));
               
                //Log.v("TEST", "i: " + R.integer.integer_name);
    }
   
    protected void onResume()
    {
        super.onResume();
       
        mGameView.onResume();
    }

    protected void onPause()
    {
        super.onPause();

        mGameView.onPause();
    }
   
    public boolean onTouch(View v, MotionEvent event)
    {
        MultitouchInput.getInstance().handleInput(event);      
        return true;
    }
   
    public void onSurfaceChanged(int w, int h)
    {
        GLUtil.getInstance().setWidth(w);
        GLUtil.getInstance().setHeight(h);
       
        MultitouchInput.getInstance().setVirtualScreenRatio(GameConsts.VIRTUAL_SCREEN_WIDTH / (float)w, GameConsts.VIRTUAL_SCREEN_HEIGHT / (float)h);

        GameStateManager.getInstance().onSurfaceChanged(w, h);
    }
   
    public void update(float deltaTime)
    {
        // Fire off a thread to do some work that we shouldn't do directly in the UI thread
        Thread t = new Thread()
        {
            public void run()
            {
                mHandler.post(mUpdateResults);
            }
        };
        t.start();
       
        GameStateManager.getInstance().update(deltaTime);
        MultitouchInput.getInstance().update(deltaTime);
    }
   
    public void render()
    {
                GameStateManager.getInstance().render();
                MultitouchInput.getInstance().render();
    }
   
}