1 |
c7238c67
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
71cda061
|
Leszek Koltunski
|
private static final int NUM_IMAGES = IMAGES.length;
|
38 |
c7238c67
|
Leszek Koltunski
|
public static final float PADDING_RATIO = 0.025f;
|
39 |
cd432dd3
|
Leszek Koltunski
|
private static final float TEXT_RATIO = 0.050f;
|
40 |
c7238c67
|
Leszek Koltunski
|
|
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 |
cd432dd3
|
Leszek Koltunski
|
String author, name;
|
52 |
|
|
int year, difficulty;
|
53 |
c7238c67
|
Leszek Koltunski
|
|
54 |
|
|
try
|
55 |
|
|
{
|
56 |
|
|
reader.parseJsonFileMetadata(stream);
|
57 |
|
|
name = reader.getObjectName();
|
58 |
cd432dd3
|
Leszek Koltunski
|
author = reader.getInventor();
|
59 |
|
|
year = reader.getYearOfInvention();
|
60 |
c7238c67
|
Leszek Koltunski
|
difficulty = reader.getComplexity();
|
61 |
|
|
}
|
62 |
|
|
catch(Exception ex)
|
63 |
|
|
{
|
64 |
|
|
name = "?";
|
65 |
cd432dd3
|
Leszek Koltunski
|
author = "?";
|
66 |
|
|
year = 0;
|
67 |
c7238c67
|
Leszek Koltunski
|
difficulty = 0;
|
68 |
|
|
}
|
69 |
|
|
|
70 |
71cda061
|
Leszek Koltunski
|
if( difficulty<0 ) difficulty=0;
|
71 |
|
|
if( difficulty>=NUM_IMAGES ) difficulty=NUM_IMAGES-1;
|
72 |
c7238c67
|
Leszek Koltunski
|
|
73 |
cd432dd3
|
Leszek Koltunski
|
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 |
71cda061
|
Leszek Koltunski
|
ImageView image = act.findViewById(R.id.purchaseDifficulty);
|
80 |
|
|
image.setImageResource(IMAGES[difficulty]);
|
81 |
c7238c67
|
Leszek Koltunski
|
}
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85 |
|
|
|
86 |
71cda061
|
Leszek Koltunski
|
PurchaseScreenPane(final PurchaseActivity act)
|
87 |
c7238c67
|
Leszek Koltunski
|
{
|
88 |
|
|
int width = act.getScreenWidthInPixels();
|
89 |
|
|
float textSize = width*TEXT_RATIO;
|
90 |
|
|
int padding = (int)(width*PADDING_RATIO);
|
91 |
|
|
|
92 |
cd432dd3
|
Leszek Koltunski
|
LinearLayout upperBar = act.findViewById(R.id.upperBar);
|
93 |
|
|
LinearLayout oneLayout = act.findViewById(R.id.purchaseLayoutOne);
|
94 |
|
|
LinearLayout allLayout = act.findViewById(R.id.purchaseLayoutAll);
|
95 |
c7238c67
|
Leszek Koltunski
|
|
96 |
af0710b6
|
Leszek Koltunski
|
upperBar.setPadding( padding,padding ,padding,padding );
|
97 |
71cda061
|
Leszek Koltunski
|
oneLayout.setPadding(padding,padding/2,padding,padding/2);
|
98 |
|
|
allLayout.setPadding(padding,padding/2,padding,padding/2);
|
99 |
c7238c67
|
Leszek Koltunski
|
|
100 |
cd432dd3
|
Leszek Koltunski
|
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 |
c7238c67
|
Leszek Koltunski
|
|
112 |
af0710b6
|
Leszek Koltunski
|
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 |
cd432dd3
|
Leszek Koltunski
|
upperBar.setLayoutParams(params1);
|
119 |
af0710b6
|
Leszek Koltunski
|
oneLayout.setLayoutParams(params3);
|
120 |
cd432dd3
|
Leszek Koltunski
|
allLayout.setLayoutParams(params2);
|
121 |
c7238c67
|
Leszek Koltunski
|
|
122 |
|
|
TextView text;
|
123 |
cd432dd3
|
Leszek Koltunski
|
text = upperBar.findViewById(R.id.purchaseUpperName);
|
124 |
|
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
125 |
|
|
text = upperBar.findViewById(R.id.purchaseUpperAuthor);
|
126 |
c7238c67
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
127 |
71cda061
|
Leszek Koltunski
|
text = oneLayout.findViewById(R.id.purchaseTextOne);
|
128 |
c7238c67
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
129 |
71cda061
|
Leszek Koltunski
|
text = allLayout.findViewById(R.id.purchaseTextAll);
|
130 |
c7238c67
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
131 |
|
|
}
|
132 |
|
|
}
|