Android Open Source - clash_of_balls Main Activity






From Project

Back to project page clash_of_balls.

License

The source code is released under:

GNU General Public License

If you think the Android project clash_of_balls 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

/*
 * Copyright (C) 2012-2013 Hans Hardmeier <hanshardmeier@gmail.com>
 * Copyright (C) 2012-2013 Andrin Jenal/*  w w w  .  ja v a 2 s.  co  m*/
 * Copyright (C) 2012-2013 Beat Kng <beat-kueng@gmx.net>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */
package com.sapos_aplastados.game.clash_of_balls;

import com.sapos_aplastados.game.clash_of_balls.MainActivity.LoadViewTask;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.content.Context;
import android.content.Intent;

public class MainActivity extends Activity {
  
  private static final String LOG_TAG="MainActivity";

  private ProgressDialog progressDialog;
    private MyGLSurfaceView m_gl_view;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        Font2D.resetFonts();
        
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // making it full screen
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        
        LoadViewTask progress_view = new LoadViewTask();
        progress_view.execute();
        // Create a GLSurfaceView instance and set it
        // as the ContentView for this Activity
        m_gl_view = new MyGLSurfaceView(this, progress_view);
        setContentView(m_gl_view);
        
        //start the network service
        Intent intent = new Intent(this, NetworkService.class);
        if(startService(intent)==null)
          Log.e(LOG_TAG, "Failed to start NetworkService");
    }
    
    @Override
    protected void onPause() {
        super.onPause();
        // The following call pauses the rendering thread.
        // If your OpenGL application is memory intensive,
        // you should consider de-allocating objects that
        // consume significant memory here.
        m_gl_view.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        // The following call resumes a paused rendering thread.
        // If you de-allocated graphic objects for onPause()
        // this is a good place to re-allocate them.
        m_gl_view.onResume();
    }
    
    @Override
    protected void onDestroy() {
      super.onDestroy();
      stopService(new Intent(this, NetworkService.class));
      m_gl_view.onDestroy();
      dismissDialog();
    }
    
    @Override
    public void onBackPressed() {
      if(m_gl_view != null && !m_gl_view.onBackPressed())
        super.onBackPressed();
    }
    
  public void dismissDialog() {
    //close the progress dialog
      ProgressDialog dialog = progressDialog;
      if(dialog != null) dialog.dismiss();
      progressDialog = null;
  }

    
    public class LoadViewTask extends AsyncTask<Void, Integer, Void>
    {
      
      private volatile int m_progress = 0; //progress: [0,100]
      
      //Before running code in the separate thread
    @Override
    protected void onPreExecute() 
    {
      //Create a new progress dialog
      progressDialog = new ProgressDialog(MainActivity.this);
      //Set the progress dialog to display a horizontal progress bar 
      progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
      //Set the dialog title to 'Loading...'
      progressDialog.setTitle("Loading Game...");
      //Set the dialog message to 'Loading application View, please wait...'
      progressDialog.setMessage("Please wait...");
      //This dialog can't be canceled by pressing the back key
      progressDialog.setCancelable(false);
      //This dialog isn't indeterminate
      progressDialog.setIndeterminate(false);
      //The maximum number of items is 100
      progressDialog.setMax(100);
      //Set the current progress to zero
      progressDialog.setProgress(0);
      //Display the progress dialog
      progressDialog.show();
    }
    
    //if progress is 100, progress bar will be hidden
    public void setProgress(int progress) {
      synchronized (this) {
        m_progress = progress;
        this.notify();
      }
    }
    
    //The code to be executed in a background thread.
    @Override
    protected Void doInBackground(Void... params) 
    {
      try 
      {
        while(m_progress < 100) {
          //Get the current thread's token
          synchronized (this) 
          {
            this.wait();
            //Set the current progress. 
            //This value is going to be passed to the onProgressUpdate() method.
            publishProgress(m_progress);
          }
        }
      } 
      catch (InterruptedException e) 
      {
        e.printStackTrace();
      }
      return null;
    }

    //Update the progress
    @Override
    protected void onProgressUpdate(Integer... values) 
    {
      //set the current progress of the progress dialog
      if(progressDialog!=null) progressDialog.setProgress(values[0]);
    }

    //after executing the code in the thread
    @Override
    protected void onPostExecute(Void result) 
    {
      dismissDialog();
    }   
    
    }

}




class MyGLSurfaceView extends GLSurfaceView {

    private final GameRenderer m_renderer;

    public MyGLSurfaceView(Context context, LoadViewTask progress_view) {
        super(context);

        // Create an OpenGL ES 2.0 context.
        setEGLContextClientVersion(2);

        // Set the Renderer for drawing on the GLSurfaceView
        m_renderer = new GameRenderer(this.getContext(), progress_view);
        setRenderer(m_renderer);

        
        setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
    }
    
    //returns true if back button is handled, false if system should handle it
    public boolean onBackPressed() {
      return m_renderer.onBackPressed();
    }
    
    public void onDestroy() {
      queueEvent(new Runnable() {
      public void run() {
        m_renderer.onDestroy();
      }
      });
    }

    @Override
    public boolean onTouchEvent(final MotionEvent e) {
        
      final float x = e.getX(), y=e.getY();
      final int event = e.getAction();
      
        switch (event) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_UP:
              //send event to the renderer
              queueEvent(new Runnable() {
          public void run() {
            m_renderer.handleTouchInput(x, y, event);
          }
              });
        }
        return true;
    }
}




Java Source Code List

