1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
import android.util.TypedValue;
|
23
|
import android.widget.LinearLayout;
|
24
|
import android.widget.RadioButton;
|
25
|
import android.widget.RadioGroup;
|
26
|
import android.widget.TextView;
|
27
|
|
28
|
import org.distorted.jsons.ObjectJson;
|
29
|
import org.distorted.main.R;
|
30
|
import org.distorted.objectlib.json.JsonReader;
|
31
|
import org.distorted.objectlib.main.ObjectType;
|
32
|
|
33
|
import java.io.InputStream;
|
34
|
|
35
|
import static android.view.View.inflate;
|
36
|
|
37
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
|
39
|
public class ConfigScreenPane
|
40
|
{
|
41
|
private static final float PADDING_RATIO = 0.015f;
|
42
|
private static final float TEXT_RATIO = 0.025f;
|
43
|
private static final float RADIO_RATIO = 0.900f;
|
44
|
|
45
|
private JsonReader mReader;
|
46
|
private int mObjectOrdinal;
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
|
50
|
private void switchMesh(ConfigActivity act, boolean simple)
|
51
|
{
|
52
|
|
53
|
}
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
void updatePane(ConfigActivity act, int objectOrdinal)
|
58
|
{
|
59
|
if( mReader==null ) mReader = new JsonReader();
|
60
|
|
61
|
mObjectOrdinal = objectOrdinal;
|
62
|
|
63
|
ObjectType type = ObjectType.getObject(objectOrdinal);
|
64
|
InputStream stream = ObjectJson.getStream(type,act);
|
65
|
mReader.parseJsonFileMetadata(stream);
|
66
|
|
67
|
String name = mReader.getObjectName();
|
68
|
String author = mReader.getInventor();
|
69
|
int year = mReader.getYearOfInvention();
|
70
|
String both = year>0 ? author+" "+year : author;
|
71
|
|
72
|
LinearLayout layout = act.findViewById(R.id.configLayout);
|
73
|
TextView view = layout.findViewById(R.id.configDetailsName2);
|
74
|
view.setText(name);
|
75
|
view = layout.findViewById(R.id.configDetailsAuthor2);
|
76
|
view.setText(both);
|
77
|
}
|
78
|
|
79
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80
|
|
81
|
ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
|
82
|
{
|
83
|
int height = act.getScreenHeightInPixels();
|
84
|
float textSize = height*TEXT_RATIO;
|
85
|
int padding = (int)(height*PADDING_RATIO);
|
86
|
|
87
|
LinearLayout detailsLayout = (LinearLayout)inflate( act, R.layout.config_details , null);
|
88
|
LinearLayout difficultyLayout = (LinearLayout)inflate( act, R.layout.config_difficulty, null);
|
89
|
LinearLayout meshLayout = (LinearLayout)inflate( act, R.layout.config_mesh , null);
|
90
|
|
91
|
detailsLayout.setPadding(padding,padding,padding,padding/2);
|
92
|
difficultyLayout.setPadding(padding,padding/2,padding,padding/2);
|
93
|
meshLayout.setPadding(padding,padding/2,padding,padding);
|
94
|
|
95
|
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f);
|
96
|
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f);
|
97
|
LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.3f);
|
98
|
|
99
|
detailsLayout.setLayoutParams(params1);
|
100
|
difficultyLayout.setLayoutParams(params2);
|
101
|
meshLayout.setLayoutParams(params3);
|
102
|
|
103
|
TextView text;
|
104
|
text = detailsLayout.findViewById(R.id.configDetailsTitle);
|
105
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
106
|
text = detailsLayout.findViewById(R.id.configDetailsName1);
|
107
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
108
|
text = detailsLayout.findViewById(R.id.configDetailsName2);
|
109
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
110
|
text = detailsLayout.findViewById(R.id.configDetailsAuthor1);
|
111
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
112
|
text = detailsLayout.findViewById(R.id.configDetailsAuthor2);
|
113
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
114
|
|
115
|
text = difficultyLayout.findViewById(R.id.configDifficultyTitle);
|
116
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
117
|
text = meshLayout.findViewById(R.id.configMeshTitle);
|
118
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
119
|
|
120
|
RadioButton butt1 = meshLayout.findViewById(R.id.meshNice);
|
121
|
butt1.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
|
122
|
RadioButton butt2 = meshLayout.findViewById(R.id.meshSimple);
|
123
|
butt2.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
|
124
|
|
125
|
LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.configDifficultyLayout);
|
126
|
layoutDiff.setPadding(padding,padding,padding,padding);
|
127
|
|
128
|
RadioGroup radioGroup = meshLayout.findViewById(R.id.meshRadioGroup);
|
129
|
|
130
|
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
|
131
|
{
|
132
|
@Override
|
133
|
public void onCheckedChanged(RadioGroup group, int checkedId)
|
134
|
{
|
135
|
switchMesh( act, checkedId != R.id.meshNice );
|
136
|
}
|
137
|
});
|
138
|
|
139
|
LinearLayout layout = act.findViewById(R.id.configLayout);
|
140
|
layout.removeAllViews();
|
141
|
layout.addView(detailsLayout);
|
142
|
layout.addView(difficultyLayout);
|
143
|
layout.addView(meshLayout);
|
144
|
|
145
|
updatePane(act,objectOrdinal);
|
146
|
}
|
147
|
}
|