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 |
71cda061
|
Leszek Koltunski
|
import android.widget.RelativeLayout;
|
16 |
c7238c67
|
Leszek Koltunski
|
import android.widget.TextView;
|
17 |
|
|
|
18 |
|
|
import org.distorted.main.R;
|
19 |
|
|
import org.distorted.objectlib.json.JsonReader;
|
20 |
|
|
import org.distorted.objects.RubikObject;
|
21 |
|
|
import org.distorted.objects.RubikObjectList;
|
22 |
|
|
|
23 |
|
|
import java.io.InputStream;
|
24 |
|
|
|
25 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26 |
|
|
|
27 |
|
|
public class PurchaseScreenPane
|
28 |
|
|
{
|
29 |
|
|
private static final int[] IMAGES =
|
30 |
|
|
{
|
31 |
|
|
R.drawable.difficulty1,
|
32 |
|
|
R.drawable.difficulty2,
|
33 |
|
|
R.drawable.difficulty3,
|
34 |
|
|
R.drawable.difficulty4,
|
35 |
|
|
R.drawable.difficulty5,
|
36 |
|
|
};
|
37 |
|
|
|
38 |
71cda061
|
Leszek Koltunski
|
private static final int NUM_IMAGES = IMAGES.length;
|
39 |
c7238c67
|
Leszek Koltunski
|
public static final float PADDING_RATIO = 0.025f;
|
40 |
|
|
private static final float TEXT_RATIO = 0.042f;
|
41 |
|
|
|
42 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
|
|
void updatePane(PurchaseActivity act, int objectOrdinal)
|
45 |
|
|
{
|
46 |
|
|
RubikObject object = RubikObjectList.getObject(objectOrdinal);
|
47 |
|
|
|
48 |
|
|
if( object!=null )
|
49 |
|
|
{
|
50 |
|
|
InputStream stream = object.getObjectStream(act);
|
51 |
|
|
JsonReader reader = JsonReader.getInstance();
|
52 |
71cda061
|
Leszek Koltunski
|
String name;
|
53 |
|
|
int difficulty;
|
54 |
c7238c67
|
Leszek Koltunski
|
|
55 |
|
|
try
|
56 |
|
|
{
|
57 |
|
|
reader.parseJsonFileMetadata(stream);
|
58 |
|
|
name = reader.getObjectName();
|
59 |
|
|
difficulty = reader.getComplexity();
|
60 |
|
|
}
|
61 |
|
|
catch(Exception ex)
|
62 |
|
|
{
|
63 |
|
|
name = "?";
|
64 |
|
|
difficulty = 0;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
71cda061
|
Leszek Koltunski
|
if( difficulty<0 ) difficulty=0;
|
68 |
|
|
if( difficulty>=NUM_IMAGES ) difficulty=NUM_IMAGES-1;
|
69 |
c7238c67
|
Leszek Koltunski
|
|
70 |
71cda061
|
Leszek Koltunski
|
TextView view = act.findViewById(R.id.purchaseDetailsName);
|
71 |
c7238c67
|
Leszek Koltunski
|
view.setText(name);
|
72 |
71cda061
|
Leszek Koltunski
|
ImageView image = act.findViewById(R.id.purchaseDifficulty);
|
73 |
|
|
image.setImageResource(IMAGES[difficulty]);
|
74 |
c7238c67
|
Leszek Koltunski
|
}
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78 |
|
|
|
79 |
71cda061
|
Leszek Koltunski
|
PurchaseScreenPane(final PurchaseActivity act)
|
80 |
c7238c67
|
Leszek Koltunski
|
{
|
81 |
|
|
int width = act.getScreenWidthInPixels();
|
82 |
|
|
float textSize = width*TEXT_RATIO;
|
83 |
|
|
int padding = (int)(width*PADDING_RATIO);
|
84 |
|
|
|
85 |
71cda061
|
Leszek Koltunski
|
RelativeLayout upperBar = act.findViewById(R.id.upperBar);
|
86 |
|
|
LinearLayout oneLayout = act.findViewById(R.id.purchaseLayoutOne);
|
87 |
|
|
LinearLayout allLayout = act.findViewById(R.id.purchaseLayoutAll);
|
88 |
c7238c67
|
Leszek Koltunski
|
|
89 |
71cda061
|
Leszek Koltunski
|
upperBar.setPadding(padding,padding,padding,padding/2);
|
90 |
|
|
oneLayout.setPadding(padding,padding/2,padding,padding/2);
|
91 |
|
|
allLayout.setPadding(padding,padding/2,padding,padding/2);
|
92 |
c7238c67
|
Leszek Koltunski
|
|
93 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
94 |
|
|
params.bottomMargin = 0;
|
95 |
|
|
params.topMargin = padding;
|
96 |
|
|
params.leftMargin = padding;
|
97 |
|
|
params.rightMargin = padding;
|
98 |
|
|
|
99 |
71cda061
|
Leszek Koltunski
|
upperBar.setLayoutParams(params);
|
100 |
|
|
oneLayout.setLayoutParams(params);
|
101 |
|
|
allLayout.setLayoutParams(params);
|
102 |
c7238c67
|
Leszek Koltunski
|
|
103 |
|
|
TextView text;
|
104 |
71cda061
|
Leszek Koltunski
|
text = upperBar.findViewById(R.id.purchaseDetailsName);
|
105 |
c7238c67
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
106 |
71cda061
|
Leszek Koltunski
|
text = oneLayout.findViewById(R.id.purchaseTextOne);
|
107 |
c7238c67
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
108 |
71cda061
|
Leszek Koltunski
|
text = allLayout.findViewById(R.id.purchaseTextAll);
|
109 |
c7238c67
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
110 |
|
|
}
|
111 |
|
|
}
|