Android Open Source - DivisionByZero Activity Main Menu






From Project

Back to project page DivisionByZero.

License

The source code is released under:

Apache License

If you think the Android project DivisionByZero 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.ggstudios.divisionbyzero;
// w  w  w .  j av a2s.co  m
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Button;

public class ActivityMainMenu extends BaseActivity {
  public static final float ALPHA_BANNER = 0.2f;
  public static final float ALPHA_TITLE = 0.10f;

  private static final int ANIMATION_DURATION = 300;
  private static final int FADE_TIME = 1000;

  private static final Handler handler = new Handler();

  private RelativeLayout layout;
  private Button btnPlay;
  private Button btnSettings;
  private Button btnAbout;
  private Button btnExit;

  private ImageView imgTitle;
  private ImageView imgBanner;

  private boolean navigatedOut = false;

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

    setContentView(R.layout.main_menu);

    layout = (RelativeLayout) findViewById(R.id.layout);
    btnPlay = (Button) findViewById(R.id.btnPlay);
    btnSettings = (Button) findViewById(R.id.btnSettings);
    btnAbout = (Button) findViewById(R.id.btnAbout);
    btnExit = (Button) findViewById(R.id.btnExit);
    imgTitle = (ImageView) findViewById(R.id.imgTitle);
    imgBanner = (ImageView) findViewById(R.id.imgBanner);

    if(savedInstanceState != null) {
      // resurrecting activity...
      navigatedOut = savedInstanceState.getBoolean("navigatedOut");
    }
  }

  @Override
  public void onSaveInstanceState(Bundle b) {
    super.onSaveInstanceState(b);
    b.putBoolean("navigatedOut", navigatedOut);
  }

  @Override
  public void onResume() {
    super.onResume();
    restoreButtons();
  }

  @Override
  public void onStop() {
    super.onStop();
  }

  private void restoreButtons() {
    if(navigatedOut) {
      navigateIn(null);
    }
  }

  private void fadeInBanner() {
    Animation fadeIn = new AlphaAnimation(ALPHA_BANNER, 1);
    fadeIn.setDuration(FADE_TIME);
    fadeIn.setFillAfter(true);

    Animation fadeIn2 = new AlphaAnimation(ALPHA_TITLE, 1);
    fadeIn2.setDuration(FADE_TIME);
    fadeIn2.setFillAfter(true);

    imgBanner.startAnimation(fadeIn);
    imgTitle.startAnimation(fadeIn2);
  }

  private void fadeOutBanner() {
    Animation fadeOut = new AlphaAnimation(1, ALPHA_BANNER);
    fadeOut.setDuration(FADE_TIME);
    fadeOut.setFillAfter(true);

    Animation fadeOut2 = new AlphaAnimation(1, ALPHA_TITLE);
    fadeOut2.setDuration(FADE_TIME);
    fadeOut2.setFillAfter(true);

    imgBanner.startAnimation(fadeOut);
    imgTitle.startAnimation(fadeOut2);
  }

  private void dismissView(final View v) {
    final float delta = layout.getWidth() - v.getLeft();
    TranslateAnimation animation = new TranslateAnimation(0, delta, 0, 0);
    animation.setDuration(ANIMATION_DURATION);
    animation.setFillAfter(true);
    v.startAnimation(animation);
  }
  
  private void introduceView(final View v) {
    final float delta = layout.getWidth() - v.getLeft();
    TranslateAnimation animation = new TranslateAnimation(delta, 0, 0, 0);
    animation.setDuration(ANIMATION_DURATION);
    animation.setFillAfter(true);
    v.startAnimation(animation);
  }

  private void navigateOut(Runnable onFinish) {
    if(navigatedOut) return; // prevent double tapping...
    
    navigatedOut = true;

    fadeOutBanner();

    dismissView(btnExit);

    final int delta = ANIMATION_DURATION/2;
    int delay = delta;

    handler.postDelayed(new Runnable() {

      @Override
      public void run() {
        dismissView(btnAbout);
      }

    }, delay);
    delay += delta;

    handler.postDelayed(new Runnable() {

      @Override
      public void run() {
        dismissView(btnSettings);
      }

    }, delay);
    delay += delta;

    handler.postDelayed(new Runnable() {

      @Override
      public void run() {
        dismissView(btnPlay);
      }

    }, delay);
    delay += delta;

    handler.postDelayed(onFinish, Math.max(delay, FADE_TIME));
  }
  
  private void navigateIn(Runnable onFinish) {
    navigatedOut = false;

    fadeInBanner();

    introduceView(btnPlay);

    final int delta = ANIMATION_DURATION/2;
    int delay = delta;

    handler.postDelayed(new Runnable() {

      @Override
      public void run() {
        introduceView(btnSettings);
      }

    }, delay);
    delay += delta;

    handler.postDelayed(new Runnable() {

      @Override
      public void run() {
        introduceView(btnAbout);
      }

    }, delay);
    delay += delta;

    handler.postDelayed(new Runnable() {

      @Override
      public void run() {
        introduceView(btnExit);
      }

    }, delay);
    delay += delta;

    if(onFinish != null)
      handler.postDelayed(onFinish, Math.max(delay, FADE_TIME));
  }

  public void onExitClicked(View v) {
    finish();
  }

  public void onSettingsClicked(View v) {
    navigateOut(new Runnable() {

      @Override
      public void run() {
        Intent i = new Intent(ActivityMainMenu.this, ActivitySettings.class);
        startActivity(i);        
      }

    });
  }

  public void onAboutClicked(View v) {
    navigateOut(new Runnable() {

      @Override
      public void run() {
        Intent i = new Intent(ActivityMainMenu.this, ActivityAbout.class);
        startActivity(i);        
      }

    });
  }

  public void onPlayClicked(View v) {
    navigateOut(new Runnable() {

      @Override
      public void run() {
        Intent i = new Intent(ActivityMainMenu.this, ActivityLevelSelection.class);
        startActivity(i);        
      }

    });

    //finish();
  }
}




