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
|
package org.happysanta.gd.Menu;
import android.content.Context;
import android.graphics.Typeface;
import android.text.Spanned;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import org.happysanta.gd.Global;
import org.happysanta.gd.Menu.Views.MenuImageView;
import org.happysanta.gd.Menu.Views.MenuLinearLayout;
import org.happysanta.gd.R;
import static org.happysanta.gd.Helpers.*;
public class HighScoreTextMenuElement
extends TextMenuElement
implements MenuElement {
protected static final int TEXT_LEFT_MARGIN = 5;
protected static final int SUBTITLE_MARGIN_BOTTOM = 8;
protected static final int SUBTITLE_TEXT_SIZE = 20;
protected static final int LAYOUT_PADDING = 3;
protected static int medals[] = new int[]{
R.drawable.s_medal_gold,
R.drawable.s_medal_silver,
R.drawable.s_medal_bronze
};
protected static Typeface defaultTypeface = null;
protected boolean showMedal = false;
protected MenuLinearLayout layout;
protected MenuImageView image;
public HighScoreTextMenuElement(String s) {
super(s);
createAllViews();
}
public HighScoreTextMenuElement(Spanned text) {
super(text);
createAllViews();
}
protected void createAllViews() {
Context context = getGDActivity();
layout = new MenuLinearLayout(context);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
image = new MenuImageView(context);
image.setScaleType(ImageView.ScaleType.CENTER);
image.setVisibility(View.GONE);
// textView was already created in super constructor
textView.setLineSpacing(0, 1);
if (defaultTypeface == null) {
defaultTypeface = textView.getTypeface();
}
LinearLayout.LayoutParams textViewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
// textViewLayoutParams.setMargins(getDp(TEXT_LEFT_MARGIN), 0, 0, 0);
textView.setLayoutParams(textViewLayoutParams);
layout.addView(image, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));
layout.addView(textView);
}
@Override
public View getView() {
return layout;
}
public void setMedal(boolean showMedal, int medalIndex) {
image.setVisibility(showMedal ? View.VISIBLE : View.GONE);
image.setImageResource(medals[medalIndex]);
LinearLayout.LayoutParams textViewLayoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
textViewLayoutParams.setMargins(showMedal ? getDp(TEXT_LEFT_MARGIN) : 0, 0, 0, 0);
textView.setLayoutParams(textViewLayoutParams);
this.showMedal = showMedal;
}
public void setIsSubtitle(boolean is) {
textView.setTextSize(is ? SUBTITLE_TEXT_SIZE : TEXT_SIZE);
textView.setTypeface(is ? Global.robotoCondensedTypeface : defaultTypeface);
LinearLayout.LayoutParams textViewLayoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
textViewLayoutParams.setMargins(!is && showMedal ? getDp(TEXT_LEFT_MARGIN) : 0, 0, 0, is ? getDp(SUBTITLE_MARGIN_BOTTOM) : 0);
textView.setLayoutParams(textViewLayoutParams);
}
public void setLayoutPadding(boolean use) {
layout.setPadding(0, use ? getDp(LAYOUT_PADDING) : 0, 0, use ? getDp(LAYOUT_PADDING) : 0);
}
}
|