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