Android Open Source - block-composer Block Composer Activity






From Project

Back to project page block-composer.

License

The source code is released under:

MIT License

If you think the Android project block-composer 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 bwr.blockcomposer;
/*from   w ww .  java2s . co m*/
import java.io.IOException;

import bwr.blockcomposer.modes.LevelImportMode;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.WindowManager;

public class BlockComposerActivity extends Activity {
  private final static int DIALOG_HELP = 4;
  private final static int DIALOG_IMPORT = 5;

  private BlockComposerRenderer renderer;
  private int currentOptionsMenu = -1;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    renderer = new BlockComposerRenderer(this);
    
    setContentView(renderer);

    Intent i = getIntent();
    if(i != null && Intent.ACTION_VIEW.equals(i.getAction())) {
      try {
        renderer.pushMode(new LevelImportMode(renderer, renderer.getGameResources(), i));
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      
      if(renderer == null || renderer.getCurrentMode() == null) return false;
      
    inflater.inflate(renderer.getCurrentMode().optionsMenu(), menu);
    currentOptionsMenu = renderer.getCurrentMode().optionsMenu();
      
      return true;
  }

  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    if(currentOptionsMenu != renderer.getCurrentMode().optionsMenu()) {
        menu.clear();
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(renderer.getCurrentMode().optionsMenu(), menu);
        currentOptionsMenu = renderer.getCurrentMode().optionsMenu();
    }
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if(item.getItemId() == R.id.help) {
      showDialog(DIALOG_HELP); 
      return true;
    } else if(item.getItemId() == R.id.importLevel) {
      showDialog(DIALOG_IMPORT); 
      return true;
    }
    if(renderer.getCurrentMode() != null) {
      return renderer.getCurrentMode().onOptionsItemSelected(this, item);
    }
      return false;
  }
  
  @Override
  protected Dialog onCreateDialog(int id) {
    switch(id) {
    case DIALOG_HELP:
      return createDialogFromResources("Help", R.layout.helpdialog);
    case DIALOG_IMPORT:
      return createDialogFromResources("How to import...", R.layout.importdialog);
    }
    
    return super.onCreateDialog(id);
  }
  
  private Dialog createDialogFromResources(String title, int layout) {
    Dialog dialog = new Dialog(this);

    dialog.setContentView(layout);
    dialog.setTitle(title);

    return dialog;  
  }

  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    return renderer.onKeyDown(keyCode, event);
  }
  
  @Override
  public boolean onTrackballEvent(MotionEvent event) {
    return renderer.onTrackballEvent(event);
  }

  @Override
  protected void onPause() {
    super.onPause();
    renderer.onPause();
  }

  @Override
  protected void onStop() {
    super.onStop();
    renderer.onStop();
  }

  @Override
  protected void onResume() {
    super.onResume();
    renderer.onResume();
  }
}




Java Source Code List

bwr.blockcomposer.AnimationFinishedListener.java
bwr.blockcomposer.BlockComposerActivity.java
bwr.blockcomposer.BlockComposerRenderer.java
bwr.blockcomposer.BlockComposer.java
bwr.blockcomposer.Camera.java
bwr.blockcomposer.GameResources.java
bwr.blockcomposer.OnUpdateAction.java
bwr.blockcomposer.gamedata.Block.java
bwr.blockcomposer.gamedata.GameEntity.java
bwr.blockcomposer.gamedata.GameState.java
bwr.blockcomposer.gamedata.LevelDimensions.java
bwr.blockcomposer.gamedata.LevelMask.java
bwr.blockcomposer.gamedata.LevelMetadata.java
bwr.blockcomposer.gamedata.LevelStore.java
bwr.blockcomposer.gamedata.Level.java
bwr.blockcomposer.gamedata.Move.java
bwr.blockcomposer.gamedata.StaticLevelStore.java
bwr.blockcomposer.gamedata.UserLevelStore.java
bwr.blockcomposer.misc.GLUtility.java
bwr.blockcomposer.misc.Timer.java
bwr.blockcomposer.models.AxisRenderer.java
bwr.blockcomposer.models.Model.java
bwr.blockcomposer.models.SelectBoxRenderer.java
bwr.blockcomposer.modes.EditMode.java
bwr.blockcomposer.modes.GameDialogMode.java
bwr.blockcomposer.modes.GameMode.java
bwr.blockcomposer.modes.LevelImportMode.java
bwr.blockcomposer.modes.LevelSelectMode.java
bwr.blockcomposer.modes.LogoDisplayMode.java
bwr.blockcomposer.modes.ModeController.java
bwr.blockcomposer.modes.Mode.java
bwr.blockcomposer.modes.OverlayMode.java
bwr.blockcomposer.types.FlipRotateFloat.java
bwr.blockcomposer.types.FloatValueVector3.java
bwr.blockcomposer.types.FloatValue.java
bwr.blockcomposer.types.IntVector.java
bwr.blockcomposer.types.RotatingFloat.java
bwr.blockcomposer.ui.TextRenderer.java
bwr.blockcomposer.ui.UIElementPicture.java
bwr.blockcomposer.ui.UIElementText.java
bwr.blockcomposer.ui.UIElement.java