1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.purchase;
|
11
|
|
12
|
import android.util.TypedValue;
|
13
|
import android.widget.ImageView;
|
14
|
import android.widget.LinearLayout;
|
15
|
import android.widget.TextView;
|
16
|
|
17
|
import org.distorted.main.R;
|
18
|
import org.distorted.objectlib.json.JsonReader;
|
19
|
import org.distorted.objects.RubikObject;
|
20
|
import org.distorted.objects.RubikObjectList;
|
21
|
|
22
|
import java.io.InputStream;
|
23
|
|
24
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25
|
|
26
|
public class PurchaseScreenPane
|
27
|
{
|
28
|
private static final int[] IMAGES =
|
29
|
{
|
30
|
R.drawable.difficulty1,
|
31
|
R.drawable.difficulty2,
|
32
|
R.drawable.difficulty3,
|
33
|
R.drawable.difficulty4,
|
34
|
R.drawable.difficulty5,
|
35
|
};
|
36
|
|
37
|
private static final int NUM_IMAGES = IMAGES.length;
|
38
|
public static final float PADDING_RATIO = 0.025f;
|
39
|
private static final float TEXT_RATIO = 0.050f;
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
void updatePane(PurchaseActivity act, int objectOrdinal)
|
44
|
{
|
45
|
RubikObject object = RubikObjectList.getObject(objectOrdinal);
|
46
|
|
47
|
if( object!=null )
|
48
|
{
|
49
|
InputStream stream = object.getObjectStream(act);
|
50
|
JsonReader reader = JsonReader.getInstance();
|
51
|
String author, name;
|
52
|
int year, difficulty;
|
53
|
|
54
|
try
|
55
|
{
|
56
|
reader.parseJsonFileMetadata(stream);
|
57
|
name = reader.getObjectName();
|
58
|
author = reader.getInventor();
|
59
|
year = reader.getYearOfInvention();
|
60
|
difficulty = reader.getComplexity();
|
61
|
}
|
62
|
catch(Exception ex)
|
63
|
{
|
64
|
name = "?";
|
65
|
author = "?";
|
66
|
year = 0;
|
67
|
difficulty = 0;
|
68
|
}
|
69
|
|
70
|
if( difficulty<0 ) difficulty=0;
|
71
|
if( difficulty>=NUM_IMAGES ) difficulty=NUM_IMAGES-1;
|
72
|
|
73
|
String both = year>0 ? author+" "+year : author;
|
74
|
|
75
|
TextView v1 = act.findViewById(R.id.purchaseUpperName);
|
76
|
v1.setText(name);
|
77
|
TextView v2 = act.findViewById(R.id.purchaseUpperAuthor);
|
78
|
v2.setText(both);
|
79
|
ImageView image = act.findViewById(R.id.purchaseDifficulty);
|
80
|
image.setImageResource(IMAGES[difficulty]);
|
81
|
}
|
82
|
}
|
83
|
|
84
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85
|
|
86
|
PurchaseScreenPane(final PurchaseActivity act)
|
87
|
{
|
88
|
int width = act.getScreenWidthInPixels();
|
89
|
float textSize = width*TEXT_RATIO;
|
90
|
int padding = (int)(width*PADDING_RATIO);
|
91
|
|
92
|
LinearLayout upperBar = act.findViewById(R.id.upperBar);
|
93
|
LinearLayout oneLayout = act.findViewById(R.id.purchaseLayoutOne);
|
94
|
LinearLayout allLayout = act.findViewById(R.id.purchaseLayoutAll);
|
95
|
|
96
|
upperBar.setPadding( padding,padding ,padding,padding );
|
97
|
oneLayout.setPadding(padding,padding/2,padding,padding/2);
|
98
|
allLayout.setPadding(padding,padding/2,padding,padding/2);
|
99
|
|
100
|
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
101
|
params1.bottomMargin = 0;
|
102
|
params1.topMargin = padding;
|
103
|
params1.leftMargin = padding;
|
104
|
params1.rightMargin = padding;
|
105
|
|
106
|
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
107
|
params2.bottomMargin = padding;
|
108
|
params2.topMargin = padding;
|
109
|
params2.leftMargin = padding;
|
110
|
params2.rightMargin = padding;
|
111
|
|
112
|
LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
113
|
params3.bottomMargin = 0;
|
114
|
params3.topMargin = 0;
|
115
|
params3.leftMargin = padding;
|
116
|
params3.rightMargin = padding;
|
117
|
|
118
|
upperBar.setLayoutParams(params1);
|
119
|
oneLayout.setLayoutParams(params3);
|
120
|
allLayout.setLayoutParams(params2);
|
121
|
|
122
|
TextView text;
|
123
|
text = upperBar.findViewById(R.id.purchaseUpperName);
|
124
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
125
|
text = upperBar.findViewById(R.id.purchaseUpperAuthor);
|
126
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
127
|
text = oneLayout.findViewById(R.id.purchaseTextOne);
|
128
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
129
|
text = allLayout.findViewById(R.id.purchaseTextAll);
|
130
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
131
|
}
|
132
|
}
|