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 java.io.InputStream;
|
23
|
|
24
|
import android.util.TypedValue;
|
25
|
import android.widget.ImageView;
|
26
|
import android.widget.LinearLayout;
|
27
|
import android.widget.RadioButton;
|
28
|
import android.widget.RadioGroup;
|
29
|
import android.widget.TextView;
|
30
|
|
31
|
import org.distorted.main.R;
|
32
|
import org.distorted.objectlib.json.JsonReader;
|
33
|
import org.distorted.objects.RubikObject;
|
34
|
import org.distorted.objects.RubikObjectList;
|
35
|
|
36
|
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
|
37
|
import static org.distorted.objectlib.main.TwistyObject.MESH_FAST;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
public class ConfigScreenPane
|
42
|
{
|
43
|
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
|
private static final int NUM_IMAGES = IMAGES.length;
|
53
|
public static final float PADDING_RATIO = 0.025f;
|
54
|
private static final float TEXT_RATIO = 0.042f;
|
55
|
private static final float RADIO_RATIO = 0.900f;
|
56
|
|
57
|
private int mObjectOrdinal;
|
58
|
private boolean mProgramatic;
|
59
|
|
60
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61
|
|
62
|
private void switchMeshState(ConfigActivity act, int meshState)
|
63
|
{
|
64
|
RubikObjectList.setMeshState(mObjectOrdinal,meshState);
|
65
|
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
66
|
act.changeMeshState(object,mObjectOrdinal);
|
67
|
}
|
68
|
|
69
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70
|
|
71
|
void updatePane(ConfigActivity act, int objectOrdinal)
|
72
|
{
|
73
|
JsonReader reader = JsonReader.getInstance();
|
74
|
|
75
|
mObjectOrdinal = objectOrdinal;
|
76
|
|
77
|
RubikObject object = RubikObjectList.getObject(objectOrdinal);
|
78
|
InputStream stream = object.getObjectStream(act);
|
79
|
reader.parseJsonFileMetadata(stream);
|
80
|
|
81
|
String name = reader.getObjectName();
|
82
|
String author = reader.getInventor();
|
83
|
int year = reader.getYearOfInvention();
|
84
|
String both = year>0 ? author+" "+year : author;
|
85
|
|
86
|
LinearLayout layout = act.findViewById(R.id.configLayout);
|
87
|
TextView view = layout.findViewById(R.id.configDetailsName2);
|
88
|
view.setText(name);
|
89
|
view = layout.findViewById(R.id.configDetailsAuthor2);
|
90
|
view.setText(both);
|
91
|
|
92
|
int difficulty = reader.getComplexity();
|
93
|
|
94
|
if( difficulty<0 ) difficulty=0;
|
95
|
if( difficulty>NUM_IMAGES ) difficulty=NUM_IMAGES;
|
96
|
|
97
|
for(int i=0; i<NUM_IMAGES; i++)
|
98
|
{
|
99
|
ImageView image = layout.findViewById(IMAGES[i]);
|
100
|
image.setImageResource( i==difficulty ? R.drawable.ui_difficulty_checked : R.drawable.ui_difficulty_unchecked );
|
101
|
}
|
102
|
|
103
|
int meshState = object.getMeshState();
|
104
|
int id = meshState==MESH_NICE ? R.id.meshNice : R.id.meshSimple;
|
105
|
RadioButton button = act.findViewById(id);
|
106
|
|
107
|
mProgramatic = true;
|
108
|
button.setChecked(true);
|
109
|
mProgramatic = false;
|
110
|
}
|
111
|
|
112
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113
|
|
114
|
ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
|
115
|
{
|
116
|
int width = act.getScreenWidthInPixels();
|
117
|
float textSize = width*TEXT_RATIO;
|
118
|
int padding = (int)(width*PADDING_RATIO);
|
119
|
|
120
|
LinearLayout configLayout = act.findViewById(R.id.configLayout);
|
121
|
LinearLayout nameLayout = configLayout.findViewById(R.id.configLayoutName);
|
122
|
LinearLayout authorLayout = configLayout.findViewById(R.id.configLayoutAuthor);
|
123
|
LinearLayout difficultyLayout= configLayout.findViewById(R.id.configLayoutDifficulty);
|
124
|
LinearLayout meshLayout = configLayout.findViewById(R.id.configLayoutMesh);
|
125
|
|
126
|
nameLayout.setPadding(padding,padding,padding,padding/2);
|
127
|
authorLayout.setPadding(padding,padding/2,padding,padding/2);
|
128
|
difficultyLayout.setPadding(padding,padding/2,padding,padding/2);
|
129
|
meshLayout.setPadding(padding,padding/2,padding,padding);
|
130
|
|
131
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
132
|
params.bottomMargin = 0;
|
133
|
params.topMargin = padding;
|
134
|
params.leftMargin = padding;
|
135
|
params.rightMargin = padding;
|
136
|
|
137
|
nameLayout.setLayoutParams(params);
|
138
|
authorLayout.setLayoutParams(params);
|
139
|
difficultyLayout.setLayoutParams(params);
|
140
|
meshLayout.setLayoutParams(params);
|
141
|
|
142
|
TextView text;
|
143
|
text = nameLayout.findViewById(R.id.configDetailsName1);
|
144
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
145
|
text = nameLayout.findViewById(R.id.configDetailsName2);
|
146
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
147
|
text = authorLayout.findViewById(R.id.configDetailsAuthor1);
|
148
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
149
|
text = authorLayout.findViewById(R.id.configDetailsAuthor2);
|
150
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
151
|
text = difficultyLayout.findViewById(R.id.configDifficultyTitle);
|
152
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
153
|
text = meshLayout.findViewById(R.id.configMeshTitle);
|
154
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
155
|
|
156
|
RadioButton butt1 = meshLayout.findViewById(R.id.meshNice);
|
157
|
butt1.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
|
158
|
RadioButton butt2 = meshLayout.findViewById(R.id.meshSimple);
|
159
|
butt2.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
|
160
|
|
161
|
LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.configDifficultyLayout);
|
162
|
layoutDiff.setPadding(padding,padding,padding,padding);
|
163
|
|
164
|
RadioGroup radioGroup = meshLayout.findViewById(R.id.meshRadioGroup);
|
165
|
|
166
|
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
|
167
|
{
|
168
|
@Override
|
169
|
public void onCheckedChanged(RadioGroup group, int checkedId)
|
170
|
{
|
171
|
if( !mProgramatic )
|
172
|
{
|
173
|
int meshState = checkedId == R.id.meshNice ? MESH_NICE : MESH_FAST;
|
174
|
switchMeshState( act, meshState );
|
175
|
}
|
176
|
}
|
177
|
});
|
178
|
|
179
|
updatePane(act,objectOrdinal);
|
180
|
}
|
181
|
}
|