1 package com.replica.replicaisland; 2 3 import java.lang.reflect.InvocationTargetException; 4 import java.lang.reflect.Method; 5 6 import android.app.Activity; 7 import android.content.Intent; 8 import android.media.AudioManager; 9 import android.os.Bundle; 10 import android.view.KeyEvent; 11 import android.view.View; 12 import android.view.animation.Animation; 13 import android.view.animation.AnimationUtils; 14 15 public class DifficultyMenuActivity extends Activity { 16 private View mBabyButton; 17 private View mKidsButton; 18 private View mAdultsButton; 19 private View mBackground; 20 private View mBabyText; 21 private View mKidsText; 22 private View mAdultsText; 23 private Animation mButtonFlickerAnimation; 24 private Animation mFadeOutAnimation; 25 private Animation mAlternateFadeOutAnimation; 26 27 private View.OnClickListener sBabyButtonListener = new View.OnClickListener() { 28 public void onClick(View v) { 29 30 Intent i = new Intent(getBaseContext(), AndouKun.class); 31 i.putExtras(getIntent()); 32 i.putExtra("difficulty", 0); 33 34 v.startAnimation(mButtonFlickerAnimation); 35 mFadeOutAnimation.setAnimationListener(new StartActivityAfterAnimation(i)); 36 mBackground.startAnimation(mFadeOutAnimation); 37 mKidsButton.startAnimation(mAlternateFadeOutAnimation); 38 mAdultsButton.startAnimation(mAlternateFadeOutAnimation); 39 40 mBabyText.startAnimation(mAlternateFadeOutAnimation); 41 mKidsText.startAnimation(mAlternateFadeOutAnimation); 42 mAdultsText.startAnimation(mAlternateFadeOutAnimation); 43 } 44 }; 45 46 private View.OnClickListener sKidsButtonListener = new View.OnClickListener() { 47 public void onClick(View v) { 48 49 Intent i = new Intent(getBaseContext(), AndouKun.class); 50 i.putExtras(getIntent()); 51 i.putExtra("difficulty", 1); 52 53 v.startAnimation(mButtonFlickerAnimation); 54 mFadeOutAnimation.setAnimationListener(new StartActivityAfterAnimation(i)); 55 mBackground.startAnimation(mFadeOutAnimation); 56 mBabyButton.startAnimation(mAlternateFadeOutAnimation); 57 mAdultsButton.startAnimation(mAlternateFadeOutAnimation); 58 59 mBabyText.startAnimation(mAlternateFadeOutAnimation); 60 mKidsText.startAnimation(mAlternateFadeOutAnimation); 61 mAdultsText.startAnimation(mAlternateFadeOutAnimation); 62 } 63 }; 64 65 private View.OnClickListener sAdultsButtonListener = new View.OnClickListener() { 66 public void onClick(View v) { 67 68 Intent i = new Intent(getBaseContext(), AndouKun.class); 69 i.putExtras(getIntent()); 70 i.putExtra("difficulty", 2); 71 72 v.startAnimation(mButtonFlickerAnimation); 73 mFadeOutAnimation.setAnimationListener(new StartActivityAfterAnimation(i)); 74 mBackground.startAnimation(mFadeOutAnimation); 75 mBabyButton.startAnimation(mAlternateFadeOutAnimation); 76 mKidsButton.startAnimation(mAlternateFadeOutAnimation); 77 78 mBabyText.startAnimation(mAlternateFadeOutAnimation); 79 mKidsText.startAnimation(mAlternateFadeOutAnimation); 80 mAdultsText.startAnimation(mAlternateFadeOutAnimation); 81 } 82 }; 83 84 @Override 85 public void onCreate(Bundle savedInstanceState) { 86 super.onCreate(savedInstanceState); 87 setContentView(R.layout.difficulty_menu); 88 89 90 mBabyButton = findViewById(R.id.babyButton); 91 mKidsButton = findViewById(R.id.kidsButton); 92 mAdultsButton = findViewById(R.id.adultsButton); 93 mBabyText = findViewById(R.id.babyText); 94 mKidsText = findViewById(R.id.kidsText); 95 mAdultsText = findViewById(R.id.adultsText); 96 mBackground = findViewById(R.id.mainMenuBackground); 97 98 mBabyButton.setOnClickListener(sBabyButtonListener); 99 mKidsButton.setOnClickListener(sKidsButtonListener); 100 mAdultsButton.setOnClickListener(sAdultsButtonListener); 101 102 mButtonFlickerAnimation = AnimationUtils.loadAnimation(this, R.anim.button_flicker); 103 mFadeOutAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_out); 104 mAlternateFadeOutAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_out); 105 106 // Keep the volume control type consistent across all activities. 107 setVolumeControlStream(AudioManager.STREAM_MUSIC); 108 } 109 110 @Override 111 public boolean onKeyDown(int keyCode, KeyEvent event) { 112 boolean result = true; 113 if (keyCode == KeyEvent.KEYCODE_BACK) { 114 finish(); 115 116 if (UIConstants.mOverridePendingTransition != null) { 117 try { 118 UIConstants.mOverridePendingTransition.invoke(DifficultyMenuActivity.this, R.anim.activity_fade_in, R.anim.activity_fade_out); 119 } catch (InvocationTargetException ite) { 120 DebugLog.d("Activity Transition", "Invocation Target Exception"); 121 } catch (IllegalAccessException ie) { 122 DebugLog.d("Activity Transition", "Illegal Access Exception"); 123 } 124 } 125 } else { 126 result = super.onKeyDown(keyCode, event); 127 } 128 return result; 129 } 130 131 protected class StartActivityAfterAnimation implements Animation.AnimationListener { 132 private Intent mIntent; 133 134 StartActivityAfterAnimation(Intent intent) { 135 mIntent = intent; 136 } 137 138 139 public void onAnimationEnd(Animation animation) { 140 mBabyButton.setVisibility(View.INVISIBLE); 141 mBabyButton.clearAnimation(); 142 mKidsButton.setVisibility(View.INVISIBLE); 143 mKidsButton.clearAnimation(); 144 mAdultsButton.setVisibility(View.INVISIBLE); 145 mAdultsButton.clearAnimation(); 146 startActivity(mIntent); 147 finish(); // This activity dies when it spawns a new intent. 148 149 if (UIConstants.mOverridePendingTransition != null) { 150 try { 151 UIConstants.mOverridePendingTransition.invoke(DifficultyMenuActivity.this, R.anim.activity_fade_in, R.anim.activity_fade_out); 152 } catch (InvocationTargetException ite) { 153 DebugLog.d("Activity Transition", "Invocation Target Exception"); 154 } catch (IllegalAccessException ie) { 155 DebugLog.d("Activity Transition", "Illegal Access Exception"); 156 } 157 } 158 } 159 160 public void onAnimationRepeat(Animation animation) { 161 // TODO Auto-generated method stub 162 163 } 164 165 public void onAnimationStart(Animation animation) { 166 // TODO Auto-generated method stub 167 168 } 169 170 } 171 172 } 173