1 |
74d088c3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.config;
|
21 |
|
|
|
22 |
2e99ba6a
|
Leszek Koltunski
|
import android.util.TypedValue;
|
23 |
2604be3b
|
Leszek Koltunski
|
import android.widget.ImageView;
|
24 |
74d088c3
|
Leszek Koltunski
|
import android.widget.LinearLayout;
|
25 |
2e99ba6a
|
Leszek Koltunski
|
import android.widget.RadioButton;
|
26 |
|
|
import android.widget.RadioGroup;
|
27 |
183d4a34
|
Leszek Koltunski
|
import android.widget.RelativeLayout;
|
28 |
74d088c3
|
Leszek Koltunski
|
import android.widget.TextView;
|
29 |
|
|
|
30 |
|
|
import org.distorted.jsons.ObjectJson;
|
31 |
|
|
import org.distorted.main.R;
|
32 |
|
|
import org.distorted.objectlib.json.JsonReader;
|
33 |
|
|
import org.distorted.objectlib.main.ObjectType;
|
34 |
|
|
|
35 |
|
|
import java.io.InputStream;
|
36 |
|
|
|
37 |
|
|
import static android.view.View.inflate;
|
38 |
|
|
|
39 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
|
41 |
|
|
public class ConfigScreenPane
|
42 |
|
|
{
|
43 |
2604be3b
|
Leszek Koltunski
|
private static final int[] IMAGES =
|
44 |
|
|
{
|
45 |
|
|
R.id.configDifficulty0,
|
46 |
|
|
R.id.configDifficulty1,
|
47 |
|
|
R.id.configDifficulty2,
|
48 |
|
|
R.id.configDifficulty3,
|
49 |
|
|
R.id.configDifficulty4
|
50 |
|
|
};
|
51 |
|
|
|
52 |
183d4a34
|
Leszek Koltunski
|
private static final int[] CHECK =
|
53 |
|
|
{
|
54 |
|
|
R.drawable.diff_check0,
|
55 |
|
|
R.drawable.diff_check1,
|
56 |
|
|
R.drawable.diff_check2,
|
57 |
|
|
R.drawable.diff_check3,
|
58 |
|
|
R.drawable.diff_check4,
|
59 |
|
|
};
|
60 |
|
|
|
61 |
|
|
private static final int[] UNCHECK =
|
62 |
|
|
{
|
63 |
|
|
R.drawable.diff_uncheck0,
|
64 |
|
|
R.drawable.diff_uncheck1,
|
65 |
|
|
R.drawable.diff_uncheck2,
|
66 |
|
|
R.drawable.diff_uncheck3,
|
67 |
|
|
R.drawable.diff_uncheck4,
|
68 |
|
|
};
|
69 |
|
|
|
70 |
2604be3b
|
Leszek Koltunski
|
private static final int NUM_IMAGES = IMAGES.length;
|
71 |
2e99ba6a
|
Leszek Koltunski
|
private static final float PADDING_RATIO = 0.015f;
|
72 |
|
|
private static final float TEXT_RATIO = 0.025f;
|
73 |
|
|
private static final float RADIO_RATIO = 0.900f;
|
74 |
|
|
|
75 |
74d088c3
|
Leszek Koltunski
|
private JsonReader mReader;
|
76 |
923d267c
|
Leszek Koltunski
|
private int mObjectOrdinal;
|
77 |
|
|
|
78 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79 |
|
|
|
80 |
|
|
private void switchMesh(ConfigActivity act, boolean simple)
|
81 |
|
|
{
|
82 |
|
|
|
83 |
|
|
}
|
84 |
74d088c3
|
Leszek Koltunski
|
|
85 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86 |
|
|
|
87 |
|
|
void updatePane(ConfigActivity act, int objectOrdinal)
|
88 |
|
|
{
|
89 |
|
|
if( mReader==null ) mReader = new JsonReader();
|
90 |
|
|
|
91 |
923d267c
|
Leszek Koltunski
|
mObjectOrdinal = objectOrdinal;
|
92 |
|
|
|
93 |
74d088c3
|
Leszek Koltunski
|
ObjectType type = ObjectType.getObject(objectOrdinal);
|
94 |
|
|
InputStream stream = ObjectJson.getStream(type,act);
|
95 |
|
|
mReader.parseJsonFileMetadata(stream);
|
96 |
|
|
|
97 |
|
|
String name = mReader.getObjectName();
|
98 |
|
|
String author = mReader.getInventor();
|
99 |
|
|
int year = mReader.getYearOfInvention();
|
100 |
cc48b275
|
Leszek Koltunski
|
String both = year>0 ? author+" "+year : author;
|
101 |
74d088c3
|
Leszek Koltunski
|
|
102 |
|
|
LinearLayout layout = act.findViewById(R.id.configLayout);
|
103 |
|
|
TextView view = layout.findViewById(R.id.configDetailsName2);
|
104 |
|
|
view.setText(name);
|
105 |
|
|
view = layout.findViewById(R.id.configDetailsAuthor2);
|
106 |
cc48b275
|
Leszek Koltunski
|
view.setText(both);
|
107 |
2604be3b
|
Leszek Koltunski
|
|
108 |
|
|
int difficulty = mReader.getComplexity();
|
109 |
|
|
|
110 |
|
|
if( difficulty<0 ) difficulty=0;
|
111 |
|
|
if( difficulty>NUM_IMAGES ) difficulty=NUM_IMAGES;
|
112 |
|
|
|
113 |
|
|
for(int i=0; i<NUM_IMAGES; i++)
|
114 |
|
|
{
|
115 |
|
|
ImageView image = layout.findViewById(IMAGES[i]);
|
116 |
183d4a34
|
Leszek Koltunski
|
image.setImageResource( i==difficulty ? CHECK[i] : UNCHECK[i] );
|
117 |
2604be3b
|
Leszek Koltunski
|
}
|
118 |
74d088c3
|
Leszek Koltunski
|
}
|
119 |
|
|
|
120 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
121 |
|
|
|
122 |
|
|
ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
|
123 |
|
|
{
|
124 |
2e99ba6a
|
Leszek Koltunski
|
int height = act.getScreenHeightInPixels();
|
125 |
|
|
float textSize = height*TEXT_RATIO;
|
126 |
|
|
int padding = (int)(height*PADDING_RATIO);
|
127 |
|
|
|
128 |
cc48b275
|
Leszek Koltunski
|
LinearLayout detailsLayout = (LinearLayout)inflate( act, R.layout.config_details , null);
|
129 |
|
|
LinearLayout difficultyLayout = (LinearLayout)inflate( act, R.layout.config_difficulty, null);
|
130 |
|
|
LinearLayout meshLayout = (LinearLayout)inflate( act, R.layout.config_mesh , null);
|
131 |
74d088c3
|
Leszek Koltunski
|
|
132 |
2e99ba6a
|
Leszek Koltunski
|
detailsLayout.setPadding(padding,padding,padding,padding/2);
|
133 |
|
|
difficultyLayout.setPadding(padding,padding/2,padding,padding/2);
|
134 |
|
|
meshLayout.setPadding(padding,padding/2,padding,padding);
|
135 |
|
|
|
136 |
183d4a34
|
Leszek Koltunski
|
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
137 |
|
|
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
138 |
|
|
LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.05f);
|
139 |
2e99ba6a
|
Leszek Koltunski
|
|
140 |
|
|
detailsLayout.setLayoutParams(params1);
|
141 |
|
|
difficultyLayout.setLayoutParams(params2);
|
142 |
|
|
meshLayout.setLayoutParams(params3);
|
143 |
74d088c3
|
Leszek Koltunski
|
|
144 |
|
|
TextView text;
|
145 |
cc48b275
|
Leszek Koltunski
|
text = detailsLayout.findViewById(R.id.configDetailsTitle);
|
146 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
147 |
cc48b275
|
Leszek Koltunski
|
text = detailsLayout.findViewById(R.id.configDetailsName1);
|
148 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
149 |
cc48b275
|
Leszek Koltunski
|
text = detailsLayout.findViewById(R.id.configDetailsName2);
|
150 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
151 |
cc48b275
|
Leszek Koltunski
|
text = detailsLayout.findViewById(R.id.configDetailsAuthor1);
|
152 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
153 |
cc48b275
|
Leszek Koltunski
|
text = detailsLayout.findViewById(R.id.configDetailsAuthor2);
|
154 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
155 |
74d088c3
|
Leszek Koltunski
|
|
156 |
cc48b275
|
Leszek Koltunski
|
text = difficultyLayout.findViewById(R.id.configDifficultyTitle);
|
157 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
158 |
cc48b275
|
Leszek Koltunski
|
text = meshLayout.findViewById(R.id.configMeshTitle);
|
159 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
160 |
|
|
|
161 |
|
|
RadioButton butt1 = meshLayout.findViewById(R.id.meshNice);
|
162 |
|
|
butt1.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
|
163 |
|
|
RadioButton butt2 = meshLayout.findViewById(R.id.meshSimple);
|
164 |
|
|
butt2.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
|
165 |
|
|
|
166 |
|
|
LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.configDifficultyLayout);
|
167 |
|
|
layoutDiff.setPadding(padding,padding,padding,padding);
|
168 |
|
|
|
169 |
|
|
RadioGroup radioGroup = meshLayout.findViewById(R.id.meshRadioGroup);
|
170 |
|
|
|
171 |
|
|
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
|
172 |
|
|
{
|
173 |
|
|
@Override
|
174 |
|
|
public void onCheckedChanged(RadioGroup group, int checkedId)
|
175 |
|
|
{
|
176 |
923d267c
|
Leszek Koltunski
|
switchMesh( act, checkedId != R.id.meshNice );
|
177 |
2e99ba6a
|
Leszek Koltunski
|
}
|
178 |
|
|
});
|
179 |
74d088c3
|
Leszek Koltunski
|
|
180 |
|
|
LinearLayout layout = act.findViewById(R.id.configLayout);
|
181 |
|
|
layout.removeAllViews();
|
182 |
cc48b275
|
Leszek Koltunski
|
layout.addView(detailsLayout);
|
183 |
|
|
layout.addView(difficultyLayout);
|
184 |
|
|
layout.addView(meshLayout);
|
185 |
74d088c3
|
Leszek Koltunski
|
|
186 |
|
|
updatePane(act,objectOrdinal);
|
187 |
|
|
}
|
188 |
|
|
}
|