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 pathThemeSelectFragment.java
More file actions
98 lines (84 loc) · 3.28 KB
/
ThemeSelectFragment.java
File metadata and controls
98 lines (84 loc) · 3.28 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
package com.snatik.matches.fragments;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
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.DecelerateInterpolator;
import android.widget.ImageView;
import com.snatik.matches.R;
import com.snatik.matches.common.Memory;
import com.snatik.matches.common.Music;
import com.snatik.matches.common.Shared;
import com.snatik.matches.events.ui.ThemeSelectedEvent;
import com.snatik.matches.themes.Theme;
import com.snatik.matches.themes.Themes;
import java.util.Locale;
public class ThemeSelectFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = LayoutInflater.from(Shared.context).inflate(R.layout.theme_select_fragment, container, false);
View animals = view.findViewById(R.id.theme_animals_container);
View monsters = view.findViewById(R.id.theme_monsters_container);
View emoji = view.findViewById(R.id.theme_emoji_container);
final Theme themeAnimals = Themes.createAnimalsTheme();
setStars((ImageView) animals.findViewById(R.id.theme_animals), themeAnimals, "animals");
final Theme themeMonsters = Themes.createMosterTheme();
setStars((ImageView) monsters.findViewById(R.id.theme_monsters), themeMonsters, "monsters");
final Theme themeEmoji = Themes.createEmojiTheme();
setStars((ImageView) emoji.findViewById(R.id.theme_emoji), themeEmoji, "emoji");
animals.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Shared.eventBus.notify(new ThemeSelectedEvent(themeAnimals));
}
});
monsters.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Shared.eventBus.notify(new ThemeSelectedEvent(themeMonsters));
}
});
emoji.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Shared.eventBus.notify(new ThemeSelectedEvent(themeEmoji));
}
});
/**
* Imporove performance first!!!
*/
animateShow(animals);
animateShow(monsters);
animateShow(emoji);
return view;
}
@Override
public void onDestroy() {
super.onDestroy();
}
private void animateShow(View view) {
ObjectAnimator animatorScaleX = ObjectAnimator.ofFloat(view, "scaleX", 0.5f, 1f);
ObjectAnimator animatorScaleY = ObjectAnimator.ofFloat(view, "scaleY", 0.5f, 1f);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(300);
animatorSet.playTogether(animatorScaleX, animatorScaleY);
animatorSet.setInterpolator(new DecelerateInterpolator(2));
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
animatorSet.start();
}
private void setStars(ImageView imageView, Theme theme, String type) {
int sum = 0;
for (int difficulty = 1; difficulty <= 6; difficulty++) {
sum += Memory.getHighStars(theme.id, difficulty);
}
int num = sum / 6;
if (num != 0) {
String drawableResourceName = String.format(Locale.US, type + "_theme_star_%d", num);
int drawableResourceId = Shared.context.getResources().getIdentifier(drawableResourceName, "drawable", Shared.context.getPackageName());
imageView.setImageResource(drawableResourceId);
}
}
}