Android Open Source - AndroidFramework Android Game






From Project

Back to project page AndroidFramework.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project AndroidFramework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.mdobbins.implementation.framework;
/*from   w  w  w  .  j ava2  s  .  co m*/


import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.Window;
import android.view.WindowManager;

import com.mdobbins.framework.Audio;
import com.mdobbins.framework.FileIO;
import com.mdobbins.framework.Game;
import com.mdobbins.framework.Graphics;
import com.mdobbins.framework.Input;
import com.mdobbins.framework.Screen;


public abstract class AndroidGame extends Activity implements Game {
    AndroidFastRenderView renderView;
    Graphics graphics;
    Audio audio;
    Input input;
    FileIO fileIO;
    Screen screen;
    WakeLock wakeLock;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
        int frameBufferWidth = isPortrait ? 800: 1280;
        int frameBufferHeight = isPortrait ? 1280: 800;
        Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
                frameBufferHeight, Config.RGB_565);
       
        float scaleX = (float) frameBufferWidth
                / getWindowManager().getDefaultDisplay().getWidth();
        float scaleY = (float) frameBufferHeight
                / getWindowManager().getDefaultDisplay().getHeight();

        renderView = new AndroidFastRenderView(this, frameBuffer);
        graphics = new AndroidGraphics(getAssets(), frameBuffer);
        fileIO = new AndroidFileIO(this);
        audio = new AndroidAudio(this);
        input = new AndroidInput(this, renderView, scaleX, scaleY);
        screen = getInitScreen();
        setContentView(renderView);
       
        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MyGame");
    }

    @Override
    public void onResume() {
        super.onResume();
        wakeLock.acquire();
        screen.resume();
        renderView.resume();
    }

    @Override
    public void onPause() {
        super.onPause();
        wakeLock.release();
        renderView.pause();
        screen.pause();

        if (isFinishing())
            screen.dispose();
    }

    @Override
    public Input getInput() {
        return input;
    }

    @Override
    public FileIO getFileIO() {
        return fileIO;
    }

    @Override
    public Graphics getGraphics() {
        return graphics;
    }

    @Override
    public Audio getAudio() {
        return audio;
    }

    @Override
    public void setScreen(Screen screen) {
        if (screen == null)
            throw new IllegalArgumentException("Screen must not be null");

        this.screen.pause();
        this.screen.dispose();
        screen.resume();
        screen.update(0);
        this.screen = screen;
    }
   
    public Screen getCurrentScreen() {

        return screen;
    }
}




Java Source Code List

com.mdobbins.framework.Audio.java
com.mdobbins.framework.Audio.java
com.mdobbins.framework.FileIO.java
com.mdobbins.framework.FileIO.java
com.mdobbins.framework.Game.java
com.mdobbins.framework.Game.java
com.mdobbins.framework.Graphics.java
com.mdobbins.framework.Graphics.java
com.mdobbins.framework.Image.java
com.mdobbins.framework.Image.java
com.mdobbins.framework.Input.java
com.mdobbins.framework.Input.java
com.mdobbins.framework.Music.java
com.mdobbins.framework.Music.java
com.mdobbins.framework.Pool.java
com.mdobbins.framework.Pool.java
com.mdobbins.framework.Screen.java
com.mdobbins.framework.Screen.java
com.mdobbins.framework.Sound.java
com.mdobbins.framework.Sound.java
com.mdobbins.implementation.framework.AndroidAudio.java
com.mdobbins.implementation.framework.AndroidFastRenderView.java
com.mdobbins.implementation.framework.AndroidFileIO.java
com.mdobbins.implementation.framework.AndroidGame.java
com.mdobbins.implementation.framework.AndroidGraphics.java
com.mdobbins.implementation.framework.AndroidImage.java
com.mdobbins.implementation.framework.AndroidInput.java
com.mdobbins.implementation.framework.AndroidMusic.java
com.mdobbins.implementation.framework.AndroidSound.java
com.mdobbins.implementation.framework.MultiTouchHandler.java
com.mdobbins.implementation.framework.SingleTouchHandler.java
com.mdobbins.implementation.framework.TouchHandler.java
com.mdobbins.sample.Assets.java
com.mdobbins.sample.GameScreen.java
com.mdobbins.sample.LoadingScreen.java
com.mdobbins.sample.MainMenuScreen.java
com.mdobbins.sample.SampleGame.java