This repository was archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 413
Expand file tree
/
Copy pathMenuFragment.java
More file actions
165 lines (142 loc) · 5.68 KB
/
MenuFragment.java
File metadata and controls
165 lines (142 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.snatik.matches.fragments;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.BounceInterpolator;
import android.widget.ImageView;
import android.widget.Toast;
import com.snatik.matches.R;
import com.snatik.matches.common.Music;
import com.snatik.matches.common.Shared;
import com.snatik.matches.events.ui.StartEvent;
import com.snatik.matches.ui.PopupManager;
import com.snatik.matches.utils.Utils;
public class MenuFragment extends Fragment {
private ImageView mTitle;
private ImageView mStartGameButton;
private ImageView mStartButtonLights;
private ImageView mTooltip;
private ImageView mSettingsGameButton;
private ImageView mGooglePlayGameButton;
private AnimatorSet mMenuAnimationSet;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.menu_fragment, container, false);
mTitle = (ImageView) view.findViewById(R.id.title);
mStartGameButton = (ImageView) view.findViewById(R.id.start_game_button);
mSettingsGameButton = (ImageView) view.findViewById(R.id.settings_game_button);
mSettingsGameButton.setSoundEffectsEnabled(false);
mSettingsGameButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(PopupManager.isShown() || mMenuAnimationSet.isRunning()) {
return;
}
PopupManager.showPopupSettings();
}
});
mGooglePlayGameButton = (ImageView) view.findViewById(R.id.google_play_button);
mGooglePlayGameButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openLeaderboards();
}
});
mStartButtonLights = (ImageView) view.findViewById(R.id.start_game_button_lights);
mTooltip = (ImageView) view.findViewById(R.id.tooltip);
mStartGameButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startGame();
}
});
mMenuAnimationSet = new AnimatorSet();
startLightsAnimation();
startTootipAnimation();
// play background music
Music.playBackgroundMusic();
return view;
}
protected void animateAllAssetsOff(AnimatorListenerAdapter adapter) {
// title
// 120dp + 50dp + buffer(30dp)
ObjectAnimator titleAnimator = ObjectAnimator.ofFloat(mTitle, "translationY", Utils.px(-200));
titleAnimator.setInterpolator(new AccelerateInterpolator(2));
titleAnimator.setDuration(300);
// lights
ObjectAnimator lightsAnimatorX = ObjectAnimator.ofFloat(mStartButtonLights, "scaleX", 0f);
ObjectAnimator lightsAnimatorY = ObjectAnimator.ofFloat(mStartButtonLights, "scaleY", 0f);
// tooltip
ObjectAnimator tooltipAnimator = ObjectAnimator.ofFloat(mTooltip, "alpha", 0f);
tooltipAnimator.setDuration(100);
// settings button
ObjectAnimator settingsAnimator = ObjectAnimator.ofFloat(mSettingsGameButton, "translationY", Utils.px(120));
settingsAnimator.setInterpolator(new AccelerateInterpolator(2));
settingsAnimator.setDuration(300);
// google play button
ObjectAnimator googlePlayAnimator = ObjectAnimator.ofFloat(mGooglePlayGameButton, "translationY", Utils.px(120));
googlePlayAnimator.setInterpolator(new AccelerateInterpolator(2));
googlePlayAnimator.setDuration(300);
// start button
ObjectAnimator startButtonAnimator = ObjectAnimator.ofFloat(mStartGameButton, "translationY", Utils.px(130));
startButtonAnimator.setInterpolator(new AccelerateInterpolator(2));
startButtonAnimator.setDuration(300);
mMenuAnimationSet.playTogether(titleAnimator, lightsAnimatorX, lightsAnimatorY, tooltipAnimator, settingsAnimator, googlePlayAnimator, startButtonAnimator);
mMenuAnimationSet.addListener(adapter);
mMenuAnimationSet.start();
}
private void startTootipAnimation() {
ObjectAnimator scaleY = ObjectAnimator.ofFloat(mTooltip, "scaleY", 0.8f);
scaleY.setDuration(200);
ObjectAnimator scaleYBack = ObjectAnimator.ofFloat(mTooltip, "scaleY", 1f);
scaleYBack.setDuration(500);
scaleYBack.setInterpolator(new BounceInterpolator());
final AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setStartDelay(1000);
animatorSet.playSequentially(scaleY, scaleYBack);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
animatorSet.setStartDelay(2000);
animatorSet.start();
}
});
mTooltip.setLayerType(View.LAYER_TYPE_HARDWARE, null);
animatorSet.start();
}
private void startLightsAnimation() {
ObjectAnimator animator = ObjectAnimator.ofFloat(mStartButtonLights, "rotation", 0f, 360f);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(6000);
animator.setRepeatCount(ValueAnimator.INFINITE);
mStartButtonLights.setLayerType(View.LAYER_TYPE_HARDWARE, null);
animator.start();
}
private void startGame() {
if(PopupManager.isShown()) {
return;
}
// animate title from place and navigation buttons from place
animateAllAssetsOff(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
Shared.eventBus.notify(new StartEvent());
}
});
}
private void openLeaderboards() {
if (PopupManager.isShown() || mMenuAnimationSet.isRunning()){
return;
}
Toast.makeText(getActivity(), "Leaderboards will be available in the next game updates", Toast.LENGTH_LONG).show();
}
}