emotionhero/app/src/main/java/com/rubenvandeven/emotionhero/MenuActivity.java

138 lines
5.0 KiB
Java

package com.rubenvandeven.emotionhero;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
/**
* @deprecated Now done using MirrorMenuActivity
*/
public class MenuActivity extends AppCompatActivity {
Player player;
ProgressDialog loadGameDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
if(getSupportActionBar() != null) {
getSupportActionBar().hide();
}
setContentView(R.layout.activity_menu);
player = Player.getInstance(getApplicationContext());
Button startButton = (Button) findViewById(R.id.startButton);
Button continueButton = (Button) findViewById(R.id.continueButton);
Button highscoreButton = (Button) findViewById(R.id.highscoresButton);
Button creditsButton = (Button) findViewById(R.id.creditsButton);
final ImageView logoEmotionHero = (ImageView) findViewById(R.id.logoEmotionHero);
if(!player.getPlayerInfo().canContinueLevel()) {
continueButton.setVisibility(View.GONE);
}
// prepare for animation
startButton.setAlpha(0f);
continueButton.setAlpha(0f);
highscoreButton.setAlpha(0f);
creditsButton.setAlpha(0f);
ObjectAnimator fadeInEmotionHero = ObjectAnimator.ofFloat(logoEmotionHero, "alpha", 0f, 1f);
fadeInEmotionHero.setDuration(1000);
ObjectAnimator fadeInstartButton = ObjectAnimator.ofFloat(startButton, "alpha", 0f, 1f);
fadeInstartButton.setDuration(1000);
ObjectAnimator fadeInContinueButton = ObjectAnimator.ofFloat(continueButton, "alpha", 0f, 1f);
fadeInContinueButton.setDuration(1000);
fadeInContinueButton.setStartDelay(300);
ObjectAnimator fadeInHighscoreButton = ObjectAnimator.ofFloat(highscoreButton, "alpha", 0f, 1f);
fadeInHighscoreButton.setDuration(1000);
fadeInHighscoreButton.setStartDelay(600);
ObjectAnimator fadeInCreditsButton = ObjectAnimator.ofFloat(creditsButton, "alpha", 0f, 1f);
fadeInCreditsButton.setDuration(1000);
fadeInCreditsButton.setStartDelay(1000);
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(1000); //You can manage the blinking time with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
logoEmotionHero.startAnimation(anim);
AnimatorSet buttonAnimatorSet = new AnimatorSet();
buttonAnimatorSet.playTogether(fadeInstartButton,
fadeInContinueButton,
fadeInHighscoreButton,
fadeInCreditsButton);
buttonAnimatorSet.start();
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadGameDialog = ProgressDialog.show(MenuActivity.this, "",
MenuActivity.this.getResources().getString(R.string.load_game_activity), true);
Intent intent = new Intent(MenuActivity.this, MirrorMenuActivity.class);
startActivity(intent);
}
});
continueButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadGameDialog= ProgressDialog.show(MenuActivity.this, "",
MenuActivity.this.getResources().getString(R.string.load_game_activity), true);
Intent intent = new Intent(MenuActivity.this, GamingActivity.class);
intent.putExtra(GamingActivity.INTENT_EXTRA_SCENARIO, player.getPlayerInfo().reachedLevelId);
startActivity(intent);
}
});
highscoreButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MenuActivity.this, HighscoreActivity.class);
// intent.putExtra(HighscoreActivity.INTENT_EXTRA_LEVEL, player.getPlayerInfo().reachedLevelId);
startActivity(intent);
}
});
creditsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MenuActivity.this, CreditsActivity.class);
startActivity(intent);
}
});
}
@Override
protected void onResume() {
super.onResume();
if(loadGameDialog != null)
loadGameDialog.dismiss();
}
}