Java Source Code List

com.ggstudios.divisionbyzero.ActivityAbout.java
com.ggstudios.divisionbyzero.ActivityLevelSelection.java
com.ggstudios.divisionbyzero.ActivityMainMenu.java
com.ggstudios.divisionbyzero.ActivitySettings.java
com.ggstudios.divisionbyzero.ActivitySplashScreen.java
com.ggstudios.divisionbyzero.ApplicationMain.java
com.ggstudios.divisionbyzero.BaseActivity.java
com.ggstudios.divisionbyzero.BaseDialog.java
com.ggstudios.divisionbyzero.BulletManager.java
com.ggstudios.divisionbyzero.Bullet.java
com.ggstudios.divisionbyzero.Button.java
com.ggstudios.divisionbyzero.Circle.java
com.ggstudios.divisionbyzero.ClickableCollection.java
com.ggstudios.divisionbyzero.Clickable.java
com.ggstudios.divisionbyzero.ConfirmDialog.java
com.ggstudios.divisionbyzero.Core.java
com.ggstudios.divisionbyzero.CustomGLSurfaceView.java
com.ggstudios.divisionbyzero.DialogManager.java
com.ggstudios.divisionbyzero.DrawableCollection.java
com.ggstudios.divisionbyzero.DrawableString.java
com.ggstudios.divisionbyzero.Drawable.java
com.ggstudios.divisionbyzero.EndDialog.java
com.ggstudios.divisionbyzero.Event.java
com.ggstudios.divisionbyzero.ExplosionGenerator.java
com.ggstudios.divisionbyzero.ExtrasManager.java
com.ggstudios.divisionbyzero.FontManager.java
com.ggstudios.divisionbyzero.GameRenderer.java
com.ggstudios.divisionbyzero.GameUpdater.java
com.ggstudios.divisionbyzero.Game.java
com.ggstudios.divisionbyzero.Grid.java
com.ggstudios.divisionbyzero.Hud.java
com.ggstudios.divisionbyzero.InGameMenu.java
com.ggstudios.divisionbyzero.InfoDialog.java
com.ggstudios.divisionbyzero.Label.java
com.ggstudios.divisionbyzero.LevelManager.java
com.ggstudios.divisionbyzero.LevelMap.java
com.ggstudios.divisionbyzero.LineGuide.java
com.ggstudios.divisionbyzero.MainActivity.java
com.ggstudios.divisionbyzero.Map.java
com.ggstudios.divisionbyzero.MessageDialog.java
com.ggstudios.divisionbyzero.ParticleEngine.java
com.ggstudios.divisionbyzero.PathFinder.java
com.ggstudios.divisionbyzero.PauseMenu.java
com.ggstudios.divisionbyzero.PictureBox.java
com.ggstudios.divisionbyzero.Player.java
com.ggstudios.divisionbyzero.PopupMenu.java
com.ggstudios.divisionbyzero.Rectangle.java
com.ggstudios.divisionbyzero.Shader.java
com.ggstudios.divisionbyzero.SpawnManager.java
com.ggstudios.divisionbyzero.SpriteAnimation.java
com.ggstudios.divisionbyzero.SpriteManager.java
com.ggstudios.divisionbyzero.Sprite.java
com.ggstudios.divisionbyzero.Statbar.java
com.ggstudios.divisionbyzero.StateManager.java
com.ggstudios.divisionbyzero.TargetRectangle.java
com.ggstudios.divisionbyzero.TextureManager.java
com.ggstudios.divisionbyzero.TowerInfoDialog.java
com.ggstudios.divisionbyzero.TowerLibrary.java
com.ggstudios.divisionbyzero.TowerManager.java
com.ggstudios.divisionbyzero.TowerMenu.java
com.ggstudios.divisionbyzero.Tower.java
com.ggstudios.divisionbyzero.UpdatableCollection.java
com.ggstudios.divisionbyzero.Updatable.java
com.ggstudios.divisionbyzero.UpgradeDialog.java
com.ggstudios.divisionbyzero.Utils.java
com.ggstudios.divisionbyzero.VBO.java
com.ggstudios.divisionbyzero.WaveControlDialog.java
com.ggstudios.divisionbyzero.WaveControlHud.java
com.ggstudios.divisionbyzero.ZoomControl.java
com.ggstudios.utils.BitmapUtils.java
com.ggstudios.utils.BufferUtils.java
com.ggstudios.utils.DebugLog.java
com.ggstudios.utils.ShaderUtils.java
com.ggstudios.widget.LevelMapBackground.java
fix.android.opengl.GLES20.java