au.com.bytecode.opencsv.CSVParser.java
au.com.bytecode.opencsv.CSVReader.java
au.com.bytecode.opencsv.CSVWriter.java
au.com.bytecode.opencsv.ResultSetHelperService.java
au.com.bytecode.opencsv.ResultSetHelper.java
com.sapos_aplastados.game.clash_of_balls.FPSCounter.java
com.sapos_aplastados.game.clash_of_balls.Font2D.java
com.sapos_aplastados.game.clash_of_balls.FontNumbers.java
com.sapos_aplastados.game.clash_of_balls.GameLevel.java
com.sapos_aplastados.game.clash_of_balls.GameRenderer.java
com.sapos_aplastados.game.clash_of_balls.GameSettings.java
com.sapos_aplastados.game.clash_of_balls.ITouchInput.java
com.sapos_aplastados.game.clash_of_balls.LevelManager.java
com.sapos_aplastados.game.clash_of_balls.MainActivity.java
com.sapos_aplastados.game.clash_of_balls.Maths.java
com.sapos_aplastados.game.clash_of_balls.NetworkService.java
com.sapos_aplastados.game.clash_of_balls.ShaderManager.java
com.sapos_aplastados.game.clash_of_balls.TextureBase.java
com.sapos_aplastados.game.clash_of_balls.TextureManager.java
com.sapos_aplastados.game.clash_of_balls.Texture.java
com.sapos_aplastados.game.clash_of_balls.UIBase.java
com.sapos_aplastados.game.clash_of_balls.UIHandler.java
com.sapos_aplastados.game.clash_of_balls.VertexBufferFloat.java
com.sapos_aplastados.game.clash_of_balls.game.DynamicGameObject.java
com.sapos_aplastados.game.clash_of_balls.game.GameBase.java
com.sapos_aplastados.game.clash_of_balls.game.GameField.java
com.sapos_aplastados.game.clash_of_balls.game.GameHole.java
com.sapos_aplastados.game.clash_of_balls.game.GameItem.java
com.sapos_aplastados.game.clash_of_balls.game.GameMenuInGame.java
com.sapos_aplastados.game.clash_of_balls.game.GameObject.java
com.sapos_aplastados.game.clash_of_balls.game.GamePlayer.java
com.sapos_aplastados.game.clash_of_balls.game.GameServer.java
com.sapos_aplastados.game.clash_of_balls.game.GameStatistics.java
com.sapos_aplastados.game.clash_of_balls.game.GameView.java
com.sapos_aplastados.game.clash_of_balls.game.GameWall.java
com.sapos_aplastados.game.clash_of_balls.game.Game.java
com.sapos_aplastados.game.clash_of_balls.game.IDrawable.java
com.sapos_aplastados.game.clash_of_balls.game.IMoveable.java
com.sapos_aplastados.game.clash_of_balls.game.RenderHelper.java
com.sapos_aplastados.game.clash_of_balls.game.SensorThread.java
com.sapos_aplastados.game.clash_of_balls.game.StaticGameObjectNoInteraction.java
com.sapos_aplastados.game.clash_of_balls.game.StaticGameObject.java
com.sapos_aplastados.game.clash_of_balls.game.Vector3D.java
com.sapos_aplastados.game.clash_of_balls.game.Vector.java
com.sapos_aplastados.game.clash_of_balls.game.event.EventGameEnd.java
com.sapos_aplastados.game.clash_of_balls.game.event.EventGameInfo.java
com.sapos_aplastados.game.clash_of_balls.game.event.EventGameStartNow.java
com.sapos_aplastados.game.clash_of_balls.game.event.EventImpact.java
com.sapos_aplastados.game.clash_of_balls.game.event.EventItemAdded.java
com.sapos_aplastados.game.clash_of_balls.game.event.EventItemRemoved.java
com.sapos_aplastados.game.clash_of_balls.game.event.EventItemUpdate.java
com.sapos_aplastados.game.clash_of_balls.game.event.EventPool.java
com.sapos_aplastados.game.clash_of_balls.game.event.Event.java
com.sapos_aplastados.game.clash_of_balls.helper.RawResourceReader.java
com.sapos_aplastados.game.clash_of_balls.helper.ShaderHelper.java
com.sapos_aplastados.game.clash_of_balls.helper.TextureHelper.java
com.sapos_aplastados.game.clash_of_balls.menu.CreationMenu.java
com.sapos_aplastados.game.clash_of_balls.menu.GameMenuBase.java
com.sapos_aplastados.game.clash_of_balls.menu.HelpMenu.java
com.sapos_aplastados.game.clash_of_balls.menu.JoinMenu.java
com.sapos_aplastados.game.clash_of_balls.menu.MainMenu.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuBackground.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuItemArrow.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuItemButton.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuItemGreyButton.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuItemImg.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuItemKeyboard.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuItemLevel.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuItemList.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuItemResultEntry.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuItemStringMultiline.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuItemString.java
com.sapos_aplastados.game.clash_of_balls.menu.MenuItem.java
com.sapos_aplastados.game.clash_of_balls.menu.PopupBase.java
com.sapos_aplastados.game.clash_of_balls.menu.PopupCredit.java
com.sapos_aplastados.game.clash_of_balls.menu.PopupGameStart.java
com.sapos_aplastados.game.clash_of_balls.menu.PopupMsg.java
com.sapos_aplastados.game.clash_of_balls.menu.ResultsMenu.java
com.sapos_aplastados.game.clash_of_balls.menu.WaitMenu.java
com.sapos_aplastados.game.clash_of_balls.network.AlljoynInterface.java
com.sapos_aplastados.game.clash_of_balls.network.NetworkClient.java
com.sapos_aplastados.game.clash_of_balls.network.NetworkServer.java
com.sapos_aplastados.game.clash_of_balls.network.Networking.java