1 |
74d088c3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
9d51b9d6
|
Leszek Koltunski
|
// 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 |
74d088c3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.config;
|
11 |
|
|
|
12 |
09cf2a36
|
Leszek Koltunski
|
import java.io.InputStream;
|
13 |
|
|
|
14 |
8375250f
|
Leszek Koltunski
|
import android.graphics.PorterDuff;
|
15 |
2e99ba6a
|
Leszek Koltunski
|
import android.util.TypedValue;
|
16 |
2604be3b
|
Leszek Koltunski
|
import android.widget.ImageView;
|
17 |
74d088c3
|
Leszek Koltunski
|
import android.widget.LinearLayout;
|
18 |
|
|
import android.widget.TextView;
|
19 |
|
|
|
20 |
|
|
import org.distorted.main.R;
|
21 |
|
|
import org.distorted.objectlib.json.JsonReader;
|
22 |
a7d8c3cd
|
Leszek Koltunski
|
import org.distorted.objects.RubikObject;
|
23 |
|
|
import org.distorted.objects.RubikObjectList;
|
24 |
74d088c3
|
Leszek Koltunski
|
|
25 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26 |
|
|
|
27 |
|
|
public class ConfigScreenPane
|
28 |
|
|
{
|
29 |
8375250f
|
Leszek Koltunski
|
private static final int[] IDS =
|
30 |
2604be3b
|
Leszek Koltunski
|
{
|
31 |
|
|
R.id.configDifficulty0,
|
32 |
|
|
R.id.configDifficulty1,
|
33 |
|
|
R.id.configDifficulty2,
|
34 |
|
|
R.id.configDifficulty3,
|
35 |
|
|
R.id.configDifficulty4
|
36 |
|
|
};
|
37 |
|
|
|
38 |
8375250f
|
Leszek Koltunski
|
private static final int[] IMAGES =
|
39 |
|
|
{
|
40 |
|
|
R.drawable.difficulty1,
|
41 |
|
|
R.drawable.difficulty2,
|
42 |
|
|
R.drawable.difficulty3,
|
43 |
|
|
R.drawable.difficulty4,
|
44 |
|
|
R.drawable.difficulty5,
|
45 |
|
|
};
|
46 |
|
|
|
47 |
|
|
private static final int NUM_IDS = IDS.length;
|
48 |
27401bea
|
Leszek Koltunski
|
private static final float PADDING_RATIO = 0.016f;
|
49 |
9c634626
|
leszek
|
private static final float TEXT_RATIO = 0.025f;
|
50 |
74d088c3
|
Leszek Koltunski
|
|
51 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
52 |
|
|
|
53 |
|
|
void updatePane(ConfigActivity act, int objectOrdinal)
|
54 |
|
|
{
|
55 |
c826d83b
|
Leszek Koltunski
|
RubikObject object = RubikObjectList.getObject(objectOrdinal);
|
56 |
74d088c3
|
Leszek Koltunski
|
|
57 |
c826d83b
|
Leszek Koltunski
|
if( object!=null )
|
58 |
|
|
{
|
59 |
|
|
InputStream stream = object.getObjectStream(act);
|
60 |
923d267c
|
Leszek Koltunski
|
|
61 |
5305fdc8
|
Leszek Koltunski
|
JsonReader reader = new JsonReader();
|
62 |
c020555e
|
Leszek Koltunski
|
String name,author;
|
63 |
|
|
int year, difficulty;
|
64 |
|
|
|
65 |
|
|
try
|
66 |
|
|
{
|
67 |
|
|
reader.parseJsonFileMetadata(stream);
|
68 |
|
|
name = reader.getObjectName();
|
69 |
|
|
author = reader.getInventor();
|
70 |
|
|
year = reader.getYearOfInvention();
|
71 |
|
|
difficulty = reader.getComplexity();
|
72 |
|
|
}
|
73 |
|
|
catch(Exception ex)
|
74 |
|
|
{
|
75 |
|
|
name = "?";
|
76 |
|
|
author = "?";
|
77 |
|
|
year = 0;
|
78 |
|
|
difficulty = 0;
|
79 |
|
|
}
|
80 |
74d088c3
|
Leszek Koltunski
|
|
81 |
c826d83b
|
Leszek Koltunski
|
LinearLayout layout = act.findViewById(R.id.configLayout);
|
82 |
|
|
TextView view = layout.findViewById(R.id.configDetailsName2);
|
83 |
|
|
view.setText(name);
|
84 |
|
|
view = layout.findViewById(R.id.configDetailsAuthor2);
|
85 |
b45b986a
|
leszek
|
view.setText(author);
|
86 |
|
|
view = layout.findViewById(R.id.configDetailsYear2);
|
87 |
|
|
view.setText( year>0 ? String.valueOf(year) : "?" );
|
88 |
2604be3b
|
Leszek Koltunski
|
|
89 |
71cda061
|
Leszek Koltunski
|
if( difficulty<0 ) difficulty=0;
|
90 |
|
|
if( difficulty>=NUM_IDS ) difficulty=NUM_IDS-1;
|
91 |
2604be3b
|
Leszek Koltunski
|
|
92 |
8375250f
|
Leszek Koltunski
|
for(int i=0; i<NUM_IDS; i++)
|
93 |
c826d83b
|
Leszek Koltunski
|
{
|
94 |
8375250f
|
Leszek Koltunski
|
ImageView image = layout.findViewById(IDS[i]);
|
95 |
|
|
image.setImageResource(IMAGES[i]);
|
96 |
|
|
image.setColorFilter( difficulty==i ? 0xffff0000 : 0xffffffff, PorterDuff.Mode.MULTIPLY );
|
97 |
c826d83b
|
Leszek Koltunski
|
}
|
98 |
|
|
}
|
99 |
74d088c3
|
Leszek Koltunski
|
}
|
100 |
|
|
|
101 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
|
103 |
|
|
ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
|
104 |
|
|
{
|
105 |
27401bea
|
Leszek Koltunski
|
int height = act.getScreenHeightInPixels();
|
106 |
|
|
float textSize = height*TEXT_RATIO;
|
107 |
|
|
int padding = (int)(height*PADDING_RATIO);
|
108 |
2e99ba6a
|
Leszek Koltunski
|
|
109 |
21efc7d7
|
Leszek Koltunski
|
LinearLayout configLayout = act.findViewById(R.id.configLayout);
|
110 |
|
|
LinearLayout nameLayout = configLayout.findViewById(R.id.configLayoutName);
|
111 |
|
|
LinearLayout difficultyLayout= configLayout.findViewById(R.id.configLayoutDifficulty);
|
112 |
b45b986a
|
leszek
|
LinearLayout authorLayout = configLayout.findViewById(R.id.configLayoutAuthor);
|
113 |
|
|
LinearLayout yearLayout = configLayout.findViewById(R.id.configLayoutYear);
|
114 |
21efc7d7
|
Leszek Koltunski
|
|
115 |
|
|
nameLayout.setPadding(padding,padding,padding,padding/2);
|
116 |
2e99ba6a
|
Leszek Koltunski
|
difficultyLayout.setPadding(padding,padding/2,padding,padding/2);
|
117 |
b45b986a
|
leszek
|
authorLayout.setPadding(padding,padding/2,padding,padding/2);
|
118 |
|
|
yearLayout.setPadding(padding,padding/2,padding,padding);
|
119 |
2e99ba6a
|
Leszek Koltunski
|
|
120 |
21efc7d7
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
121 |
|
|
params.bottomMargin = 0;
|
122 |
|
|
params.topMargin = padding;
|
123 |
|
|
params.leftMargin = padding;
|
124 |
|
|
params.rightMargin = padding;
|
125 |
2e99ba6a
|
Leszek Koltunski
|
|
126 |
21efc7d7
|
Leszek Koltunski
|
nameLayout.setLayoutParams(params);
|
127 |
|
|
difficultyLayout.setLayoutParams(params);
|
128 |
b45b986a
|
leszek
|
authorLayout.setLayoutParams(params);
|
129 |
|
|
yearLayout.setLayoutParams(params);
|
130 |
74d088c3
|
Leszek Koltunski
|
|
131 |
|
|
TextView text;
|
132 |
21efc7d7
|
Leszek Koltunski
|
text = nameLayout.findViewById(R.id.configDetailsName1);
|
133 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
134 |
21efc7d7
|
Leszek Koltunski
|
text = nameLayout.findViewById(R.id.configDetailsName2);
|
135 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
136 |
21efc7d7
|
Leszek Koltunski
|
text = authorLayout.findViewById(R.id.configDetailsAuthor1);
|
137 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
138 |
21efc7d7
|
Leszek Koltunski
|
text = authorLayout.findViewById(R.id.configDetailsAuthor2);
|
139 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
140 |
cc48b275
|
Leszek Koltunski
|
text = difficultyLayout.findViewById(R.id.configDifficultyTitle);
|
141 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
142 |
b45b986a
|
leszek
|
text = yearLayout.findViewById(R.id.configDetailsYear1);
|
143 |
|
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
144 |
|
|
text = yearLayout.findViewById(R.id.configDetailsYear2);
|
145 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
146 |
|
|
|
147 |
|
|
LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.configDifficultyLayout);
|
148 |
|
|
layoutDiff.setPadding(padding,padding,padding,padding);
|
149 |
|
|
|
150 |
74d088c3
|
Leszek Koltunski
|
updatePane(act,objectOrdinal);
|
151 |
|
|
}
|
152 |
|
|
}
|